Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion functions/private/Set-WinUtilService.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ Function Set-WinUtilService {

# Service exists, proceed with changing properties -- while handling auto delayed start for PWSH 5
if (($PSVersionTable.PSVersion.Major -lt 7) -and ($StartupType -eq "AutomaticDelayedStart")) {
sc.exe config $Name start=delayed-auto
sc.exe config $Name start= delayed-auto
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if ($LASTEXITCODE -ne 0) {
throw "sc.exe config failed with exit code $LASTEXITCODE"
}
} else {
$service | Set-Service -StartupType $StartupType -ErrorAction Stop
}
Expand Down
6 changes: 3 additions & 3 deletions functions/public/Invoke-WPFFixesUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ function Invoke-WPFFixesUpdate {
if (Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate") {
Write-Progress -Id 0 -Activity "Repairing Windows Update" -Status "Removing WSUS client settings..." -PercentComplete 60
Write-Progress -Id 6 -ParentId 0 -Activity "Removing WSUS client settings" -PercentComplete 0
Start-Process -NoNewWindow -FilePath "REG" -ArgumentList "DELETE", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate", "/v", "AccountDomainSid", "/f" -RedirectStandardError "NUL"
Start-Process -NoNewWindow -FilePath "REG" -ArgumentList "DELETE", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate", "/v", "PingID", "/f" -RedirectStandardError "NUL"
Start-Process -NoNewWindow -FilePath "REG" -ArgumentList "DELETE", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate", "/v", "SusClientId", "/f" -RedirectStandardError "NUL"
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" -Name "AccountDomainSid" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" -Name "PingID" -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" -Name "SusClientId" -ErrorAction SilentlyContinue
Write-Progress -Id 6 -ParentId 0 -Activity "Removing WSUS client settings" -Status "Completed" -PercentComplete 100
}

Expand Down
14 changes: 11 additions & 3 deletions functions/public/Invoke-WPFImpex.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,17 @@ function Invoke-WPFImpex {
Write-Error "Failed to load the JSON file from the specified path or URL: $_"
return
}
# TODO how to handle old style? detected json type then flatten it in a func?
# $flattenedJson = $jsonFile.PSObject.Properties.Where({ $_.Name -ne "Install" }).ForEach({ $_.Value })
$flattenedJson = $jsonFile
if ($null -ne $jsonFile -and $jsonFile.PSObject.Properties['Install']) {
Write-WinUtilLog -Component "Impex" -Message "Detected legacy WinUtil config structure; flattening import object."
$flattenedJson = @()
foreach ($prop in $jsonFile.PSObject.Properties) {
if ($prop.Name -ne "Install" -and $null -ne $prop.Value) {
$flattenedJson += @($prop.Value)
Comment thread
ChrisTitusTech marked this conversation as resolved.
}
}
} else {
$flattenedJson = $jsonFile
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

if (-not $flattenedJson) {
[System.Windows.MessageBox]::Show(
Expand Down
24 changes: 24 additions & 0 deletions pester/ui-state.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,30 @@ Describe "Invoke-WPFImpex import selection state" {
Should -Invoke -CommandName Write-Error -Times 0 -Exactly
}

It "imports legacy selection groups without treating Install metadata as a selection" {
$legacyConfigPath = Join-Path $TestDrive "legacy-config.json"
[ordered]@{
Install = @(
[pscustomobject]@{
winget = "Git.Git"
choco = "git"
}
)
WPFInstall = @("WPFInstallGit")
WPFTweaks = @("WPFTweaksTelemetry")
WPFToggle = @("WPFToggleDarkMode")
WPFFeature = @("WPFFeatureSandbox")
} | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath $legacyConfigPath

Invoke-WPFImpex -type "import" -Config $legacyConfigPath

@($script:sync.selectedApps) | Should -Be @("WPFInstallGit")
@($script:sync.selectedTweaks) | Should -Be @("WPFTweaksTelemetry")
@($script:sync.selectedToggles) | Should -Be @("WPFToggleDarkMode")
@($script:sync.selectedFeatures) | Should -Be @("WPFFeatureSandbox")
Should -Invoke -CommandName Write-Error -Times 0 -Exactly
}

It "preserves selections and does not reset the UI after an invalid import" {
$script:sync.selectedApps.Add("WPFInstallExisting")
$script:sync.selectedTweaks.Add("WPFTweaksExisting")
Expand Down
Loading