mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-04-05 22:28:31 +00:00
Fix import/export functionality (#4131)
* fix: cast selections to string to prevent PSCustomObject type issues * fix(presets): clear existing selections before importing to replace state instead of merging * refactor(impex): warn user when exporting empty selections or importing empty config
This commit is contained in:
@@ -44,7 +44,13 @@ function Invoke-WPFImpex {
|
||||
try {
|
||||
$Config = ConfigDialog
|
||||
if ($Config) {
|
||||
$allConfs = $sync.selectedApps + $sync.selectedTweaks + $sync.selectedToggles + $sync.selectedFeatures
|
||||
$allConfs = ($sync.selectedApps + $sync.selectedTweaks + $sync.selectedToggles + $sync.selectedFeatures) | ForEach-Object { [string]$_ }
|
||||
if (-not $allConfs) {
|
||||
[System.Windows.MessageBox]::Show(
|
||||
"No settings are selected to export. Please select at least one app, tweak, toggle, or feature before exporting.",
|
||||
"Nothing to Export", "OK", "Warning")
|
||||
return
|
||||
}
|
||||
$jsonFile = $allConfs | ConvertTo-Json
|
||||
$jsonFile | Out-File $Config -Force
|
||||
"iex ""& { `$(irm https://christitus.com/win) } -Config '$Config'""" | Set-Clipboard
|
||||
@@ -70,6 +76,21 @@ function Invoke-WPFImpex {
|
||||
# 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 (-not $flattenedJson) {
|
||||
[System.Windows.MessageBox]::Show(
|
||||
"The selected file contains no settings to import. No changes have been made.",
|
||||
"Empty Configuration", "OK", "Warning")
|
||||
return
|
||||
}
|
||||
|
||||
# Clear all existing selections before importing so the import replaces
|
||||
# the current state rather than merging with it
|
||||
$sync.selectedApps = [System.Collections.Generic.List[string]]::new()
|
||||
$sync.selectedTweaks = [System.Collections.Generic.List[string]]::new()
|
||||
$sync.selectedToggles = [System.Collections.Generic.List[string]]::new()
|
||||
$sync.selectedFeatures = [System.Collections.Generic.List[string]]::new()
|
||||
|
||||
Update-WinUtilSelections -flatJson $flattenedJson
|
||||
|
||||
if (!$PARAM_NOUI) {
|
||||
|
||||
Reference in New Issue
Block a user