mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-02-17 07:56:24 +00:00
Refactor code structure for improved readability and maintainability (#473)
* Add ToolTips to Tweaks
This commit is contained in:
45
Scripts/FileIO/LoadAppsFromFile.ps1
Normal file
45
Scripts/FileIO/LoadAppsFromFile.ps1
Normal file
@@ -0,0 +1,45 @@
|
||||
# Returns list of apps from the specified file, it trims the app names and removes any comments
|
||||
function LoadAppsFromFile {
|
||||
param (
|
||||
$appsFilePath
|
||||
)
|
||||
|
||||
$appsList = @()
|
||||
|
||||
if (-not (Test-Path $appsFilePath)) {
|
||||
return $appsList
|
||||
}
|
||||
|
||||
try {
|
||||
# Check if file is JSON or text format
|
||||
if ($appsFilePath -like "*.json") {
|
||||
# JSON file format
|
||||
$jsonContent = Get-Content -Path $appsFilePath -Raw | ConvertFrom-Json
|
||||
Foreach ($appData in $jsonContent.Apps) {
|
||||
$appId = $appData.AppId.Trim()
|
||||
$selectedByDefault = $appData.SelectedByDefault
|
||||
if ($selectedByDefault -and $appId.length -gt 0) {
|
||||
$appsList += $appId
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
# Legacy text file format
|
||||
Foreach ($app in (Get-Content -Path $appsFilePath | Where-Object { $_ -notmatch '^#.*' -and $_ -notmatch '^\s*$' } )) {
|
||||
if (-not ($app.IndexOf('#') -eq -1)) {
|
||||
$app = $app.Substring(0, $app.IndexOf('#'))
|
||||
}
|
||||
|
||||
$app = $app.Trim()
|
||||
$appString = $app.Trim('*')
|
||||
$appsList += $appString
|
||||
}
|
||||
}
|
||||
|
||||
return $appsList
|
||||
}
|
||||
catch {
|
||||
Write-Error "Unable to read apps list from file: $appsFilePath"
|
||||
AwaitKeyToExit
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user