Skip to content

Commit 669ecd9

Browse files
expand ui and fix clean and reset
1 parent 64ea075 commit 669ecd9

File tree

2 files changed

+142
-59
lines changed

2 files changed

+142
-59
lines changed

functions/private/Invoke-WinUtilISO.ps1

Lines changed: 121 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ function Invoke-WinUtilISOModify {
376376
# the UI thread here.
377377
$sync["WPFWin11ISOOutputSection"].Dispatcher.Invoke([action]{
378378
$sync["WPFWin11ISOOutputSection"].Visibility = "Visible"
379+
$sync["WPFWin11ISOStatusLog"].Height = 300
379380
})
380381
}
381382
catch {
@@ -480,12 +481,13 @@ function Invoke-WinUtilISOCheckExistingWork {
480481
$sync["WPFWin11ISOMountSection"].Visibility = "Collapsed"
481482
$sync["WPFWin11ISOModifySection"].Visibility = "Collapsed"
482483
$sync["WPFWin11ISOOutputSection"].Visibility = "Visible"
484+
$sync["WPFWin11ISOStatusLog"].Height = 300
483485

484486
# Notify via the status log
485487
$dirName = $existingWorkDir.Name
486488
$modified = $existingWorkDir.LastWriteTime.ToString("yyyy-MM-dd HH:mm")
487489
Write-Win11ISOLog "Existing working directory found: $($existingWorkDir.FullName)"
488-
Write-Win11ISOLog "Last modified: $modified Skipping Steps 1-3 and resuming at Step 4."
490+
Write-Win11ISOLog "Last modified: $modified - Skipping Steps 1-3 and resuming at Step 4."
489491
Write-Win11ISOLog "Click 'Clean & Reset' if you want to start over with a new ISO."
490492

491493
[System.Windows.MessageBox]::Show(
@@ -498,6 +500,8 @@ function Invoke-WinUtilISOCleanAndReset {
498500
.SYNOPSIS
499501
Deletes the temporary working directory created during ISO modification
500502
and resets the entire ISO UI back to its initial state (Step 1 only).
503+
Deletion runs in a background runspace so the UI stays responsive and
504+
progress is reported to the user.
501505
#>
502506

503507
$workDir = $sync["Win11ISOWorkDir"]
@@ -507,37 +511,126 @@ function Invoke-WinUtilISOCleanAndReset {
507511
"This will delete the temporary working directory:`n`n$workDir`n`nAnd reset the interface back to the start.`n`nContinue?",
508512
"Clean & Reset", "YesNo", "Warning")
509513
if ($confirm -ne "Yes") { return }
514+
}
515+
516+
# Disable button so it cannot be clicked twice
517+
$sync["WPFWin11ISOCleanResetButton"].IsEnabled = $false
518+
519+
$runspace = [Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
520+
$runspace.ApartmentState = "STA"
521+
$runspace.ThreadOptions = "ReuseThread"
522+
$runspace.Open()
523+
$runspace.SessionStateProxy.SetVariable("sync", $sync)
524+
$runspace.SessionStateProxy.SetVariable("workDir", $workDir)
525+
526+
$script = [Management.Automation.PowerShell]::Create()
527+
$script.Runspace = $runspace
528+
$script.AddScript({
529+
530+
function Log($msg) {
531+
$ts = (Get-Date).ToString("HH:mm:ss")
532+
$sync["WPFWin11ISOStatusLog"].Dispatcher.Invoke([action]{
533+
$sync["WPFWin11ISOStatusLog"].Text += "`n[$ts] $msg"
534+
$sync["WPFWin11ISOStatusLog"].CaretIndex = $sync["WPFWin11ISOStatusLog"].Text.Length
535+
$sync["WPFWin11ISOStatusLog"].ScrollToEnd()
536+
})
537+
}
538+
function SetProgress($label, $pct) {
539+
$sync["WPFWin11ISOStatusLog"].Dispatcher.Invoke([action]{
540+
$sync.progressBarTextBlock.Text = $label
541+
$sync.progressBarTextBlock.ToolTip = $label
542+
$sync.ProgressBar.Value = [Math]::Max($pct, 5)
543+
})
544+
}
510545

511546
try {
512-
Write-Win11ISOLog "Deleting temp directory: $workDir"
513-
Remove-Item -Path $workDir -Recurse -Force -ErrorAction Stop
514-
Write-Win11ISOLog "Temp directory deleted."
515-
} catch {
516-
Write-Win11ISOLog "WARNING: could not fully delete temp directory: $_"
547+
if ($workDir -and (Test-Path $workDir)) {
548+
Log "Scanning files to delete in: $workDir"
549+
SetProgress "Scanning files..." 5
550+
551+
$allItems = @(Get-ChildItem -Path $workDir -Recurse -Force -ErrorAction SilentlyContinue)
552+
$total = $allItems.Count
553+
$deleted = 0
554+
555+
Log "Found $total items to delete."
556+
557+
# Delete files first, then directories (deepest first)
558+
$files = $allItems | Where-Object { -not $_.PSIsContainer }
559+
$dirs = $allItems | Where-Object { $_.PSIsContainer } |
560+
Sort-Object { $_.FullName.Length } -Descending
561+
562+
foreach ($f in $files) {
563+
try { Remove-Item -Path $f.FullName -Force -ErrorAction Stop } catch {}
564+
$deleted++
565+
$pct = [math]::Round(($deleted / [Math]::Max($total,1)) * 85) + 5
566+
SetProgress "Deleting files... ($deleted / $total)" $pct
567+
}
568+
569+
foreach ($d in $dirs) {
570+
try { Remove-Item -Path $d.FullName -Force -Recurse -ErrorAction Stop } catch {}
571+
$deleted++
572+
$pct = [math]::Round(($deleted / [Math]::Max($total,1)) * 85) + 5
573+
SetProgress "Removing directories... ($deleted / $total)" $pct
574+
}
575+
576+
# Remove the root work directory itself
577+
try { Remove-Item -Path $workDir -Force -Recurse -ErrorAction Stop } catch {}
578+
579+
if (Test-Path $workDir) {
580+
Log "WARNING: some items could not be deleted in $workDir"
581+
} else {
582+
Log "Temp directory deleted successfully."
583+
}
584+
} else {
585+
Log "No temp directory found — resetting UI."
586+
}
587+
588+
SetProgress "Resetting UI..." 95
589+
Log "Resetting interface..."
590+
591+
# ── Full UI reset on the dispatcher thread ──────────────────────
592+
$sync["WPFWin11ISOStatusLog"].Dispatcher.Invoke([action]{
593+
# Clear stored state
594+
$sync["Win11ISOWorkDir"] = $null
595+
$sync["Win11ISOContentsDir"] = $null
596+
$sync["Win11ISOImagePath"] = $null
597+
$sync["Win11ISODriveLetter"] = $null
598+
$sync["Win11ISOWimPath"] = $null
599+
$sync["Win11ISOImageInfo"] = $null
600+
$sync["Win11ISOUSBDisks"] = $null
601+
602+
# Reset UI elements
603+
$sync["WPFWin11ISOPath"].Text = "No ISO selected..."
604+
$sync["WPFWin11ISOFileInfo"].Visibility = "Collapsed"
605+
$sync["WPFWin11ISOVerifyResultPanel"].Visibility = "Collapsed"
606+
$sync["WPFWin11ISOOptionUSB"].Visibility = "Collapsed"
607+
$sync["WPFWin11ISOOutputSection"].Visibility = "Collapsed"
608+
$sync["WPFWin11ISOModifySection"].Visibility = "Collapsed"
609+
$sync["WPFWin11ISOMountSection"].Visibility = "Collapsed"
610+
$sync["WPFWin11ISOSelectSection"].Visibility = "Visible"
611+
$sync["WPFWin11ISOModifyButton"].IsEnabled = $true
612+
$sync["WPFWin11ISOCleanResetButton"].IsEnabled = $true
613+
614+
$sync.progressBarTextBlock.Text = ""
615+
$sync.progressBarTextBlock.ToolTip = ""
616+
$sync.ProgressBar.Value = 0
617+
618+
$sync["WPFWin11ISOStatusLog"].Height = 140
619+
$sync["WPFWin11ISOStatusLog"].Text = "Ready. Please select a Windows 11 ISO to begin."
620+
})
517621
}
518-
}
622+
catch {
623+
Log "ERROR during Clean & Reset: $_"
624+
$sync["WPFWin11ISOStatusLog"].Dispatcher.Invoke([action]{
625+
$sync.progressBarTextBlock.Text = ""
626+
$sync.progressBarTextBlock.ToolTip = ""
627+
$sync.ProgressBar.Value = 0
628+
$sync["WPFWin11ISOCleanResetButton"].IsEnabled = $true
629+
})
630+
}
631+
}) | Out-Null
519632

520-
# Clear all stored ISO state
521-
$sync["Win11ISOWorkDir"] = $null
522-
$sync["Win11ISOContentsDir"] = $null
523-
$sync["Win11ISOImagePath"] = $null
524-
$sync["Win11ISODriveLetter"] = $null
525-
$sync["Win11ISOWimPath"] = $null
526-
$sync["Win11ISOImageInfo"] = $null
527-
$sync["Win11ISOUSBDisks"] = $null
528-
529-
# Reset the UI to the initial state
530-
$sync["WPFWin11ISOPath"].Text = "No ISO selected..."
531-
$sync["WPFWin11ISOFileInfo"].Visibility = "Collapsed"
532-
$sync["WPFWin11ISOVerifyResultPanel"].Visibility = "Collapsed"
533-
$sync["WPFWin11ISOOptionUSB"].Visibility = "Collapsed"
534-
$sync["WPFWin11ISOOutputSection"].Visibility = "Collapsed"
535-
$sync["WPFWin11ISOModifySection"].Visibility = "Collapsed"
536-
$sync["WPFWin11ISOMountSection"].Visibility = "Collapsed"
537-
$sync["WPFWin11ISOSelectSection"].Visibility = "Visible"
538-
$sync["WPFWin11ISOStatusLog"].Text = "Ready. Please select a Windows 11 ISO to begin."
539-
$sync["WPFWin11ISOStatusLog"].Height = 140
540-
$sync["WPFWin11ISOModifyButton"].IsEnabled = $true
633+
$script.BeginInvoke() | Out-Null
541634
}
542635

543636
function Invoke-WinUtilISOExport {

xaml/inputXML.xaml

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,8 +1377,7 @@
13771377
<!-- ═══════════════════════════════════════════════════════════ -->
13781378
<!-- STEP 1 : Select Windows 11 ISO -->
13791379
<!-- ═══════════════════════════════════════════════════════════ -->
1380-
<Border Grid.Row="0" Name="WPFWin11ISOSelectSection" Style="{StaticResource BorderStyle}" HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
1381-
<Grid Margin="5">
1380+
<Grid Grid.Row="0" Name="WPFWin11ISOSelectSection" Margin="5" HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
13821381
<Grid.ColumnDefinitions>
13831382
<ColumnDefinition Width="*"/>
13841383
<ColumnDefinition Width="*"/>
@@ -1464,18 +1463,16 @@
14641463
Height="{DynamicResource ButtonHeight}"/>
14651464
</StackPanel>
14661465
</Border>
1467-
</Grid>
1468-
</Border>
1466+
</Grid>
14691467

14701468
<!-- ═══════════════════════════════════════════════════════════ -->
14711469
<!-- STEP 2 : Mount & Verify ISO -->
14721470
<!-- ═══════════════════════════════════════════════════════════ -->
1473-
<Border Grid.Row="1"
1474-
Name="WPFWin11ISOMountSection"
1475-
Style="{StaticResource BorderStyle}"
1476-
Visibility="Collapsed"
1477-
HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
1478-
<Grid Margin="5">
1471+
<Grid Grid.Row="1"
1472+
Name="WPFWin11ISOMountSection"
1473+
Margin="5"
1474+
Visibility="Collapsed"
1475+
HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
14791476
<Grid.ColumnDefinitions>
14801477
<ColumnDefinition Width="Auto"/>
14811478
<ColumnDefinition Width="*"/>
@@ -1529,18 +1526,16 @@
15291526
Margin="0,0,0,0"/>
15301527
</StackPanel>
15311528
</Border>
1532-
</Grid>
1533-
</Border>
1529+
</Grid>
15341530

15351531
<!-- ═══════════════════════════════════════════════════════════ -->
15361532
<!-- STEP 3 : Modify install.wim -->
15371533
<!-- ═══════════════════════════════════════════════════════════ -->
1538-
<Border Grid.Row="2"
1539-
Name="WPFWin11ISOModifySection"
1540-
Style="{StaticResource BorderStyle}"
1541-
Visibility="Collapsed"
1542-
HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
1543-
<StackPanel Margin="5">
1534+
<StackPanel Grid.Row="2"
1535+
Name="WPFWin11ISOModifySection"
1536+
Margin="5"
1537+
Visibility="Collapsed"
1538+
HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
15441539
<TextBlock FontSize="{DynamicResource FontSize}" FontWeight="Bold"
15451540
Foreground="{DynamicResource MainForegroundColor}" Margin="0,0,0,8">
15461541
Step 3 - Modify install.wim
@@ -1558,18 +1553,16 @@
15581553
HorizontalAlignment="Left"
15591554
Width="Auto" Padding="12,0"
15601555
Height="{DynamicResource ButtonHeight}"/>
1561-
</StackPanel>
1562-
</Border>
1556+
</StackPanel>
15631557

15641558
<!-- ═══════════════════════════════════════════════════════════ -->
15651559
<!-- STEP 4 : Output Options -->
15661560
<!-- ═══════════════════════════════════════════════════════════ -->
1567-
<Border Grid.Row="3"
1568-
Name="WPFWin11ISOOutputSection"
1569-
Style="{StaticResource BorderStyle}"
1570-
Visibility="Collapsed"
1571-
HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
1572-
<StackPanel Margin="5">
1561+
<StackPanel Grid.Row="3"
1562+
Name="WPFWin11ISOOutputSection"
1563+
Margin="5"
1564+
Visibility="Collapsed"
1565+
HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
15731566
<!-- Header row: title + Clean & Reset button -->
15741567
<Grid Margin="0,0,0,12">
15751568
<Grid.ColumnDefinitions>
@@ -1654,14 +1647,12 @@
16541647
</StackPanel>
16551648
</Border>
16561649

1657-
</StackPanel>
1658-
</Border>
1650+
</StackPanel>
16591651

16601652
<!-- ═══════════════════════════════════════════════════════════ -->
16611653
<!-- Status / Log Output -->
16621654
<!-- ═══════════════════════════════════════════════════════════ -->
1663-
<Border Grid.Row="4" Style="{StaticResource BorderStyle}">
1664-
<StackPanel>
1655+
<StackPanel Grid.Row="4" Margin="5">
16651656
<TextBlock FontSize="{DynamicResource FontSize}" FontWeight="Bold"
16661657
Foreground="{DynamicResource MainForegroundColor}" Margin="0,0,0,6">
16671658
Status Log
@@ -1677,7 +1668,6 @@
16771668
BorderThickness="1"
16781669
Text="Ready. Please select a Windows 11 ISO to begin."/>
16791670
</StackPanel>
1680-
</Border>
16811671

16821672
</Grid>
16831673
</ScrollViewer>

0 commit comments

Comments
 (0)