mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-04-03 14:06:27 +00:00
Add ability to export/import settings configuration (#522)
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
WindowStyle="None"
|
WindowStyle="None"
|
||||||
AllowsTransparency="True"
|
AllowsTransparency="True"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
Topmost="True"
|
Topmost="False"
|
||||||
ShowInTaskbar="False">
|
ShowInTaskbar="False">
|
||||||
|
|
||||||
<Border BorderBrush="{DynamicResource BorderColor}"
|
<Border BorderBrush="{DynamicResource BorderColor}"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
WindowStyle="None"
|
WindowStyle="None"
|
||||||
AllowsTransparency="True"
|
AllowsTransparency="True"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
Topmost="True"
|
Topmost="False"
|
||||||
ShowInTaskbar="False">
|
ShowInTaskbar="False">
|
||||||
|
|
||||||
<Border BorderBrush="{DynamicResource BorderColor}"
|
<Border BorderBrush="{DynamicResource BorderColor}"
|
||||||
|
|||||||
77
Schemas/ImportExportConfigWindow.xaml
Normal file
77
Schemas/ImportExportConfigWindow.xaml
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
Title="Select Settings to Import/Export"
|
||||||
|
Width="440"
|
||||||
|
SizeToContent="Height"
|
||||||
|
MaxHeight="501"
|
||||||
|
ResizeMode="NoResize"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
WindowStyle="None"
|
||||||
|
AllowsTransparency="True"
|
||||||
|
Background="Transparent"
|
||||||
|
Topmost="False"
|
||||||
|
ShowInTaskbar="False">
|
||||||
|
|
||||||
|
<Border BorderBrush="{DynamicResource BorderColor}"
|
||||||
|
BorderThickness="1"
|
||||||
|
CornerRadius="8"
|
||||||
|
Background="{DynamicResource CardBgColor}"
|
||||||
|
Margin="25">
|
||||||
|
<Border.Effect>
|
||||||
|
<DropShadowEffect Color="Black"
|
||||||
|
Opacity="0.15"
|
||||||
|
BlurRadius="20"
|
||||||
|
ShadowDepth="0"
|
||||||
|
Direction="0"/>
|
||||||
|
</Border.Effect>
|
||||||
|
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<!-- Title Bar -->
|
||||||
|
<Grid Grid.Row="0" x:Name="TitleBar" Height="40" Background="Transparent">
|
||||||
|
<TextBlock x:Name="TitleText"
|
||||||
|
Foreground="{DynamicResource FgColor}"
|
||||||
|
FontSize="16"
|
||||||
|
FontWeight="SemiBold"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Margin="16,0,0,0"/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Content -->
|
||||||
|
<StackPanel Grid.Row="1" x:Name="ContentPanel" Margin="20,12,20,9">
|
||||||
|
<TextBlock x:Name="PromptText"
|
||||||
|
TextWrapping="Wrap"
|
||||||
|
FontSize="14"
|
||||||
|
LineHeight="20"
|
||||||
|
Foreground="{DynamicResource FgColor}"
|
||||||
|
Margin="0,0,0,14"/>
|
||||||
|
<!-- Checkboxes are added dynamically at runtime -->
|
||||||
|
<StackPanel x:Name="CheckboxPanel"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<!-- Button Footer -->
|
||||||
|
<Border Grid.Row="2"
|
||||||
|
Background="{DynamicResource BgColor}"
|
||||||
|
BorderBrush="{DynamicResource BorderColor}"
|
||||||
|
BorderThickness="0,1,0,0"
|
||||||
|
Padding="16,12"
|
||||||
|
CornerRadius="0,0,8,8">
|
||||||
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||||
|
<Button x:Name="OkButton"
|
||||||
|
Content="OK"
|
||||||
|
Height="32" MinWidth="80" Margin="4,0"
|
||||||
|
Style="{DynamicResource PrimaryButtonStyle}"/>
|
||||||
|
<Button x:Name="CancelButton"
|
||||||
|
Content="Cancel"
|
||||||
|
Height="32" MinWidth="80" Margin="4,0"
|
||||||
|
Style="{DynamicResource SecondaryButtonStyle}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</Window>
|
||||||
@@ -649,6 +649,29 @@
|
|||||||
<Button x:Name="MenuBtn" Content="" FontFamily="Segoe Fluent Icons" FontSize="15" Style="{StaticResource TitlebarButton}" ToolTip="Options" AutomationProperties.Name="Options">
|
<Button x:Name="MenuBtn" Content="" FontFamily="Segoe Fluent Icons" FontSize="15" Style="{StaticResource TitlebarButton}" ToolTip="Options" AutomationProperties.Name="Options">
|
||||||
<Button.ContextMenu>
|
<Button.ContextMenu>
|
||||||
<ContextMenu x:Name="MainMenu">
|
<ContextMenu x:Name="MainMenu">
|
||||||
|
<ContextMenu.Resources>
|
||||||
|
<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="Separator">
|
||||||
|
<Setter Property="Margin" Value="4,6"/>
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="Separator">
|
||||||
|
<Border Height="1" Background="{DynamicResource BorderColor}" SnapsToDevicePixels="True" HorizontalAlignment="Stretch"/>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</ContextMenu.Resources>
|
||||||
|
<MenuItem x:Name="ImportConfigBtn" Header="Import config" AutomationProperties.Name="Import configuration">
|
||||||
|
<MenuItem.Icon>
|
||||||
|
<TextBlock Text="" FontFamily="Segoe Fluent Icons" FontSize="16" Foreground="{DynamicResource FgColor}"/>
|
||||||
|
</MenuItem.Icon>
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem x:Name="ExportConfigBtn" Header="Export config" AutomationProperties.Name="Export configuration">
|
||||||
|
<MenuItem.Icon>
|
||||||
|
<TextBlock Text="" FontFamily="Segoe Fluent Icons" FontSize="16" Foreground="{DynamicResource FgColor}"/>
|
||||||
|
</MenuItem.Icon>
|
||||||
|
</MenuItem>
|
||||||
|
<Separator />
|
||||||
<MenuItem x:Name="MenuDocumentation" Header="Documentation" AutomationProperties.Name="Documentation">
|
<MenuItem x:Name="MenuDocumentation" Header="Documentation" AutomationProperties.Name="Documentation">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<TextBlock Text="" FontFamily="Segoe MDL2 Assets" FontSize="16" Foreground="{DynamicResource FgColor}"/>
|
<TextBlock Text="" FontFamily="Segoe MDL2 Assets" FontSize="16" Foreground="{DynamicResource FgColor}"/>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
WindowStyle="None"
|
WindowStyle="None"
|
||||||
AllowsTransparency="True"
|
AllowsTransparency="True"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
Topmost="True"
|
Topmost="False"
|
||||||
ShowInTaskbar="False">
|
ShowInTaskbar="False">
|
||||||
|
|
||||||
<Border BorderBrush="{DynamicResource BorderColor}"
|
<Border BorderBrush="{DynamicResource BorderColor}"
|
||||||
|
|||||||
@@ -16,10 +16,7 @@ function SaveSettings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (-not (SaveToFile -Config $settings -FilePath $script:SavedSettingsFilePath)) {
|
||||||
$settings | ConvertTo-Json -Depth 10 | Set-Content $script:SavedSettingsFilePath
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Write-Output ""
|
Write-Output ""
|
||||||
Write-Host "Error: Failed to save settings to LastUsedSettings.json file" -ForegroundColor Red
|
Write-Host "Error: Failed to save settings to LastUsedSettings.json file" -ForegroundColor Red
|
||||||
}
|
}
|
||||||
|
|||||||
19
Scripts/FileIO/SaveToFile.ps1
Normal file
19
Scripts/FileIO/SaveToFile.ps1
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Saves configuration JSON to a file.
|
||||||
|
# Returns $true on success, $false on failure.
|
||||||
|
function SaveToFile {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[hashtable]$Config,
|
||||||
|
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$FilePath
|
||||||
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
$Config | ConvertTo-Json -Depth 10 | Set-Content -Path $FilePath -Encoding UTF8
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,7 +40,7 @@ function Show-AboutDialog {
|
|||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Apply theme resources
|
# Apply theme resources
|
||||||
SetWindowThemeResources -window $aboutWindow -usesDarkMode $usesDarkMode
|
SetWindowThemeResources -window $aboutWindow -usesDarkMode $usesDarkMode
|
||||||
|
|
||||||
@@ -83,13 +83,16 @@ function Show-AboutDialog {
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Show dialog
|
# Show dialog
|
||||||
$aboutWindow.ShowDialog() | Out-Null
|
try {
|
||||||
|
$aboutWindow.ShowDialog() | Out-Null
|
||||||
# Hide overlay after dialog closes
|
}
|
||||||
if ($overlay) {
|
finally {
|
||||||
try {
|
# Hide overlay after dialog closes
|
||||||
$ownerWindow.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Collapsed' })
|
if ($overlay) {
|
||||||
|
try {
|
||||||
|
$ownerWindow.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Collapsed' })
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
}
|
}
|
||||||
catch { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,13 +242,16 @@ function Show-ApplyModal {
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Show dialog
|
# Show dialog
|
||||||
$applyWindow.ShowDialog() | Out-Null
|
try {
|
||||||
|
$applyWindow.ShowDialog() | Out-Null
|
||||||
# Hide overlay after dialog closes
|
}
|
||||||
if ($overlay) {
|
finally {
|
||||||
try {
|
# Hide overlay after dialog closes
|
||||||
$ownerWindow.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Collapsed' })
|
if ($overlay) {
|
||||||
|
try {
|
||||||
|
$ownerWindow.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Collapsed' })
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
}
|
}
|
||||||
catch { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
389
Scripts/GUI/Show-ConfigWindow.ps1
Normal file
389
Scripts/GUI/Show-ConfigWindow.ps1
Normal file
@@ -0,0 +1,389 @@
|
|||||||
|
function Show-ImportExportConfigWindow {
|
||||||
|
param (
|
||||||
|
[System.Windows.Window]$Owner,
|
||||||
|
[bool]$UsesDarkMode,
|
||||||
|
[string]$Title,
|
||||||
|
[string]$Prompt,
|
||||||
|
[string[]]$Categories = @('Applications', 'System Tweaks', 'Deployment Settings'),
|
||||||
|
[string[]]$DisabledCategories = @()
|
||||||
|
)
|
||||||
|
|
||||||
|
# Show overlay on owner window
|
||||||
|
$overlay = $null
|
||||||
|
$overlayWasAlreadyVisible = $false
|
||||||
|
try {
|
||||||
|
$overlay = $Owner.FindName('ModalOverlay')
|
||||||
|
if ($overlay) {
|
||||||
|
$overlayWasAlreadyVisible = ($overlay.Visibility -eq 'Visible')
|
||||||
|
if (-not $overlayWasAlreadyVisible) {
|
||||||
|
$Owner.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Visible' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
|
||||||
|
# Load XAML from schema file
|
||||||
|
$schemaPath = $script:ImportExportConfigSchema
|
||||||
|
|
||||||
|
if (-not $schemaPath -or -not (Test-Path $schemaPath)) {
|
||||||
|
Show-MessageBox -Message 'Import/Export window schema file could not be found.' -Title 'Error' -Button 'OK' -Icon 'Error' -Owner $Owner | Out-Null
|
||||||
|
if ($overlay -and -not $overlayWasAlreadyVisible) {
|
||||||
|
try { $Owner.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Collapsed' }) } catch { }
|
||||||
|
}
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
$xaml = Get-Content -Path $schemaPath -Raw
|
||||||
|
$reader = [System.Xml.XmlReader]::Create([System.IO.StringReader]::new($xaml))
|
||||||
|
try {
|
||||||
|
$dlg = [System.Windows.Markup.XamlReader]::Load($reader)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
$reader.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
$dlg.Owner = $Owner
|
||||||
|
SetWindowThemeResources -window $dlg -usesDarkMode $UsesDarkMode
|
||||||
|
|
||||||
|
# Copy the CheckBox default style from the main window so checkboxes get the themed template
|
||||||
|
try {
|
||||||
|
$mainCheckBoxStyle = $Owner.FindResource([type][System.Windows.Controls.CheckBox])
|
||||||
|
if ($mainCheckBoxStyle) {
|
||||||
|
$dlg.Resources.Add([type][System.Windows.Controls.CheckBox], $mainCheckBoxStyle)
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
|
||||||
|
# Populate named elements
|
||||||
|
$dlg.Title = $Title
|
||||||
|
$dlg.FindName('TitleText').Text = $Title
|
||||||
|
$dlg.FindName('PromptText').Text = $Prompt
|
||||||
|
|
||||||
|
$titleBar = $dlg.FindName('TitleBar')
|
||||||
|
$titleBar.Add_MouseLeftButtonDown({ $dlg.DragMove() })
|
||||||
|
|
||||||
|
# Add a themed checkbox per category
|
||||||
|
$checkboxPanel = $dlg.FindName('CheckboxPanel')
|
||||||
|
$checkboxes = @{}
|
||||||
|
foreach ($cat in $Categories) {
|
||||||
|
$cb = New-Object System.Windows.Controls.CheckBox
|
||||||
|
$cb.Content = $cat
|
||||||
|
$cb.IsChecked = $true
|
||||||
|
$cb.Margin = [System.Windows.Thickness]::new(0,0,0,8)
|
||||||
|
$cb.FontSize = 14
|
||||||
|
$cb.Foreground = $dlg.FindResource('FgColor')
|
||||||
|
if ($DisabledCategories -contains $cat) {
|
||||||
|
$cb.IsChecked = $false
|
||||||
|
$cb.IsEnabled = $false
|
||||||
|
$cb.Opacity = 0.65
|
||||||
|
$cb.ToolTip = 'No selected settings available in this category.'
|
||||||
|
}
|
||||||
|
$checkboxPanel.Children.Add($cb) | Out-Null
|
||||||
|
$checkboxes[$cat] = $cb
|
||||||
|
}
|
||||||
|
|
||||||
|
$okBtn = $dlg.FindName('OkButton')
|
||||||
|
$cancelBtn = $dlg.FindName('CancelButton')
|
||||||
|
$okBtn.Add_Click({ $dlg.Tag = 'OK'; $dlg.Close() })
|
||||||
|
$cancelBtn.Add_Click({ $dlg.Tag = 'Cancel'; $dlg.Close() })
|
||||||
|
|
||||||
|
# Handle Escape key
|
||||||
|
$dlg.Add_KeyDown({
|
||||||
|
param($s, $e)
|
||||||
|
if ($e.Key -eq 'Escape') { $dlg.Tag = 'Cancel'; $dlg.Close() }
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
$dlg.ShowDialog() | Out-Null
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
# Hide overlay
|
||||||
|
if ($overlay -and -not $overlayWasAlreadyVisible) {
|
||||||
|
try { $Owner.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Collapsed' }) } catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($dlg.Tag -ne 'OK') { return $null }
|
||||||
|
|
||||||
|
$selected = @()
|
||||||
|
foreach ($cat in $Categories) {
|
||||||
|
if ($checkboxes[$cat].IsEnabled -and $checkboxes[$cat].IsChecked) { $selected += $cat }
|
||||||
|
}
|
||||||
|
if ($selected.Count -eq 0) { return $null }
|
||||||
|
return $selected
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-SelectedApplications {
|
||||||
|
param (
|
||||||
|
[System.Windows.Controls.Panel]$AppsPanel
|
||||||
|
)
|
||||||
|
|
||||||
|
$selectedApps = @()
|
||||||
|
foreach ($child in $AppsPanel.Children) {
|
||||||
|
if ($child -is [System.Windows.Controls.CheckBox] -and $child.IsChecked) {
|
||||||
|
$selectedApps += $child.Tag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $selectedApps
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-SelectedTweakSettings {
|
||||||
|
param (
|
||||||
|
[System.Windows.Window]$Owner,
|
||||||
|
[hashtable]$UiControlMappings
|
||||||
|
)
|
||||||
|
|
||||||
|
$tweakSettings = @()
|
||||||
|
if (-not $UiControlMappings) {
|
||||||
|
return $tweakSettings
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($mappingKey in $UiControlMappings.Keys) {
|
||||||
|
$control = $Owner.FindName($mappingKey)
|
||||||
|
if (-not $control) { continue }
|
||||||
|
|
||||||
|
$mapping = $UiControlMappings[$mappingKey]
|
||||||
|
if ($control -is [System.Windows.Controls.CheckBox] -and $control.IsChecked) {
|
||||||
|
if ($mapping.Type -eq 'feature') {
|
||||||
|
$tweakSettings += @{ Name = $mapping.FeatureId; Value = $true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($control -is [System.Windows.Controls.ComboBox] -and $control.SelectedIndex -gt 0) {
|
||||||
|
if ($mapping.Type -eq 'group') {
|
||||||
|
$selectedValue = $mapping.Values[$control.SelectedIndex - 1]
|
||||||
|
foreach ($fid in $selectedValue.FeatureIds) {
|
||||||
|
$tweakSettings += @{ Name = $fid; Value = $true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($mapping.Type -eq 'feature') {
|
||||||
|
$tweakSettings += @{ Name = $mapping.FeatureId; Value = $true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tweakSettings
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-DeploymentSettings {
|
||||||
|
param (
|
||||||
|
[System.Windows.Window]$Owner,
|
||||||
|
[System.Windows.Controls.ComboBox]$UserSelectionCombo,
|
||||||
|
[System.Windows.Controls.TextBox]$OtherUsernameTextBox
|
||||||
|
)
|
||||||
|
|
||||||
|
$deploySettings = @(
|
||||||
|
@{ Name = 'UserSelectionIndex'; Value = $UserSelectionCombo.SelectedIndex }
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($UserSelectionCombo.SelectedIndex -eq 1) {
|
||||||
|
$deploySettings += @{ Name = 'OtherUsername'; Value = $OtherUsernameTextBox.Text.Trim() }
|
||||||
|
}
|
||||||
|
|
||||||
|
$appRemovalScopeCombo = $Owner.FindName('AppRemovalScopeCombo')
|
||||||
|
if ($appRemovalScopeCombo) {
|
||||||
|
$deploySettings += @{ Name = 'AppRemovalScopeIndex'; Value = $appRemovalScopeCombo.SelectedIndex }
|
||||||
|
}
|
||||||
|
|
||||||
|
$restorePointCheckBox = $Owner.FindName('RestorePointCheckBox')
|
||||||
|
if ($restorePointCheckBox) {
|
||||||
|
$deploySettings += @{ Name = 'CreateRestorePoint'; Value = [bool]$restorePointCheckBox.IsChecked }
|
||||||
|
}
|
||||||
|
|
||||||
|
$restartExplorerCheckBox = $Owner.FindName('RestartExplorerCheckBox')
|
||||||
|
if ($restartExplorerCheckBox) {
|
||||||
|
$deploySettings += @{ Name = 'RestartExplorer'; Value = [bool]$restartExplorerCheckBox.IsChecked }
|
||||||
|
}
|
||||||
|
|
||||||
|
return $deploySettings
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-AvailableImportExportCategories {
|
||||||
|
param (
|
||||||
|
$Config
|
||||||
|
)
|
||||||
|
|
||||||
|
$availableCategories = @()
|
||||||
|
if ($Config.Apps) { $availableCategories += 'Applications' }
|
||||||
|
if ($Config.Tweaks) { $availableCategories += 'System Tweaks' }
|
||||||
|
if ($Config.Deployment) { $availableCategories += 'Deployment Settings' }
|
||||||
|
|
||||||
|
return $availableCategories
|
||||||
|
}
|
||||||
|
|
||||||
|
function Apply-ImportedApplications {
|
||||||
|
param (
|
||||||
|
[System.Windows.Controls.Panel]$AppsPanel,
|
||||||
|
[string[]]$AppIds
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach ($child in $AppsPanel.Children) {
|
||||||
|
if ($child -is [System.Windows.Controls.CheckBox]) {
|
||||||
|
$child.IsChecked = ($AppIds -contains $child.Tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Apply-ImportedTweakSettings {
|
||||||
|
param (
|
||||||
|
[System.Windows.Window]$Owner,
|
||||||
|
[hashtable]$UiControlMappings,
|
||||||
|
[array]$TweakSettings
|
||||||
|
)
|
||||||
|
|
||||||
|
$settingsJson = [PSCustomObject]@{ Settings = @($TweakSettings) }
|
||||||
|
ApplySettingsToUiControls -window $Owner -settingsJson $settingsJson -uiControlMappings $UiControlMappings
|
||||||
|
}
|
||||||
|
|
||||||
|
function Apply-ImportedDeploymentSettings {
|
||||||
|
param (
|
||||||
|
[System.Windows.Window]$Owner,
|
||||||
|
[System.Windows.Controls.ComboBox]$UserSelectionCombo,
|
||||||
|
[System.Windows.Controls.TextBox]$OtherUsernameTextBox,
|
||||||
|
[array]$DeploymentSettings
|
||||||
|
)
|
||||||
|
|
||||||
|
$lookup = @{}
|
||||||
|
foreach ($setting in $DeploymentSettings) {
|
||||||
|
$lookup[$setting.Name] = $setting.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($lookup.ContainsKey('UserSelectionIndex')) {
|
||||||
|
$UserSelectionCombo.SelectedIndex = [int]$lookup['UserSelectionIndex']
|
||||||
|
}
|
||||||
|
if ($lookup.ContainsKey('OtherUsername') -and $UserSelectionCombo.SelectedIndex -eq 1) {
|
||||||
|
$OtherUsernameTextBox.Text = $lookup['OtherUsername']
|
||||||
|
}
|
||||||
|
|
||||||
|
$appRemovalScopeCombo = $Owner.FindName('AppRemovalScopeCombo')
|
||||||
|
if ($lookup.ContainsKey('AppRemovalScopeIndex') -and $appRemovalScopeCombo) {
|
||||||
|
$appRemovalScopeCombo.SelectedIndex = [int]$lookup['AppRemovalScopeIndex']
|
||||||
|
}
|
||||||
|
|
||||||
|
$restorePointCheckBox = $Owner.FindName('RestorePointCheckBox')
|
||||||
|
if ($lookup.ContainsKey('CreateRestorePoint') -and $restorePointCheckBox) {
|
||||||
|
$restorePointCheckBox.IsChecked = [bool]$lookup['CreateRestorePoint']
|
||||||
|
}
|
||||||
|
|
||||||
|
$restartExplorerCheckBox = $Owner.FindName('RestartExplorerCheckBox')
|
||||||
|
if ($lookup.ContainsKey('RestartExplorer') -and $restartExplorerCheckBox) {
|
||||||
|
$restartExplorerCheckBox.IsChecked = [bool]$lookup['RestartExplorer']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Export-Configuration {
|
||||||
|
param (
|
||||||
|
[System.Windows.Window]$Owner,
|
||||||
|
[bool]$UsesDarkMode,
|
||||||
|
[System.Windows.Controls.Panel]$AppsPanel,
|
||||||
|
[hashtable]$UiControlMappings,
|
||||||
|
[System.Windows.Controls.ComboBox]$UserSelectionCombo,
|
||||||
|
[System.Windows.Controls.TextBox]$OtherUsernameTextBox
|
||||||
|
)
|
||||||
|
|
||||||
|
# Precompute exportable data so empty categories can be disabled in the picker.
|
||||||
|
$selectedApps = Get-SelectedApplications -AppsPanel $AppsPanel
|
||||||
|
$tweakSettings = Get-SelectedTweakSettings -Owner $Owner -UiControlMappings $UiControlMappings
|
||||||
|
|
||||||
|
$disabledCategories = @()
|
||||||
|
if ($selectedApps.Count -eq 0) { $disabledCategories += 'Applications' }
|
||||||
|
if ($tweakSettings.Count -eq 0) { $disabledCategories += 'System Tweaks' }
|
||||||
|
|
||||||
|
$categories = Show-ImportExportConfigWindow -Owner $Owner -UsesDarkMode $UsesDarkMode -Title 'Export Configuration' -Prompt 'Select which settings to include in the export:' -DisabledCategories $disabledCategories
|
||||||
|
if (-not $categories) { return }
|
||||||
|
|
||||||
|
$config = @{ Version = '1.0' }
|
||||||
|
|
||||||
|
if ($categories -contains 'Applications') {
|
||||||
|
$config['Apps'] = @($selectedApps)
|
||||||
|
}
|
||||||
|
if ($categories -contains 'System Tweaks') {
|
||||||
|
$config['Tweaks'] = @($tweakSettings)
|
||||||
|
}
|
||||||
|
if ($categories -contains 'Deployment Settings') {
|
||||||
|
$config['Deployment'] = @(Get-DeploymentSettings -Owner $Owner -UserSelectionCombo $UserSelectionCombo -OtherUsernameTextBox $OtherUsernameTextBox)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Show native save-file dialog
|
||||||
|
$saveDialog = New-Object Microsoft.Win32.SaveFileDialog
|
||||||
|
$saveDialog.Title = 'Export Configuration'
|
||||||
|
$saveDialog.Filter = 'JSON files (*.json)|*.json|All files (*.*)|*.*'
|
||||||
|
$saveDialog.DefaultExt = '.json'
|
||||||
|
$saveDialog.FileName = "Win11Debloat-Config-$(Get-Date -Format 'yyyyMMdd').json"
|
||||||
|
|
||||||
|
if ($saveDialog.ShowDialog($Owner) -ne $true) { return }
|
||||||
|
|
||||||
|
if (SaveToFile -Config $config -FilePath $saveDialog.FileName) {
|
||||||
|
Show-MessageBox -Message "Configuration exported successfully." -Title 'Export Configuration' -Button 'OK' -Icon 'Information' | Out-Null
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Show-MessageBox -Message "Failed to export configuration" -Title 'Error' -Button 'OK' -Icon 'Error' | Out-Null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Import-Configuration {
|
||||||
|
param (
|
||||||
|
[System.Windows.Window]$Owner,
|
||||||
|
[bool]$UsesDarkMode,
|
||||||
|
[System.Windows.Controls.Panel]$AppsPanel,
|
||||||
|
[hashtable]$UiControlMappings,
|
||||||
|
[System.Windows.Controls.ComboBox]$UserSelectionCombo,
|
||||||
|
[System.Windows.Controls.TextBox]$OtherUsernameTextBox,
|
||||||
|
[scriptblock]$OnAppsImported,
|
||||||
|
[scriptblock]$OnImportCompleted
|
||||||
|
)
|
||||||
|
|
||||||
|
# Show native open-file dialog
|
||||||
|
$openDialog = New-Object Microsoft.Win32.OpenFileDialog
|
||||||
|
$openDialog.Title = 'Import Configuration'
|
||||||
|
$openDialog.Filter = 'JSON files (*.json)|*.json|All files (*.*)|*.*'
|
||||||
|
$openDialog.DefaultExt = '.json'
|
||||||
|
|
||||||
|
if ($openDialog.ShowDialog($Owner) -ne $true) { return }
|
||||||
|
|
||||||
|
$config = LoadJsonFile -filePath $openDialog.FileName -expectedVersion '1.0'
|
||||||
|
if (-not $config) {
|
||||||
|
Show-MessageBox -Message "Failed to read configuration file" -Title 'Error' -Button 'OK' -Icon 'Error' | Out-Null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $config.Version) {
|
||||||
|
Show-MessageBox -Message "Invalid configuration file format." -Title 'Error' -Button 'OK' -Icon 'Error' | Out-Null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$availableCategories = Get-AvailableImportExportCategories -Config $config
|
||||||
|
|
||||||
|
if ($availableCategories.Count -eq 0) {
|
||||||
|
Show-MessageBox -Message "The configuration file contains no importable data." -Title 'Import Configuration' -Button 'OK' -Icon 'Information' | Out-Null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$categories = Show-ImportExportConfigWindow -Owner $Owner -UsesDarkMode $UsesDarkMode -Title 'Import Configuration' -Prompt 'Select which settings to import:' -Categories $availableCategories
|
||||||
|
if (-not $categories) { return }
|
||||||
|
|
||||||
|
if ($categories -contains 'Applications' -and $config.Apps) {
|
||||||
|
$appIds = @(
|
||||||
|
$config.Apps |
|
||||||
|
Where-Object { $_ -is [string] } |
|
||||||
|
ForEach-Object { $_.Trim() } |
|
||||||
|
Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
|
||||||
|
)
|
||||||
|
|
||||||
|
Apply-ImportedApplications -AppsPanel $AppsPanel -AppIds $appIds
|
||||||
|
|
||||||
|
if ($OnAppsImported) {
|
||||||
|
& $OnAppsImported
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($categories -contains 'System Tweaks' -and $config.Tweaks) {
|
||||||
|
Apply-ImportedTweakSettings -Owner $Owner -UiControlMappings $UiControlMappings -TweakSettings @($config.Tweaks)
|
||||||
|
}
|
||||||
|
if ($categories -contains 'Deployment Settings' -and $config.Deployment) {
|
||||||
|
Apply-ImportedDeploymentSettings -Owner $Owner -UserSelectionCombo $UserSelectionCombo -OtherUsernameTextBox $OtherUsernameTextBox -DeploymentSettings @($config.Deployment)
|
||||||
|
}
|
||||||
|
|
||||||
|
Show-MessageBox -Message "Configuration imported successfully." -Title 'Import Configuration' -Button 'OK' -Icon 'Information' | Out-Null
|
||||||
|
|
||||||
|
if ($OnImportCompleted) {
|
||||||
|
& $OnImportCompleted $categories
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,8 @@ function Show-MainWindow {
|
|||||||
$menuReportBug = $window.FindName('MenuReportBug')
|
$menuReportBug = $window.FindName('MenuReportBug')
|
||||||
$menuLogs = $window.FindName('MenuLogs')
|
$menuLogs = $window.FindName('MenuLogs')
|
||||||
$menuAbout = $window.FindName('MenuAbout')
|
$menuAbout = $window.FindName('MenuAbout')
|
||||||
|
$importConfigBtn = $window.FindName('ImportConfigBtn')
|
||||||
|
$exportConfigBtn = $window.FindName('ExportConfigBtn')
|
||||||
|
|
||||||
# Title bar event handlers
|
# Title bar event handlers
|
||||||
$titleBar.Add_MouseLeftButtonDown({
|
$titleBar.Add_MouseLeftButtonDown({
|
||||||
@@ -67,6 +69,22 @@ function Show-MainWindow {
|
|||||||
Show-AboutDialog -Owner $window
|
Show-AboutDialog -Owner $window
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# --- Import/Export Configuration ---
|
||||||
|
$exportConfigBtn.Add_Click({
|
||||||
|
Export-Configuration -Owner $window -UsesDarkMode $usesDarkMode -AppsPanel $appsPanel -UiControlMappings $script:UiControlMappings -UserSelectionCombo $userSelectionCombo -OtherUsernameTextBox $otherUsernameTextBox
|
||||||
|
})
|
||||||
|
|
||||||
|
$importConfigBtn.Add_Click({
|
||||||
|
Import-Configuration -Owner $window -UsesDarkMode $usesDarkMode -AppsPanel $appsPanel -UiControlMappings $script:UiControlMappings -UserSelectionCombo $userSelectionCombo -OtherUsernameTextBox $otherUsernameTextBox -OnAppsImported { UpdateAppSelectionStatus; UpdatePresetStates } -OnImportCompleted {
|
||||||
|
$tabControl.SelectedIndex = 3
|
||||||
|
UpdateNavigationButtons
|
||||||
|
|
||||||
|
$window.Dispatcher.BeginInvoke([System.Windows.Threading.DispatcherPriority]::Loaded, [action]{
|
||||||
|
Show-Bubble -TargetControl $reviewChangesBtn -Message 'View the selected changes here'
|
||||||
|
}) | Out-Null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
$closeBtn.Add_Click({
|
$closeBtn.Add_Click({
|
||||||
$window.Close()
|
$window.Close()
|
||||||
})
|
})
|
||||||
@@ -254,6 +272,11 @@ function Show-MainWindow {
|
|||||||
$script:PendingDefaultMode = $false
|
$script:PendingDefaultMode = $false
|
||||||
# Holds apps data preloaded before ShowDialog() so the first load skips the background job
|
# Holds apps data preloaded before ShowDialog() so the first load skips the background job
|
||||||
$script:PreloadedAppData = $null
|
$script:PreloadedAppData = $null
|
||||||
|
|
||||||
|
# Prevent app import until the apps list has finished initial population.
|
||||||
|
if ($importConfigBtn) {
|
||||||
|
$importConfigBtn.IsEnabled = $false
|
||||||
|
}
|
||||||
|
|
||||||
# Set script-level variable for GUI window reference
|
# Set script-level variable for GUI window reference
|
||||||
$script:GuiWindow = $window
|
$script:GuiWindow = $window
|
||||||
@@ -738,6 +761,9 @@ function Show-MainWindow {
|
|||||||
|
|
||||||
if ($appsToAdd.Count -eq 0) {
|
if ($appsToAdd.Count -eq 0) {
|
||||||
$window.FindName('DeploymentApplyBtn').IsEnabled = $true
|
$window.FindName('DeploymentApplyBtn').IsEnabled = $true
|
||||||
|
if ($importConfigBtn) {
|
||||||
|
$importConfigBtn.IsEnabled = $true
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -830,6 +856,9 @@ function Show-MainWindow {
|
|||||||
|
|
||||||
# Re-enable Apply button now that the full, correctly-checked app list is ready
|
# Re-enable Apply button now that the full, correctly-checked app list is ready
|
||||||
$window.FindName('DeploymentApplyBtn').IsEnabled = $true
|
$window.FindName('DeploymentApplyBtn').IsEnabled = $true
|
||||||
|
if ($importConfigBtn) {
|
||||||
|
$importConfigBtn.IsEnabled = $true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Loads apps into the UI
|
# Loads apps into the UI
|
||||||
@@ -838,6 +867,10 @@ function Show-MainWindow {
|
|||||||
if ($script:IsLoadingApps) { return }
|
if ($script:IsLoadingApps) { return }
|
||||||
$script:IsLoadingApps = $true
|
$script:IsLoadingApps = $true
|
||||||
|
|
||||||
|
if ($importConfigBtn) {
|
||||||
|
$importConfigBtn.IsEnabled = $false
|
||||||
|
}
|
||||||
|
|
||||||
# Show loading indicator and clear existing apps
|
# Show loading indicator and clear existing apps
|
||||||
$loadingAppsIndicator.Visibility = 'Visible'
|
$loadingAppsIndicator.Visibility = 'Visible'
|
||||||
$appsPanel.Children.Clear()
|
$appsPanel.Children.Clear()
|
||||||
|
|||||||
@@ -152,14 +152,17 @@ function Show-MessageBox {
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Show dialog and return result from Tag
|
# Show dialog and return result from Tag
|
||||||
$msgWindow.ShowDialog() | Out-Null
|
try {
|
||||||
|
$msgWindow.ShowDialog() | Out-Null
|
||||||
# Hide overlay after dialog closes (only if this dialog was the one that showed it)
|
}
|
||||||
if ($overlay -and -not $overlayWasAlreadyVisible) {
|
finally {
|
||||||
try {
|
# Hide overlay after dialog closes (only if this dialog was the one that showed it)
|
||||||
$ownerWindow.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Collapsed' })
|
if ($overlay -and -not $overlayWasAlreadyVisible) {
|
||||||
|
try {
|
||||||
|
$ownerWindow.Dispatcher.Invoke([action]{ $overlay.Visibility = 'Collapsed' })
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
}
|
}
|
||||||
catch { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $msgWindow.Tag
|
return $msgWindow.Tag
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ param (
|
|||||||
[switch]$RunDefaults,
|
[switch]$RunDefaults,
|
||||||
[switch]$RunDefaultsLite,
|
[switch]$RunDefaultsLite,
|
||||||
[switch]$RunSavedSettings,
|
[switch]$RunSavedSettings,
|
||||||
|
[string]$Config,
|
||||||
[string]$Apps,
|
[string]$Apps,
|
||||||
[string]$AppRemovalTarget,
|
[string]$AppRemovalTarget,
|
||||||
[switch]$RemoveApps,
|
[switch]$RemoveApps,
|
||||||
|
|||||||
127
Scripts/Helpers/ImportConfigToParams.ps1
Normal file
127
Scripts/Helpers/ImportConfigToParams.ps1
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
function ImportConfigToParams {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]$ConfigPath,
|
||||||
|
[int]$CurrentBuild,
|
||||||
|
[string]$ExpectedVersion = '1.0'
|
||||||
|
)
|
||||||
|
|
||||||
|
$resolvedConfigPath = $null
|
||||||
|
try {
|
||||||
|
$resolvedConfigPath = (Resolve-Path -LiteralPath $ConfigPath -ErrorAction Stop).Path
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
throw "Unable to find config file at path: $ConfigPath"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path -LiteralPath $resolvedConfigPath -PathType Leaf)) {
|
||||||
|
throw "Provided config path is not a file: $resolvedConfigPath"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([System.IO.Path]::GetExtension($resolvedConfigPath) -ne '.json') {
|
||||||
|
throw "Provided config file must be a .json file: $resolvedConfigPath"
|
||||||
|
}
|
||||||
|
|
||||||
|
$configJson = LoadJsonFile -filePath $resolvedConfigPath -expectedVersion $ExpectedVersion
|
||||||
|
if ($null -eq $configJson) {
|
||||||
|
throw "Failed to read config file: $resolvedConfigPath"
|
||||||
|
}
|
||||||
|
|
||||||
|
$importedItems = 0
|
||||||
|
|
||||||
|
if ($configJson.Apps) {
|
||||||
|
$appIds = @(
|
||||||
|
$configJson.Apps |
|
||||||
|
Where-Object { $_ -is [string] } |
|
||||||
|
ForEach-Object { $_.Trim() } |
|
||||||
|
Where-Object { -not [string]::IsNullOrWhiteSpace($_) }
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($appIds.Count -gt 0) {
|
||||||
|
AddParameter 'RemoveApps'
|
||||||
|
AddParameter 'Apps' ($appIds -join ',')
|
||||||
|
$importedItems++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($configJson.Tweaks) {
|
||||||
|
foreach ($setting in @($configJson.Tweaks)) {
|
||||||
|
if (-not $setting -or -not $setting.Name -or $setting.Value -ne $true) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
$feature = $script:Features[$setting.Name]
|
||||||
|
if (-not $feature) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($feature.MinVersion -and $CurrentBuild -lt $feature.MinVersion) -or ($feature.MaxVersion -and $CurrentBuild -gt $feature.MaxVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
AddParameter $setting.Name $true
|
||||||
|
$importedItems++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($configJson.Deployment) {
|
||||||
|
$deploymentLookup = @{}
|
||||||
|
foreach ($setting in @($configJson.Deployment)) {
|
||||||
|
if ($setting -and $setting.Name) {
|
||||||
|
$deploymentLookup[$setting.Name] = $setting.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($deploymentLookup.ContainsKey('CreateRestorePoint') -and [bool]$deploymentLookup['CreateRestorePoint']) {
|
||||||
|
AddParameter 'CreateRestorePoint'
|
||||||
|
$importedItems++
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($deploymentLookup.ContainsKey('RestartExplorer') -and -not [bool]$deploymentLookup['RestartExplorer']) {
|
||||||
|
AddParameter 'NoRestartExplorer'
|
||||||
|
$importedItems++
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($deploymentLookup.ContainsKey('UserSelectionIndex')) {
|
||||||
|
switch ([int]$deploymentLookup['UserSelectionIndex']) {
|
||||||
|
1 {
|
||||||
|
$otherUserName = if ($deploymentLookup.ContainsKey('OtherUsername')) { "$($deploymentLookup['OtherUsername'])".Trim() } else { '' }
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($otherUserName)) {
|
||||||
|
AddParameter 'User' $otherUserName
|
||||||
|
$importedItems++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2 {
|
||||||
|
AddParameter 'Sysprep'
|
||||||
|
$importedItems++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($deploymentLookup.ContainsKey('AppRemovalScopeIndex') -and $script:Params.ContainsKey('RemoveApps')) {
|
||||||
|
switch ([int]$deploymentLookup['AppRemovalScopeIndex']) {
|
||||||
|
0 {
|
||||||
|
AddParameter 'AppRemovalTarget' 'AllUsers'
|
||||||
|
$importedItems++
|
||||||
|
}
|
||||||
|
1 {
|
||||||
|
AddParameter 'AppRemovalTarget' 'CurrentUser'
|
||||||
|
$importedItems++
|
||||||
|
}
|
||||||
|
2 {
|
||||||
|
$targetUser = if ($deploymentLookup.ContainsKey('OtherUsername')) { "$($deploymentLookup['OtherUsername'])".Trim() } else { '' }
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($targetUser)) {
|
||||||
|
AddParameter 'AppRemovalTarget' $targetUser
|
||||||
|
$importedItems++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($importedItems -eq 0) {
|
||||||
|
throw "The config file contains no importable data: $resolvedConfigPath"
|
||||||
|
}
|
||||||
|
|
||||||
|
return $resolvedConfigPath
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ param (
|
|||||||
[switch]$RunDefaults,
|
[switch]$RunDefaults,
|
||||||
[switch]$RunDefaultsLite,
|
[switch]$RunDefaultsLite,
|
||||||
[switch]$RunSavedSettings,
|
[switch]$RunSavedSettings,
|
||||||
|
[string]$Config,
|
||||||
[string]$Apps,
|
[string]$Apps,
|
||||||
[string]$AppRemovalTarget,
|
[string]$AppRemovalTarget,
|
||||||
[switch]$RemoveApps,
|
[switch]$RemoveApps,
|
||||||
@@ -119,9 +120,10 @@ $script:AboutWindowSchema = "$PSScriptRoot/Schemas/AboutWindow.xaml"
|
|||||||
$script:ApplyChangesWindowSchema = "$PSScriptRoot/Schemas/ApplyChangesWindow.xaml"
|
$script:ApplyChangesWindowSchema = "$PSScriptRoot/Schemas/ApplyChangesWindow.xaml"
|
||||||
$script:SharedStylesSchema = "$PSScriptRoot/Schemas/SharedStyles.xaml"
|
$script:SharedStylesSchema = "$PSScriptRoot/Schemas/SharedStyles.xaml"
|
||||||
$script:BubbleHintSchema = "$PSScriptRoot/Schemas/BubbleHint.xaml"
|
$script:BubbleHintSchema = "$PSScriptRoot/Schemas/BubbleHint.xaml"
|
||||||
|
$script:ImportExportConfigSchema = "$PSScriptRoot/Schemas/ImportExportConfigWindow.xaml"
|
||||||
$script:LoadAppsDetailsScriptPath = "$PSScriptRoot/Scripts/FileIO/LoadAppsDetailsFromJson.ps1"
|
$script:LoadAppsDetailsScriptPath = "$PSScriptRoot/Scripts/FileIO/LoadAppsDetailsFromJson.ps1"
|
||||||
|
|
||||||
$script:ControlParams = 'WhatIf', 'Confirm', 'Verbose', 'Debug', 'LogPath', 'Silent', 'Sysprep', 'User', 'NoRestartExplorer', 'RunDefaults', 'RunDefaultsLite', 'RunSavedSettings', 'RunAppsListGenerator', 'CLI', 'AppRemovalTarget'
|
$script:ControlParams = 'WhatIf', 'Confirm', 'Verbose', 'Debug', 'LogPath', 'Silent', 'Sysprep', 'User', 'NoRestartExplorer', 'RunDefaults', 'RunDefaultsLite', 'RunSavedSettings', 'Config', 'RunAppsListGenerator', 'CLI', 'AppRemovalTarget'
|
||||||
|
|
||||||
# Script-level variables for GUI elements
|
# Script-level variables for GUI elements
|
||||||
$script:GuiWindow = $null
|
$script:GuiWindow = $null
|
||||||
@@ -249,6 +251,7 @@ if (-not $script:WingetInstalled -and -not $Silent) {
|
|||||||
|
|
||||||
# File I/O functions
|
# File I/O functions
|
||||||
. "$PSScriptRoot/Scripts/FileIO/LoadJsonFile.ps1"
|
. "$PSScriptRoot/Scripts/FileIO/LoadJsonFile.ps1"
|
||||||
|
. "$PSScriptRoot/Scripts/FileIO/SaveToFile.ps1"
|
||||||
. "$PSScriptRoot/Scripts/FileIO/SaveSettings.ps1"
|
. "$PSScriptRoot/Scripts/FileIO/SaveSettings.ps1"
|
||||||
. "$PSScriptRoot/Scripts/FileIO/LoadSettings.ps1"
|
. "$PSScriptRoot/Scripts/FileIO/LoadSettings.ps1"
|
||||||
. "$PSScriptRoot/Scripts/FileIO/SaveCustomAppsListToFile.ps1"
|
. "$PSScriptRoot/Scripts/FileIO/SaveCustomAppsListToFile.ps1"
|
||||||
@@ -263,6 +266,7 @@ if (-not $script:WingetInstalled -and -not $Silent) {
|
|||||||
. "$PSScriptRoot/Scripts/GUI/AttachShiftClickBehavior.ps1"
|
. "$PSScriptRoot/Scripts/GUI/AttachShiftClickBehavior.ps1"
|
||||||
. "$PSScriptRoot/Scripts/GUI/ApplySettingsToUiControls.ps1"
|
. "$PSScriptRoot/Scripts/GUI/ApplySettingsToUiControls.ps1"
|
||||||
. "$PSScriptRoot/Scripts/GUI/Show-MessageBox.ps1"
|
. "$PSScriptRoot/Scripts/GUI/Show-MessageBox.ps1"
|
||||||
|
. "$PSScriptRoot/Scripts/GUI/Show-ConfigWindow.ps1"
|
||||||
. "$PSScriptRoot/Scripts/GUI/Show-ApplyModal.ps1"
|
. "$PSScriptRoot/Scripts/GUI/Show-ApplyModal.ps1"
|
||||||
. "$PSScriptRoot/Scripts/GUI/Show-AppSelectionWindow.ps1"
|
. "$PSScriptRoot/Scripts/GUI/Show-AppSelectionWindow.ps1"
|
||||||
. "$PSScriptRoot/Scripts/GUI/Show-MainWindow.ps1"
|
. "$PSScriptRoot/Scripts/GUI/Show-MainWindow.ps1"
|
||||||
@@ -275,6 +279,7 @@ if (-not $script:WingetInstalled -and -not $Silent) {
|
|||||||
. "$PSScriptRoot/Scripts/Helpers/CheckModernStandbySupport.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/CheckModernStandbySupport.ps1"
|
||||||
. "$PSScriptRoot/Scripts/Helpers/GenerateAppsList.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/GenerateAppsList.ps1"
|
||||||
. "$PSScriptRoot/Scripts/Helpers/GetFriendlyTargetUserName.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/GetFriendlyTargetUserName.ps1"
|
||||||
|
. "$PSScriptRoot/Scripts/Helpers/ImportConfigToParams.ps1"
|
||||||
. "$PSScriptRoot/Scripts/Helpers/GetTargetUserForAppRemoval.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/GetTargetUserForAppRemoval.ps1"
|
||||||
. "$PSScriptRoot/Scripts/Helpers/GetUserDirectory.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/GetUserDirectory.ps1"
|
||||||
. "$PSScriptRoot/Scripts/Helpers/GetUserName.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/GetUserName.ps1"
|
||||||
@@ -371,7 +376,7 @@ if ($RunAppsListGenerator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Change script execution based on provided parameters or user input
|
# Change script execution based on provided parameters or user input
|
||||||
if ((-not $script:Params.Count) -or $RunDefaults -or $RunDefaultsLite -or $RunSavedSettings -or ($controlParamsCount -eq $script:Params.Count)) {
|
if ((-not $script:Params.Count) -or $RunDefaults -or $RunDefaultsLite -or $RunSavedSettings -or $Config -or ($controlParamsCount -eq $script:Params.Count)) {
|
||||||
if ($RunDefaults -or $RunDefaultsLite) {
|
if ($RunDefaults -or $RunDefaultsLite) {
|
||||||
ShowCLIDefaultModeOptions
|
ShowCLIDefaultModeOptions
|
||||||
}
|
}
|
||||||
@@ -384,6 +389,21 @@ if ((-not $script:Params.Count) -or $RunDefaults -or $RunDefaultsLite -or $RunSa
|
|||||||
|
|
||||||
ShowCLILastUsedSettings
|
ShowCLILastUsedSettings
|
||||||
}
|
}
|
||||||
|
elseif ($Config) {
|
||||||
|
try {
|
||||||
|
ImportConfigToParams -ConfigPath $Config -CurrentBuild $WinVersion -ExpectedVersion '1.0'
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "$_"
|
||||||
|
AwaitKeyToExit
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $Silent) {
|
||||||
|
PrintHeader 'Custom Mode'
|
||||||
|
PrintPendingChanges
|
||||||
|
PrintHeader 'Custom Mode'
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if ($CLI) {
|
if ($CLI) {
|
||||||
$Mode = ShowCLIMenuOptions
|
$Mode = ShowCLIMenuOptions
|
||||||
|
|||||||
Reference in New Issue
Block a user