From c34c804037d282c1fd9de44b91bb926957aa084f Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:43:35 +0100 Subject: [PATCH] Update files - Add detections for whether the image to be processed by MicroWin is Windows 10 or later - Add procedure to clear the indexes ComboBox (WinForms term) every time an ISO is specified --- functions/private/Invoke-MicroWin-Helper.ps1 | 30 +++++++++++++ functions/public/Invoke-WPFGetIso.ps1 | 1 + functions/public/Invoke-WPFMicrowin.ps1 | 12 +++++ winutil.ps1 | 47 +++++++++++++++++++- 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/functions/private/Invoke-MicroWin-Helper.ps1 b/functions/private/Invoke-MicroWin-Helper.ps1 index fb679b47..37d7ae9f 100644 --- a/functions/private/Invoke-MicroWin-Helper.ps1 +++ b/functions/private/Invoke-MicroWin-Helper.ps1 @@ -14,6 +14,36 @@ function Invoke-MicroWin-Helper { } +function Is-CompatibleImage() { +<# + + .SYNOPSIS + Checks the version of a Windows image and determines whether or not it is compatible depending on the Major property + + .PARAMETER imgVersion + The version of the Windows image + +#> + + param + ( + [Parameter(Mandatory = $true)] [string] $imgVersion + ) + + try { + $version = [Version]$imgVersion + if ($version.Major -ge 10) + { + return $True + } + else + { + return $False + } + } catch { + return $False + } +} function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender = $false) { <# diff --git a/functions/public/Invoke-WPFGetIso.ps1 b/functions/public/Invoke-WPFGetIso.ps1 index 072b0c51..dfa5038c 100644 --- a/functions/public/Invoke-WPFGetIso.ps1 +++ b/functions/public/Invoke-WPFGetIso.ps1 @@ -132,6 +132,7 @@ function Invoke-WPFGetIso { [System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error) throw } + $sync.MicrowinWindowsFlavors.Items.Clear() Get-WindowsImage -ImagePath $wimFile | ForEach-Object { $imageIdx = $_.ImageIndex $imageName = $_.ImageName diff --git a/functions/public/Invoke-WPFMicrowin.ps1 b/functions/public/Invoke-WPFMicrowin.ps1 index cc947aaf..914638c1 100644 --- a/functions/public/Invoke-WPFMicrowin.ps1 +++ b/functions/public/Invoke-WPFMicrowin.ps1 @@ -57,6 +57,18 @@ public class PowerManagement { $mountDir = $sync.MicrowinMountDir.Text $scratchDir = $sync.MicrowinScratchDir.Text + $imgVersion = (Get-WindowsImage -ImagePath $mountDir\sources\install.wim -Index $index).Version + + # Detect image version to avoid performing MicroWin processing on Windows 8 and earlier + if ((Is-CompatibleImage $imgVersion) -eq $false) + { + $msg = "This image is not compatible with MicroWin processing. Make sure it isn't a Windows 8 or earlier image." + $dlg_msg = $msg + "`n`nIf you want more information, the version of the image selected is $($imgVersion)`n`nIf an image has been incorrectly marked as incompatible, report an issue to the developers." + Write-Host $msg + [System.Windows.MessageBox]::Show($dlg_msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Exclamation) + return + } + $mountDirExists = Test-Path $mountDir $scratchDirExists = Test-Path $scratchDir if (-not $mountDirExists -or -not $scratchDirExists) diff --git a/winutil.ps1 b/winutil.ps1 index b563c15e..60809b7b 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -10,7 +10,7 @@ Author : Chris Titus @christitustech Runspace Author: @DeveloperDurp GitHub : https://github.com/ChrisTitusTech - Version : 24.01.26 + Version : 24.01.27 #> param ( [switch]$Debug, @@ -47,7 +47,7 @@ Add-Type -AssemblyName System.Windows.Forms # Variable to sync between runspaces $sync = [Hashtable]::Synchronized(@{}) $sync.PSScriptRoot = $PSScriptRoot -$sync.version = "24.01.26" +$sync.version = "24.01.27" $sync.configs = @{} $sync.ProcessRunning = $false @@ -645,6 +645,36 @@ function Invoke-MicroWin-Helper { } +function Is-CompatibleImage() { +<# + + .SYNOPSIS + Checks the version of a Windows image and determines whether or not it is compatible depending on the Major property + + .PARAMETER imgVersion + The version of the Windows image + +#> + + param + ( + [Parameter(Mandatory = $true)] [string] $imgVersion + ) + + try { + $version = [Version]$imgVersion + if ($version.Major -ge 10) + { + return $True + } + else + { + return $False + } + } catch { + return $False + } +} function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender = $false) { <# @@ -2748,6 +2778,7 @@ function Invoke-WPFGetIso { [System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error) throw } + $sync.MicrowinWindowsFlavors.Items.Clear() Get-WindowsImage -ImagePath $wimFile | ForEach-Object { $imageIdx = $_.ImageIndex $imageName = $_.ImageName @@ -2965,6 +2996,18 @@ public class PowerManagement { $mountDir = $sync.MicrowinMountDir.Text $scratchDir = $sync.MicrowinScratchDir.Text + $imgVersion = (Get-WindowsImage -ImagePath $mountDir\sources\install.wim -Index $index).Version + + # Detect image version to avoid performing MicroWin processing on Windows 8 and earlier + if ((Is-CompatibleImage $imgVersion) -eq $false) + { + $msg = "This image is not compatible with MicroWin processing. Make sure it isn't a Windows 8 or earlier image." + $dlg_msg = $msg + "`n`nIf you want more information, the version of the image selected is $($imgVersion)`n`nIf an image has been incorrectly marked as incompatible, report an issue to the developers." + Write-Host $msg + [System.Windows.MessageBox]::Show($dlg_msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Exclamation) + return + } + $mountDirExists = Test-Path $mountDir $scratchDirExists = Test-Path $scratchDir if (-not $mountDirExists -or -not $scratchDirExists)