瀏覽代碼

Merge branch 'pr-628' into develop

Antony Male 4 年之前
父節點
當前提交
1b222bba27
共有 3 個文件被更改,包括 76 次插入43 次删除
  1. 1 1
      chocolatey/synctrayzor.nuspec
  2. 75 8
      chocolatey/tools/chocolateyinstall.ps1
  3. 0 34
      chocolatey/tools/chocolateyuninstall.ps1

+ 1 - 1
chocolatey/synctrayzor.nuspec

@@ -38,7 +38,7 @@ Features include:
     <iconUrl>https://cdn.statically.io/gh/canton7/SyncTrayzor/develop/SyncTrayzor.png</iconUrl>
     <dependencies>
       <!-- Chocolatey 0.9.9 required in order to access the chocolateyPackageName and chocolateyPackageVersion environment variables -->
-      <dependency id="chocolatey" version="0.9.9" />
+      <dependency id="chocolatey" version="0.9.10" />
       <!-- Make sure that .Net 4.7.2 or better is installed -->
       <dependency id="dotnetfx" version="4.7.2" />
     </dependencies>

+ 75 - 8
chocolatey/tools/chocolateyinstall.ps1

@@ -1,13 +1,80 @@
 $ErrorActionPreference = 'Stop'; # stop on all errors
+
+# Copied from https://github.com/chocolatey-community/chocolatey-coreteampackages/blob/a2371345f182da74589897055e3b3703deb0cce3/extensions/chocolatey-core.extension/extensions/Get-UninstallRegistryKey.ps1
+function Get-UninstallRegistryKeySilent {
+    param(
+        [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
+        [ValidateNotNullOrEmpty()]
+        [string] $SoftwareName,
+        [parameter(ValueFromRemainingArguments = $true)]
+        [Object[]] $IgnoredArguments
+    )
+    Write-Debug "Running 'Get-UninstallRegistryKey' for `'$env:ChocolateyPackageName`' with SoftwareName:`'$SoftwareName`'";
+
+    $ErrorActionPreference = 'Stop'
+    $local_key       = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
+    $machine_key     = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
+    $machine_key6432 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
+
+    Write-Verbose "Retrieving all uninstall registry keys"
+    [array]$keys = Get-ChildItem -Path @($machine_key6432, $machine_key, $local_key) -ea 0
+    Write-Debug "Registry uninstall keys on system: $($keys.Count)"
+
+    Write-Debug "Error handling check: `'Get-ItemProperty`' fails if a registry key is encoded incorrectly."
+    [int]$maxAttempts = $keys.Count
+    for ([int]$attempt = 1; $attempt -le $maxAttempts; $attempt++)
+    {
+        $success = $false
+
+        $keyPaths = $keys | Select-Object -ExpandProperty PSPath
+        try {
+            [array]$foundKey = Get-ItemProperty -Path $keyPaths -ea 0 | ? { $_.DisplayName -like $SoftwareName }
+            $success = $true
+        } catch {
+            Write-Debug "Found bad key."
+            foreach ($key in $keys){ try{ Get-ItemProperty $key.PsPath > $null } catch { $badKey = $key.PsPath }}
+            Write-Verbose "Skipping bad key: $badKey"
+            [array]$keys = $keys | ? { $badKey -NotContains $_.PsPath }
+        }
+
+        if ($success) { break; }
+        if ($attempt -eq 10) {
+            Write-Warning "Found more than 10 bad registry keys. Run command again with `'--verbose --debug`' for more info."
+            Write-Debug "Each key searched should correspond to an installed program. It is very unlikely to have more than a few programs with incorrectly encoded keys, if any at all. This may be indicative of one or more corrupted registry branches."
+        }
+    }
+
+    Write-Debug "Found $($foundKey.Count) uninstall registry key(s) with SoftwareName:`'$SoftwareName`'";
+    return $foundKey
+}
+
 $toolsDir              = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
+$file                  = (Join-Path $toolsDir 'SyncTrayzorSetup-x86.exe')
+$file64                = (Join-Path $toolsDir 'SyncTrayzorSetup-x64.exe')
+
+$packageArgs = @{
+    packageName   = 'SyncTrayzor'
+    file          = $file
+    file64        = $file64
+    silentArgs    = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP- /SkipDotNetInstall'
+    fileType      = 'exe'
+    validExitCodes = @(0)
+}
 
-$packageName= 'SyncTrayzor'
-$file       = (Join-Path $toolsDir 'SyncTrayzorSetup-x86.exe')
-$file64     = (Join-Path $toolsDir 'SyncTrayzorSetup-x64.exe')
-$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP- /SkipDotNetInstall'
-$fileType   = 'exe'
-$validExitCodes = @(0)
+# Version 1.1.28 had a bug which installed x86 on x64 machines. Forcefully transitioning someone from
+# x86 to x64 is risky, as it potentially loses their config, Syncthing version, etc.
+# Therefore if they've got the x86 version and not the x64 version, upgrade using the x86 version to
+# avoid breaking them.
+if ((Get-OSArchitectureWidth -compare 64) -and ($env:chocolateyForceX86 -ne $true) -and (Get-UninstallRegistryKeySilent -SoftwareName 'SyncTrayzor (x86)*')) {
+    if (Get-UninstallRegistryKeySilent -SoftwareName 'SyncTrayzor (x64)*') {
+        Write-Host -ForegroundColor green "Both the 32-bit and 64-bit versions of SyncTrayzor are installed. Upgrading the 64-bit version."
+    } else {
+        Write-Host -ForegroundColor green "You have the 32-bit version of SyncTrayzor installed, so upgrading this. If you intended to install the 64-bit version, please uninstall the 32-bit version first."
+        # null out the 64 bit file parameter, so only the 32 bit file is available to install
+        $packageArgs['file64'] = $null
+    }
+}
 
-Install-ChocolateyInstallPackage $packageName $fileType $silentArgs $file $file64 -validExitCodes $validExitCodes
+Install-ChocolateyInstallPackage @packageArgs
 
-Remove-Item -Force -ea 0 $file, $file64
+Remove-Item -Force -ea 0 $file, $file64

+ 0 - 34
chocolatey/tools/chocolateyuninstall.ps1

@@ -1,34 +0,0 @@
-$ErrorActionPreference = 'Stop'; # stop on all errors
-
-$packageName = 'SyncTrayzor'
-$softwareName = 'SyncTrayzor*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique
-$installerType = 'exe' 
-$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-'
-$validExitCodes = @(0)
-
-$uninstalled = $false
-$local_key     = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
-$machine_key   = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
-$machine_key6432 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
-
-[array]$key = Get-ItemProperty -Path @($machine_key6432,$machine_key, $local_key) `
-                        -ErrorAction SilentlyContinue `
-         | ? { $_.DisplayName -like "$softwareName" }
-
-if ($key.Count -eq 1) {
-  $key | % { 
-    $file = "$($_.UninstallString)"
-    Uninstall-ChocolateyPackage -PackageName $packageName `
-                                -FileType $installerType `
-                                -SilentArgs "$silentArgs" `
-                                -ValidExitCodes $validExitCodes `
-                                -File "$file"
-  }
-} elseif ($key.Count -eq 0) {
-  Write-Warning "$packageName has already been uninstalled by other means."
-} elseif ($key.Count -gt 1) {
-  Write-Warning "$key.Count matches found!"
-  Write-Warning "To prevent accidental data loss, no programs will be uninstalled."
-  Write-Warning "Please alert package maintainer the following keys were matched:"
-  $key | % {Write-Warning "- $_.DisplayName"}
-}