Refactor Update-Scripts function to enhance file copying logic and preserve directory structure during updates
This commit is contained in:
@@ -151,10 +151,40 @@ function Update-Scripts {
|
||||
if ($applyChoice -eq "Y" -or $applyChoice -eq "y") {
|
||||
Write-Host "Installing updates..." -ForegroundColor Cyan
|
||||
|
||||
# Copy files from the extracted directory directly
|
||||
Get-ChildItem -Path $extractedDir.FullName | Where-Object { $_.Name -ne ".git" } | ForEach-Object {
|
||||
# Copy all content from extracted directory to the root, preserving structure
|
||||
Write-Host "Copying files from $($extractedDir.FullName) to $updateScriptDir..." -ForegroundColor Cyan
|
||||
|
||||
# First, copy all individual files at the root level
|
||||
Get-ChildItem -Path $extractedDir.FullName -File | Where-Object { $_.Name -ne ".gitignore" -and $_.Name -ne ".gitattributes" } | ForEach-Object {
|
||||
$destPath = Join-Path -Path $updateScriptDir -ChildPath $_.Name
|
||||
Copy-Item -Path $_.FullName -Destination $destPath -Recurse -Force
|
||||
Copy-Item -Path $_.FullName -Destination $destPath -Force
|
||||
Write-Host " Copied file: $($_.Name)" -ForegroundColor DarkGray
|
||||
}
|
||||
|
||||
# Then, copy all directories (but not .git)
|
||||
Get-ChildItem -Path $extractedDir.FullName -Directory | Where-Object { $_.Name -ne ".git" } | ForEach-Object {
|
||||
$dirName = $_.Name
|
||||
$destDirPath = Join-Path -Path $updateScriptDir -ChildPath $dirName
|
||||
|
||||
# Create destination directory if it doesn't exist
|
||||
if (-not (Test-Path $destDirPath -PathType Container)) {
|
||||
New-Item -Path $destDirPath -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
# Copy all files from this subdirectory
|
||||
Get-ChildItem -Path $_.FullName -Recurse -File | ForEach-Object {
|
||||
$relPath = $_.FullName.Substring($extractedDir.FullName.Length + 1)
|
||||
$destFilePath = Join-Path -Path $updateScriptDir -ChildPath $relPath
|
||||
$destFileDir = Split-Path -Parent $destFilePath
|
||||
|
||||
# Ensure directory exists
|
||||
if (-not (Test-Path $destFileDir -PathType Container)) {
|
||||
New-Item -Path $destFileDir -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
Copy-Item -Path $_.FullName -Destination $destFilePath -Force
|
||||
Write-Host " Copied: $relPath" -ForegroundColor DarkGray
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Update completed successfully!" -ForegroundColor Green
|
||||
|
||||
Reference in New Issue
Block a user