Refactor Update-Scripts function to improve error handling and streamline file operations

This commit is contained in:
2025-09-15 12:42:53 -05:00
parent f85d9ad03a
commit ae33b35354
4 changed files with 79 additions and 3 deletions

View File

@@ -73,9 +73,26 @@ function Update-Scripts {
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
Write-Host "Comparing update files with current installation..." -ForegroundColor Cyan
# Function to get file hash
# Function to get file hash that normalizes line endings
function Get-FileHashQuick($filePath) {
if (Test-Path $filePath -PathType Leaf) {
$fileExt = [System.IO.Path]::GetExtension($filePath).ToLower()
# List of text file extensions that might have line ending differences
$textExtensions = @(".ps1", ".txt", ".json", ".js", ".py", ".csv", ".md", ".ini", ".sh")
if ($textExtensions -contains $fileExt) {
# For text files, normalize line endings before computing hash
$content = Get-Content -Path $filePath -Raw
if ($content) {
# Normalize to LF
$normalizedContent = $content.Replace("`r`n", "`n")
$stream = [System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes($normalizedContent))
return (Get-FileHash -InputStream $stream -Algorithm MD5).Hash
}
}
# For binary files or if normalization failed
return (Get-FileHash -Path $filePath -Algorithm MD5).Hash
}
return $null