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:
32
Scripts/FileIO/LoadJsonFile.ps1
Normal file
32
Scripts/FileIO/LoadJsonFile.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
# Loads a JSON file from the specified path and returns the parsed object
|
||||
# Returns $null if the file doesn't exist or if parsing fails
|
||||
function LoadJsonFile {
|
||||
param (
|
||||
[string]$filePath,
|
||||
[string]$expectedVersion = $null,
|
||||
[switch]$optionalFile
|
||||
)
|
||||
|
||||
if (-not (Test-Path $filePath)) {
|
||||
if (-not $optionalFile) {
|
||||
Write-Error "File not found: $filePath"
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
try {
|
||||
$jsonContent = Get-Content -Path $filePath -Raw | ConvertFrom-Json
|
||||
|
||||
# Validate version if specified
|
||||
if ($expectedVersion -and $jsonContent.Version -and $jsonContent.Version -ne $expectedVersion) {
|
||||
Write-Error "$(Split-Path $filePath -Leaf) version mismatch (expected $expectedVersion, found $($jsonContent.Version))"
|
||||
return $null
|
||||
}
|
||||
|
||||
return $jsonContent
|
||||
}
|
||||
catch {
|
||||
Write-Error "Failed to parse JSON file: $filePath"
|
||||
return $null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user