Skip to content

Commit cd8c745

Browse files
committed
Fix error 2
1 parent 4fd7342 commit cd8c745

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

Sources/Winget-AutoUpdate/Winget-Install.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,13 @@ function Test-ModsInstall ($AppID) {
101101
$ModsCustom = (Get-Content "$Mods\$AppID-custom.txt" -Raw).Trim()
102102
}
103103
if (Test-Path "$Mods\$AppID-arguments.txt") {
104-
$ModsArguments = (Get-Content "$Mods\$AppID-arguments.txt" -Raw).Trim()
104+
# Read file and filter out comments and empty lines
105+
$lines = Get-Content "$Mods\$AppID-arguments.txt" | Where-Object {
106+
$_.Trim() -ne "" -and -not $_.TrimStart().StartsWith("#")
107+
}
108+
if ($lines) {
109+
$ModsArguments = ($lines -join " ").Trim()
110+
}
105111
}
106112
if (Test-Path "$Mods\$AppID-install.ps1") {
107113
$ModsInstall = "$Mods\$AppID-install.ps1"
@@ -160,7 +166,7 @@ function Install-App ($AppID, $AppArgs) {
160166
}
161167
elseif ($ModsArguments) {
162168
Write-ToLog "-> Arguments (winget-level): $ModsArguments" # Winget parameters with -h
163-
$argArray = Parse-WingetArguments $ModsArguments
169+
$argArray = ConvertTo-WingetArgumentArray $ModsArguments
164170
$WingetArgs = @("install", "--id", $AppID, "-e", "--accept-package-agreements", "--accept-source-agreements", "-s", "winget") + $argArray + @("-h") + @($AppArgs -split " ")
165171
}
166172
else {

Sources/Winget-AutoUpdate/functions/ConvertTo-WingetArgumentArray.ps1

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
Array of individual argument strings
1515
1616
.EXAMPLE
17-
Parse-WingetArguments "--skip-dependencies"
17+
ConvertTo-WingetArgumentArray "--skip-dependencies"
1818
Returns: @("--skip-dependencies")
1919
2020
.EXAMPLE
21-
Parse-WingetArguments '--locale "en-US" --architecture x64'
21+
ConvertTo-WingetArgumentArray '--locale "en-US" --architecture x64'
2222
Returns: @("--locale", "en-US", "--architecture", "x64")
2323
2424
.EXAMPLE
25-
Parse-WingetArguments "--override '-sfx_nu /sAll /msi EULA_ACCEPT=YES'"
25+
ConvertTo-WingetArgumentArray "--override '-sfx_nu /sAll /msi EULA_ACCEPT=YES'"
2626
Returns: @("--override", "-sfx_nu /sAll /msi EULA_ACCEPT=YES")
2727
#>
28-
function Parse-WingetArguments {
28+
function ConvertTo-WingetArgumentArray {
2929
[CmdletBinding()]
3030
[OutputType([string[]])]
3131
param(
@@ -51,10 +51,12 @@ function Parse-WingetArguments {
5151
$pattern = '(?:"([^"]*)"|''([^'']*)''|(\S+))'
5252

5353
try {
54-
$matches = [regex]::Matches($ArgumentString, $pattern)
54+
# Use [regex]::Matches() to find all argument tokens
55+
$regex = [regex]::new($pattern)
56+
$regexMatches = $regex.Matches($ArgumentString)
5557

5658
$result = @()
57-
foreach ($match in $matches) {
59+
foreach ($match in $regexMatches) {
5860
# Get the captured value from whichever group matched
5961
$value = if ($match.Groups[1].Success) {
6062
# Double-quoted value
@@ -82,6 +84,7 @@ function Parse-WingetArguments {
8284
Write-ToLog "Falling back to simple space split" "Yellow"
8385

8486
# Fallback to simple split if regex parsing fails
85-
return $ArgumentString.Trim() -split '\s+'
87+
$fallbackResult = $ArgumentString.Trim() -split '\s+'
88+
return $fallbackResult
8689
}
8790
}

Sources/Winget-AutoUpdate/functions/Test-Mods.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ function Test-Mods ($app) {
3636
if (Test-Path "$Mods\$app-preinstall.ps1") { $result.PreInstall = "$Mods\$app-preinstall.ps1" }
3737
if (Test-Path "$Mods\$app-override.txt") { $result.Override = (Get-Content "$Mods\$app-override.txt" -Raw).Trim() }
3838
if (Test-Path "$Mods\$app-custom.txt") { $result.Custom = (Get-Content "$Mods\$app-custom.txt" -Raw).Trim() }
39-
if (Test-Path "$Mods\$app-arguments.txt") { $result.Arguments = (Get-Content "$Mods\$app-arguments.txt" -Raw).Trim() }
39+
if (Test-Path "$Mods\$app-arguments.txt") {
40+
# Read file and filter out comments and empty lines
41+
$lines = Get-Content "$Mods\$app-arguments.txt" | Where-Object {
42+
$_.Trim() -ne "" -and -not $_.TrimStart().StartsWith("#")
43+
}
44+
if ($lines) {
45+
$result.Arguments = ($lines -join " ").Trim()
46+
}
47+
}
4048
if (Test-Path "$Mods\$app-install.ps1") {
4149
$result.Install = "$Mods\$app-install.ps1"
4250
$result.Upgrade = "$Mods\$app-install.ps1"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Function Update-App ($app) {
2424
}
2525
elseif ($ModsArguments) {
2626
# Parse arguments respecting quotes and spaces
27-
$argArray = Parse-WingetArguments $ModsArguments
27+
$argArray = ConvertTo-WingetArgumentArray $ModsArguments
2828
return @{ Params = $params + $argArray + "-h"; Log = "$Command (arguments): $ModsArguments" }
2929
}
3030
return @{ Params = $params + "-h"; Log = $Command }

0 commit comments

Comments
 (0)