diff --git a/bucket/speccy.json b/bucket/speccy.json index 3942e8e0e687d0..2a853f7c220a24 100644 --- a/bucket/speccy.json +++ b/bucket/speccy.json @@ -13,23 +13,48 @@ ] ], "pre_install": [ - "# Construct EXE file name based on $architecture", - "$FileName = [string] 'Speccy{0}.exe' -f $(if($architecture -eq '64bit'){'64'})", - "# Copy EXE to $dir root and rename it to Speccy.exe if 64 bit", - "Get-ChildItem -Recurse -File -Path \"$dir\" -Name $FileName -ErrorAction Stop |", - " ForEach-Object -Process {", - " Move-Item -Path \"$dir\\$_\" -Destination \"$dir\\Speccy.exe\"", - " }", - "# Remove everything else", - "Get-ChildItem -Path $dir |", - " Where-Object -Property 'Name' -ne 'Speccy.exe' |", - " ForEach-Object -Process {", - " Remove-Item -Recurse -Force -Path $_.FullName", - " }", - "# Set settings", + "$ExeFile = [string] 'Speccy{0}.exe' -f $(if ($architecture -eq '64bit') {'64'})", + "# The executable file might be in a subfolder, or not. Keep this check for backwards compatibility.", + "if (-not (Test-Path \"$dir\\$ExeFile\")) {", + " Get-ChildItem -Path \"$dir\" -Filter \"$ExeFile\" -Recurse | ForEach-Object -Process { Move-Item -Path $_.FullName -Destination \"$dir\" -ErrorAction Stop }", + "}", + "Get-ChildItem -Path \"$dir\" -Exclude \"$ExeFile\", \"Lang\" | ForEach-Object -Process { Remove-Item -Recurse -Force -Path $_.FullName -ErrorAction Stop }", + "if ($architecture -eq '64bit') { Rename-Item -Path \"$dir\\Speccy64.exe\" -NewName \"Speccy.exe\" -ErrorAction Stop }", "Set-Content -Path \"$dir\\portable.dat\" -Value '#PORTABLE#' -Encoding ASCII", "if (-not (Test-Path \"$persist_dir\\Speccy.ini\")) {", " Set-Content \"$dir\\Speccy.ini\" (@('[Software\\Piriform\\Speccy]', 'NeedUpdate=0') -join \"`r`n\") -Encoding ASCII", + "}", + "Write-Host \"`nExtracting app dependencies from installer...\" -NoNewline", + "$CachedInstaller = cache_path \"speccy\" $manifest.version $manifest.url", + "if (-not (Test-Path \"$CachedInstaller\")) {", + " Write-Host \"failed!\" -ForegroundColor Red", + " warn \"Can not find cached installer file in path $CachedInstaller\"", + " warn \"App functions may be limited due to missing dependencies.\"", + " warn \"Please check the downloaded cache and try again.\"", + " return", + "}", + "if ($manifest.hash -ne (Get-FileHash -Path \"$CachedInstaller\" -Algorithm SHA256).Hash) {", + " Write-Host \"failed!\" -ForegroundColor Red", + " warn \"Cached installer file hash mismatch in path $CachedInstaller\"", + " warn \"App functions may be limited due to missing dependencies.\"", + " warn \"Please check the downloaded cache and try again.\"", + " return", + "}", + "try {", + " Expand-7zipArchive -Path \"$CachedInstaller\" -DestinationPath \"$dir\" -Switches \"cpuidsdk.dll\" -Overwrite Rename", + " # There are usually two, assuming 64bit uses the larger one.", + " switch ($architecture) {", + " '64bit' { Get-ChildItem -Path \"$dir\" -Filter \"cpuidsdk*.dll\" | Sort-Object -Property Length | Select-Object -First 1 | Remove-Item -Force -ErrorAction Stop }", + " '32bit' { Get-ChildItem -Path \"$dir\" -Filter \"cpuidsdk*.dll\" | Sort-Object -Property Length | Select-Object -Last 1 | Remove-Item -Force -ErrorAction Stop }", + " }", + " Get-ChildItem -Path \"$dir\" -Filter \"cpuidsdk*.dll\" | Rename-Item -NewName \"cpuidsdk.dll\" -ErrorAction Stop", + " if (-not (Test-Path \"$dir\\cpuidsdk.dll\")) { throw }", + " Write-Host \"success!\" -ForegroundColor Green", + "} catch {", + " Write-Host \"failed!\" -ForegroundColor Red", + " warn \"Failed to extract app dependencies from $CachedInstaller\"", + " warn \"App functions may be limited due to missing dependencies.\"", + " warn \"Please check the downloaded cache and try again.\"", "}" ], "persist": "Speccy.ini",