From 251e591abf08018a7665fe7c7266940fc30db77d Mon Sep 17 00:00:00 2001 From: orin Date: Tue, 21 Nov 2023 01:18:41 +0100 Subject: [PATCH] Improve Windows converter downloading --- autodl_files/converter_windows | 7 +++ autodl_files/depends_win.ps1 | 91 ---------------------------------- autodl_files/get_aria2.ps1 | 64 ++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 91 deletions(-) create mode 100644 autodl_files/converter_windows delete mode 100644 autodl_files/depends_win.ps1 create mode 100644 autodl_files/get_aria2.ps1 diff --git a/autodl_files/converter_windows b/autodl_files/converter_windows new file mode 100644 index 0000000..91e943c --- /dev/null +++ b/autodl_files/converter_windows @@ -0,0 +1,7 @@ +https://uupdump.net/misc/7zr.exe + out=7zr.exe + checksum=sha-256=108ab5f1e36f2068e368fe97cd763c639e403cac8f511c6681eaf19fc585d814 + +https://uupdump.net/misc/uup-converter-wimlib.7z + out=uup-converter-wimlib.7z + checksum=sha-256=7f07dfc0fa041820746c55c2704fd18f8930b984ca472d2ac397a1c69f15f3af diff --git a/autodl_files/depends_win.ps1 b/autodl_files/depends_win.ps1 deleted file mode 100644 index 63ee168..0000000 --- a/autodl_files/depends_win.ps1 +++ /dev/null @@ -1,91 +0,0 @@ -<# -This was made because I refuse to continue taking part in the unwritten -PowerShell/Batch obfuscation contest. -#> - -param ( - [Parameter()] - [Switch]$ForDownload -) - -<# -There are myths that some Windows versions do not work without this. - -Since I can't be arsed to verify this, I'm just adding this to lower the number -of reports to which I would normally respond with "works on my machine". -#> -try { - [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -} catch { - Write-Error "Outdated operating systems are not supported." - Exit 1 -} - -$filesDownload = @('aria2c.exe') -$filesConvert = @('aria2c.exe', '7zr.exe', 'uup-converter-wimlib.7z') - -$urls = @{ - 'aria2c.exe' = 'https://uupdump.net/misc/aria2c.exe'; - '7zr.exe' = 'https://uupdump.net/misc/7zr.exe'; - 'uup-converter-wimlib.7z' = 'https://uupdump.net/misc/uup-converter-wimlib.7z'; -} - -$hashes = @{ - 'aria2c.exe' = '0ae98794b3523634b0af362d6f8c04a9bbd32aeda959b72ca0e7fc24e84d2a66'; - '7zr.exe' = '108ab5f1e36f2068e368fe97cd763c639e403cac8f511c6681eaf19fc585d814'; - 'uup-converter-wimlib.7z' = '7f07dfc0fa041820746c55c2704fd18f8930b984ca472d2ac397a1c69f15f3af'; -} - -function Retrieve-File { - param ( - [String]$File, - [String]$Url - ) - - Write-Host -BackgroundColor Black -ForegroundColor Yellow "Downloading ${File}..." - Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile "files\$File" -ErrorAction Stop -} - -function Test-Hash { - param ( - [String]$File, - [String]$Hash - ) - - Write-Host -BackgroundColor Black -ForegroundColor Cyan "Verifying ${File}..." - - $fileHash = (Get-FileHash -Path "files\$File" -Algorithm SHA256 -ErrorAction Stop).Hash - return ($fileHash.ToLower() -eq $Hash) -} - -if($ForDownload.IsPresent) { - $files = $filesDownload -} else { - $files = $filesConvert -} - -if(-not (Test-Path -PathType Container -Path "files")) { - $null = New-Item -Path "files" -ItemType Directory -} - -foreach($file in $files) { - try { - Retrieve-File -File $file -Url $urls[$file] - } catch { - Write-Host "Failed to download $file" - Write-Host $_ - Exit 1 - } -} - -Write-Host "" - -foreach($file in $files) { - if(-not (Test-Hash -File $file -Hash $hashes[$file])) { - Write-Error "$file appears to be tampered with" - Exit 1 - } -} - -Write-Host "" -Write-Host -BackgroundColor Black -ForegroundColor Green "It appears all the dependencies are ready." diff --git a/autodl_files/get_aria2.ps1 b/autodl_files/get_aria2.ps1 new file mode 100644 index 0000000..7e43db2 --- /dev/null +++ b/autodl_files/get_aria2.ps1 @@ -0,0 +1,64 @@ +try { + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +} catch { + Write-Error "Outdated operating systems are not supported." + Exit 1 +} + +$file = 'aria2c.exe' +$url = 'https://uupdump.net/misc/aria2c.exe'; +$hash = '0ae98794b3523634b0af362d6f8c04a9bbd32aeda959b72ca0e7fc24e84d2a66'; + +function Test-Existece { + param ( + [String]$File + ) + + return Test-Path -PathType Leaf -Path "files\$File" +} + +function Retrieve-File { + param ( + [String]$File, + [String]$Url + ) + + Write-Host -BackgroundColor Black -ForegroundColor Yellow "Downloading ${File}..." + Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile "files\$File" -ErrorAction Stop +} + +function Test-Hash { + param ( + [String]$File, + [String]$Hash + ) + + Write-Host -BackgroundColor Black -ForegroundColor Cyan "Verifying ${File}..." + + $fileHash = (Get-FileHash -Path "files\$File" -Algorithm SHA256 -ErrorAction Stop).Hash + return ($fileHash.ToLower() -eq $Hash) +} + +if((Test-Existece -File $file) -and (Test-Hash -File $file -Hash $hash)) { + Write-Host -BackgroundColor Black -ForegroundColor Green "Ready." + Exit 0 +} + +if(-not (Test-Path -PathType Container -Path "files")) { + $null = New-Item -Path "files" -ItemType Directory +} + +try { + Retrieve-File -File $file -Url $url +} catch { + Write-Host "Failed to download $file" + Write-Host $_ + Exit 1 +} + +if(-not (Test-Hash -File $file -Hash $hash)) { + Write-Error "$file appears to be tampered with" + Exit 1 +} + +Write-Host -BackgroundColor Black -ForegroundColor Green "Ready."