Skip to content

Commit c04f758

Browse files
Fix winget bundle fetch fallback
1 parent d727264 commit c04f758

1 file changed

Lines changed: 133 additions & 36 deletions

File tree

scripts/fetch-winget-cli.ps1

Lines changed: 133 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ param(
2121
[string] $Version = "v1.12.470",
2222
[string[]] $Architectures = @("x64", "arm64"),
2323
[string] $DestinationRoot = (Join-Path $PSScriptRoot ".." "src" "UniGetUI.PackageEngine.Managers.WinGet"),
24-
[string] $UpstreamRepo = "marticliment/UniGetUI",
24+
[string] $UpstreamRepo = "",
2525
[string] $UpstreamRef = "main",
26-
[string] $UpstreamReferencePath = "src/UniGetUI.PackageEngine.Managers.WinGet/winget-cli_x64",
26+
[string] $UpstreamReferencePath = "",
2727
[string] $GitHubToken = "",
2828
[switch] $Force
2929
)
@@ -52,9 +52,65 @@ else {
5252
Write-Warning "No GitHub token found (GITHUB_TOKEN/GH_TOKEN). Requests may be rate-limited."
5353
}
5454

55-
$X64OnlyReferenceFiles = @(
56-
"AppInstallerBackgroundTasks.dll"
57-
)
55+
$BundledReferenceFiles = @{
56+
x64 = @(
57+
"concrt140_app.dll",
58+
"libsmartscreenn.dll",
59+
"Microsoft.Management.Configuration.dll",
60+
"Microsoft.Web.WebView2.Core.dll",
61+
"msvcp140_1_app.dll",
62+
"msvcp140_2_app.dll",
63+
"msvcp140_app.dll",
64+
"msvcp140_atomic_wait_app.dll",
65+
"resources.pri",
66+
"vcamp140_app.dll",
67+
"vccorlib140_app.dll",
68+
"vcomp140_app.dll",
69+
"vcruntime140_1_app.dll",
70+
"vcruntime140_app.dll",
71+
"WindowsPackageManager.dll",
72+
"WindowsPackageManagerServer.exe",
73+
"winget.exe"
74+
)
75+
arm64 = @(
76+
"concrt140_app.dll",
77+
"libsmartscreenn.dll",
78+
"Microsoft.Management.Configuration.dll",
79+
"Microsoft.Web.WebView2.Core.dll",
80+
"msvcp140_1_app.dll",
81+
"msvcp140_2_app.dll",
82+
"msvcp140_app.dll",
83+
"msvcp140_atomic_wait_app.dll",
84+
"resources.pri",
85+
"vcamp140_app.dll",
86+
"vccorlib140_app.dll",
87+
"vcomp140_app.dll",
88+
"vcruntime140_1_app.dll",
89+
"vcruntime140_app.dll",
90+
"WindowsPackageManager.dll",
91+
"WindowsPackageManagerServer.exe",
92+
"winget.exe"
93+
)
94+
x86 = @(
95+
"concrt140_app.dll",
96+
"libsmartscreenn.dll",
97+
"Microsoft.Management.Configuration.dll",
98+
"Microsoft.Web.WebView2.Core.dll",
99+
"msvcp140_1_app.dll",
100+
"msvcp140_2_app.dll",
101+
"msvcp140_app.dll",
102+
"msvcp140_atomic_wait_app.dll",
103+
"resources.pri",
104+
"vcamp140_app.dll",
105+
"vccorlib140_app.dll",
106+
"vcomp140_app.dll",
107+
"vcruntime140_1_app.dll",
108+
"vcruntime140_app.dll",
109+
"WindowsPackageManager.dll",
110+
"WindowsPackageManagerServer.exe",
111+
"winget.exe"
112+
)
113+
}
58114

59115
function Get-ReleaseInfo {
60116
param([string] $Tag)
@@ -126,6 +182,62 @@ function Resolve-UpstreamReferencePathForArchitecture {
126182
return $BasePath
127183
}
128184

185+
function Get-BundledReferenceFiles {
186+
param([string] $Architecture)
187+
188+
$archKey = $Architecture.ToLowerInvariant()
189+
if ($BundledReferenceFiles.ContainsKey($archKey)) {
190+
return @($BundledReferenceFiles[$archKey])
191+
}
192+
193+
return @($BundledReferenceFiles["x64"])
194+
}
195+
196+
function Get-ReferenceFiles {
197+
param([string] $Architecture)
198+
199+
$archKey = $Architecture.ToLowerInvariant()
200+
$upstreamConfigured = -not [string]::IsNullOrWhiteSpace($UpstreamRepo) -and -not [string]::IsNullOrWhiteSpace($UpstreamReferencePath)
201+
202+
if ($upstreamConfigured) {
203+
$upstreamReferencePathForArch = Resolve-UpstreamReferencePathForArchitecture -BasePath $UpstreamReferencePath -Architecture $archKey
204+
205+
try {
206+
$upstreamFiles = Get-UpstreamReferenceFiles -Repository $UpstreamRepo -Ref $UpstreamRef -DirectoryPath $upstreamReferencePathForArch
207+
208+
return @{
209+
Files = @($upstreamFiles)
210+
SourceDescription = "$UpstreamRepo@$UpstreamRef/$upstreamReferencePathForArch"
211+
}
212+
}
213+
catch {
214+
if ($upstreamReferencePathForArch -ne $UpstreamReferencePath) {
215+
Write-Warning "Unable to load architecture-specific upstream reference '$upstreamReferencePathForArch'. Falling back to '$UpstreamReferencePath'."
216+
217+
try {
218+
$upstreamFiles = Get-UpstreamReferenceFiles -Repository $UpstreamRepo -Ref $UpstreamRef -DirectoryPath $UpstreamReferencePath
219+
220+
return @{
221+
Files = @($upstreamFiles)
222+
SourceDescription = "$UpstreamRepo@$UpstreamRef/$UpstreamReferencePath"
223+
}
224+
}
225+
catch {
226+
Write-Warning "Unable to load upstream reference '$UpstreamRepo@$UpstreamRef/$UpstreamReferencePath'. Falling back to bundled reference manifest."
227+
}
228+
}
229+
else {
230+
Write-Warning "Unable to load upstream reference '$UpstreamRepo@$UpstreamRef/$UpstreamReferencePath'. Falling back to bundled reference manifest."
231+
}
232+
}
233+
}
234+
235+
return @{
236+
Files = @(Get-BundledReferenceFiles -Architecture $archKey)
237+
SourceDescription = "bundled manifest ($archKey)"
238+
}
239+
}
240+
129241
$release = Get-ReleaseInfo -Tag $Version
130242
Write-Host "Using winget-cli release: $($release.tag_name)"
131243

@@ -154,30 +266,10 @@ Expand-Archive -Path $depsPath -DestinationPath $depsDir -Force
154266

155267
foreach ($arch in $Architectures) {
156268
$archKey = $arch.ToLowerInvariant()
157-
$upstreamReferencePathForArch = Resolve-UpstreamReferencePathForArchitecture -BasePath $UpstreamReferencePath -Architecture $archKey
269+
$reference = Get-ReferenceFiles -Architecture $archKey
270+
$expectedFiles = @($reference.Files)
158271

159-
try {
160-
$upstreamFiles = Get-UpstreamReferenceFiles -Repository $UpstreamRepo -Ref $UpstreamRef -DirectoryPath $upstreamReferencePathForArch
161-
}
162-
catch {
163-
if ($upstreamReferencePathForArch -ne $UpstreamReferencePath) {
164-
Write-Warning "Unable to load architecture-specific upstream reference '$upstreamReferencePathForArch'. Falling back to '$UpstreamReferencePath'."
165-
$upstreamReferencePathForArch = $UpstreamReferencePath
166-
$upstreamFiles = Get-UpstreamReferenceFiles -Repository $UpstreamRepo -Ref $UpstreamRef -DirectoryPath $upstreamReferencePathForArch
167-
}
168-
else {
169-
throw
170-
}
171-
}
172-
173-
$expectedFiles = if ($archKey -eq 'x64') {
174-
$upstreamFiles
175-
}
176-
else {
177-
@($upstreamFiles | Where-Object { $_ -notin $X64OnlyReferenceFiles })
178-
}
179-
180-
Write-Host "[$archKey] Using upstream reference list from $UpstreamRepo@$UpstreamRef/$upstreamReferencePathForArch ($($upstreamFiles.Count) files)"
272+
Write-Host "[$archKey] Using reference list from $($reference.SourceDescription) ($($expectedFiles.Count) files)"
181273

182274
$msix = Get-ChildItem $bundleDir -Filter "*${archKey}*.msix" -Recurse | Select-Object -First 1
183275
if (-not $msix) {
@@ -207,15 +299,20 @@ foreach ($arch in $Architectures) {
207299
$source = Get-ChildItem $depsArchDir -Recurse -Filter $fileName -File | Select-Object -First 1
208300
}
209301
if (-not $source) {
210-
$fallbackUrl = "https://raw.githubusercontent.com/${UpstreamRepo}/${UpstreamRef}/${upstreamReferencePathForArch}/${fileName}"
211-
Write-Warning "Release payload missing '$fileName' for $arch. Downloading fallback from upstream reference."
212-
try {
213-
Invoke-WebRequest -Uri $fallbackUrl -OutFile $destinationFile -Headers $Headers
214-
continue
215-
}
216-
catch {
217-
throw "Required upstream file '$fileName' not found for $arch and fallback download failed: $fallbackUrl"
302+
if (-not [string]::IsNullOrWhiteSpace($UpstreamRepo) -and -not [string]::IsNullOrWhiteSpace($UpstreamReferencePath)) {
303+
$upstreamReferencePathForArch = Resolve-UpstreamReferencePathForArchitecture -BasePath $UpstreamReferencePath -Architecture $archKey
304+
$fallbackUrl = "https://raw.githubusercontent.com/${UpstreamRepo}/${UpstreamRef}/${upstreamReferencePathForArch}/${fileName}"
305+
Write-Warning "Release payload missing '$fileName' for $arch. Downloading fallback from upstream reference."
306+
try {
307+
Invoke-WebRequest -Uri $fallbackUrl -OutFile $destinationFile -Headers $Headers
308+
continue
309+
}
310+
catch {
311+
throw "Required upstream file '$fileName' not found for $arch and fallback download failed: $fallbackUrl"
312+
}
218313
}
314+
315+
throw "Required file '$fileName' not found for $arch in the winget release payload."
219316
}
220317

221318
Copy-Item $source.FullName $destinationFile -Force

0 commit comments

Comments
 (0)