mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-08-09 17:41:14 +10:00
* 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>
74 lines
2.1 KiB
PowerShell
74 lines
2.1 KiB
PowerShell
function Set-Preferences{
|
|
|
|
param(
|
|
[switch]$save=$false
|
|
)
|
|
|
|
# TODO delete this function sometime later
|
|
function Clean-OldPrefs{
|
|
if (Test-Path -Path "$winutildir\LightTheme.ini") {
|
|
$sync.preferences.theme = "Light"
|
|
Remove-Item -Path "$winutildir\LightTheme.ini"
|
|
}
|
|
|
|
if (Test-Path -Path "$winutildir\DarkTheme.ini") {
|
|
$sync.preferences.theme = "Dark"
|
|
Remove-Item -Path "$winutildir\DarkTheme.ini"
|
|
}
|
|
|
|
# check old prefs, if its first line has no =, then absorb it as pm
|
|
if (Test-Path -Path $iniPath) {
|
|
$oldPM = Get-Content $iniPath
|
|
if ($oldPM -notlike "*=*") {
|
|
$sync.preferences.packagemanager = $oldPM
|
|
}
|
|
}
|
|
|
|
if (Test-Path -Path "$winutildir\preferChocolatey.ini") {
|
|
$sync.preferences.packagemanager = "Choco"
|
|
Remove-Item -Path "$winutildir\preferChocolatey.ini"
|
|
}
|
|
}
|
|
|
|
function Save-Preferences{
|
|
$ini = ""
|
|
foreach($key in $sync.preferences.Keys) {
|
|
$pref = "$($key)=$($sync.preferences.$key)"
|
|
$ini = $ini + $pref + "`r`n"
|
|
}
|
|
$ini | Out-File $iniPath
|
|
}
|
|
|
|
function Load-Preferences{
|
|
Clean-OldPrefs
|
|
if (Test-Path -Path $iniPath) {
|
|
$iniData = Get-Content "$winutildir\preferences.ini"
|
|
foreach ($line in $iniData) {
|
|
if ($line -like "*=*") {
|
|
$arr = $line -split "=",-2
|
|
$key = $arr[0] -replace "\s",""
|
|
$value = $arr[1] -replace "\s",""
|
|
$sync.preferences.$key = $value
|
|
}
|
|
}
|
|
}
|
|
|
|
# write defaults in case preferences dont exist
|
|
if ($null -eq $sync.preferences.theme) {
|
|
$sync.preferences.theme = "Auto"
|
|
}
|
|
if ($null -eq $sync.preferences.packagemanager) {
|
|
$sync.preferences.packagemanager = "Winget"
|
|
}
|
|
}
|
|
|
|
$iniPath = "$winutildir\preferences.ini"
|
|
|
|
if ($save) {
|
|
Save-Preferences
|
|
}
|
|
else {
|
|
Load-Preferences
|
|
}
|
|
}
|