Skip to content

Commit

Permalink
Download SHA256 file instead of hardcoding
Browse files Browse the repository at this point in the history
Summary:
  * Change Checksum format to either hold the
    checksum or a URL for downloading it.
  • Loading branch information
uroesch committed Jun 30, 2020
1 parent ea7aa1b commit 92a42e6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion App/AppInfo/appinfo.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Freeware=true
CommercialUse=true

[Version]
PackageVersion=7.1.1.0
PackageVersion=7.1.1.1
DisplayVersion=7.1.1-beta5-uroesch

[Dependencies]
Expand Down
6 changes: 3 additions & 3 deletions App/AppInfo/update.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[Version]
Package = 7.1.1.1
Display = 7.1.1-beta5-uroesch
Package = 7.1.1.2
Display = 7.1.1-beta6-uroesch

[Archive]
URL1 = https://dbeaver.io/files/7.1.1/dbeaver-ce-7.1.1-win32.win32.x86_64.zip
Checksum1 = SHA256:b0b0758755681bbaab7adcf5eea0ab24e3caa69c320d062f1f2c265b5e39fd26
Checksum1 = SHA256::https://dbeaver.io/files/7.1.1/checksum/dbeaver-ce-7.1.1-win32.win32.x86_64.zip.sha256
TargetName1 = DBeaver
ExtractName1 = dbeaver
30 changes: 27 additions & 3 deletions Other/Update/PortableAppsCommon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$AppRoot = $(Convert-Path "$PSScriptRoot\..\..")
$AppName = (Get-Item $AppRoot).Basename
$AppDir = "$AppRoot\App"
$DownloadDir = "$AppRoot\Download"
$AppInfoDir = "$AppDir\AppInfo"
$AppInfoIni = "$AppInfoDir\appinfo.ini"
$UpdateIni = "$AppInfoDir\update.ini"
Expand Down Expand Up @@ -191,27 +192,50 @@ Function Debug() {
Write-Host $Message.Replace($(Switch-Path "$AppRoot\"), '')
}

# -----------------------------------------------------------------------------
Function Download-Checksum() {
Param(
[String] $Uri
)
Try {
$OutFile = $DownloadDir + "\" + ($Uri.split('/'))[-1]
Invoke-WebRequest `
-Uri $Uri `
-OutFile $OutFile
$Sum = (Get-Content -Path $OutFile)
Return $Sum
}
Catch {
Debug error "Unable to download checksum from URL '$Uri'"
Exit 124
}
}

# -----------------------------------------------------------------------------
Function Compare-Checksum {
param(
[string] $Path,
[string] $Checksum
)

($Algorithm, $Sum) = $Checksum.Split(':')
($Algorithm, $Sum) = $Checksum.Split('::')
If ($Sum -like 'http*') {
$Sum = Download-Checksum -Uri $Sum
$Checksum = $Algorithm + "::" + $Sum
}
$Result = Get-Checksum -Path $Path -Algorithm $Algorithm
Debug info "Checksum of INI ($($Checksum.ToUpper())) and download ($Result)"
return ($Checksum.ToUpper() -eq $Result)
}

# -----------------------------------------------------------------------------
Function Get-Checksum {
param(
Param(
[string] $Path,
[string] $Algorithm
)
$Hash = (Get-FileHash -Path $Path -Algorithm $Algorithm).Hash
Return ($Algorithm + ":" + $Hash).ToUpper()
Return ($Algorithm + "::" + $Hash).ToUpper()
}

# -----------------------------------------------------------------------------
Expand Down

0 comments on commit 92a42e6

Please sign in to comment.