@@ -1372,6 +1372,86 @@ Function Read-InstallerEntry {
13721372 }
13731373}
13741374
1375+ # Downloads and processes an installer file to update installer metadata
1376+ # Takes an installer hashtable, downloads the file from InstallerUrl, and updates:
1377+ # - InstallerSha256
1378+ # - InstallerType (if MSI/WIX/NULLSOFT/INNO/BURN detected)
1379+ # - ProductCode (for MSI installers)
1380+ # - SignatureSha256 (for MSIX/APPX installers)
1381+ # - PackageFamilyName (for MSIX/APPX installers)
1382+ # Returns the updated installer hashtable
1383+ Function Update-InstallerEntry {
1384+ Param (
1385+ [Parameter (Mandatory = $true )]
1386+ [PSCustomObject ] $Installer ,
1387+ [Parameter (Mandatory = $false )]
1388+ [switch ] $ShowProgress
1389+ )
1390+
1391+ try {
1392+ if ($ShowProgress ) { Write-Host - ForegroundColor ' Green' ' Downloading Installer. . .' }
1393+ $script :dest = Get-InstallerFile - URI $Installer [' InstallerUrl' ] - PackageIdentifier $PackageIdentifier - PackageVersion $PackageVersion
1394+ } catch {
1395+ # Here we also want to pass any exceptions through for potential debugging
1396+ throw [System.Net.WebException ]::new(' The file could not be downloaded. Try running the script again' , $_.Exception )
1397+ }
1398+
1399+ if ($ShowProgress ) { Write-Host - ForegroundColor ' Green' " Installer Downloaded!`n Processing installer data. . . " }
1400+
1401+ # Check that MSI's aren't actually WIX, and EXE's aren't NSIS, INNO or BURN
1402+ if ($Installer [' InstallerType' ] -in @ (' msi' ; ' exe' )) {
1403+ $DetectedType = Resolve-InstallerType $script :dest
1404+ if ($DetectedType -in @ (' msi' ; ' wix' ; ' nullsoft' ; ' inno' ; ' burn' )) { $Installer [' InstallerType' ] = $DetectedType }
1405+ }
1406+
1407+ # Get the Sha256
1408+ $Installer [' InstallerSha256' ] = (Get-FileHash - Path $script :dest - Algorithm SHA256).Hash
1409+
1410+ # Update the product code, if a new one exists
1411+ # If a new product code doesn't exist, and the installer isn't an `.exe` file, remove the product code if it exists
1412+ $MSIProductCode = $null
1413+ if ([System.Environment ]::OSVersion.Platform -match ' Win' -and ($script :dest ).EndsWith(' .msi' )) {
1414+ $MSIProductCode = [string ](Get-MSIProperty - Path $script :dest - Property ' ProductCode' ).Value
1415+ } elseif ([System.Environment ]::OSVersion.Platform -match ' Unix' -and (Get-Item $script :dest ).Name.EndsWith(' .msi' )) {
1416+ $MSIProductCode = ([string ](file $script :dest ) | Select-String - Pattern ' {[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}' ).Matches.Value
1417+ }
1418+ if (Test-String -not $MSIProductCode - IsNull) {
1419+ $Installer [' ProductCode' ] = $MSIProductCode
1420+ } elseif ( ($Installer.Keys -contains ' ProductCode' ) -and ((Get-EffectiveInstallerType $Installer ) -in @ (' appx' ; ' msi' ; ' msix' ; ' wix' ; ' burn' ))) {
1421+ $Installer.Remove (' ProductCode' )
1422+ }
1423+
1424+ # If the installer is msix or appx, try getting the new SignatureSha256
1425+ # If the new SignatureSha256 can't be found, remove it if it exists
1426+ $NewSignatureSha256 = $null
1427+ if ($Installer.InstallerType -in @ (' msix' , ' appx' )) {
1428+ if (Get-Command ' winget' - ErrorAction SilentlyContinue) { $NewSignatureSha256 = winget hash - m $script :dest | Select-String - Pattern ' SignatureSha256:' | ConvertFrom-String ; if ($NewSignatureSha256.P2 ) { $NewSignatureSha256 = $NewSignatureSha256.P2.ToUpper () } }
1429+ }
1430+ if (Test-String -not $NewSignatureSha256 - IsNull) {
1431+ $Installer [' SignatureSha256' ] = $NewSignatureSha256
1432+ } elseif ($Installer.Keys -contains ' SignatureSha256' ) {
1433+ $Installer.Remove (' SignatureSha256' )
1434+ }
1435+
1436+ # If the installer is msix or appx, try getting the new package family name
1437+ # If the new package family name can't be found, remove it if it exists
1438+ if ($script :dest -match ' \.(msix|appx)(bundle){0,1}$' ) {
1439+ $PackageFamilyName = Get-PackageFamilyName $script :dest
1440+ if (Test-String $PackageFamilyName - MatchPattern $Patterns.FamilyName ) {
1441+ $Installer [' PackageFamilyName' ] = $PackageFamilyName
1442+ } elseif ($Installer.Keys -contains ' PackageFamilyName' ) {
1443+ $Installer.Remove (' PackageFamilyName' )
1444+ }
1445+ }
1446+
1447+ # Remove the downloaded files
1448+ SafeRemovePath - Path $script :dest
1449+
1450+ if ($ShowProgress ) { Write-Host - ForegroundColor ' Green' " Installer updated!`n " }
1451+
1452+ return $Installer
1453+ }
1454+
13751455# Prompts user for Installer Values using the `Quick Update` Method
13761456# Sets the $script:Installers value as an output
13771457# Returns void
@@ -1416,58 +1496,7 @@ Function Read-QuickInstallerEntry {
14161496 }
14171497
14181498 if ($_NewInstaller.Keys -notcontains ' InstallerSha256' ) {
1419- try {
1420- Write-Host - ForegroundColor ' Green' ' Downloading Installer. . .'
1421- $script :dest = Get-InstallerFile - URI $_NewInstaller [' InstallerUrl' ] - PackageIdentifier $PackageIdentifier - PackageVersion $PackageVersion
1422- } catch {
1423- # Here we also want to pass any exceptions through for potential debugging
1424- throw [System.Net.WebException ]::new(' The file could not be downloaded. Try running the script again' , $_.Exception )
1425- }
1426- # Check that MSI's aren't actually WIX, and EXE's aren't NSIS, INNO or BURN
1427- Write-Host - ForegroundColor ' Green' " Installer Downloaded!`n Processing installer data. . . "
1428- if ($_NewInstaller [' InstallerType' ] -in @ (' msi' ; ' exe' )) {
1429- $DetectedType = Resolve-InstallerType $script :dest
1430- if ($DetectedType -in @ (' msi' ; ' wix' ; ' nullsoft' ; ' inno' ; ' burn' )) { $_NewInstaller [' InstallerType' ] = $DetectedType }
1431- }
1432- # Get the Sha256
1433- $_NewInstaller [' InstallerSha256' ] = (Get-FileHash - Path $script :dest - Algorithm SHA256).Hash
1434- # Update the product code, if a new one exists
1435- # If a new product code doesn't exist, and the installer isn't an `.exe` file, remove the product code if it exists
1436- $MSIProductCode = $null
1437- if ([System.Environment ]::OSVersion.Platform -match ' Win' -and ($script :dest ).EndsWith(' .msi' )) {
1438- $MSIProductCode = [string ](Get-MSIProperty - Path $script :dest - Property ' ProductCode' ).Value
1439- } elseif ([System.Environment ]::OSVersion.Platform -match ' Unix' -and (Get-Item $script :dest ).Name.EndsWith(' .msi' )) {
1440- $MSIProductCode = ([string ](file $script :dest ) | Select-String - Pattern ' {[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}' ).Matches.Value
1441- }
1442- if (Test-String -not $MSIProductCode - IsNull) {
1443- $_NewInstaller [' ProductCode' ] = $MSIProductCode
1444- } elseif ( ($_NewInstaller.Keys -contains ' ProductCode' ) -and ((Get-EffectiveInstallerType $_NewInstaller ) -in @ (' appx' ; ' msi' ; ' msix' ; ' wix' ; ' burn' ))) {
1445- $_NewInstaller.Remove (' ProductCode' )
1446- }
1447- # If the installer is msix or appx, try getting the new SignatureSha256
1448- # If the new SignatureSha256 can't be found, remove it if it exists
1449- $NewSignatureSha256 = $null
1450- if ($_NewInstaller.InstallerType -in @ (' msix' , ' appx' )) {
1451- if (Get-Command ' winget' - ErrorAction SilentlyContinue) { $NewSignatureSha256 = winget hash - m $script :dest | Select-String - Pattern ' SignatureSha256:' | ConvertFrom-String ; if ($NewSignatureSha256.P2 ) { $NewSignatureSha256 = $NewSignatureSha256.P2.ToUpper () } }
1452- }
1453- if (Test-String -not $NewSignatureSha256 - IsNull) {
1454- $_NewInstaller [' SignatureSha256' ] = $NewSignatureSha256
1455- } elseif ($_NewInstaller.Keys -contains ' SignatureSha256' ) {
1456- $_NewInstaller.Remove (' SignatureSha256' )
1457- }
1458- # If the installer is msix or appx, try getting the new package family name
1459- # If the new package family name can't be found, remove it if it exists
1460- if ($script :dest -match ' \.(msix|appx)(bundle){0,1}$' ) {
1461- $PackageFamilyName = Get-PackageFamilyName $script :dest
1462- if (Test-String $PackageFamilyName - MatchPattern $Patterns.FamilyName ) {
1463- $_NewInstaller [' PackageFamilyName' ] = $PackageFamilyName
1464- } elseif ($_NewInstaller.Keys -contains ' PackageFamilyName' ) {
1465- $_NewInstaller.Remove (' PackageFamilyName' )
1466- }
1467- }
1468- # Remove the downloaded files
1469- SafeRemovePath - Path $script :dest
1470- Write-Host - ForegroundColor ' Green' " Installer updated!`n "
1499+ $_NewInstaller = Update-InstallerEntry - Installer $_NewInstaller - ShowProgress
14711500 }
14721501
14731502 # Force a re-check of the Nested Installer Paths in case they changed between versions
@@ -3062,56 +3091,7 @@ Switch ($script:Option) {
30623091 foreach ($_Installer in $script :OldInstallerManifest.Installers ) {
30633092 $_Installer [' InstallerUrl' ] = [System.Web.HttpUtility ]::UrlDecode($_Installer.InstallerUrl.Replace (' +' , ' %2B' ))
30643093 $_Installer [' InstallerUrl' ] = $_Installer.InstallerUrl.Replace (' ' , ' %20' )
3065- try {
3066- $script :dest = Get-InstallerFile - URI $_Installer.InstallerUrl - PackageIdentifier $PackageIdentifier - PackageVersion $PackageVersion
3067- } catch {
3068- # Here we also want to pass any exceptions through for potential debugging
3069- throw [System.Net.WebException ]::new(' The file could not be downloaded. Try running the script again' , $_.Exception )
3070- }
3071- # Check that MSI's aren't actually WIX, and EXE's aren't NSIS, INNO or BURN
3072- if ($_Installer [' InstallerType' ] -in @ (' msi' ; ' exe' )) {
3073- $DetectedType = Resolve-InstallerType $script :dest
3074- if ($DetectedType -in @ (' msi' ; ' wix' ; ' nullsoft' ; ' inno' ; ' burn' )) { $_Installer [' InstallerType' ] = $DetectedType }
3075- }
3076- # Get the Sha256
3077- $_Installer [' InstallerSha256' ] = (Get-FileHash - Path $script :dest - Algorithm SHA256).Hash
3078- # Update the product code, if a new one exists
3079- # If a new product code doesn't exist, and the installer isn't an `.exe` file, remove the product code if it exists
3080- $MSIProductCode = $null
3081- if ([System.Environment ]::OSVersion.Platform -match ' Win' -and ($script :dest ).EndsWith(' .msi' )) {
3082- $MSIProductCode = [string ](Get-MSIProperty - Path $script :dest - Property ' ProductCode' ).Value
3083- } elseif ([System.Environment ]::OSVersion.Platform -match ' Unix' -and (Get-Item $script :dest ).Name.EndsWith(' .msi' )) {
3084- $MSIProductCode = ([string ](file $script :dest ) | Select-String - Pattern ' {[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}' ).Matches.Value
3085- }
3086- if (Test-String -not $MSIProductCode - IsNull) {
3087- $_Installer [' ProductCode' ] = $MSIProductCode
3088- } elseif ( ($_Installer.Keys -contains ' ProductCode' ) -and ($_Installer.InstallerType -in @ (' appx' ; ' msi' ; ' msix' ; ' wix' ; ' burn' ))) {
3089- $_Installer.Remove (' ProductCode' )
3090- }
3091- # If the installer is msix or appx, try getting the new SignatureSha256
3092- # If the new SignatureSha256 can't be found, remove it if it exists
3093- $NewSignatureSha256 = $null
3094- if ($_Installer.InstallerType -in @ (' msix' , ' appx' )) {
3095- if (Get-Command ' winget' - ErrorAction SilentlyContinue) { $NewSignatureSha256 = winget hash - m $script :dest | Select-String - Pattern ' SignatureSha256:' | ConvertFrom-String ; if ($NewSignatureSha256.P2 ) { $NewSignatureSha256 = $NewSignatureSha256.P2.ToUpper () } }
3096- }
3097- if (Test-String -not $NewSignatureSha256 - IsNull) {
3098- $_Installer [' SignatureSha256' ] = $NewSignatureSha256
3099- } elseif ($_Installer.Keys -contains ' SignatureSha256' ) {
3100- $_Installer.Remove (' SignatureSha256' )
3101- }
3102- # If the installer is msix or appx, try getting the new package family name
3103- # If the new package family name can't be found, remove it if it exists
3104- if ($script :dest -match ' \.(msix|appx)(bundle){0,1}$' ) {
3105- $PackageFamilyName = Get-PackageFamilyName $script :dest
3106-
3107- if (Test-String $PackageFamilyName - MatchPattern $Patterns.FamilyName ) {
3108- $_Installer [' PackageFamilyName' ] = $PackageFamilyName
3109- } elseif ($_NewInstaller.Keys -contains ' PackageFamilyName' ) {
3110- $_Installer.Remove (' PackageFamilyName' )
3111- }
3112- }
3113- # Remove the downloaded files
3114- SafeRemovePath - Path $script :dest
3094+ $_Installer = Update-InstallerEntry - Installer $_Installer
31153095 $_NewInstallers += Restore-YamlKeyOrder $_Installer $InstallerEntryProperties - NoComments
31163096 }
31173097 # Write the new manifests
0 commit comments