mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-06-27 08:34:46 -05:00
[Microwin] Adaptive Busy Icon + Message (#3433)
* Adaptive Busy Icon + Message - added adaptive color & message of busy indicator - fixed placement at some places for "Set-WinUtilTaskbaritem" as dialogbox which waits for user input came before * seperate long Errormessaged for BusyIndication * add CharacterEllipsis as TextTrimming on BusyText Co-authored-by: CodingWonders <101426328+CodingWonders@users.noreply.github.com> * fix BusyIndication + add more detailed one * removing wip busymessages before process * Improve reporting of messages significantly (#15) - Added parameter sets - Implemented detections for interactive/noninteractive processes * Fix hidden message action (#16) --------- Co-authored-by: CodingWonders <101426328+CodingWonders@users.noreply.github.com>
This commit is contained in:
@ -59,6 +59,7 @@
|
||||
"ScrollBarHoverColor": "#5A5D62",
|
||||
"ScrollBarDraggingColor": "#6A6D72",
|
||||
|
||||
"MicrowinBusyColor": "#2e77ff",
|
||||
"ProgressBarForegroundColor": "#2e77ff",
|
||||
"ProgressBarBackgroundColor": "Transparent",
|
||||
"ProgressBarTextColor": "#232629",
|
||||
@ -99,6 +100,7 @@
|
||||
"ScrollBarHoverColor": "#3B4252",
|
||||
"ScrollBarDraggingColor": "#5E81AC",
|
||||
|
||||
"MicrowinBusyColor": "#2e77ff",
|
||||
"ProgressBarForegroundColor": "#222222",
|
||||
"ProgressBarBackgroundColor": "Transparent",
|
||||
"ProgressBarTextColor": "#232629",
|
||||
|
@ -39,12 +39,15 @@ public class PowerManagement {
|
||||
$SaveDialog.ShowDialog() | Out-Null
|
||||
|
||||
if ($SaveDialog.FileName -eq "") {
|
||||
Write-Host "No file name for the target image was specified"
|
||||
$msg = "No file name for the target image was specified"
|
||||
Write-Host $msg
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
return
|
||||
}
|
||||
|
||||
Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Busy..." -interactive $false
|
||||
|
||||
Write-Host "Target ISO location: $($SaveDialog.FileName)"
|
||||
|
||||
@ -70,9 +73,10 @@ public class PowerManagement {
|
||||
$index = 1
|
||||
} else {
|
||||
$msg = "The export process has failed and MicroWin processing cannot continue"
|
||||
Write-Host "Failed to export the image"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
Write-Host $msg
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -87,6 +91,7 @@ public class PowerManagement {
|
||||
Write-Host $msg
|
||||
[System.Windows.MessageBox]::Show($dlg_msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Exclamation)
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
return
|
||||
}
|
||||
|
||||
@ -101,8 +106,10 @@ public class PowerManagement {
|
||||
$mountDirExists = Test-Path $mountDir
|
||||
$scratchDirExists = Test-Path $scratchDir
|
||||
if (-not $mountDirExists -or -not $scratchDirExists) {
|
||||
Write-Error "Required directories '$mountDirExists' '$scratchDirExists' and do not exist."
|
||||
$msg = "Required directories '$mountDirExists' '$scratchDirExists' and do not exist."
|
||||
Write-Error $msg
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
return
|
||||
}
|
||||
|
||||
@ -113,8 +120,10 @@ public class PowerManagement {
|
||||
if ($?) {
|
||||
Write-Host "The Windows image has been mounted successfully. Continuing processing..."
|
||||
} else {
|
||||
Write-Host "Could not mount image. Exiting..."
|
||||
$msg = "Could not mount image. Exiting..."
|
||||
Write-Host $msg
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
return
|
||||
}
|
||||
|
||||
@ -368,7 +377,9 @@ public class PowerManagement {
|
||||
Rename-Item "$mountDir\sources\install2.wim" "$mountDir\sources\install.wim"
|
||||
|
||||
if (-not (Test-Path -Path "$mountDir\sources\install.wim")) {
|
||||
Write-Error "Something went wrong and '$mountDir\sources\install.wim' doesn't exist. Please report this bug to the devs"
|
||||
$msg = "Something went wrong. Please report this bug to the devs."
|
||||
Write-Error "$($msg) '$($mountDir)\sources\install.wim' doesn't exist"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
return
|
||||
}
|
||||
@ -459,6 +470,7 @@ public class PowerManagement {
|
||||
$msg = "Done. ISO image is located here: $($SaveDialog.FileName)"
|
||||
Write-Host $msg
|
||||
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
|
||||
Invoke-MicrowinBusyInfo -action "done" -message "Finished!"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
||||
} else {
|
||||
Write-Host "ISO creation failed. The "$($mountDir)" directory has not been removed."
|
||||
@ -467,6 +479,8 @@ public class PowerManagement {
|
||||
# Now, this will NOT throw an exception
|
||||
$exitCode = New-Object System.ComponentModel.Win32Exception($LASTEXITCODE)
|
||||
Write-Host "Reason: $($exitCode.Message)"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $exitCode.Message
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
} catch {
|
||||
# Could not get error description from Windows APIs
|
||||
}
|
||||
|
65
functions/microwin/Invoke-MicrowinBusyInfo.ps1
Normal file
65
functions/microwin/Invoke-MicrowinBusyInfo.ps1
Normal file
@ -0,0 +1,65 @@
|
||||
function Invoke-MicrowinBusyInfo {
|
||||
<#
|
||||
.DESCRIPTION
|
||||
Function to display the busy info for the Microwin process
|
||||
#>
|
||||
[CmdletBinding(DefaultParameterSetName='done')]
|
||||
param(
|
||||
[Parameter(ParameterSetName='wip', Mandatory, Position = 0)]
|
||||
[Parameter(ParameterSetName='warning', Mandatory, Position = 0)]
|
||||
[Parameter(ParameterSetName='done', Mandatory, Position = 0)]
|
||||
[Parameter(ParameterSetName='hide', Mandatory, Position = 0)]
|
||||
[ValidateSet('wip', 'warning', 'done', 'hide')]
|
||||
[string]$action,
|
||||
|
||||
[Parameter(ParameterSetName='wip', Mandatory, Position = 1)]
|
||||
[Parameter(ParameterSetName='warning', Mandatory, Position = 1)]
|
||||
[Parameter(ParameterSetName='done', Mandatory, Position = 1)]
|
||||
[string]$message,
|
||||
|
||||
[Parameter(ParameterSetName='wip', Position = 2)] [bool]$interactive = $false
|
||||
)
|
||||
|
||||
switch ($action) {
|
||||
"wip" {
|
||||
$sync.form.Dispatcher.BeginInvoke([action]{
|
||||
$sync.MicrowinBusyIndicator.Visibility="Visible"
|
||||
$finalMessage = ""
|
||||
if ($interactive -eq $false) {
|
||||
$finalMessage += "Please wait. "
|
||||
}
|
||||
$finalMessage += $message
|
||||
$sync.BusyText.Text = $finalMessage
|
||||
$sync.BusyIcon.Foreground="#FFA500"
|
||||
$sync.BusyText.Foreground="#FFA500"
|
||||
})
|
||||
}
|
||||
"warning" {
|
||||
$sync.form.Dispatcher.BeginInvoke([action]{
|
||||
$sync.MicrowinBusyIndicator.Visibility="Visible"
|
||||
$sync.BusyText.Text=$message
|
||||
$sync.BusyText.Foreground="#FF0000"
|
||||
$sync.BusyIcon.Foreground="#FF0000"
|
||||
})
|
||||
}
|
||||
"done" {
|
||||
$sync.form.Dispatcher.BeginInvoke([action]{
|
||||
$sync.MicrowinBusyIndicator.Visibility="Visible"
|
||||
$sync.BusyText.Text=$message
|
||||
$sync.BusyText.Foreground="#00FF00"
|
||||
$sync.BusyIcon.Foreground="#00FF00"
|
||||
})
|
||||
}
|
||||
"hide" {
|
||||
$sync.form.Dispatcher.BeginInvoke([action]{
|
||||
$sync.MicrowinBusyIndicator.Visibility="Hidden"
|
||||
$sync.BusyText.Foreground=$sync.Form.Resources.MicrowinBusyColor
|
||||
$sync.BusyIcon.Foreground=$sync.Form.Resources.MicrowinBusyColor
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
# Force the UI to process pending messages
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
Start-Sleep -Milliseconds 50
|
||||
}
|
@ -12,10 +12,8 @@ function Invoke-MicrowinGetIso {
|
||||
return
|
||||
}
|
||||
|
||||
$sync.BusyMessage.Visibility="Visible"
|
||||
$sync.BusyText.Text="N Busy"
|
||||
|
||||
|
||||
# Provide immediate feedback to user
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Initializing MicroWin process..." -interactive $false
|
||||
|
||||
Write-Host " _ __ __ _ "
|
||||
Write-Host " /\/\ (_) ___ _ __ ___ / / /\ \ \(_) _ __ "
|
||||
@ -23,47 +21,9 @@ function Invoke-MicrowinGetIso {
|
||||
Write-Host "/ /\/\ \| || (__ | | | (_) | \ /\ / | || | | | "
|
||||
Write-Host "\/ \/|_| \___||_| \___/ \/ \/ |_||_| |_| "
|
||||
|
||||
$oscdimgPath = Join-Path $env:TEMP 'oscdimg.exe'
|
||||
$oscdImgFound = [bool] (Get-Command -ErrorAction Ignore -Type Application oscdimg.exe) -or (Test-Path $oscdimgPath -PathType Leaf)
|
||||
Write-Host "oscdimg.exe on system: $oscdImgFound"
|
||||
|
||||
if (!$oscdImgFound) {
|
||||
$downloadFromGitHub = $sync.WPFMicrowinDownloadFromGitHub.IsChecked
|
||||
$sync.BusyMessage.Visibility="Hidden"
|
||||
|
||||
if (!$downloadFromGitHub) {
|
||||
# only show the message to people who did check the box to download from github, if you check the box
|
||||
# you consent to downloading it, no need to show extra dialogs
|
||||
[System.Windows.MessageBox]::Show("oscdimge.exe is not found on the system, winutil will now attempt do download and install it using choco. This might take a long time.")
|
||||
# the step below needs choco to download oscdimg
|
||||
# Install Choco if not already present
|
||||
Install-WinUtilChoco
|
||||
$chocoFound = [bool] (Get-Command -ErrorAction Ignore -Type Application choco)
|
||||
Write-Host "choco on system: $chocoFound"
|
||||
if (!$chocoFound) {
|
||||
[System.Windows.MessageBox]::Show("choco.exe is not found on the system, you need choco to download oscdimg.exe")
|
||||
return
|
||||
}
|
||||
|
||||
Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install windows-adk-oscdimg"
|
||||
[System.Windows.MessageBox]::Show("oscdimg is installed, now close, reopen PowerShell terminal and re-launch winutil.ps1")
|
||||
return
|
||||
} else {
|
||||
[System.Windows.MessageBox]::Show("oscdimge.exe is not found on the system, winutil will now attempt do download and install it from github. This might take a long time.")
|
||||
Microwin-GetOscdimg -oscdimgPath $oscdimgPath
|
||||
$oscdImgFound = Test-Path $oscdimgPath -PathType Leaf
|
||||
if (!$oscdImgFound) {
|
||||
$msg = "oscdimg was not downloaded can not proceed"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
return
|
||||
} else {
|
||||
Write-Host "oscdimg.exe was successfully downloaded from github"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($sync["ISOmanual"].IsChecked) {
|
||||
# Open file dialog to let user choose the ISO file
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Please select an ISO file..." -interactive $true
|
||||
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
|
||||
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
|
||||
$openFileDialog.initialDirectory = $initialDirectory
|
||||
@ -73,20 +33,26 @@ function Invoke-MicrowinGetIso {
|
||||
|
||||
if ([string]::IsNullOrEmpty($filePath)) {
|
||||
Write-Host "No ISO is chosen"
|
||||
$sync.BusyMessage.Visibility="Hidden"
|
||||
Invoke-MicrowinBusyInfo -action "hide" -message " "
|
||||
return
|
||||
}
|
||||
|
||||
} elseif ($sync["ISOdownloader"].IsChecked) {
|
||||
# Create folder browsers for user-specified locations
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Please select download location..." -interactive $true
|
||||
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
|
||||
$isoDownloaderFBD = New-Object System.Windows.Forms.FolderBrowserDialog
|
||||
$isoDownloaderFBD.Description = "Please specify the path to download the ISO file to:"
|
||||
$isoDownloaderFBD.ShowNewFolderButton = $true
|
||||
if ($isoDownloaderFBD.ShowDialog() -ne [System.Windows.Forms.DialogResult]::OK)
|
||||
{
|
||||
Invoke-MicrowinBusyInfo -action "hide" -message " "
|
||||
return
|
||||
}
|
||||
|
||||
Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Preparing to download ISO..." -interactive $false
|
||||
|
||||
# Grab the location of the selected path
|
||||
$targetFolder = $isoDownloaderFBD.SelectedPath
|
||||
|
||||
@ -95,6 +61,7 @@ function Invoke-MicrowinGetIso {
|
||||
$fidopath = "$env:temp\Fido.ps1"
|
||||
$originalLocation = $PSScriptRoot
|
||||
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Downloading Fido script..." -interactive $false
|
||||
Invoke-WebRequest "https://github.com/pbatard/Fido/raw/master/Fido.ps1" -OutFile $fidopath
|
||||
|
||||
Set-Location -Path $env:temp
|
||||
@ -105,11 +72,14 @@ function Invoke-MicrowinGetIso {
|
||||
$sync["ISOLanguage"].SelectedItem
|
||||
}
|
||||
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Downloading Windows ISO... (This may take a long time)" -interactive $false
|
||||
& $fidopath -Win 'Windows 11' -Rel $sync["ISORelease"].SelectedItem -Arch "x64" -Lang $lang -Ed "Windows 11 Home/Pro/Edu"
|
||||
if (-not $?)
|
||||
{
|
||||
Write-Host "Could not download the ISO file. Look at the output of the console for more information."
|
||||
$msg = "The ISO file could not be downloaded"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
return
|
||||
}
|
||||
@ -131,8 +101,11 @@ function Invoke-MicrowinGetIso {
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Host "Unable to move the ISO file to the location you specified. The downloaded ISO is in the `"$env:TEMP`" folder"
|
||||
$msg = "Unable to move the ISO file to the location you specified. The downloaded ISO is in the `"$env:TEMP`" folder"
|
||||
Write-Host $msg
|
||||
Write-Host "Error information: $($_.Exception.Message)" -ForegroundColor Yellow
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,11 +113,57 @@ function Invoke-MicrowinGetIso {
|
||||
Write-Host "File path $($filePath)"
|
||||
if (-not (Test-Path -Path "$filePath" -PathType Leaf)) {
|
||||
$msg = "File you've chosen doesn't exist"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
return
|
||||
}
|
||||
|
||||
Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Checking system requirements..." -interactive $false
|
||||
|
||||
$oscdimgPath = Join-Path $env:TEMP 'oscdimg.exe'
|
||||
$oscdImgFound = [bool] (Get-Command -ErrorAction Ignore -Type Application oscdimg.exe) -or (Test-Path $oscdimgPath -PathType Leaf)
|
||||
Write-Host "oscdimg.exe on system: $oscdImgFound"
|
||||
|
||||
if (!$oscdImgFound) {
|
||||
$downloadFromGitHub = $sync.WPFMicrowinDownloadFromGitHub.IsChecked
|
||||
|
||||
if (!$downloadFromGitHub) {
|
||||
# only show the message to people who did check the box to download from github, if you check the box
|
||||
# you consent to downloading it, no need to show extra dialogs
|
||||
[System.Windows.MessageBox]::Show("oscdimge.exe is not found on the system, winutil will now attempt do download and install it using choco. This might take a long time.")
|
||||
# the step below needs choco to download oscdimg
|
||||
# Install Choco if not already present
|
||||
Install-WinUtilChoco
|
||||
$chocoFound = [bool] (Get-Command -ErrorAction Ignore -Type Application choco)
|
||||
Write-Host "choco on system: $chocoFound"
|
||||
if (!$chocoFound) {
|
||||
[System.Windows.MessageBox]::Show("choco.exe is not found on the system, you need choco to download oscdimg.exe")
|
||||
return
|
||||
}
|
||||
|
||||
Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install windows-adk-oscdimg"
|
||||
$msg = "oscdimg is installed, now close, reopen PowerShell terminal and re-launch winutil.ps1"
|
||||
Invoke-MicrowinBusyInfo -action "done" -message $msg # We set it to done because it immediately returns from this function
|
||||
[System.Windows.MessageBox]::Show($msg)
|
||||
return
|
||||
} else {
|
||||
[System.Windows.MessageBox]::Show("oscdimge.exe is not found on the system, winutil will now attempt do download and install it from github. This might take a long time.")
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Downloading oscdimg.exe..." -interactive $false
|
||||
Microwin-GetOscdimg -oscdimgPath $oscdimgPath
|
||||
$oscdImgFound = Test-Path $oscdimgPath -PathType Leaf
|
||||
if (!$oscdImgFound) {
|
||||
$msg = "oscdimg was not downloaded can not proceed"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
return
|
||||
} else {
|
||||
Write-Host "oscdimg.exe was successfully downloaded from github"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Checking disk space..." -interactive $false
|
||||
|
||||
# Detect the file size of the ISO and compare it with the free space of the system drive
|
||||
$isoSize = (Get-Item -Path "$filePath").Length
|
||||
@ -159,14 +178,17 @@ function Invoke-MicrowinGetIso {
|
||||
}
|
||||
elseif ($driveSpace -lt $isoSize) {
|
||||
# It's critical and we can't continue. Output an error
|
||||
Write-Host "You don't have enough space for this operation. You need at least $([Math]::Round(($isoSize / ([Math]::Pow(1024, 2))) * 2, 2)) MB of free space to copy the ISO files to a temp directory and to be able to perform additional operations."
|
||||
$msg = "You don't have enough space for this operation. You need at least $([Math]::Round(($isoSize / ([Math]::Pow(1024, 2))) * 2, 2)) MB of free space to copy the ISO files to a temp directory and to be able to perform additional operations."
|
||||
Write-Host $msg
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
return
|
||||
} else {
|
||||
Write-Host "You have enough space for this operation."
|
||||
}
|
||||
|
||||
try {
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Mounting ISO file..." -interactive $false
|
||||
Write-Host "Mounting Iso. Please wait."
|
||||
$mountedISO = Mount-DiskImage -PassThru "$filePath"
|
||||
Write-Host "Done mounting Iso `"$($mountedISO.ImagePath)`""
|
||||
@ -174,10 +196,12 @@ function Invoke-MicrowinGetIso {
|
||||
Write-Host "Iso mounted to '$driveLetter'"
|
||||
} catch {
|
||||
# @ChrisTitusTech please copy this wiki and change the link below to your copy of the wiki
|
||||
Write-Error "Failed to mount the image. Error: $($_.Exception.Message)"
|
||||
$msg = "Failed to mount the image. Error: $($_.Exception.Message)"
|
||||
Write-Error $msg
|
||||
Write-Error "This is NOT winutil's problem, your ISO might be corrupt, or there is a problem on the system"
|
||||
Write-Host "Please refer to this wiki for more details: https://christitustech.github.io/winutil/KnownIssues/#troubleshoot-errors-during-microwin-usage" -ForegroundColor Red
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
return
|
||||
}
|
||||
# storing off values in hidden fields for further steps
|
||||
@ -236,23 +260,32 @@ function Invoke-MicrowinGetIso {
|
||||
try {
|
||||
|
||||
#$data = @($driveLetter, $filePath)
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Creating directories..." -interactive $false
|
||||
New-Item -ItemType Directory -Force -Path "$($mountDir)" | Out-Null
|
||||
New-Item -ItemType Directory -Force -Path "$($scratchDir)" | Out-Null
|
||||
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Copying Windows files... (This may take several minutes)" -interactive $false
|
||||
Write-Host "Copying Windows image. This will take awhile, please don't use UI or cancel this step!"
|
||||
|
||||
# xcopy we can verify files and also not copy files that already exist, but hard to measure
|
||||
# xcopy.exe /E /I /H /R /Y /J $DriveLetter":" $mountDir >$null
|
||||
$totalTime = Measure-Command { Copy-Files "$($driveLetter):" "$mountDir" -Recurse -Force }
|
||||
$totalTime = Measure-Command {
|
||||
Copy-Files "$($driveLetter):" "$mountDir" -Recurse -Force
|
||||
# Force UI update during long operation
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
}
|
||||
Write-Host "Copy complete! Total Time: $($totalTime.Minutes) minutes, $($totalTime.Seconds) seconds"
|
||||
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Processing Windows image..." -interactive $false
|
||||
$wimFile = "$mountDir\sources\install.wim"
|
||||
Write-Host "Getting image information $wimFile"
|
||||
|
||||
if ((-not (Test-Path -Path "$wimFile" -PathType Leaf)) -and (-not (Test-Path -Path "$($wimFile.Replace(".wim", ".esd").Trim())" -PathType Leaf))) {
|
||||
$msg = "Neither install.wim nor install.esd exist in the image, this could happen if you use unofficial Windows images. Please don't use shady images from the internet, use only official images. Here are instructions how to download ISO images if the Microsoft website is not showing the link to download and ISO. https://www.techrepublic.com/article/how-to-download-a-windows-10-iso-file-without-using-the-media-creation-tool/"
|
||||
Write-Host $msg
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
$msg = "Neither install.wim nor install.esd exist in the image, this could happen if you use unofficial Windows images. Please don't use shady images from the internet."
|
||||
Write-Host "$($msg) Only use official images. Here are instructions how to download ISO images if the Microsoft website is not showing the link to download and ISO. https://www.techrepublic.com/article/how-to-download-a-windows-10-iso-file-without-using-the-media-creation-tool/"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message $msg
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
|
||||
throw
|
||||
}
|
||||
elseif ((-not (Test-Path -Path $wimFile -PathType Leaf)) -and (Test-Path -Path $wimFile.Replace(".wim", ".esd").Trim() -PathType Leaf)) {
|
||||
@ -265,14 +298,21 @@ function Invoke-MicrowinGetIso {
|
||||
$imageName = $_.ImageName
|
||||
$sync.MicrowinWindowsFlavors.Items.Add("$imageIdx : $imageName")
|
||||
}
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
|
||||
$sync.MicrowinWindowsFlavors.SelectedIndex = 0
|
||||
Write-Host "Finding suitable Pro edition. This can take some time. Do note that this is an automatic process that might not select the edition you want."
|
||||
Invoke-MicrowinBusyInfo -action "wip" -message "Finding suitable Pro edition..." -interactive $false
|
||||
|
||||
Get-WindowsImage -ImagePath $wimFile | ForEach-Object {
|
||||
if ((Get-WindowsImage -ImagePath $wimFile -Index $_.ImageIndex).EditionId -eq "Professional") {
|
||||
# We have found the Pro edition
|
||||
$sync.MicrowinWindowsFlavors.SelectedIndex = $_.ImageIndex - 1
|
||||
}
|
||||
# Allow UI updates during this loop
|
||||
[System.Windows.Forms.Application]::DoEvents()
|
||||
}
|
||||
|
||||
Get-Volume $driveLetter | Get-DiskImage | Dismount-DiskImage
|
||||
Write-Host "Selected value '$($sync.MicrowinWindowsFlavors.SelectedValue)'....."
|
||||
|
||||
@ -283,6 +323,9 @@ function Invoke-MicrowinGetIso {
|
||||
Get-Volume $driveLetter | Get-DiskImage | Dismount-DiskImage
|
||||
Remove-Item -Recurse -Force "$($scratchDir)"
|
||||
Remove-Item -Recurse -Force "$($mountDir)"
|
||||
Invoke-MicrowinBusyInfo -action "warning" -message "Failed to read and unpack ISO"
|
||||
Set-WinUtilTaskbaritem -state "Error" -value 1 -overlay "warning"
|
||||
|
||||
}
|
||||
|
||||
Write-Host "Done reading and unpacking ISO"
|
||||
@ -290,7 +333,7 @@ function Invoke-MicrowinGetIso {
|
||||
Write-Host "*********************************"
|
||||
Write-Host "Check the UI for further steps!!!"
|
||||
|
||||
$sync.BusyMessage.Visibility="Hidden"
|
||||
Invoke-MicrowinBusyInfo -action "done" -message "Done! Proceed with customization."
|
||||
$sync.ProcessRunning = $false
|
||||
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
|
||||
}
|
||||
|
@ -1407,11 +1407,17 @@
|
||||
Grid.Row="0" Grid.Column="1">
|
||||
<StackPanel HorizontalAlignment="Left" Background="{DynamicResource MainBackgroundColor}" SnapsToDevicePixels="True" Visibility="Visible">
|
||||
|
||||
<Grid Name = "BusyMessage" Visibility="Collapsed">
|
||||
<TextBlock Name = "BusyText" Text="NBusy" Padding="22,2,1,1" />
|
||||
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Segoe MDL2 Assets"
|
||||
FontSize="{DynamicResource IconFontSize}" Margin="16,0,0,0"></TextBlock>
|
||||
</Grid>
|
||||
<StackPanel x:Name="MicrowinBusyIndicator" Orientation="Horizontal" Margin="15,15,15,0">
|
||||
<TextBlock x:Name="BusyIcon" FontFamily="Segoe MDL2 Assets" Text=""
|
||||
Margin="0,0,8,2"
|
||||
FontSize="16"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource MicrowinBusyColor}"/>
|
||||
<TextBlock x:Name="BusyText" Text="Microwin"
|
||||
VerticalAlignment="Center"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
Foreground="{DynamicResource MicrowinBusyColor}"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock x:Name = "asciiTextBlock"
|
||||
xml:space ="preserve"
|
||||
|
Reference in New Issue
Block a user