Skip to content

Commit 096002a

Browse files
authored
Merge pull request #7 from Miiraak/GUI-Improvement-&-issue-dismount-image
UI adjustments, logging, window hiding and dismounting image
2 parents 1e232a1 + 7a76db0 commit 096002a

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

tiny11makerGUI.ps1

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
$t = '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);'
2+
add-type -name win -member $t -namespace native
3+
[native.win]::ShowWindow(([System.Diagnostics.Process]::GetCurrentProcess() | Get-Process).MainWindowHandle, 0) # by Andy Lowry found at : https://stackoverflow.com/questions/1802127/how-to-run-a-powershell-script-without-displaying-a-window
4+
15
# Enable debugging
26
#Set-PSDebug -Trace 1
37

@@ -45,7 +49,7 @@ if (! $myWindowsPrincipal.IsInRole($adminRole))
4549
Add-Type -assembly System.Windows.Forms
4650
Add-Type -assembly System.Drawing
4751

48-
# Fonction pour ajouter des logs
52+
# Log function
4953
function Add-Log {
5054
param (
5155
[string]$message
@@ -58,7 +62,7 @@ function Add-Log {
5862
# Main Form
5963
$main_form = New-Object System.Windows.Forms.Form
6064
$main_form.Text = 'Tiny11makerGUI'
61-
$main_form.Width = 600
65+
$main_form.Width = 485
6266
$main_form.Height = 450
6367
$main_form.StartPosition = 'CenterScreen'
6468

@@ -80,14 +84,14 @@ $TitleLabel.Location = New-Object System.Drawing.Point(
8084
# ISO Selection TextBox
8185
$IsoTextBox = New-Object System.Windows.Forms.TextBox
8286
$IsoTextBox.Text = "Select an .iso to mount"
83-
$IsoTextBox.Width = 360
87+
$IsoTextBox.Width = 250
8488
$IsoTextBox.Location = New-Object System.Drawing.Point(20, 65)
8589
$IsoTextBox.Enabled = $false
8690

8791
# Choose Button
8892
$ChooseButton = New-Object System.Windows.Forms.Button
8993
$ChooseButton.Text = "Choose"
90-
$ChooseButton.Location = New-Object System.Drawing.Point(400, 60)
94+
$ChooseButton.Location = New-Object System.Drawing.Point(280, 60)
9195
$ChooseButton.Size = New-Object System.Drawing.Size(80, 30)
9296
$ChooseButton.Add_Click({
9397
# Placeholder logic to simulate file selection
@@ -103,11 +107,13 @@ $ChooseButton.Add_Click({
103107
# Mount Button
104108
$MountButton = New-Object System.Windows.Forms.Button
105109
$MountButton.Text = "Mount"
106-
$MountButton.Location = New-Object System.Drawing.Point(490, 60)
110+
$MountButton.Location = New-Object System.Drawing.Point(370, 60)
107111
$MountButton.Size = New-Object System.Drawing.Size(80, 30)
108112
$MountButton.Enabled = $false
109113
$MountButton.Add_Click({
110114
Add-Log "Mounting: $($IsoTextBox.Text)"
115+
$ChooseButton.Enabled = $false
116+
$MountButton.Enabled = $false
111117

112118
try {
113119
Mount-DiskImage -ImagePath $IsoTextBox.Text
@@ -140,32 +146,34 @@ $DriveLabel.Enabled = $false
140146

141147
# Drive Letter ComboBox
142148
$DriveComboBox = New-Object System.Windows.Forms.ComboBox
143-
$DriveComboBox.Width = 150
149+
$DriveComboBox.Width = 120
144150
$DriveComboBox.Location = New-Object System.Drawing.Point(20, 135)
145151
$DriveComboBox.Enabled = $false
146152

147153
# SKU Index Label
148154
$ImageIndexLabel = New-Object System.Windows.Forms.Label
149155
$ImageIndexLabel.Text = "SKU:"
150156
$ImageIndexLabel.Font = New-Object System.Drawing.Font('Consolas', 10)
151-
$ImageIndexLabel.Location = New-Object System.Drawing.Point(200, 110)
157+
$ImageIndexLabel.Location = New-Object System.Drawing.Point(150, 110)
152158
$ImageIndexLabel.AutoSize = $true
153-
$ImageIndexLabel.Enabled = $false
159+
$ImageIndexLabel.Enabled = $false
154160

155161
# SKU Index ComboBox
156162
$ImageIndexComboBox = New-Object System.Windows.Forms.ComboBox
157-
$ImageIndexComboBox.Width = 150
158-
$ImageIndexComboBox.Location = New-Object System.Drawing.Point(200, 135)
163+
$ImageIndexComboBox.Width = 120
164+
$ImageIndexComboBox.Location = New-Object System.Drawing.Point(150, 135)
159165
$ImageIndexComboBox.Enabled = $false
160166

161167
# Start Button
162168
$StartButton = New-Object System.Windows.Forms.Button
163169
$StartButton.Text = "Start"
164-
$StartButton.Location = New-Object System.Drawing.Point(400, 135)
170+
$StartButton.Location = New-Object System.Drawing.Point(280, 130)
165171
$StartButton.Size = New-Object System.Drawing.Size(170, 30)
166172
$StartButton.Enabled = $false
167173
$StartButton.Add_Click({
168174
$StartButton.Enabled = $false
175+
$DriveComboBox.Enabled = $false
176+
$DriveLabel.Enabled = $false
169177
Add-Log "Starting..."
170178
Add-Log "Drive: $($DriveComboBox.SelectedItem)"
171179
Add-Log "Scratch disk: $ScratchDisk"
@@ -208,6 +216,7 @@ Get-WindowsImage -ImagePath $ScratchDisk\tiny11\sources\install.wim
208216
$ImageIndexComboBox.Items.AddRange((Get-WindowsImage -ImagePath $ScratchDisk\tiny11\sources\install.wim).ImageIndex)
209217
$ImageIndexLabel.Enabled = $true
210218
$ImageIndexComboBox.Enabled = $true
219+
[System.Windows.Forms.MessageBox]::Show("Please select the image under ""SKU"".", "Image selection", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
211220
Add-Log "Please select the image index in 'SKU'"
212221
Add-Log ' '
213222
$ImageIndexComboBox.Add_SelectedIndexChanged({
@@ -596,6 +605,10 @@ Add-Log "Performing Cleanup..."
596605
Remove-Item -Path "$ScratchDisk\tiny11" -Recurse -Force | Out-Null
597606
Remove-Item -Path "$ScratchDisk\scratchdir" -Recurse -Force | Out-Null
598607
Add-Log "Cleanup complete!"
608+
Add-Log "Dismount used images..."
609+
Get-Volume -DriveLetter $DriveComboBox.SelectedItem | Get-DiskImage | Dismount-DiskImage # by 790 at https://rcmtech.wordpress.com/2012/12/07/powershell-mounting-and-dismounting-iso-images-on-windows-server-2012-and-windows-8/
610+
Add-Log "Dismount complete!"
611+
Add-Log "All done !"
599612
})
600613
})
601614

@@ -611,7 +624,7 @@ $LogsTextBox = New-Object System.Windows.Forms.TextBox
611624
$LogsTextBox.Multiline = $true
612625
$LogsTextBox.ScrollBars = 'Vertical'
613626
$LogsTextBox.Location = New-Object System.Drawing.Point(20, 210)
614-
$LogsTextBox.Width = 550
627+
$LogsTextBox.Width = 430
615628
$LogsTextBox.Height = 180
616629
$LogsTextBox.ReadOnly = $true
617630
Add-Log "main_form.Controls loaded..."

0 commit comments

Comments
 (0)