aboutsummaryrefslogtreecommitdiffstats
path: root/coin/provisioning/common/windows/helpers.ps1
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-01-12 12:51:53 +0100
committerLiang Qi <liang.qi@qt.io>2018-01-12 21:13:56 +0100
commitc2d188f225a96ccf409f4dbebd19f6e59caf7da6 (patch)
tree35d0320171ad60a4e25c41f0718d02016dfd4242 /coin/provisioning/common/windows/helpers.ps1
parentab25cb7af6602a558c84e3d30e8ce1c6e7ca6e73 (diff)
parent19872ea84352182ee974ff84d2e3872a21427117 (diff)
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts: coin/platform_configs/default.txt coin/platform_configs/qt5.txt Task-number: QTBUG-65688 Change-Id: I17a303731dab4b967c9ef8a852ee0c1097b88f10
Diffstat (limited to 'coin/provisioning/common/windows/helpers.ps1')
-rw-r--r--coin/provisioning/common/windows/helpers.ps1130
1 files changed, 130 insertions, 0 deletions
diff --git a/coin/provisioning/common/windows/helpers.ps1 b/coin/provisioning/common/windows/helpers.ps1
new file mode 100644
index 00000000..ff781b6c
--- /dev/null
+++ b/coin/provisioning/common/windows/helpers.ps1
@@ -0,0 +1,130 @@
+function Verify-Checksum
+{
+ Param (
+ [string]$File=$(throw("You must specify a filename to get the checksum of.")),
+ [string]$Expected=$(throw("Checksum required")),
+ [ValidateSet("sha1","md5")][string]$Algorithm="sha1"
+ )
+ $fs = new-object System.IO.FileStream $File, "Open"
+ $algo = [type]"System.Security.Cryptography.$Algorithm"
+ $crypto = $algo::Create()
+ $hash = [BitConverter]::ToString($crypto.ComputeHash($fs)).Replace("-", "")
+ $fs.Close()
+ if ($hash -ne $Expected) {
+ Write-Error "Checksum verification failed, got: '$hash' expected: '$Expected'"
+ }
+}
+
+function Extract-7Zip
+{
+ Param (
+ [string]$Source,
+ [string]$Destination
+ )
+ echo "Extracting '$Source' to '$Destination'..."
+
+ if ((Get-Command "7z.exe" -ErrorAction SilentlyContinue) -eq $null) {
+ $zipExe = join-path (${env:ProgramFiles(x86)}, ${env:ProgramFiles} -ne $null)[0] '7-zip\7z.exe'
+ if (-not (test-path $zipExe)) {
+ $zipExe = join-path ${env:ProgramW6432} '7-zip\7z.exe'
+ if (-not (test-path $zipExe)) {
+ $zipExe = "C:\Utils\sevenzip\7z.exe"
+ if (-not (test-path $zipExe)) {
+ throw "Could not find 7-zip."
+ }
+ }
+ }
+ } else {
+ $zipExe = "7z.exe"
+ }
+
+ & $zipExe x $Source "-o$Destination" -y
+}
+
+function Extract-Zip
+{
+ Param (
+ [string]$Source,
+ [string]$Destination
+ )
+ echo "Extracting '$Source' to '$Destination'..."
+
+ New-Item -ItemType Directory -Force -Path $Destination
+ $shell = new-object -com shell.application
+ $zipfile = $shell.Namespace($Source)
+ $destinationFolder = $shell.Namespace($Destination)
+ $destinationFolder.CopyHere($zipfile.Items(), 16)
+}
+
+function Extract-Dev-Folders-From-Zip
+{
+ Param (
+ [string]$package,
+ [string]$zipDir,
+ [string]$installPath
+ )
+
+ $shell = new-object -com shell.application
+
+ echo "Extracting contents of $package"
+ foreach ($subDir in "lib", "include", "bin", "share") {
+ $zip = $shell.Namespace($package + "\" + $zipDir + "\" + $subDir)
+ if ($zip) {
+ Write-Host "Extracting $subDir from zip archive"
+ } else {
+ Write-Host "$subDir is missing from zip archive - skipping"
+ continue
+ }
+ $destDir = $installPath + "\" + $subdir
+ New-Item $destDir -type directory
+ $destinationFolder = $shell.Namespace($destDir)
+ $destinationFolder.CopyHere($zip.Items(), 16)
+ }
+}
+
+function BadParam
+{
+ Param ([string]$Description)
+ throw("You must specify $Description")
+}
+
+function Download
+{
+ Param (
+ [string] $OfficialUrl = $(BadParam("the official download URL")),
+ [string] $CachedUrl = $(BadParam("the locally cached URL")),
+ [string] $Destination = $(BadParam("a download target location"))
+ )
+ $ProgressPreference = 'SilentlyContinue'
+ try {
+ if ($CachedUrl.StartsWith("http")) {
+ Invoke-WebRequest -UseBasicParsing $CachedUrl -OutFile $Destination
+ } else {
+ Copy-Item $CachedUrl $Destination
+ }
+ } catch {
+ Invoke-WebRequest -UseBasicParsing $OfficialUrl -OutFile $Destination
+ }
+}
+
+function Add-Path
+{
+ Param (
+ [string]$Path
+ )
+ echo "Adding $Path to Path"
+
+ $oldPath = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
+ [Environment]::SetEnvironmentVariable("Path", $oldPath + ";$Path", [EnvironmentVariableTarget]::Machine)
+ $Env:PATH = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
+}
+
+function is64bitWinHost
+{
+ if(($env:PROCESSOR_ARCHITECTURE -eq "AMD64") -or ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64")) {
+ return 1
+ }
+ else {
+ return 0
+ }
+}