From d1ca1231045e38316733495e1fdb8590a225be67 Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Wed, 17 Sep 2025 13:22:17 -0700 Subject: [PATCH] Sanitizes app names for storage and paths Applies name sanitization when persisting the app list and when building/checking Win32 and Store download directories. Prevents invalid characters in folder names, aligns persisted names with on-disk structure, and improves detection of existing content to avoid redundant downloads and errors. --- FFUDevelopment/FFUUI.Core/FFUUI.Core.Winget.psm1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Winget.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Winget.psm1 index cba85f8..0505e7b 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Winget.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Winget.psm1 @@ -98,7 +98,7 @@ function Save-WingetList { $appList = @{ apps = @($selectedApps | ForEach-Object { [ordered]@{ - name = $_.Name + name = (ConvertTo-SafeName -Name $_.Name) id = $_.Id source = $_.Source.ToLower() architecture = $_.Architecture @@ -394,6 +394,7 @@ function Start-WingetAppDownloadTask { $source = $ApplicationItemData.Source $status = "Checking..." # Initial local status $resultCode = -1 # Default to error/unknown + $sanitizedAppName = ConvertTo-SafeName -Name $appName # Initial status update Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $appId -Status $status @@ -415,7 +416,7 @@ function Start-WingetAppDownloadTask { $userAppEntry = $userAppListContent | Where-Object { $_.Name -eq $appName } if ($userAppEntry) { - $appFolder = Join-Path -Path "$AppsPath\Win32" -ChildPath $appName + $appFolder = Join-Path -Path "$AppsPath\Win32" -ChildPath $sanitizedAppName if (Test-Path -Path $appFolder -PathType Container) { $folderSize = (Get-ChildItem -Path $appFolder -Recurse | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum if ($folderSize -gt 1MB) { @@ -449,7 +450,7 @@ function Start-WingetAppDownloadTask { # 2. Check existing downloaded Win32 content (folder-based; no WinGetWin32Apps.json dependency) if (-not $appFound -and $source -eq 'winget') { - $appFolder = Join-Path -Path "$AppsPath\Win32" -ChildPath $appName + $appFolder = Join-Path -Path "$AppsPath\Win32" -ChildPath $sanitizedAppName if (Test-Path -Path $appFolder -PathType Container) { $contentFound = $false if ($ApplicationItemData.Architecture -eq 'x86 x64') { @@ -481,7 +482,7 @@ function Start-WingetAppDownloadTask { # Check MSStore folder if (-not $appFound -and (Test-Path -Path "$AppsPath\MSStore" -PathType Container)) { - $appFolder = Join-Path -Path "$AppsPath\MSStore" -ChildPath $appName + $appFolder = Join-Path -Path "$AppsPath\MSStore" -ChildPath $sanitizedAppName if (Test-Path -Path $appFolder -PathType Container) { $folderSize = (Get-ChildItem -Path $appFolder -Recurse | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum if ($folderSize -gt 1MB) { @@ -529,7 +530,7 @@ function Start-WingetAppDownloadTask { } if (-not $appExistsInAppList) { - $newApp = @{ name = $appName; id = $appId; source = $source } + $newApp = @{ name = $sanitizedAppName; id = $appId; source = $source } if (-not ($appListContent.apps -is [array])) { $appListContent.apps = @() } $appListContent.apps += $newApp try {