Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase, System.Windows.Forms
# --- THE CLEANING FUNCTION ---
# This makes it easy to load any XAML you copy from Visual Studio
function Load-VisualStudioXaml {
param([string]$RawXaml)
$Cleaned = $RawXaml -replace 'mc:Ignorable="d"','' `
-replace "x:Class.*?[^\x20]*",' ' `
-replace "xmlns:local.*?[^\x20]*",' ' `
-replace 'd:ItemsSource=".*?"',' ' `
-replace 'd:SampleData=".*?"',' ' `
-replace 'd:DesignHeight=".*?"',' ' `
-replace 'd:DesignWidth=".*?"',' '
[xml]$xml = $Cleaned
$reader = New-Object System.Xml.XmlNodeReader $xml
return [Windows.Markup.XamlReader]::Load($reader)
}
# --- SPLASH XAML ---
$splashXML = @"
"@
# --- MAIN XAML ---
$mainXML = @"
"@
# 1. Show Splashscreen
$Splash = Load-VisualStudioXaml -RawXaml $splashXML
$Splash.Show()
Start-Sleep -Seconds 5
$Splash.Close()
# 2. Load main GUI object (This makes $Main exist!)
$Main = Load-VisualStudioXaml -RawXaml $mainXML
# --- FUNCTIONS SECTION ---
# --- Function from InstallDefaultWingetApps.ps1 ---
function Install-DefaultWingetApps {
# Pre-defined list of IDs
$Apps = @("Google.Chrome", "7zip.7zip", "VideoLAN.VLC")
foreach ($App in $Apps) {
# Process runs and displays output in its own console window area
Start-Process winget -ArgumentList "install --id $App --silent --accept-source-agreements" -Wait -PassThru -NoNewWindow
}
return "Completed"
}
# --- Function from TestFunction.ps1 ---
function TestFunction {
Write-Host "Hello, World!"
Start-Sleep -Seconds 10
Write-Host "Sleepy!"
}
# --- Function from Update-Status.ps1 ---
function Update-Status {
param(
[string]$Message,
[ValidateSet("Busy", "Ready")]
[string]$State
)
$LblStatus.Content = $Message
if ($State -eq "Busy") {
$LblStatus.Foreground = [System.Windows.Media.Brushes]::Red
} else {
$LblStatus.Foreground = [System.Windows.Media.Brushes]::LimeGreen
}
[System.Windows.Forms.Application]::DoEvents()
}
# --- UI ELEMENT MAPPING ---
$BtnInstallDefaultWingetApps = $Main.FindName("BtnInstallDefaultWingetApps")
$LblStatus = $Main.FindName("LblStatus")
# --- BUTTON CLICK EVENTS ---
$BtnInstallDefaultWingetApps.Add_Click({
Update-Status -Message "Busy..." -State "Busy"
[System.Windows.Forms.Application]::DoEvents()
Install-DefaultWingetApps
Update-Status -Message "Ready..." -State "Ready"
})
# 3. OPEN THE WINDOW (Last Step)
$Main.ShowDialog()