[MicroWin] Add automatic configuration settings

This commit is contained in:
CodingWonders 2024-08-24 19:49:27 +02:00
parent bcfbce66fd
commit 1f52790241
5 changed files with 75 additions and 2 deletions

View File

@ -248,7 +248,7 @@ function Remove-FileOrDirectory([string]$pathToDelete, [string]$mask = "", [swit
function New-Unattend {
param (
[Parameter(Mandatory, Position = 0)] [string] $userName,
[Parameter(Mandatory, Position = 0)] [string]$userName,
[Parameter(Position = 1)] [string] $userPassword
)
@ -719,6 +719,12 @@ function New-FirstRun {
# Done create WinUtil shortcut on the desktop
# ************************************************
if (Test-Path -Path "$env:HOMEDRIVE\winutil-config.json")
{
Write-Host "Configuration file detected. Applying..."
iex "& { $(irm christitus.com/win) } -Config `"$env:HOMEDRIVE\winutil-config.json`" -Run"
}
Start-Process explorer
'@

View File

@ -0,0 +1,24 @@
function Invoke-AutoConfigDialog {
<#
.SYNOPSIS
Sets the automatic configuration file based on a specified JSON file
#>
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$OFD = New-Object System.Windows.Forms.OpenFileDialog
$OFD.Filter = "JSON Files (*.json)|*.json"
$OFD.ShowDialog()
if (($OFD.FileName -eq "") -and ($sync.MicrowinAutoConfigBox.Text -eq ""))
{
Write-Host "No automatic config file has been selected. Continuing without one..."
return
}
elseif ($OFD.FileName -ne "")
{
$sync.MicrowinAutoConfigBox.Text = "$($OFD.FileName)"
}
}

View File

@ -57,5 +57,6 @@ function Invoke-WPFButton {
"WPFMicrowin" {Invoke-WPFMicrowin}
"WPFCloseButton" {Invoke-WPFCloseButton}
"MicrowinScratchDirBT" {Invoke-ScratchDialog}
"MicrowinAutoConfigBtn" {Invoke-AutoConfigDialog}
}
}

View File

@ -178,7 +178,21 @@ public class PowerManagement {
Write-Host "Removal complete!"
Write-Host "Create unattend.xml"
#New-Unattend
if (($sync.MicrowinAutoConfigBox.Text -ne "") -and (Test-Path "$($sync.MicrowinAutoConfigBox.Text)"))
{
try
{
Write-Host "A configuration file has been specified. Copying to WIM file..."
Copy-Item "$($sync.MicrowinAutoConfigBox.Text)" "$($scratchDir)\winutil-config.json"
}
catch
{
Write-Host "The config file could not be copied. Continuing without it..."
}
}
# Create unattended answer file with user information - Check condition to learn more about this functionality
if ($sync.MicrowinUserName.Text -eq "")
{
New-Unattend -userName "User"

View File

@ -968,6 +968,34 @@
Foreground="{LabelboxForegroundColor}"
/>
<Rectangle Fill="{MainForegroundColor}" Height="2" HorizontalAlignment="Stretch" Margin="0,10,0,10"/>
<TextBlock Margin="6" Padding="1" TextWrapping="Wrap"><Bold>Automatic configuration (optional):</Bold></TextBlock>
<TextBlock Margin="6" Padding="1" TextWrapping="Wrap">WinUtil configuration file (JSON)</TextBlock>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" /> <!-- Takes the remaining space -->
<ColumnDefinition Width="32" /> <!-- Fixed width for Button -->
</Grid.ColumnDefinitions>
<TextBox Name="MicrowinAutoConfigBox" Background="Transparent" BorderBrush="{MainForegroundColor}"
Text=""
Margin="2"
IsReadOnly="False"
ToolTip="Path of your configuration file"
Grid.Column="0"
VerticalAlignment="Center"
Foreground="{LabelboxForegroundColor}">
</TextBox>
<Button Name="MicrowinAutoConfigBtn"
Width="Auto"
Height="Auto"
Grid.Column="1"
Margin="2"
Padding="1" VerticalAlignment="Center">
<Button.Content>
...
</Button.Content>
</Button>
</Grid>
<Rectangle Fill="{MainForegroundColor}" Height="2" HorizontalAlignment="Stretch" Margin="0,10,0,10"/>
<Button Name="WPFMicrowin" Content="Start the process" Margin="2" Padding="15"/>
</StackPanel>
<StackPanel HorizontalAlignment="Left" SnapsToDevicePixels="True" Margin="1" Visibility="Collapsed">