Created
October 19, 2021 18:58
-
-
Save Kagre/a7160eef0f68c449d0d7c4bc08d4ac9f to your computer and use it in GitHub Desktop.
Downloads and loads the current SQLite DLL that should work with 64-bit Win10 Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Download-SQLiteDLL{ | |
[Net.ServicePointManager]::SecurityProtocol = 'Tls11,Tls12' | |
$BaseURI = 'https://system.data.sqlite.org' | |
$DownloadsURI = $BaseURI + '/index.html/doc/trunk/www/downloads.wiki' | |
$r = Invoke-WebRequest -URI $DownloadsURI | |
$Entry = ([regex]'(?s)(?<=<tr>).*?(?=</tr>)').Matches($r.Content).where{$_.value -match 'sqlite-netFx46-binary-bundle-x64'}.value | |
$HashType = $Entry -replace '(?s).*\(\s*(.*?):?\s*[0-9a-fA-F]{40,}\s*\).*','$1' | |
$Hash = $Entry -replace "(?s).*\(\s*${HashType}:?\s*(.*)\).*",'$1' | |
if([string]::IsNullOrEmpty($hash)) | |
{throw 'could not parse the verification hash value'} | |
$ZipURI = $BaseURI + ($entry -replace '(?s).*href="(.*?)".*','$1').Replace('/downloads/','/blobs/') | |
$r = Invoke-WebRequest -URI $ZipURI | |
$ms = [System.IO.MemoryStream]::new([byte[]]([char[]]$r.Content)) | |
$toVerify = Get-FileHash -InputStream $ms -Algorithm $HashType | |
if($toVerify.hash -ne $hash) | |
{throw 'Failed: data validation'} | |
if('System.IO.Compression.ZipArchive' -as [Type] -eq $null){ | |
try{ | |
Add-Type -AssemblyName System.IO.Compression.FileSystem | |
}catch { | |
Add-Type -Path ([Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')).Location | |
} | |
try{[System.IO.Compression.ZipFile]::OpenRead()}catch {} | |
} | |
$zip = [System.IO.Compression.ZipArchive]::new($ms) | |
$e = $zip.GetEntry('System.Data.SQLite.dll') | |
if($e -eq $null) | |
{throw [System.IO.FileNotFoundException]'System.Data.SQLite.dll is missing from the archive'} | |
$buff = new-object byte[] $e.Length | |
$r = $e.Open() | |
$null = $r.Read($buff,0,$e.Length) | |
$r.Close();$r.Dispose() | |
set-content -Path '.\System.Data.SQLite.dll' -Value $buff -Encoding Byte | |
add-type -Path '.\System.Data.SQLite.dll' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment