Files
ProjectStructure_HOME/UpgradeSeqBatches.ps1

111 lines
4.6 KiB
PowerShell
Raw Normal View History

2025-08-26 15:59:26 -06:00
# Update subfolders with the latest UpdateSequences and UpdateAllSequences scripts
2025-08-19 12:11:03 -06:00
2025-11-08 02:36:20 -07:00
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
2025-08-19 12:11:03 -06:00
2025-11-08 02:36:20 -07:00
if (-not $PSScriptRoot) {
$PSScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
}
2025-08-19 12:11:03 -06:00
2025-11-08 02:36:20 -07:00
$configLoader = Join-Path -Path $PSScriptRoot -ChildPath 'ConfigLoader.ps1'
if (-not (Test-Path -LiteralPath $configLoader)) {
throw "Missing ConfigLoader.ps1 in $PSScriptRoot"
}
. $configLoader
$structDir = Get-StructDirectory
$projectsRoot = Get-ProjectsRoot
$sourceBat = Join-Path -Path $structDir -ChildPath 'UpdateSequences.bat'
$sourceAllBat = Join-Path -Path $structDir -ChildPath 'UpdateAllSequences.bat'
$sourceZipBat = Join-Path -Path $structDir -ChildPath 'ZipSeqArchv.bat'
$sourceUnzipBat = Join-Path -Path $structDir -ChildPath 'UnzipSeqArchv.bat'
$configLoaderSource = Join-Path -Path $structDir -ChildPath 'ConfigLoader.ps1'
$configJsonSource = Join-Path -Path $structDir -ChildPath 'config.json'
if (-not (Test-Path -LiteralPath $sourceBat)) { Write-Error "Source file not found: $sourceBat"; exit 1 }
if (-not (Test-Path -LiteralPath $sourceAllBat)) { Write-Error "Source file not found: $sourceAllBat"; exit 1 }
if (-not (Test-Path -LiteralPath $sourceZipBat)) { Write-Error "Source file not found: $sourceZipBat"; exit 1 }
if (-not (Test-Path -LiteralPath $sourceUnzipBat)) { Write-Error "Source file not found: $sourceUnzipBat"; exit 1 }
if (-not (Test-Path -LiteralPath $configLoaderSource)) { Write-Error "Config loader not found: $configLoaderSource"; exit 1 }
if (-not (Test-Path -LiteralPath $configJsonSource)) { Write-Error "Config file not found: $configJsonSource"; exit 1 }
2025-08-19 12:11:03 -06:00
2025-08-26 15:59:26 -06:00
$specs = @(
2025-08-26 16:14:56 -06:00
@{ Name = "UpdateSequences.bat"; Source = $sourceBat },
2025-11-08 02:36:20 -07:00
@{ Name = "UpdateAllSequences.bat"; Source = $sourceAllBat },
@{ Name = "ZipSeqArchv.bat"; Source = $sourceZipBat },
@{ Name = "UnzipSeqArchv.bat"; Source = $sourceUnzipBat }
)
$sharedAssets = @(
@{ Name = 'ConfigLoader.ps1'; Source = $configLoaderSource },
@{ Name = 'config.json'; Source = $configJsonSource }
2025-08-26 15:59:26 -06:00
)
2025-08-19 12:11:03 -06:00
2025-08-26 15:59:26 -06:00
$grandTotal = 0
$grandUpdated = 0
$grandFailed = 0
2025-11-08 02:36:20 -07:00
$touchedDirs = @{}
2025-08-19 12:11:03 -06:00
2025-08-26 15:59:26 -06:00
foreach ($spec in $specs) {
Write-Host "=== Updating $($spec.Name) files ===" -ForegroundColor Cyan
Write-Host "Source: $($spec.Source)" -ForegroundColor White
Write-Host ""
2025-11-08 02:36:20 -07:00
$targets = Get-ChildItem -LiteralPath $projectsRoot -Recurse -Filter $spec.Name -File -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -ne $spec.Source }
2025-08-26 15:59:26 -06:00
Write-Host "Found $($targets.Count) target files to update:" -ForegroundColor Yellow
foreach ($t in $targets) { Write-Host " - $($t.FullName)" -ForegroundColor Gray }
Write-Host ""
2025-08-19 12:11:03 -06:00
2025-08-26 15:59:26 -06:00
$updated = 0
$failed = 0
foreach ($t in $targets) {
2025-11-08 02:36:20 -07:00
$targetDir = $t.Directory.FullName
2025-08-26 15:59:26 -06:00
try {
Copy-Item -Path $spec.Source -Destination $t.FullName -Force
2025-09-16 22:11:55 -06:00
Write-Host "✓ Updated: $($t.FullName)" -ForegroundColor Green
2025-08-26 15:59:26 -06:00
$updated++
2025-11-08 02:36:20 -07:00
if (-not $touchedDirs.ContainsKey($targetDir)) {
foreach ($asset in $sharedAssets) {
try {
Copy-Item -Path $asset.Source -Destination (Join-Path -Path $targetDir -ChildPath $asset.Name) -Force
}
catch {
Write-Host "✗ Failed to copy $($asset.Name) to $targetDir" -ForegroundColor Red
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red
}
}
$touchedDirs[$targetDir] = $true
}
2025-08-26 15:59:26 -06:00
}
catch {
2025-09-16 22:11:55 -06:00
Write-Host "✗ Failed to update: $($t.FullName)" -ForegroundColor Red
2025-08-26 15:59:26 -06:00
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red
$failed++
}
2025-08-19 12:11:03 -06:00
}
2025-08-26 15:59:26 -06:00
Write-Host ""
Write-Host "=== $($spec.Name) SUMMARY ===" -ForegroundColor Magenta
Write-Host "Successfully updated: $updated" -ForegroundColor Green
Write-Host "Failed updates: $failed" -ForegroundColor Red
Write-Host "Total targets: $($targets.Count)" -ForegroundColor White
Write-Host ""
$grandTotal += $targets.Count
$grandUpdated += $updated
$grandFailed += $failed
}
2025-08-19 12:11:03 -06:00
2025-08-26 15:59:26 -06:00
Write-Host "=== OVERALL SUMMARY ===" -ForegroundColor Magenta
Write-Host "Total targets across all files: $grandTotal" -ForegroundColor White
Write-Host "Total successfully updated: $grandUpdated" -ForegroundColor Green
Write-Host "Total failed: $grandFailed" -ForegroundColor Red
if ($grandFailed -eq 0) {
2025-09-16 22:11:55 -06:00
Write-Host "`n🎉 All files updated successfully!" -ForegroundColor Green
2025-08-19 12:11:03 -06:00
} else {
2025-09-16 22:11:55 -06:00
Write-Host "`n⚠️ Some updates failed. See errors above." -ForegroundColor Yellow
2025-08-19 12:11:03 -06:00
}