mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Add Save, Load, and Clear functionality for BYO applications with JSON support
This commit is contained in:
@@ -1390,6 +1390,42 @@ $window.Add_Loaded({
|
||||
$script:chkBringYourOwnApps.Add_Unchecked({
|
||||
$script:byoApplicationPanel.Visibility = 'Collapsed'
|
||||
})
|
||||
|
||||
# Add event handlers for Save/Load/Clear buttons
|
||||
$script:btnSaveBYOApplications = $window.FindName('btnSaveBYOApplications')
|
||||
$script:btnLoadBYOApplications = $window.FindName('btnLoadBYOApplications')
|
||||
$script:btnClearBYOApplications = $window.FindName('btnClearBYOApplications')
|
||||
|
||||
$script:btnSaveBYOApplications.Add_Click({
|
||||
$saveDialog = New-Object Microsoft.Win32.SaveFileDialog
|
||||
$saveDialog.Filter = "JSON files (*.json)|*.json|All files (*.*)|*.*"
|
||||
$saveDialog.DefaultExt = ".json"
|
||||
$saveDialog.Title = "Save Application List"
|
||||
if ($saveDialog.ShowDialog()) {
|
||||
Save-BYOApplicationList -Path $saveDialog.FileName
|
||||
}
|
||||
})
|
||||
|
||||
$script:btnLoadBYOApplications.Add_Click({
|
||||
$openDialog = New-Object Microsoft.Win32.OpenFileDialog
|
||||
$openDialog.Filter = "JSON files (*.json)|*.json|All files (*.*)|*.*"
|
||||
$openDialog.Title = "Import Application List"
|
||||
if ($openDialog.ShowDialog()) {
|
||||
Import-BYOApplicationList -Path $openDialog.FileName
|
||||
}
|
||||
})
|
||||
|
||||
$script:btnClearBYOApplications.Add_Click({
|
||||
$result = [System.Windows.MessageBox]::Show(
|
||||
"Are you sure you want to clear all applications?",
|
||||
"Clear Applications",
|
||||
[System.Windows.MessageBoxButton]::YesNo,
|
||||
[System.Windows.MessageBoxImage]::Question
|
||||
)
|
||||
if ($result -eq [System.Windows.MessageBoxResult]::Yes) {
|
||||
$window.FindName('lstApplications').Items.Clear()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
# Function to search for Winget apps
|
||||
@@ -1521,6 +1557,71 @@ function Remove-Application {
|
||||
$listView.Items.Refresh()
|
||||
}
|
||||
|
||||
# Function to save BYO applications to JSON
|
||||
function Save-BYOApplicationList {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$Path
|
||||
)
|
||||
|
||||
$listView = $window.FindName('lstApplications')
|
||||
if (-not $listView -or $listView.Items.Count -eq 0) {
|
||||
[System.Windows.MessageBox]::Show("No applications to save.", "Save Applications", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
$applications = $listView.Items | Select-Object Priority, Name, CommandLine, Source
|
||||
$applications | ConvertTo-Json | Set-Content -Path $Path -Force
|
||||
[System.Windows.MessageBox]::Show("Applications saved successfully.", "Save Applications", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
||||
}
|
||||
catch {
|
||||
[System.Windows.MessageBox]::Show("Failed to save applications: $_", "Error", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
}
|
||||
}
|
||||
|
||||
# Function to load BYO applications from JSON
|
||||
function Import-BYOApplicationList {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$Path
|
||||
)
|
||||
|
||||
if (-not (Test-Path $Path)) {
|
||||
[System.Windows.MessageBox]::Show("Application list file not found.", "Import Applications", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
$applications = Get-Content -Path $Path -Raw | ConvertFrom-Json
|
||||
$listView = $window.FindName('lstApplications')
|
||||
$listView.Items.Clear()
|
||||
|
||||
foreach ($app in $applications) {
|
||||
$listView.Items.Add([PSCustomObject]@{
|
||||
Priority = $app.Priority
|
||||
Name = $app.Name
|
||||
CommandLine = $app.CommandLine
|
||||
Source = $app.Source
|
||||
})
|
||||
}
|
||||
|
||||
# Reorder priorities to ensure they are sequential
|
||||
$currentPriority = 1
|
||||
foreach ($item in $listView.Items) {
|
||||
$item.Priority = $currentPriority
|
||||
$currentPriority++
|
||||
}
|
||||
|
||||
[System.Windows.MessageBox]::Show("Applications imported successfully.", "Import Applications", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
||||
}
|
||||
catch {
|
||||
[System.Windows.MessageBox]::Show("Failed to import applications: $_", "Error", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
}
|
||||
}
|
||||
|
||||
# Button: Build FFU
|
||||
$btnRun = $window.FindName('btnRun')
|
||||
$btnRun.Add_Click({
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
Title="FFU Builder UI"
|
||||
Height="750"
|
||||
Width="980">
|
||||
Title="FFU Builder UI">
|
||||
<!--
|
||||
─────────────────────────────────────────────────────────────────
|
||||
1) Window.Resources:
|
||||
@@ -78,7 +76,7 @@
|
||||
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -99,12 +97,14 @@
|
||||
Grid.Row="0">
|
||||
<!-- TAB: Home -->
|
||||
<TabItem Header="Home" Padding="20">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<Grid Margin="10">
|
||||
<TextBlock Text="Welcome to FFU Builder"
|
||||
FontSize="20"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
|
||||
<!-- TAB: Build -->
|
||||
@@ -256,6 +256,7 @@
|
||||
|
||||
<!-- TAB: Hyper-V Settings -->
|
||||
<TabItem Header="Hyper-V Settings" Padding="20">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -367,10 +368,12 @@
|
||||
<ComboBoxItem Content="4096"/>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
|
||||
<!-- TAB: Windows Settings -->
|
||||
<TabItem Header="Windows Settings" Padding="20">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -506,10 +509,12 @@
|
||||
</ScrollViewer>
|
||||
</Expander>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
|
||||
<!-- TAB: Updates -->
|
||||
<TabItem Header="Updates" Padding="20">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Margin="5">
|
||||
<CheckBox x:Name="chkUpdateLatestCU" Content="Update Latest Cumulative Update" Margin="5" VerticalAlignment="Center" ToolTip="When set to $true, will download and install the latest cumulative update for Windows 10/11. Default is $false."/>
|
||||
<CheckBox x:Name="chkUpdateLatestNet" Content="Update .NET" Margin="5" VerticalAlignment="Center" ToolTip="When set to $true, will download and install the latest .NET Framework for Windows 10/11. Default is $false."/>
|
||||
@@ -519,10 +524,12 @@
|
||||
<CheckBox x:Name="chkUpdateLatestMSRT" Content="Update Microsoft Software Removal Tool (MSRT)" Margin="5" VerticalAlignment="Center" ToolTip="When set to $true, will download and install the latest Windows Malicious Software Removal Tool. Default is $false."/>
|
||||
<CheckBox x:Name="chkUpdatePreviewCU" Content="Update Preview Cumulative Update" Margin="5" VerticalAlignment="Center" ToolTip="When set to $true, will download and install the latest Preview cumulative update for Windows 10/11. Default is $false."/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
|
||||
<!-- TAB: Applications -->
|
||||
<TabItem Header="Applications" Padding="20">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -640,12 +647,12 @@
|
||||
<!-- Save/Import/Clear Buttons -->
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||
<Button x:Name="btnSaveWingetList"
|
||||
Content="Save Applist.json"
|
||||
Content="Save AppList.json"
|
||||
Padding="15,5"
|
||||
Margin="0,0,10,0"
|
||||
ToolTip="Save selected applications to a JSON file"/>
|
||||
<Button x:Name="btnImportWingetList"
|
||||
Content="Import Applist.json"
|
||||
Content="Import AppList.json"
|
||||
Padding="15,5"
|
||||
Margin="0,0,10,0"
|
||||
ToolTip="Import applications from a JSON file"/>
|
||||
@@ -725,20 +732,46 @@
|
||||
<GridViewColumn Header="Action" Width="80">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Content="Remove" Tag="{Binding Priority}" Width="70"/>
|
||||
<Grid HorizontalAlignment="Stretch">
|
||||
<Button Content="Remove"
|
||||
Tag="{Binding Priority}"
|
||||
Width="70"
|
||||
HorizontalAlignment="Center"
|
||||
ToolTip="Remove this application from the list and reorder priorities"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
|
||||
<!-- Save/Import/Clear Buttons -->
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,10">
|
||||
<Button x:Name="btnSaveBYOApplications"
|
||||
Content="Save UserAppList.json"
|
||||
Margin="0,0,10,0"
|
||||
Padding="10,5"
|
||||
ToolTip="Save application list to JSON file"/>
|
||||
<Button x:Name="btnLoadBYOApplications"
|
||||
Content="Import UserAppList.json"
|
||||
Margin="0,0,10,0"
|
||||
Padding="10,5"
|
||||
ToolTip="Import application list from JSON file"/>
|
||||
<Button x:Name="btnClearBYOApplications"
|
||||
Content="Clear List"
|
||||
Padding="10,5"
|
||||
ToolTip="Clear all applications from the list"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
|
||||
<!-- TAB: M365 Apps/Office -->
|
||||
<TabItem Header="M365 Apps/Office" Padding="20">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -779,10 +812,12 @@
|
||||
<Button x:Name="btnBrowseOfficeConfigXMLFile" Grid.Column="1" Content="Browse..." Width="80" Margin="5,0,0,0" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
|
||||
<!-- TAB: Drivers -->
|
||||
<TabItem Header="Drivers" Padding="20">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@@ -852,6 +887,7 @@
|
||||
<Button x:Name="btnBrowsePEDriversFolder" Grid.Column="1" Content="Browse..." Width="80" Margin="5,0,0,0" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user