Refactor Update-Scripts function to improve error handling and streamline file operations
This commit is contained in:
25
.gitattributes
vendored
Normal file
25
.gitattributes
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Set default behavior to LF line endings
|
||||||
|
* text=auto eol=lf
|
||||||
|
|
||||||
|
# Explicitly declare text files you want to always be normalized and converted
|
||||||
|
# to native line endings on checkout.
|
||||||
|
*.ps1 text eol=lf
|
||||||
|
*.txt text eol=lf
|
||||||
|
*.json text eol=lf
|
||||||
|
*.js text eol=lf
|
||||||
|
*.py text eol=lf
|
||||||
|
*.csv text eol=lf
|
||||||
|
*.md text eol=lf
|
||||||
|
*.ini text eol=lf
|
||||||
|
*.sh text eol=lf
|
||||||
|
|
||||||
|
# Denote all files that are truly binary and should not be modified.
|
||||||
|
*.png binary
|
||||||
|
*.jpg binary
|
||||||
|
*.jpeg binary
|
||||||
|
*.gif binary
|
||||||
|
*.ico binary
|
||||||
|
*.ttf binary
|
||||||
|
*.zip binary
|
||||||
|
*.db binary
|
||||||
|
*.ptb binary
|
||||||
@@ -73,9 +73,26 @@ function Update-Scripts {
|
|||||||
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
||||||
Write-Host "Comparing update files with current installation..." -ForegroundColor Cyan
|
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) {
|
function Get-FileHashQuick($filePath) {
|
||||||
if (Test-Path $filePath -PathType Leaf) {
|
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 (Get-FileHash -Path $filePath -Algorithm MD5).Hash
|
||||||
}
|
}
|
||||||
return $null
|
return $null
|
||||||
|
|||||||
@@ -73,9 +73,26 @@ function Update-Scripts {
|
|||||||
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
||||||
Write-Host "Comparing update files with current installation..." -ForegroundColor Cyan
|
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) {
|
function Get-FileHashQuick($filePath) {
|
||||||
if (Test-Path $filePath -PathType Leaf) {
|
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 (Get-FileHash -Path $filePath -Algorithm MD5).Hash
|
||||||
}
|
}
|
||||||
return $null
|
return $null
|
||||||
|
|||||||
@@ -73,9 +73,26 @@ function Update-Scripts {
|
|||||||
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
if (($extractedDir) -and ((Test-Path $extractedDir.FullName))) {
|
||||||
Write-Host "Comparing update files with current installation..." -ForegroundColor Cyan
|
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) {
|
function Get-FileHashQuick($filePath) {
|
||||||
if (Test-Path $filePath -PathType Leaf) {
|
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 (Get-FileHash -Path $filePath -Algorithm MD5).Hash
|
||||||
}
|
}
|
||||||
return $null
|
return $null
|
||||||
|
|||||||
Reference in New Issue
Block a user