Deleted Test-WinUtilPackageManager.ps1 + custom winget and choco installs + remove winget/choco enums and exeptions (#4606)

* Update Invoke-WPFGetInstalled.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Delete functions/private/Test-WinUtilPackageManager.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilChoco.ps1

* Update Invoke-WPFGetInstalled.ps1

* Update Invoke-WPFGetInstalled.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Fixed lastrun.json

* refactor: remove PackageManagers enum and unused custom exception classes

* Update Invoke-WPFUIElements.ps1

* Update Get-WinUtilSelectedPackages.ps1

* Update Set-Preferences.ps1

* Update main.ps1

* Complete package manager enum removal

Use string package-manager preferences throughout the remaining helpers and focused tests. Restore the existing Winget install flow and package-manager probe helper so PR 4606 keeps the current WinGet repair method.

* Fix string keyed package split

---------

Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
Gabi
2026-07-02 12:50:57 -05:00
committed by GitHub
co-authored by Chris Titus
parent d45c62e470
commit 727ba52a4d
11 changed files with 52 additions and 124 deletions
@@ -4,7 +4,7 @@ function Get-WinUtilPackageLogSummary {
[object[]]$Packages, [object[]]$Packages,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[PackageManagers]$Preference [string]$Preference
) )
@($Packages | ForEach-Object { @($Packages | ForEach-Object {
@@ -17,7 +17,7 @@ function Get-WinUtilPackageLogSummary {
$packageName = "Unknown package" $packageName = "Unknown package"
} }
if ($Preference -eq [PackageManagers]::Choco -and -not [string]::IsNullOrWhiteSpace([string]$package.choco) -and $package.choco -ne "na") { if ($Preference -eq "Choco" -and -not [string]::IsNullOrWhiteSpace([string]$package.choco) -and $package.choco -ne "na") {
"$packageName (choco: $($package.choco))" "$packageName (choco: $($package.choco))"
} elseif (-not [string]::IsNullOrWhiteSpace([string]$package.winget) -and $package.winget -ne "na") { } elseif (-not [string]::IsNullOrWhiteSpace([string]$package.winget) -and $package.winget -ne "na") {
"$packageName (winget: $($package.winget))" "$packageName (winget: $($package.winget))"
@@ -5,7 +5,7 @@ function Get-WinUtilSelectedPackages {
[object] $PackageList, [object] $PackageList,
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[PackageManagers] $Preference [string] $Preference
) )
if ($PackageList.count -eq 1) { if ($PackageList.count -eq 1) {
@@ -17,8 +17,8 @@ function Get-WinUtilSelectedPackages {
$packagesWinget = [System.Collections.ArrayList]::new() $packagesWinget = [System.Collections.ArrayList]::new()
$packagesChoco = [System.Collections.ArrayList]::new() $packagesChoco = [System.Collections.ArrayList]::new()
$packages = @{ $packages = @{
([PackageManagers]::Winget) = $packagesWinget Winget = $packagesWinget
([PackageManagers]::Choco) = $packagesChoco Choco = $packagesChoco
} }
function Add-PackageId { function Add-PackageId {
+4 -13
View File
@@ -1,16 +1,7 @@
function Install-WinUtilChoco { function Install-WinUtilChoco {
if (-not (Get-Command -Name choco)) {
<# Write-Host "Chocolatey is not installed. Installing now..."
$installScript = Invoke-WebRequest -Uri https://community.chocolatey.org/install.ps1 -UseBasicParsing
.SYNOPSIS Invoke-Command -ScriptBlock ([scriptblock]::Create($installScript.Content))
Installs Chocolatey if it is not already installed
#>
if ((Test-WinUtilPackageManager -choco) -eq "installed") {
return
} }
Write-Host "Chocolatey is not installed. Installing now..."
$installScript = Invoke-WebRequest -Uri https://community.chocolatey.org/install.ps1 -UseBasicParsing
Invoke-Command -ScriptBlock ([scriptblock]::Create($installScript.Content))
} }
-8
View File
@@ -60,14 +60,6 @@ function Set-Preferences{
if ($null -eq $sync.preferences.packagemanager) { if ($null -eq $sync.preferences.packagemanager) {
$sync.preferences.packagemanager = "Winget" $sync.preferences.packagemanager = "Winget"
} }
# convert packagemanager to enum
if ($sync.preferences.packagemanager -eq "Choco") {
$sync.preferences.packagemanager = [PackageManagers]::Choco
}
elseif ($sync.preferences.packagemanager -eq "Winget") {
$sync.preferences.packagemanager = [PackageManagers]::Winget
}
} }
$iniPath = "$winutildir\preferences.ini" $iniPath = "$winutildir\preferences.ini"
+1 -1
View File
@@ -23,7 +23,7 @@ function Invoke-WPFGetInstalled {
Invoke-WPFRunspace -ParameterList @(("managerPreference", $managerPreference),("checkbox", $checkbox)) -ScriptBlock { Invoke-WPFRunspace -ParameterList @(("managerPreference", $managerPreference),("checkbox", $checkbox)) -ScriptBlock {
param ( param (
[string]$checkbox, [string]$checkbox,
[PackageManagers]$managerPreference [string]$managerPreference
) )
$sync.ProcessRunning = $true $sync.ProcessRunning = $true
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Indeterminate" } Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Indeterminate" }
+2 -2
View File
@@ -29,8 +29,8 @@ function Invoke-WPFInstall {
$packagesSorted = Get-WinUtilSelectedPackages -PackageList $PackagesToInstall -Preference $ManagerPreference $packagesSorted = Get-WinUtilSelectedPackages -PackageList $PackagesToInstall -Preference $ManagerPreference
$packagesWinget = $packagesSorted[[PackageManagers]::Winget] $packagesWinget = $packagesSorted['Winget']
$packagesChoco = $packagesSorted[[PackageManagers]::Choco] $packagesChoco = $packagesSorted['Choco']
Write-WinUtilLog -Component "Install" -Message "Install package manager split: winget=$(@($packagesWinget).Count), choco=$(@($packagesChoco).Count)" Write-WinUtilLog -Component "Install" -Message "Install package manager split: winget=$(@($packagesWinget).Count), choco=$(@($packagesChoco).Count)"
try { try {
+3 -2
View File
@@ -39,8 +39,9 @@ function Invoke-WPFUnInstall {
param($PackagesToUninstall, $ManagerPreference) param($PackagesToUninstall, $ManagerPreference)
$packagesSorted = Get-WinUtilSelectedPackages -PackageList $PackagesToUninstall -Preference $ManagerPreference $packagesSorted = Get-WinUtilSelectedPackages -PackageList $PackagesToUninstall -Preference $ManagerPreference
$packagesWinget = $packagesSorted[[PackageManagers]::Winget]
$packagesChoco = $packagesSorted[[PackageManagers]::Choco] $packagesWinget = $packagesSorted['Winget']
$packagesChoco = $packagesSorted['Choco']
Write-WinUtilLog -Component "Uninstall" -Message "Uninstall package manager split: winget=$(@($packagesWinget).Count), choco=$(@($packagesChoco).Count)" Write-WinUtilLog -Component "Uninstall" -Message "Uninstall package manager split: winget=$(@($packagesWinget).Count), choco=$(@($packagesChoco).Count)"
try { try {
+14 -24
View File
@@ -5,16 +5,6 @@
BeforeAll { BeforeAll {
$script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path $script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
if (-not ("PackageManagers" -as [type])) {
Add-Type @"
public enum PackageManagers
{
Winget,
Choco
}
"@
}
. (Join-Path $script:repoRoot "functions\private\Get-WinUtilPackageLogSummary.ps1") . (Join-Path $script:repoRoot "functions\private\Get-WinUtilPackageLogSummary.ps1")
. (Join-Path $script:repoRoot "functions\public\Invoke-WPFInstall.ps1") . (Join-Path $script:repoRoot "functions\public\Invoke-WPFInstall.ps1")
. (Join-Path $script:repoRoot "functions\public\Invoke-WPFUnInstall.ps1") . (Join-Path $script:repoRoot "functions\public\Invoke-WPFUnInstall.ps1")
@@ -26,7 +16,7 @@ public enum PackageManagers
param($ArgumentList, $ParameterList, [scriptblock]$ScriptBlock) param($ArgumentList, $ParameterList, [scriptblock]$ScriptBlock)
} }
function Get-WinUtilSelectedPackages { function Get-WinUtilSelectedPackages {
param($PackageList, [PackageManagers]$Preference) param($PackageList, [string]$Preference)
} }
function Show-WPFInstallAppBusy { function Show-WPFInstallAppBusy {
param($text) param($text)
@@ -82,7 +72,7 @@ public enum PackageManagers
ProcessRunning = $ProcessRunning ProcessRunning = $ProcessRunning
selectedApps = $selectedApps selectedApps = $selectedApps
preferences = [pscustomobject]@{ preferences = [pscustomobject]@{
packagemanager = [PackageManagers]::Winget packagemanager = "Winget"
} }
configs = @{ configs = @{
applicationsHashtable = $applications applicationsHashtable = $applications
@@ -97,15 +87,15 @@ public enum PackageManagers
) )
$packages = @{} $packages = @{}
$packages[[PackageManagers]::Winget] = [System.Collections.Generic.List[string]]::new() $packages["Winget"] = [System.Collections.Generic.List[string]]::new()
$packages[[PackageManagers]::Choco] = [System.Collections.Generic.List[string]]::new() $packages["Choco"] = [System.Collections.Generic.List[string]]::new()
foreach ($package in $Winget) { foreach ($package in $Winget) {
$null = $packages[[PackageManagers]::Winget].Add($package) $null = $packages["Winget"].Add($package)
} }
foreach ($package in $Choco) { foreach ($package in $Choco) {
$null = $packages[[PackageManagers]::Choco].Add($package) $null = $packages["Choco"].Add($package)
} }
$packages $packages
@@ -145,7 +135,7 @@ Describe "Invoke-WPFInstall entrypoint" {
@($ParameterList[0][1]).Count -eq 1 -and @($ParameterList[0][1]).Count -eq 1 -and
@($ParameterList[0][1])[0].winget -eq "Git.Git" -and @($ParameterList[0][1])[0].winget -eq "Git.Git" -and
$ParameterList[1][0] -eq "ManagerPreference" -and $ParameterList[1][0] -eq "ManagerPreference" -and
$ParameterList[1][1] -eq [PackageManagers]::Winget $ParameterList[1][1] -eq "Winget"
} }
Should -Invoke -CommandName Show-WinUtilMessage -Times 0 -Exactly Should -Invoke -CommandName Show-WinUtilMessage -Times 0 -Exactly
Should -Invoke -CommandName Write-WinUtilLog -Times 1 -Exactly -ParameterFilter { Should -Invoke -CommandName Write-WinUtilLog -Times 1 -Exactly -ParameterFilter {
@@ -217,10 +207,10 @@ Describe "Invoke-WPFInstall runspace body" {
It "installs split winget and choco packages and cleans up on success" { It "installs split winget and choco packages and cleans up on success" {
Invoke-WPFInstall Invoke-WPFInstall
& $script:capturedInstallScriptBlock -PackagesToInstall @($script:package) -ManagerPreference ([PackageManagers]::Winget) & $script:capturedInstallScriptBlock -PackagesToInstall @($script:package) -ManagerPreference "Winget"
Should -Invoke -CommandName Get-WinUtilSelectedPackages -Times 1 -Exactly -ParameterFilter { Should -Invoke -CommandName Get-WinUtilSelectedPackages -Times 1 -Exactly -ParameterFilter {
@($PackageList).Count -eq 1 -and $Preference -eq [PackageManagers]::Winget @($PackageList).Count -eq 1 -and $Preference -eq "Winget"
} }
Should -Invoke -CommandName Show-WPFInstallAppBusy -Times 1 -Exactly -ParameterFilter { Should -Invoke -CommandName Show-WPFInstallAppBusy -Times 1 -Exactly -ParameterFilter {
$text -eq "Installing apps..." $text -eq "Installing apps..."
@@ -245,7 +235,7 @@ Describe "Invoke-WPFInstall runspace body" {
Invoke-WPFInstall Invoke-WPFInstall
& $script:capturedInstallScriptBlock -PackagesToInstall @($script:package) -ManagerPreference ([PackageManagers]::Winget) & $script:capturedInstallScriptBlock -PackagesToInstall @($script:package) -ManagerPreference "Winget"
Should -Invoke -CommandName Hide-WPFInstallAppBusy -Times 1 -Exactly Should -Invoke -CommandName Hide-WPFInstallAppBusy -Times 1 -Exactly
Should -Invoke -CommandName Invoke-WPFUIThread -Times 1 -Exactly -ParameterFilter { Should -Invoke -CommandName Invoke-WPFUIThread -Times 1 -Exactly -ParameterFilter {
@@ -298,7 +288,7 @@ Describe "Invoke-WPFUnInstall entrypoint" {
@($ParameterList[0][1]).Count -eq 1 -and @($ParameterList[0][1]).Count -eq 1 -and
@($ParameterList[0][1])[0].winget -eq "Git.Git" -and @($ParameterList[0][1])[0].winget -eq "Git.Git" -and
$ParameterList[1][0] -eq "ManagerPreference" -and $ParameterList[1][0] -eq "ManagerPreference" -and
$ParameterList[1][1] -eq [PackageManagers]::Winget $ParameterList[1][1] -eq "Winget"
} }
Should -Invoke -CommandName Write-WinUtilLog -Times 1 -Exactly -ParameterFilter { Should -Invoke -CommandName Write-WinUtilLog -Times 1 -Exactly -ParameterFilter {
$Component -eq "Uninstall" -and $Component -eq "Uninstall" -and
@@ -374,10 +364,10 @@ Describe "Invoke-WPFUnInstall runspace body" {
It "uninstalls split winget and choco packages and cleans up on success" { It "uninstalls split winget and choco packages and cleans up on success" {
Invoke-WPFUnInstall -PackagesToUninstall @($script:package) Invoke-WPFUnInstall -PackagesToUninstall @($script:package)
& $script:capturedUninstallScriptBlock -PackagesToUninstall @($script:package) -ManagerPreference ([PackageManagers]::Winget) & $script:capturedUninstallScriptBlock -PackagesToUninstall @($script:package) -ManagerPreference "Winget"
Should -Invoke -CommandName Get-WinUtilSelectedPackages -Times 1 -Exactly -ParameterFilter { Should -Invoke -CommandName Get-WinUtilSelectedPackages -Times 1 -Exactly -ParameterFilter {
@($PackageList).Count -eq 1 -and $Preference -eq [PackageManagers]::Winget @($PackageList).Count -eq 1 -and $Preference -eq "Winget"
} }
Should -Invoke -CommandName Show-WPFInstallAppBusy -Times 1 -Exactly -ParameterFilter { Should -Invoke -CommandName Show-WPFInstallAppBusy -Times 1 -Exactly -ParameterFilter {
$text -eq "Uninstalling apps..." $text -eq "Uninstalling apps..."
@@ -400,7 +390,7 @@ Describe "Invoke-WPFUnInstall runspace body" {
Invoke-WPFUnInstall -PackagesToUninstall @($script:package) Invoke-WPFUnInstall -PackagesToUninstall @($script:package)
& $script:capturedUninstallScriptBlock -PackagesToUninstall @($script:package) -ManagerPreference ([PackageManagers]::Winget) & $script:capturedUninstallScriptBlock -PackagesToUninstall @($script:package) -ManagerPreference "Winget"
Should -Invoke -CommandName Hide-WPFInstallAppBusy -Times 1 -Exactly Should -Invoke -CommandName Hide-WPFInstallAppBusy -Times 1 -Exactly
Should -Invoke -CommandName Invoke-WPFUIThread -Times 1 -Exactly -ParameterFilter { Should -Invoke -CommandName Invoke-WPFUIThread -Times 1 -Exactly -ParameterFilter {
+15 -25
View File
@@ -5,16 +5,6 @@
BeforeAll { BeforeAll {
$script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path $script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
if (-not ("PackageManagers" -as [type])) {
Add-Type @"
public enum PackageManagers
{
Winget,
Choco
}
"@
}
. (Join-Path $script:repoRoot "functions\private\Get-WinUtilSelectedPackages.ps1") . (Join-Path $script:repoRoot "functions\private\Get-WinUtilSelectedPackages.ps1")
. (Join-Path $script:repoRoot "functions\private\Test-WinUtilPackageManager.ps1") . (Join-Path $script:repoRoot "functions\private\Test-WinUtilPackageManager.ps1")
. (Join-Path $script:repoRoot "functions\private\Install-WinUtilProgramWinget.ps1") . (Join-Path $script:repoRoot "functions\private\Install-WinUtilProgramWinget.ps1")
@@ -35,10 +25,10 @@ Describe "Get-WinUtilSelectedPackages" {
[pscustomobject]@{ winget = "VideoLAN.VLC"; choco = "vlc" } [pscustomobject]@{ winget = "VideoLAN.VLC"; choco = "vlc" }
) )
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference ([PackageManagers]::Winget) $result = Get-WinUtilSelectedPackages -PackageList $packages -Preference "Winget"
(@($result[[PackageManagers]::Winget]) -join "|") | Should -Be "Git.Git|VideoLAN.VLC" (@($result["Winget"]) -join "|") | Should -Be "Git.Git|VideoLAN.VLC"
@($result[[PackageManagers]::Choco]).Count | Should -Be 0 @($result["Choco"]).Count | Should -Be 0
} }
It "uses choco IDs and falls back to winget for na or missing choco IDs" { It "uses choco IDs and falls back to winget for na or missing choco IDs" {
@@ -48,10 +38,10 @@ Describe "Get-WinUtilSelectedPackages" {
[pscustomobject]@{ winget = "Mozilla.Firefox" } [pscustomobject]@{ winget = "Mozilla.Firefox" }
) )
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference ([PackageManagers]::Choco) $result = Get-WinUtilSelectedPackages -PackageList $packages -Preference "Choco"
(@($result[[PackageManagers]::Choco]) -join "|") | Should -Be "git" (@($result["Choco"]) -join "|") | Should -Be "git"
(@($result[[PackageManagers]::Winget]) -join "|") | Should -Be "VideoLAN.VLC|Mozilla.Firefox" (@($result["Winget"]) -join "|") | Should -Be "VideoLAN.VLC|Mozilla.Firefox"
} }
It "skips blank, na, and missing package IDs" { It "skips blank, na, and missing package IDs" {
@@ -62,10 +52,10 @@ Describe "Get-WinUtilSelectedPackages" {
[pscustomobject]@{ winget = " " } [pscustomobject]@{ winget = " " }
) )
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference ([PackageManagers]::Winget) $result = Get-WinUtilSelectedPackages -PackageList $packages -Preference "Winget"
@($result[[PackageManagers]::Winget]).Count | Should -Be 0 @($result["Winget"]).Count | Should -Be 0
@($result[[PackageManagers]::Choco]).Count | Should -Be 0 @($result["Choco"]).Count | Should -Be 0
} }
It "deduplicates package IDs" { It "deduplicates package IDs" {
@@ -75,17 +65,17 @@ Describe "Get-WinUtilSelectedPackages" {
[pscustomobject]@{ winget = "VideoLAN.VLC"; choco = "vlc" } [pscustomobject]@{ winget = "VideoLAN.VLC"; choco = "vlc" }
) )
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference ([PackageManagers]::Choco) $result = Get-WinUtilSelectedPackages -PackageList $packages -Preference "Choco"
(@($result[[PackageManagers]::Choco]) -join "|") | Should -Be "git|vlc" (@($result["Choco"]) -join "|") | Should -Be "git|vlc"
@($result[[PackageManagers]::Winget]).Count | Should -Be 0 @($result["Winget"]).Count | Should -Be 0
} }
It "returns empty package lists for an empty selection" { It "returns empty package lists for an empty selection" {
$result = Get-WinUtilSelectedPackages -PackageList @() -Preference ([PackageManagers]::Winget) $result = Get-WinUtilSelectedPackages -PackageList @() -Preference "Winget"
@($result[[PackageManagers]::Winget]).Count | Should -Be 0 @($result["Winget"]).Count | Should -Be 0
@($result[[PackageManagers]::Choco]).Count | Should -Be 0 @($result["Choco"]).Count | Should -Be 0
} }
} }
+6 -16
View File
@@ -5,16 +5,6 @@
BeforeAll { BeforeAll {
$script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path $script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
if (-not ("PackageManagers" -as [type])) {
Add-Type @"
public enum PackageManagers
{
Winget,
Choco
}
"@
}
if (-not ("Windows.Media.SolidColorBrush" -as [type])) { if (-not ("Windows.Media.SolidColorBrush" -as [type])) {
Add-Type @" Add-Type @"
namespace Windows.Media namespace Windows.Media
@@ -213,10 +203,10 @@ Describe "Set-Preferences" {
Set-Preferences Set-Preferences
$script:sync.preferences.theme | Should -Be "Auto" $script:sync.preferences.theme | Should -Be "Auto"
$script:sync.preferences.packagemanager | Should -Be ([PackageManagers]::Winget) $script:sync.preferences.packagemanager | Should -Be "Winget"
} }
It "loads saved preferences and converts the package manager to an enum" { It "loads saved preferences and keeps the package manager as a string" {
$script:testRoot = New-WinUtilPreferencesTestRoot $script:testRoot = New-WinUtilPreferencesTestRoot
$global:winutildir = $script:testRoot $global:winutildir = $script:testRoot
New-WinUtilPreferenceSync New-WinUtilPreferenceSync
@@ -228,7 +218,7 @@ Describe "Set-Preferences" {
Set-Preferences Set-Preferences
$script:sync.preferences.theme | Should -Be "Dark" $script:sync.preferences.theme | Should -Be "Dark"
$script:sync.preferences.packagemanager | Should -Be ([PackageManagers]::Choco) $script:sync.preferences.packagemanager | Should -Be "Choco"
} }
It "saves current preferences to preferences.ini" { It "saves current preferences to preferences.ini" {
@@ -236,7 +226,7 @@ Describe "Set-Preferences" {
$global:winutildir = $script:testRoot $global:winutildir = $script:testRoot
New-WinUtilPreferenceSync -Preferences @{ New-WinUtilPreferenceSync -Preferences @{
theme = "Light" theme = "Light"
packagemanager = [PackageManagers]::Winget packagemanager = "Winget"
} }
Set-Preferences -save Set-Preferences -save
@@ -256,7 +246,7 @@ Describe "Set-Preferences" {
Set-Preferences Set-Preferences
$script:sync.preferences.theme | Should -Be "Light" $script:sync.preferences.theme | Should -Be "Light"
$script:sync.preferences.packagemanager | Should -Be ([PackageManagers]::Choco) $script:sync.preferences.packagemanager | Should -Be "Choco"
Test-Path (Join-Path $script:testRoot "LightTheme.ini") | Should -BeFalse Test-Path (Join-Path $script:testRoot "LightTheme.ini") | Should -BeFalse
Test-Path (Join-Path $script:testRoot "preferChocolatey.ini") | Should -BeFalse Test-Path (Join-Path $script:testRoot "preferChocolatey.ini") | Should -BeFalse
} }
@@ -270,7 +260,7 @@ Describe "Set-Preferences" {
Set-Preferences Set-Preferences
$script:sync.preferences.theme | Should -Be "Auto" $script:sync.preferences.theme | Should -Be "Auto"
$script:sync.preferences.packagemanager | Should -Be ([PackageManagers]::Choco) $script:sync.preferences.packagemanager | Should -Be "Choco"
} }
} }
+2 -28
View File
@@ -20,32 +20,6 @@ CCC::::::::::::C T:::::::::T T:::::::::T
=====Windows Toolbox===== =====Windows Toolbox=====
"@ "@
# Create enums
Add-Type @"
public enum PackageManagers
{
Winget,
Choco
}
"@
# Create classes for different exceptions
class WingetFailedInstall : Exception {
[string]$additionalData
WingetFailedInstall($Message) : base($Message) {}
}
class ChocoFailedInstall : Exception {
[string]$additionalData
ChocoFailedInstall($Message) : base($Message) {}
}
class GenericException : Exception {
[string]$additionalData
GenericException($Message) : base($Message) {}
}
# Load the configuration files # Load the configuration files
$sync.configs.applicationsHashtable = @{} $sync.configs.applicationsHashtable = @{}
@@ -165,11 +139,11 @@ $xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"]
#Persist Package Manager preference across winutil restarts #Persist Package Manager preference across winutil restarts
$sync.ChocoRadioButton.Add_Checked({ $sync.ChocoRadioButton.Add_Checked({
$sync.preferences.packagemanager = [PackageManagers]::Choco $sync.preferences.packagemanager = "Choco"
Set-Preferences -save Set-Preferences -save
}) })
$sync.WingetRadioButton.Add_Checked({ $sync.WingetRadioButton.Add_Checked({
$sync.preferences.packagemanager = [PackageManagers]::Winget $sync.preferences.packagemanager = "Winget"
Set-Preferences -save Set-Preferences -save
}) })