Skip to content

Commit 2038597

Browse files
authored
Merge pull request #1135 from Salamek/main
fix: Correctly pass value of WingetSourceCustom, Fixes #1043
2 parents 9bc9f4e + fead5a2 commit 2038597

7 files changed

Lines changed: 53 additions & 42 deletions

File tree

.github/workflows/GA_Close-Inactive-Issues.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
permissions:
1313
issues: write
1414
pull-requests: write
15-
contents: write
1615
steps:
1716
- uses: actions/stale@v10.2.0
1817
with:

Sources/Winget-AutoUpdate/Winget-Install.ps1

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<#
22
.SYNOPSIS
33
Install apps with Winget through Intune or SCCM.
4-
(Can be used standalone.) - Deprecated in favor of Winget-AutoUpdate.
54
65
.DESCRIPTION
76
Allow to run Winget in System Context to install your apps.
8-
(https://github.com/Romanitho/Winget-Install) - Deprecated in favor of Winget-AutoUpdate.
97
108
.PARAMETER AppIDs
119
Forward Winget App ID to install. For multiple apps, separate with ",". Case sensitive.
@@ -48,7 +46,8 @@ param(
4846
[Parameter(Mandatory = $False)] [Switch] $Uninstall,
4947
[Parameter(Mandatory = $False)] [String] $LogPath,
5048
[Parameter(Mandatory = $False)] [Switch] $WAUWhiteList,
51-
[Parameter(Mandatory = $False)] [Switch] $AllowUpgrade
49+
[Parameter(Mandatory = $False)] [Switch] $AllowUpgrade,
50+
[Parameter(Mandatory = $False)] [String] $Source = "winget"
5251
)
5352

5453

@@ -76,7 +75,7 @@ else {
7675
#Check if App exists in Winget Repository
7776
function Confirm-Exist ($AppID) {
7877
#Check is app exists in the winget repository
79-
$WingetApp = & $winget show --Id $AppID -e --accept-source-agreements -s winget | Out-String
78+
$WingetApp = & $winget show --Id $AppID -e --accept-source-agreements -s $Source | Out-String
8079

8180
#Return if AppID exists
8281
if ($WingetApp -match [regex]::Escape($AppID)) {
@@ -139,8 +138,8 @@ function Test-ModsUninstall ($AppID) {
139138
}
140139

141140
#Install function
142-
function Install-App ($AppID, $AppArgs) {
143-
$IsInstalled = Confirm-Installation $AppID
141+
function Install-App ($AppID, $AppArgs, $Source = 'winget') {
142+
$IsInstalled = Confirm-Installation $AppID -src $Source
144143
if (!($IsInstalled) -or $AllowUpgrade ) {
145144
#Check if mods exist (or already exist) for preinstall/override/custom/arguments/install/installed
146145
$ModsPreInstall, $ModsOverride, $ModsCustom, $ModsArguments, $ModsInstall, $ModsInstalled = Test-ModsInstall $($AppID)
@@ -159,21 +158,21 @@ function Install-App ($AppID, $AppArgs) {
159158
Write-ToLog "-> Installing $AppID..." "DarkYellow"
160159
if ($ModsOverride) {
161160
Write-ToLog "-> Arguments (overriding default): $ModsOverride" # Without -h (user overrides default)
162-
$WingetArgs = "install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget --override $ModsOverride" -split " "
161+
$WingetArgs = @("install", "--id", $AppID, "-e", "--accept-package-agreements", "--accept-source-agreements", "-s", $Source, "--override", $ModsOverride)
163162
}
164163
elseif ($ModsCustom) {
165164
Write-ToLog "-> Arguments (customizing default): $ModsCustom" # With -h (user customizes default)
166-
$WingetArgs = "install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget -h --custom $ModsCustom" -split " "
165+
$WingetArgs = @("install", "--id", $AppID, "-e", "--accept-package-agreements", "--accept-source-agreements", "-s", $Source, "-h", "--custom", $ModsCustom)
167166
}
168167
elseif ($ModsArguments -or (-not [string]::IsNullOrWhiteSpace($AppArgs))) {
169168
# Prioritize ModsArguments from file over AppArgs from command line
170169
$finalArgs = if ($ModsArguments) { $ModsArguments } else { $AppArgs }
171170
Write-ToLog "-> Arguments (winget-level): $finalArgs" # Winget parameters with -h
172171
$argArray = ConvertTo-WingetArgumentArray $finalArgs
173-
$WingetArgs = @("install", "--id", $AppID, "-e", "--accept-package-agreements", "--accept-source-agreements", "-s", "winget") + $argArray + @("-h")
172+
$WingetArgs = @("install", "--id", $AppID, "-e", "--accept-package-agreements", "--accept-source-agreements", "-s", $Source) + $argArray + @("-h")
174173
}
175174
else {
176-
$WingetArgs = "install --id $AppID -e --accept-package-agreements --accept-source-agreements -s winget -h" -split " "
175+
$WingetArgs = @("install", "--id", $AppID, "-e", "--accept-package-agreements", "--accept-source-agreements", "-s", $Source, "-h")
177176
}
178177

179178
Write-ToLog "-> Running: `"$Winget`" $WingetArgs"
@@ -185,7 +184,7 @@ function Install-App ($AppID, $AppArgs) {
185184
}
186185

187186
#Check if install is ok
188-
$IsInstalled = Confirm-Installation $AppID
187+
$IsInstalled = Confirm-Installation $AppID -src $Source
189188
if ($IsInstalled) {
190189
Write-ToLog "-> $AppID successfully installed." "Green"
191190

@@ -209,8 +208,8 @@ function Install-App ($AppID, $AppArgs) {
209208
}
210209

211210
#Uninstall function
212-
function Uninstall-App ($AppID, $AppArgs) {
213-
$IsInstalled = Confirm-Installation $AppID
211+
function Uninstall-App ($AppID, $AppArgs, $Source = 'winget') {
212+
$IsInstalled = Confirm-Installation $AppID -src $Source
214213
if ($IsInstalled) {
215214
#Check if mods exist (or already exist) for preuninstall/uninstall/uninstalled
216215
$ModsPreUninstall, $ModsUninstall, $ModsUninstalled = Test-ModsUninstall $AppID
@@ -244,7 +243,7 @@ function Uninstall-App ($AppID, $AppArgs) {
244243
}
245244

246245
#Check if uninstall is ok
247-
$IsInstalled = Confirm-Installation $AppID
246+
$IsInstalled = Confirm-Installation $AppID -src $Source
248247
if (!($IsInstalled)) {
249248
Write-ToLog "-> $AppID successfully uninstalled." "Green"
250249
if ($ModsUninstalled) {
@@ -399,14 +398,14 @@ if ($Winget) {
399398

400399
#Install or Uninstall command
401400
if ($Uninstall) {
402-
Uninstall-App $AppID $AppArgs
401+
Uninstall-App $AppID $AppArgs $Source
403402
}
404403
else {
405404
#Check if app exists on Winget Repo
406405
$Exists = Confirm-Exist $AppID
407406
if ($Exists) {
408407
#Install
409-
Install-App $AppID $AppArgs
408+
Install-App $AppID $AppArgs $Source
410409
}
411410
}
412411

Sources/Winget-AutoUpdate/Winget-Upgrade.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ if (Test-Network) {
307307
}
308308
#if app is in "include list", update it
309309
elseif ($toUpdate -contains $app.Id) {
310-
Update-App $app
310+
Update-App $app -src $Script:WingetSourceCustom
311311
}
312312
#if app with wildcard is in "include list", update it
313313
elseif ($toUpdate | Where-Object { $app.Id -like $_ }) {
314314
Write-ToLog "$($app.Name) is wildcard in the include list."
315-
Update-App $app
315+
Update-App $app -src $Script:WingetSourceCustom
316316
}
317317
#else, skip it
318318
else {
@@ -338,7 +338,7 @@ if (Test-Network) {
338338
}
339339
# else, update it
340340
else {
341-
Update-App $app
341+
Update-App $app -src $Script:WingetSourceCustom
342342
}
343343
}
344344
}

Sources/Winget-AutoUpdate/functions/Confirm-Installation.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
.PARAMETER AppVer
99
Expected version prefix.
1010
11+
.PARAMETER src
12+
The WinGet source to query (e.g. "winget", "msstore"). Required; passed
13+
directly to `winget export -s`.
14+
1115
.OUTPUTS
1216
Boolean: True if installed at version.
1317
#>
14-
Function Confirm-Installation ($AppName, $AppVer) {
18+
Function Confirm-Installation ($AppName, $AppVer, $src) {
1519

1620
$JsonFile = "$env:TEMP\InstalledApps.json"
17-
& $Winget export -s winget -o $JsonFile --include-versions | Out-Null
21+
& $Winget export -s $src -o $JsonFile --include-versions | Out-Null
1822

1923
$Packages = (Get-Content $JsonFile -Raw | ConvertFrom-Json).Sources.Packages
2024
$match = $Packages | Where-Object { $_.PackageIdentifier -eq $AppName -and $_.Version -like "$AppVer*" }

Sources/Winget-AutoUpdate/functions/Get-AppInfo.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,25 @@
99
.PARAMETER AppID
1010
The WinGet package identifier to query.
1111
12+
.PARAMETER src
13+
The WinGet source to query (e.g. "winget", "msstore").
14+
1215
.OUTPUTS
1316
String containing the release notes URL, or empty if not found.
1417
1518
.EXAMPLE
16-
$releaseUrl = Get-AppInfo "Microsoft.PowerShell"
19+
$releaseUrl = Get-AppInfo "Microsoft.PowerShell" "winget"
1720
1821
.NOTES
1922
Uses WinGet show command with source agreements accepted.
2023
#>
21-
Function Get-AppInfo ($AppID) {
24+
Function Get-AppInfo ($AppID, $src = 'winget') {
2225

26+
if ([string]::IsNullOrWhiteSpace($src)) {
27+
$src = 'winget'
28+
}
2329
# Query WinGet for application details
24-
$String = & $winget show $AppID --accept-source-agreements -s winget | Out-String
30+
$String = & $winget show $AppID --accept-source-agreements -s $src | Out-String
2531

2632
# Extract Release Notes URL using regex
2733
$ReleaseNote = [regex]::match($String, "(?<=Release Notes Url: )(.*)(?=\n)").Groups[0].Value

Sources/Winget-AutoUpdate/functions/Update-App.ps1

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
99
.PARAMETER app
1010
PSCustomObject with Name, Id, Version, AvailableVersion properties.
11+
12+
.PARAMETER src
13+
The WinGet source to use (e.g. 'winget', 'msstore'). Defaults to 'winget'.
1114
#>
12-
Function Update-App ($app) {
15+
Function Update-App ($app, $src = "winget") {
1316

1417
# Helper function to build winget command parameters
1518
function Get-WingetParams ($Command, $ModsOverride, $ModsCustom, $ModsArguments) {
16-
$params = @($Command, "--id", $app.Id, "-e", "--accept-package-agreements", "--accept-source-agreements", "-s", "winget")
19+
$params = @($Command, "--id", $app.Id, "-e", "--accept-package-agreements", "--accept-source-agreements", "-s", $src)
1720
if ($Command -eq "install") { $params += "--force" }
1821

1922
if ($ModsOverride) {
@@ -50,7 +53,7 @@ Function Update-App ($app) {
5053
}
5154

5255
# Get release notes for notification button
53-
$ReleaseNoteURL = Get-AppInfo $app.Id
56+
$ReleaseNoteURL = Get-AppInfo $app.Id $src
5457
$Button1Text = if ($ReleaseNoteURL) { $NotifLocale.local.outputs.output[10].message } else { $null }
5558

5659
# Send "updating" notification
@@ -80,7 +83,7 @@ Function Update-App ($app) {
8083
& $ModsUpgrade
8184
}
8285

83-
$ConfirmInstall = Confirm-Installation $app.Id $app.AvailableVersion
86+
$ConfirmInstall = Confirm-Installation $app.Id $app.AvailableVersion $src
8487

8588
# Fallback to install if upgrade failed
8689
if (-not $ConfirmInstall) {
@@ -98,7 +101,7 @@ Function Update-App ($app) {
98101
& $ModsInstall
99102
}
100103

101-
$ConfirmInstall = Confirm-Installation $app.Id $app.AvailableVersion
104+
$ConfirmInstall = Confirm-Installation $app.Id $app.AvailableVersion $src
102105
}
103106
}
104107

Sources/Winget-AutoUpdate/mods/_Mods-Functions.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ function Wait-ModsProc ($Wait) {
4949
Return
5050
}
5151

52-
function Install-WingetID ($WingetIDInst) {
52+
function Install-WingetID ($WingetIDInst, $src = 'winget') {
5353
foreach ($app in $WingetIDInst) {
54-
& $Winget install --id $app -e --accept-package-agreements --accept-source-agreements -s winget -h
54+
& $Winget install --id $app -e --accept-package-agreements --accept-source-agreements -s $src -h
5555
}
5656
Return
5757
}
5858

59-
function Uninstall-WingetID ($WingetIDUninst) {
59+
function Uninstall-WingetID ($WingetIDUninst, $src = 'winget') {
6060
foreach ($app in $WingetIDUninst) {
61-
& $Winget uninstall --id $app -e --accept-source-agreements -s winget -h
61+
& $Winget uninstall --id $app -e --accept-source-agreements -s $src -h
6262
}
6363
Return
6464
}
@@ -188,37 +188,37 @@ function Remove-ModsLnk ($Lnk) {
188188
function Add-ProgramsShortcuts ($Shortcuts, $ShortcutsTargets) {
189189
$programsPath = "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs"
190190
$createdCount = 0
191-
191+
192192
# Validate arrays match in length and are not just empty placeholders
193193
if ($Shortcuts.Count -ne $ShortcutsTargets.Count -or ($Shortcuts.Count -eq 1 -and [string]::IsNullOrEmpty($Shortcuts[0]))) {
194194
Return $createdCount
195195
}
196-
196+
197197
# Create WScript.Shell COM object
198198
$WshShell = New-Object -ComObject WScript.Shell -ErrorAction SilentlyContinue
199199
if (!$WshShell) {
200200
Return $createdCount
201201
}
202-
202+
203203
# Iterate through shortcuts
204204
for ($i = 0; $i -lt $Shortcuts.Count; $i++) {
205205
$shortcutName = $Shortcuts[$i]
206206
$targetPath = $ShortcutsTargets[$i]
207-
207+
208208
# Skip empty entries
209209
if ([string]::IsNullOrEmpty($shortcutName) -or [string]::IsNullOrEmpty($targetPath)) {
210210
continue
211211
}
212-
212+
213213
# Construct full shortcut path
214214
$shortcutPath = Join-Path $programsPath "$shortcutName.lnk"
215-
215+
216216
# Create parent directory if it doesn't exist
217217
$shortcutDir = Split-Path $shortcutPath -Parent
218218
if (!(Test-Path $shortcutDir)) {
219219
New-Item -Path $shortcutDir -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null
220220
}
221-
221+
222222
# Verify target exists
223223
if (Test-Path $targetPath) {
224224
# Create shortcut
@@ -232,7 +232,7 @@ function Add-ProgramsShortcuts ($Shortcuts, $ShortcutsTargets) {
232232
$createdCount++
233233
}
234234
}
235-
235+
236236
Return $createdCount
237237
}
238238

0 commit comments

Comments
 (0)