revert runspace

This commit is contained in:
MyDrift 2024-09-29 10:37:20 +02:00
parent 7a23bd6e0e
commit f22ae6b49e

View File

@ -15,7 +15,6 @@ function Invoke-WPFGetIso {
$sync.BusyMessage.Visibility="Visible"
$sync.BusyText.Text="N Busy"
# Initialize the $sync.GetISOProcess object if it doesn't exist
if (-not $sync.GetISOProcess) {
$sync.GetISOProcess = New-Object PSObject -Property @{
ISOmanual = $false
@ -33,6 +32,7 @@ function Invoke-WPFGetIso {
$sync.GetISOProcess.ISOdownloader = if ($sync["ISOdownloader"].IsChecked) { $true } else { $false }
$sync.GetISOProcess.ISOReleaseItem = $sync["ISORelease"].SelectedItem
$sync.GetISOProcess.ISOLanguageItem = $sync["ISOLanguage"].SelectedItem
$sync.GetISOProcess.isoDownloaderFBD = if ($isoDownloaderFBD.SelectedPath -eq [System.Windows.Forms.DialogResult]::OK) { $true } else { $false }
$sync.GetISOProcess.ISOScratchDir = if ($sync["WPFMicrowinISOScratchDir"].IsChecked) { $true } else { $false }
$sync.GetISOProcess.ISOScratchDirPath = $sync["MicrowinScratchDirBox"].Text
@ -52,12 +52,6 @@ function Invoke-WPFGetIso {
$sync.BusyMessage.Visibility="Hidden"
return
}
Write-Host "File path $($filePath)"
if (-not (Test-Path -Path "$filePath" -PathType Leaf)) {
$msg = "File you've chosen doesn't exist"
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
return
}
} elseif ($sync["ISOdownloader"].IsChecked) {
# Create folder browsers for user-specified locations
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
@ -67,7 +61,6 @@ function Invoke-WPFGetIso {
if ($isoDownloaderFBD.ShowDialog() -ne [System.Windows.Forms.DialogResult]::OK) {
return
}
$FidoTargetFolder = $isoDownloaderFBD.SelectedPath
}
Write-Host " _ __ __ _ "
@ -77,30 +70,28 @@ function Invoke-WPFGetIso {
Write-Host "\/ \/|_| \___||_| \___/ \/ \/ |_||_| |_| "
Write-Host " "
Invoke-WPFRunspace -Argumentlist ($filePath, $FidoTargetFolder) -Debugpreference $DebugPreference -Scriptblock {
param($filePath, $FidoTargetFolder, $DebugPreference)
if ($isoDownloaderFBD.SelectedPath -eq [System.Windows.Forms.DialogResult]::OK) {
# Grab the location of the selected path
$targetFolder = $isoDownloaderFBD.SelectedPath
write-host $filepath
if ($FidoTargetFolder -eq [System.Windows.Forms.DialogResult]::OK) {
# Auto download newest ISO
# Credit: https://github.com/pbatard/Fido
$fidopath = "$env:temp\Fido.ps1"
$originalLocation = $PSScriptRoot
Write-Host "Starting download Process, this will take a while ..."
write-host "Starting download Process, this will take a while ..."
Invoke-WebRequest "https://github.com/pbatard/Fido/raw/master/Fido.ps1" -OutFile $fidopath
Set-Location -Path $env:temp
# Detect if the first option ("System language") has been selected and get a Fido-approved language from the current culture
$lang = if ($sync.GetISOProcess.ISOLanguageItem -eq 0) {
$lang = if ($sync["ISOLanguage"].SelectedIndex -eq 0) {
Get-FidoLangFromCulture -langName (Get-Culture).Name
} else {
$sync.GetISOProcess.ISOLanguageItem
$sync["ISOLanguage"].SelectedItem
}
& $fidopath -Win 'Windows 11' -Rel $sync.GetISOProcess.ISOReleaseItem -Arch "x64" -Lang $lang -Ed "Windows 11 Home/Pro/Edu"
& $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"
@ -113,10 +104,10 @@ function Invoke-WPFGetIso {
$filePath = (Get-ChildItem -Path "$env:temp" -Filter "Win11*.iso").FullName | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$fileName = [IO.Path]::GetFileName("$filePath")
if (($FidoTargetFolder -ne "") -and (Test-Path "$FidoTargetFolder")) {
if (($targetFolder -ne "") -and (Test-Path "$targetFolder")) {
try {
# "Let it download to $env:TEMP and then we **move** it to the file path." - CodingWonders
$destinationFilePath = "$FidoTargetFolder\$fileName"
$destinationFilePath = "$targetFolder\$fileName"
Write-Host "Moving ISO file. Please wait..."
Move-Item -Path "$filePath" -Destination "$destinationFilePath" -Force
$filePath = $destinationFilePath
@ -133,8 +124,15 @@ function Invoke-WPFGetIso {
Write-Host "oscdimg.exe on system: $oscdImgFound"
if (!$oscdImgFound) {
if (!$sync.GetISOProcess.DownloadFromGitHub) {
$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"
@ -160,6 +158,13 @@ function Invoke-WPFGetIso {
}
}
Write-Host "File path $($filePath)"
if (-not (Test-Path -Path "$filePath" -PathType Leaf)) {
$msg = "File you've chosen doesn't exist"
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
return
}
Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
# Detect the file size of the ISO and compare it with the free space of the system drive
@ -183,15 +188,15 @@ function Invoke-WPFGetIso {
}
try {
Write-Host "Mounting Iso. Please wait. ($($filePath))"
$mountedISO = (Mount-DiskImage -PassThru "$filePath")
Write-Host "Mounting Iso. Please wait."
$mountedISO = Mount-DiskImage -PassThru "$filePath"
Write-Host "Done mounting Iso $mountedISO"
$driveLetter = (Get-Volume -DiskImage $mountedISO).DriveLetter
Write-Host "Iso mounted to '$driveLetter'"
} catch {
# @ChrisTitusTech please copy this wiki and change the link below to your copy of the wiki
Write-Host "Failed to mount the image. Error: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "This is NOT winutil's problem, your ISO might be corrupt, or there is a problem on the system" -ForegroundColor Red
Write-Error "Failed to mount the image. Error: $($_.Exception.Message)"
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"
return
@ -202,7 +207,7 @@ function Invoke-WPFGetIso {
$mountedISOPath = (Split-Path -Path "$filePath")
if ($sync.MicrowinScratchDirBox.Text.Trim() -eq "Scratch") {
$sync.MicrowinScratchDirBox.Text = ""
$sync.MicrowinScratchDirBox.Text =""
}
$UseISOScratchDir = $sync.WPFMicrowinISOScratchDir.IsChecked
@ -211,8 +216,10 @@ function Invoke-WPFGetIso {
$sync.MicrowinScratchDirBox.Text=$mountedISOPath
}
if ( -Not $sync.MicrowinScratchDirBox.Text.EndsWith('\') -And $sync.MicrowinScratchDirBox.Text.Length -gt 1) {
if( -Not $sync.MicrowinScratchDirBox.Text.EndsWith('\') -And $sync.MicrowinScratchDirBox.Text.Length -gt 1) {
$sync.MicrowinScratchDirBox.Text = Join-Path $sync.MicrowinScratchDirBox.Text.Trim() '\'
}
# Detect if the folders already exist and remove them
@ -316,7 +323,6 @@ function Invoke-WPFGetIso {
Write-Host ""
Write-Host "*********************************"
Write-Host "Check the UI for further steps!!!"
}
$sync.BusyMessage.Visibility="Hidden"
$sync.ProcessRunning = $false