Improves driver source selection UI clarity

Enhances the driver source selection menu by displaying relative paths instead of full paths, making it easier to identify manufacturer and model folders at a glance.

Adds logic to surface Manufacturer\Model folder structures by expanding top-level folders that contain subdirectories, while preserving simple folder listings when no nested structure exists.

Includes a relative path resolver that normalizes paths and calculates display-friendly names relative to the drivers root directory.

Updates logging and console output to show relative paths for better readability while maintaining full path information internally for file operations.
This commit is contained in:
rbalsleyMSFT
2025-11-18 15:41:19 -08:00
parent beb48e500e
commit 3cb4003bcd
+57 -16
View File
@@ -1120,21 +1120,59 @@ if ($null -eq $DriverSourcePath) {
# Get all WIM files # Get all WIM files
$WimFiles = Get-ChildItem -Path $DriversPath -Filter *.wim -Recurse $WimFiles = Get-ChildItem -Path $DriversPath -Filter *.wim -Recurse
# Get all top-level driver folders # Build folder list that surfaces Manufacturer\Model entries
$DriverFolders = Get-ChildItem -Path $DriversPath -Directory $DriverFolders = Get-ChildItem -Path $DriversPath -Directory
$driversRootFullPath = (Get-Item -Path $DriversPath).FullName.TrimEnd('\')
$relativePathResolver = {
param(
[string]$candidatePath,
[string]$rootPath
)
try {
$normalizedPath = [System.IO.Path]::GetFullPath($candidatePath)
if ($normalizedPath.StartsWith($rootPath, [System.StringComparison]::OrdinalIgnoreCase)) {
$relativeSegment = $normalizedPath.Substring($rootPath.Length).TrimStart('\','/')
if ([string]::IsNullOrWhiteSpace($relativeSegment)) {
return Split-Path -Path $normalizedPath -Leaf
}
return $relativeSegment
}
return $normalizedPath
}
catch {
return $candidatePath
}
}
# Create a combined list # Create a combined list
$DriverSources = @() $DriverSources = @()
$WimFiles | ForEach-Object { foreach ($wimFile in $WimFiles) {
$relativePath = & $relativePathResolver -candidatePath $wimFile.FullName -rootPath $driversRootFullPath
$DriverSources += [PSCustomObject]@{ $DriverSources += [PSCustomObject]@{
Type = 'WIM' Type = 'WIM'
Path = $_.FullName Path = $wimFile.FullName
RelativePath = $relativePath
} }
} }
$DriverFolders | ForEach-Object { foreach ($driverFolder in $DriverFolders) {
$DriverSources += [PSCustomObject]@{ $childModelFolders = Get-ChildItem -Path $driverFolder.FullName -Directory -ErrorAction SilentlyContinue
Type = 'Folder' if (($childModelFolders.Count -gt 0) -and ($driverFolder.Parent.FullName -eq $driversRootFullPath)) {
Path = $_.FullName foreach ($modelFolder in $childModelFolders) {
$relativePath = & $relativePathResolver -candidatePath $modelFolder.FullName -rootPath $driversRootFullPath
$DriverSources += [PSCustomObject]@{
Type = 'Folder'
Path = $modelFolder.FullName
RelativePath = $relativePath
}
}
}
else {
$relativePath = & $relativePathResolver -candidatePath $driverFolder.FullName -rootPath $driversRootFullPath
$DriverSources += [PSCustomObject]@{
Type = 'Folder'
Path = $driverFolder.FullName
RelativePath = $relativePath
}
} }
} }
@@ -1145,8 +1183,9 @@ if ($null -eq $DriverSourcePath) {
if ($DriverSourcesCount -eq 1) { if ($DriverSourcesCount -eq 1) {
$DriverSourcePath = $DriverSources[0].Path $DriverSourcePath = $DriverSources[0].Path
$DriverSourceType = $DriverSources[0].Type $DriverSourceType = $DriverSources[0].Type
WriteLog "Single driver source found. Type: $DriverSourceType, Path: $DriverSourcePath" $selectedRelativePath = $DriverSources[0].RelativePath
Write-Host "Single driver source found. Type: $DriverSourceType, Path: $DriverSourcePath" WriteLog "Single driver source found. Type: $DriverSourceType, Path: $DriverSourcePath, RelativePath: $selectedRelativePath"
Write-Host "Single driver source found. Type: $DriverSourceType, RelativePath: $selectedRelativePath"
} }
else { else {
# Multiple sources found, prompt user # Multiple sources found, prompt user
@@ -1154,12 +1193,13 @@ if ($null -eq $DriverSourcePath) {
$displayArray = @() $displayArray = @()
for ($i = 0; $i -lt $DriverSourcesCount; $i++) { for ($i = 0; $i -lt $DriverSourcesCount; $i++) {
$displayArray += [PSCustomObject]@{ $displayArray += [PSCustomObject]@{
Number = $i + 1 Number = $i + 1
Type = $DriverSources[$i].Type Type = $DriverSources[$i].Type
Path = $DriverSources[$i].Path RelativePath = $DriverSources[$i].RelativePath
Path = $DriverSources[$i].Path
} }
} }
$displayArray | Format-Table -AutoSize $displayArray | Format-Table -Property Number,Type,RelativePath,Path -AutoSize
do { do {
try { try {
@@ -1175,8 +1215,9 @@ if ($null -eq $DriverSourcePath) {
$DriverSourcePath = $DriverSources[$DriverSelected].Path $DriverSourcePath = $DriverSources[$DriverSelected].Path
$DriverSourceType = $DriverSources[$DriverSelected].Type $DriverSourceType = $DriverSources[$DriverSelected].Type
WriteLog "User selected Type: $DriverSourceType, Path: $DriverSourcePath" $selectedRelativePath = $DriverSources[$DriverSelected].RelativePath
Write-Host "`nUser selected Type: $DriverSourceType, Path: $DriverSourcePath" WriteLog "User selected Type: $DriverSourceType, Path: $DriverSourcePath, RelativePath: $selectedRelativePath"
Write-Host "`nUser selected Type: $DriverSourceType, RelativePath: $selectedRelativePath"
} }
} }
else { else {