mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
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.
This commit is contained in:
@@ -98,7 +98,7 @@ function Save-WingetList {
|
|||||||
$appList = @{
|
$appList = @{
|
||||||
apps = @($selectedApps | ForEach-Object {
|
apps = @($selectedApps | ForEach-Object {
|
||||||
[ordered]@{
|
[ordered]@{
|
||||||
name = $_.Name
|
name = (ConvertTo-SafeName -Name $_.Name)
|
||||||
id = $_.Id
|
id = $_.Id
|
||||||
source = $_.Source.ToLower()
|
source = $_.Source.ToLower()
|
||||||
architecture = $_.Architecture
|
architecture = $_.Architecture
|
||||||
@@ -394,6 +394,7 @@ function Start-WingetAppDownloadTask {
|
|||||||
$source = $ApplicationItemData.Source
|
$source = $ApplicationItemData.Source
|
||||||
$status = "Checking..." # Initial local status
|
$status = "Checking..." # Initial local status
|
||||||
$resultCode = -1 # Default to error/unknown
|
$resultCode = -1 # Default to error/unknown
|
||||||
|
$sanitizedAppName = ConvertTo-SafeName -Name $appName
|
||||||
|
|
||||||
# Initial status update
|
# Initial status update
|
||||||
Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $appId -Status $status
|
Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $appId -Status $status
|
||||||
@@ -415,7 +416,7 @@ function Start-WingetAppDownloadTask {
|
|||||||
$userAppEntry = $userAppListContent | Where-Object { $_.Name -eq $appName }
|
$userAppEntry = $userAppListContent | Where-Object { $_.Name -eq $appName }
|
||||||
|
|
||||||
if ($userAppEntry) {
|
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) {
|
if (Test-Path -Path $appFolder -PathType Container) {
|
||||||
$folderSize = (Get-ChildItem -Path $appFolder -Recurse | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum
|
$folderSize = (Get-ChildItem -Path $appFolder -Recurse | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum
|
||||||
if ($folderSize -gt 1MB) {
|
if ($folderSize -gt 1MB) {
|
||||||
@@ -449,7 +450,7 @@ function Start-WingetAppDownloadTask {
|
|||||||
|
|
||||||
# 2. Check existing downloaded Win32 content (folder-based; no WinGetWin32Apps.json dependency)
|
# 2. Check existing downloaded Win32 content (folder-based; no WinGetWin32Apps.json dependency)
|
||||||
if (-not $appFound -and $source -eq 'winget') {
|
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) {
|
if (Test-Path -Path $appFolder -PathType Container) {
|
||||||
$contentFound = $false
|
$contentFound = $false
|
||||||
if ($ApplicationItemData.Architecture -eq 'x86 x64') {
|
if ($ApplicationItemData.Architecture -eq 'x86 x64') {
|
||||||
@@ -481,7 +482,7 @@ function Start-WingetAppDownloadTask {
|
|||||||
|
|
||||||
# Check MSStore folder
|
# Check MSStore folder
|
||||||
if (-not $appFound -and (Test-Path -Path "$AppsPath\MSStore" -PathType Container)) {
|
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) {
|
if (Test-Path -Path $appFolder -PathType Container) {
|
||||||
$folderSize = (Get-ChildItem -Path $appFolder -Recurse | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum
|
$folderSize = (Get-ChildItem -Path $appFolder -Recurse | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum
|
||||||
if ($folderSize -gt 1MB) {
|
if ($folderSize -gt 1MB) {
|
||||||
@@ -529,7 +530,7 @@ function Start-WingetAppDownloadTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (-not $appExistsInAppList) {
|
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 = @() }
|
if (-not ($appListContent.apps -is [array])) { $appListContent.apps = @() }
|
||||||
$appListContent.apps += $newApp
|
$appListContent.apps += $newApp
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user