#Global settings . "../Settings.ps1" # Function to extract version number from filename function Extract-VersionNumber($filename) { if ($filename -match "known-hashes-v(\d+\.\d+)\.encrypted\.zip") { return $matches[1] } return $null } # Get the list of available files (assuming a directory listing is available) $response = Invoke-WebRequest -Uri $baseUrl $files = $response.Links | Where-Object { $_.href -like "known-hashes-v*.encrypted.zip" } | Select-Object -ExpandProperty href # Determine the latest version $latestVersion = "0.0" $latestFile = $null foreach ($file in $files) { $version = Extract-VersionNumber $file if ([version]$version -gt [version]$latestVersion) { $latestVersion = $version $latestFile = $file } } # Check local file version $localVersion = "0.0" if (Test-Path "$localFilePath.encrypted") { $localVersion = Extract-VersionNumber (Get-Item "$localFilePath.encrypted").Name } # Download and extract if the online version is newer if ([version]$latestVersion -gt [version]$localVersion) { $downloadUrl = $baseUrl + $latestFile $localZipPath = "$localFilePath-v$latestVersion.encrypted.zip" Invoke-WebRequest -Uri $downloadUrl -OutFile $localZipPath # Ask for the ZIP password Write-Host "Enter the password to unzip the file:" $zipPassword = Read-Host -AsSecureString # Unzip the file (requires .NET 4.5 or higher and external tools like 7-Zip) $zipPasswordPlainText = [Runtime.InteropServices.Marshal]::PtrToStringBSTR([Runtime.InteropServices.Marshal]::SecureStringToBSTR($zipPassword)) $7zipPath = "C:\Path\To\7Zip\7z.exe" # Update with the actual path to 7-Zip executable $arguments = "x `"$localZipPath`" -p$zipPasswordPlainText -o`"$localFilePath`" -y" Start-Process $7zipPath -ArgumentList $arguments -NoNewWindow -Wait Write-Host "File downloaded and extracted successfully. Latest version: v$latestVersion" } else { Write-Host "Local known-hashes file is up-to-date. Current version: v$localVersion" }