Skip to content

Commit 6153ad0

Browse files
committed
[MicroWin] Update temp path code to use .NET
Apparently special characters in the user path cause %TEMP% to go to the older, crappier, DOS style (8.3)
1 parent 29efb98 commit 6153ad0

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

functions/microwin/Invoke-Microwin.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,11 @@ public class PowerManagement {
557557
$expectedADKPath = "$($adkKitsRoot)Assessment and Deployment Kit"
558558
$expectedADKPath_WOW64Environ = "$($adkKitsRoot_WOW64Environ)Assessment and Deployment Kit"
559559

560+
$tempDir = [IO.Path]::GetTempPath().TrimEnd("\")
561+
560562
# if we downloaded oscdimg from github it will be in the temp directory so use it
561563
# if it is not in temp it is part of ADK and is in global PATH so just set it to oscdimg.exe
562-
$oscdimgPath = Join-Path $env:TEMP 'oscdimg.exe'
564+
$oscdimgPath = "$tempDir\oscdimg.exe"
563565
$oscdImgFound = Test-Path -Path "$oscdimgPath" -PathType Leaf
564566
if ((-not ($oscdImgFound)) -and ((Microwin-TestKitsRootPaths -adkKitsRootPath "$expectedADKPath" -adkKitsRootPath_WOW64Environ "$expectedADKPath_WOW64Environ") -eq $true)) {
565567
if ($expectedADKPath -ne "Assessment and Deployment Kit") { $peToolsPath = $expectedADKPath }

functions/microwin/Invoke-MicrowinGetIso.ps1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function Invoke-MicrowinGetIso {
2121
Write-Host "/ /\/\ \| || (__ | | | (_) | \ /\ / | || | | | "
2222
Write-Host "\/ \/|_| \___||_| \___/ \/ \/ |_||_| |_| "
2323

24+
$tempDir = [IO.Path]::GetTempPath().TrimEnd("\")
25+
2426
if ($sync["ISOmanual"].IsChecked) {
2527
# Open file dialog to let user choose the ISO file
2628
Invoke-MicrowinBusyInfo -action "wip" -message "Please select an ISO file..." -interactive $true
@@ -64,7 +66,7 @@ function Invoke-MicrowinGetIso {
6466
Invoke-MicrowinBusyInfo -action "wip" -message "Downloading Fido script..." -interactive $false
6567
Invoke-WebRequest "https://github.com/pbatard/Fido/raw/master/Fido.ps1" -OutFile $fidopath
6668

67-
Set-Location -Path $env:temp
69+
Set-Location -Path "$tempDir"
6870
# Detect if the first option ("System language") has been selected and get a Fido-approved language from the current culture
6971
$lang = if ($sync["ISOLanguage"].SelectedIndex -eq 0) {
7072
Microwin-GetLangFromCulture -langName (Get-Culture).Name
@@ -84,7 +86,7 @@ function Invoke-MicrowinGetIso {
8486
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
8587
return
8688
}
87-
Set-Location $originalLocation
89+
Set-Location "$originalLocation"
8890
# Use the FullName property to only grab the file names. Using this property is necessary as, without it, you're passing the usual output of Get-ChildItem
8991
# to the variable, and let's be honest, that does NOT exist in the file system
9092
$filePath = (Get-ChildItem -Path "$env:temp" -Filter "Win11*.iso").FullName | Sort-Object LastWriteTime -Descending | Select-Object -First 1
@@ -128,7 +130,7 @@ function Invoke-MicrowinGetIso {
128130
$expectedADKPath = "$($adkKitsRoot)Assessment and Deployment Kit"
129131
$expectedADKPath_WOW64Environ = "$($adkKitsRoot_WOW64Environ)Assessment and Deployment Kit"
130132

131-
$oscdimgPath = Join-Path $env:TEMP 'oscdimg.exe'
133+
$oscdimgPath = "$tempDir\oscdimg.exe"
132134
$oscdImgFound = [bool] (Microwin-TestKitsRootPaths -adkKitsRootPath "$expectedADKPath" -adkKitsRootPath_WOW64Environ "$expectedADKPath_WOW64Environ") -or (Test-Path $oscdimgPath -PathType Leaf)
133135
Write-Host "oscdimg.exe on system: $oscdImgFound"
134136

@@ -241,8 +243,8 @@ function Invoke-MicrowinGetIso {
241243
$randomMicrowinScratch = "MicrowinScratch_${timestamp}_${randomNumber}"
242244
$sync.BusyText.Text=" - Mounting"
243245
Write-Host "Mounting Iso. Please wait."
244-
$mountDir = Join-Path $env:TEMP $randomMicrowin
245-
$scratchDir = Join-Path $env:TEMP $randomMicrowinScratch
246+
$mountDir = "$tempDir\$randomMicrowin"
247+
$scratchDir = "$tempDir\$randomMicrowinScratch"
246248

247249
$sync.MicrowinMountDir.Text = $mountDir
248250
$sync.MicrowinScratchDir.Text = $scratchDir

0 commit comments

Comments
 (0)