Skip to content

Commit 14c83e0

Browse files
committed
Download WAU.msi from GitHub if not present in temp directory when creating a transform file for 'WAU.msi'
1 parent 0c92ee5 commit 14c83e0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Sources/Winget-AutoUpdate/WAU-Settings-GUI.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,50 @@ function Set-WAUConfig {
440440
function New-WAUTransformFile {
441441
param($controls)
442442
try {
443+
444+
# Configuration
445+
$TempPath = "$env:TEMP\WAU_Settings"
446+
$GitHubRepo = "Romanitho/Winget-AutoUpdate"
447+
448+
# Create temp directory
449+
if (!(Test-Path $TempPath)) {
450+
New-Item -ItemType Directory -Path $TempPath -Force | Out-Null
451+
}
452+
# Check if WAU.msi exists in temp directory, if not, download it
453+
$msiFilePath = Join-Path $TempPath "WAU.msi"
454+
if (-not (Test-Path $msiFilePath)) {
455+
Start-PopUp "Downloading WAU MSI..."
456+
try {
457+
# Get latest release info from GitHub API
458+
$ApiUrl = "https://api.github.com/repos/$GitHubRepo/releases/latest"
459+
$Release = Invoke-RestMethod -Uri $ApiUrl -UseBasicParsing
460+
461+
# Find MSI download URL
462+
$MsiAsset = $Release.assets | Where-Object { $_.name -like "*.msi" }
463+
if (!$MsiAsset) {
464+
throw "MSI file not found in latest release"
465+
}
466+
467+
$MsiUrl = $MsiAsset.browser_download_url
468+
$MsiPath = Join-Path $TempPath $MsiAsset.name
469+
470+
Start-PopUp "Downloading MSI: $($MsiAsset.name)..."
471+
Invoke-WebRequest -Uri $MsiUrl -OutFile $MsiPath -UseBasicParsing
472+
} catch {
473+
Close-PopUp
474+
[System.Windows.MessageBox]::Show("MSI file not found in $GitHubRepo latest release", "Error", "OK", "Error")
475+
}
476+
Close-PopUp
477+
}
478+
443479
Start-PopUp "Locate WAU MSI..."
444480

445481
# Open a file selection dialog to choose a location for WAU.msi
446482
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
447483
$openFileDialog.Title = "Locate WAU.msi"
448484
$openFileDialog.Filter = "WAU.msi|WAU.msi"
449485
$openFileDialog.FileName = "WAU.msi"
486+
$openFileDialog.InitialDirectory = $TempPath
450487
$openFileDialog.RestoreDirectory = $true
451488

452489
if ($openFileDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
@@ -621,6 +658,7 @@ function New-WAUTransformFile {
621658
Set-Content -Path $cmdFilePath -Value $cmdContent -Encoding ASCII
622659

623660
[System.Windows.MessageBox]::Show("Transform file created successfully!`n`nTransform File: $transformName`nLocation: $transformPath`n`nInstall script created: $cmdFileName`n`nProperties Set:`n$propertiesSummary`n`nProduct Code: $guid`nThe Product Code has been copied to your clipboard.", "Transform Created", "OK", "Information")
661+
Start-Process "explorer.exe" -ArgumentList "$msiDirectory"
624662
} else {
625663
[System.Windows.MessageBox]::Show("Could not extract Product Code from the MSI file.", "Error", "OK", "Error")
626664
}

0 commit comments

Comments
 (0)