newproject working

This commit is contained in:
Nathan
2025-11-06 10:47:19 -07:00
parent 16fee83832
commit ce9f8da4b9
4 changed files with 1444 additions and 181 deletions

View File

@@ -40,8 +40,11 @@ mkdir "%projectRoot%\Pr\RnR\RIFE"
if not exist "%projectRoot%\Renders" mkdir "%projectRoot%\Renders"
:: Place helper scripts into Renders
if exist "%~dp0NewDaily.bat" copy /Y "%~dp0NewDaily.bat" "%projectRoot%\Renders\NewDaily.bat" >nul
if exist "%~dp0UpdateSequences.bat" copy /Y "%~dp0UpdateSequences.bat" "%projectRoot%\Renders\UpdateSequences.bat" >nul
set "templateRoot=%~dp0"
if not exist "%templateRoot%ZipSeqArchv.bat" set "templateRoot=A:\1 Amazon_Active_Projects\3 ProjectStructure\"
if exist "%templateRoot%UpdateSequences.bat" copy /Y "%templateRoot%UpdateSequences.bat" "%projectRoot%\Renders\UpdateSequences.bat" >nul
if exist "%templateRoot%ZipSeqArchv.bat" copy /Y "%templateRoot%ZipSeqArchv.bat" "%projectRoot%\Renders\ZipSeqArchv.bat" >nul
if exist "%templateRoot%UnzipSeqArchv.bat" copy /Y "%templateRoot%UnzipSeqArchv.bat" "%projectRoot%\Renders\UnzipSeqArchv.bat" >nul
:: Use repo-provided templates for git config files
if exist "%~dp0components\gitignore" copy /Y "%~dp0components\gitignore" "%projectRoot%\.gitignore" >nul

View File

@@ -6,17 +6,6 @@ param(
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Get-YoungestTimestamp {
param(
[Parameter(Mandatory)] [string]$FolderPath
)
$files = Get-ChildItem -LiteralPath $FolderPath -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -notlike '*\_archive\*' }
$young = $files | Sort-Object LastWriteTime -Descending | Select-Object -First 1 -ExpandProperty LastWriteTime
if (-not $young) { return [datetime]::Parse('1900-01-01') }
return $young
}
function Sync-SequenceFilenames {
param(
[Parameter(Mandatory)] [string]$SequenceFolderPath,
@@ -149,196 +138,83 @@ function Rename-SequencePreviewMp4 {
try {
$root = (Get-Location).ProviderPath
$currentDir = Join-Path $root '_CURRENT'
if (-not (Test-Path -LiteralPath $currentDir)) {
New-Item -ItemType Directory -Path $currentDir -Force | Out-Null
$logFile = $null
if ($DebugMode) {
$logFile = Join-Path $root ("UpdateSequences_{0}.log" -f (Get-Date -Format 'yyyyMMdd_HHmmss'))
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] === UpdateSequences started in '$root' ===" | Out-File -LiteralPath $logFile -Encoding UTF8
}
$logFile = Join-Path $currentDir '_UpdateSequences.log'
$sequenceFolders = @()
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] === UpdateSequences (ps1) started in '$root' ===" | Add-Content -LiteralPath $logFile
$dailyDirs = Get-ChildItem -LiteralPath $root -Directory -Filter 'daily_*' -ErrorAction SilentlyContinue |
Where-Object { $_.Name -ne '_archive' }
foreach ($d in $dailyDirs) {
$seqDirs = @(Get-ChildItem -LiteralPath $d.FullName -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -ne '_archive' })
if ($seqDirs.Count -eq 0) {
$sequenceFolders += $d
} else {
$sequenceFolders += $seqDirs
}
}
# Scan for folders with work convention: daily_*
$dailyDirs = Get-ChildItem -LiteralPath $root -Directory -Filter 'daily_*' | Where-Object { $_.Name -ne '_archive' }
$directSeqs = Get-ChildItem -LiteralPath $root -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -ne '_archive' -and $_.Name -notlike 'daily_*' }
$sequenceFolders += $directSeqs
$mapDaily = @{}
$dailiesScanned = 0
$sequenceFolders = $sequenceFolders | Sort-Object -Property FullName -Unique
if (-not $sequenceFolders) {
Write-Host "No sequence folders found." -ForegroundColor Yellow
if ($logFile) { "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] No sequence folders found." | Add-Content -LiteralPath $logFile }
exit 0
}
$totalSequences = 0
$filesRenamedTotal = 0
$renameCollisions = 0
$renameErrors = 0
$mp4RenamedTotal = 0
$mp4Collisions = 0
$mp4Errors = 0
foreach ($d in $dailyDirs) {
$dailiesScanned++
$seqDirs = @(Get-ChildItem -LiteralPath $d.FullName -Directory | Where-Object { $_.Name -ne '_archive' })
if ($seqDirs.Count -eq 0) { $seqDirs = @($d) }
foreach ($s in $seqDirs) {
if (-not (Test-Path -LiteralPath $s.FullName)) { continue }
$renameResult = Sync-SequenceFilenames -SequenceFolderPath $s.FullName -SequenceName $s.Name -LogFile $logFile
foreach ($seq in $sequenceFolders) {
$totalSequences++
$renameResult = Sync-SequenceFilenames -SequenceFolderPath $seq.FullName -SequenceName $seq.Name -LogFile $logFile
if ($DebugMode -or $renameResult.Renamed -gt 0 -or $renameResult.Collisions -gt 0 -or $renameResult.Errors -gt 0) {
Write-Host "[RENAME]|$($s.FullName)|$($s.Name)|checked=$($renameResult.Checked)|renamed=$($renameResult.Renamed)|collisions=$($renameResult.Collisions)|errors=$($renameResult.Errors)" -ForegroundColor Cyan
Write-Host "[RENAME]|$($seq.FullName)|$($seq.Name)|checked=$($renameResult.Checked)|renamed=$($renameResult.Renamed)|collisions=$($renameResult.Collisions)|errors=$($renameResult.Errors)" -ForegroundColor Cyan
}
$filesRenamedTotal += $renameResult.Renamed
$renameCollisions += $renameResult.Collisions
$renameErrors += $renameResult.Errors
if ($renameResult.Renamed -gt 0 -and $renameResult.FrameCount -gt 0 -and $null -ne $renameResult.MinFrame -and $null -ne $renameResult.MaxFrame) {
$mp4Result = Rename-SequencePreviewMp4 -SequenceFolderPath $s.FullName -SequenceName $s.Name -StartFrame $renameResult.MinFrame -EndFrame $renameResult.MaxFrame -LogFile $logFile
if ($renameResult.FrameCount -gt 0 -and $renameResult.MinFrame -ne $null -and $renameResult.MaxFrame -ne $null) {
$mp4Result = Rename-SequencePreviewMp4 -SequenceFolderPath $seq.FullName -SequenceName $seq.Name -StartFrame $renameResult.MinFrame -EndFrame $renameResult.MaxFrame -LogFile $logFile
if ($DebugMode -or $mp4Result.Renamed -gt 0 -or $mp4Result.Collisions -gt 0 -or $mp4Result.Errors -gt 0) {
Write-Host "[MP4]|$($s.FullName)|$($s.Name)|renamed=$($mp4Result.Renamed)|collisions=$($mp4Result.Collisions)|errors=$($mp4Result.Errors)" -ForegroundColor Cyan
Write-Host "[MP4]|$($seq.FullName)|$($seq.Name)|renamed=$($mp4Result.Renamed)|collisions=$($mp4Result.Collisions)|errors=$($mp4Result.Errors)" -ForegroundColor Cyan
}
$mp4RenamedTotal += $mp4Result.Renamed
$mp4Collisions += $mp4Result.Collisions
$mp4Errors += $mp4Result.Errors
}
$young = Get-YoungestTimestamp -FolderPath $s.FullName
$filesCount = @(Get-ChildItem -LiteralPath $s.FullName -Recurse -File -ErrorAction SilentlyContinue | Where-Object { $_.FullName -notlike '*\_archive\*' }).Count
$seqName = $s.Name
$cand = [pscustomobject]@{
Seq = $seqName
SrcFull = $s.FullName
Young = $young
FilesCount = $filesCount
}
if ($mapDaily.ContainsKey($seqName)) {
if ($mapDaily[$seqName].Young -lt $young) { $mapDaily[$seqName] = $cand }
} else {
$mapDaily[$seqName] = $cand
}
}
}
$mapCurrent = @{}
if (Test-Path -LiteralPath $currentDir) {
foreach ($c in Get-ChildItem -LiteralPath $currentDir -Directory | Where-Object { $_.Name -ne '_archive' }) {
$mapCurrent[$c.Name] = Get-YoungestTimestamp -FolderPath $c.FullName
}
}
$lines = @()
$lines += "[MAPCOUNT]|count=$($mapDaily.Count)"
$total = 0
$toCopy = 0
foreach ($k in $mapDaily.Keys) {
$total++
$d = $mapDaily[$k]
$curYoung = if ($mapCurrent.ContainsKey($k)) { $mapCurrent[$k] } else { [datetime]::Parse('1900-01-01') }
if ($d.Young -gt $curYoung) {
$toCopy++
$lines += "[COPY]|$($d.SrcFull)|$($d.Seq)|files=$($d.FilesCount)|young=$($d.Young.ToString('s'))"
} else {
$lines += "[SKIP]|$($d.SrcFull)|$($d.Seq)|reason=notNewer|srcYoung=$($d.Young.ToString('s'))|curYoung=$($curYoung.ToString('s'))"
}
}
$lines += "[META]|dailiesScanned=$dailiesScanned|sequencesTotal=$total|toCopy=$toCopy"
# Print plan to console instead of writing to file
Write-Host "=== UPDATE PLAN ===" -ForegroundColor Cyan
foreach ($line in $lines) {
if ($line -like '[COPY]*') {
Write-Host $line -ForegroundColor Green
} elseif ($line -like '[SKIP]*') {
Write-Host $line -ForegroundColor Yellow
} else {
Write-Host $line -ForegroundColor White
}
}
Write-Host "==================" -ForegroundColor Cyan
$sequencesMirrored = 0
$mirrorFailures = 0
foreach ($line in $lines) {
if ($line.StartsWith('[COPY]')) {
$parts = $line -split '\|'
$srcFull = $parts[1]
$seqName = $parts[2]
$dstAbs = Join-Path $currentDir $seqName
if (Test-Path -LiteralPath $dstAbs) {
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] WIPE: removing existing destination '$dstAbs'" | Add-Content -LiteralPath $logFile
try {
Remove-Item -LiteralPath $dstAbs -Recurse -Force -ErrorAction Stop
}
catch {
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] WIPE ERROR: $($_.Exception.Message)" | Add-Content -LiteralPath $logFile
}
}
if (-not (Test-Path -LiteralPath $dstAbs)) { New-Item -ItemType Directory -Path $dstAbs -Force | Out-Null }
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] Mirror: '$srcFull' -> '$dstAbs'" | Add-Content -LiteralPath $logFile
$robocopyArgs = @(
$srcFull,
$dstAbs,
'/MIR','/MT:8','/R:1','/W:1','/COPY:DAT','/DCOPY:DAT','/FFT','/NFL','/NDL','/NP','/NJH','/NJS','/XD','_archive'
)
$null = & robocopy @robocopyArgs 2>&1 | Add-Content -LiteralPath $logFile
$rc = $LASTEXITCODE
if ($rc -lt 8) {
$sequencesMirrored++
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] OK rc=$rc" | Add-Content -LiteralPath $logFile
} else {
$mirrorFailures++
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] ERROR rc=$rc" | Add-Content -LiteralPath $logFile
}
}
}
# Print summary report to console
Write-Host "=== SUMMARY REPORT ===" -ForegroundColor Magenta
Write-Host "Dailies scanned: $dailiesScanned" -ForegroundColor White
Write-Host "Sequences found: $total" -ForegroundColor White
Write-Host "Planned copies: $toCopy" -ForegroundColor Green
Write-Host "Completed OK: $sequencesMirrored" -ForegroundColor Green
Write-Host "Completed FAIL: $mirrorFailures" -ForegroundColor Red
Write-Host "Sequences scanned: $totalSequences" -ForegroundColor White
Write-Host "Files renamed: $filesRenamedTotal (collisions: $renameCollisions, errors: $renameErrors)" -ForegroundColor White
Write-Host "Preview MP4s renamed: $mp4RenamedTotal (collisions: $mp4Collisions, errors: $mp4Errors)" -ForegroundColor White
# Summarize skipped sequences
$skippedLines = @()
foreach ($line in $lines) {
if ($line.StartsWith('[SKIP]')) {
$skippedLines += $line
}
}
if ($skippedLines.Count -gt 0) {
Write-Host "`n=== SKIPPED SEQUENCES ===" -ForegroundColor Yellow
$skippedByReason = @{}
foreach ($skip in $skippedLines) {
$parts = $skip -split '\|'
$reason = $parts[3]
$seqName = $parts[2]
if (-not $skippedByReason.ContainsKey($reason)) {
$skippedByReason[$reason] = @()
}
$skippedByReason[$reason] += $seqName
}
foreach ($reason in $skippedByReason.Keys) {
$seqs = $skippedByReason[$reason]
Write-Host "$reason ($($seqs.Count) sequences):" -ForegroundColor Yellow
foreach ($seq in $seqs | Sort-Object) {
Write-Host " - $seq" -ForegroundColor White
}
}
Write-Host "========================" -ForegroundColor Yellow
}
Write-Host "=====================" -ForegroundColor Magenta
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] === UpdateSequences (ps1) completed (d=$dailiesScanned seq=$total ok=$sequencesMirrored fail=$mirrorFailures) ===" | Add-Content -LiteralPath $logFile
if ($logFile) {
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] === UpdateSequences completed (seq=$totalSequences renamed=$filesRenamedTotal mp4=$mp4RenamedTotal) ===" | Add-Content -LiteralPath $logFile
}
Write-Host "@$logFile"
exit 0
}
catch {
$root = (Get-Location).ProviderPath
$currentDir = Join-Path $root '_CURRENT'
if (-not (Test-Path -LiteralPath $currentDir)) {
New-Item -ItemType Directory -Path $currentDir -Force | Out-Null
if ($logFile) {
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] ERROR: $($_.Exception.Message)" | Add-Content -LiteralPath $logFile
}
$planFile = Join-Path $currentDir '_UpdatePlan.txt'
($_.Exception | Out-String) | Set-Content -LiteralPath ($planFile + '.error.txt') -Encoding ASCII
Write-Host "ERROR: $_"
Write-Host "ERROR: $_" -ForegroundColor Red
exit 1
}

View File

@@ -44,7 +44,7 @@ if not exist "%rendersDir%" (
)
)
for %%F in (NewDaily.bat UpdateSequences.bat) do (
for %%F in (UpdateSequences.bat ZipSeqArchv.bat UnzipSeqArchv.bat) do (
if exist "%scriptDir%%%F" (
if "%DRY%"=="1" (
echo [DRY] copy "%scriptDir%%%F" "%rendersDir%\%%F"
@@ -122,12 +122,14 @@ if exist "%animDir%" (
rem Ensure submodule dir exists and place helper scripts there
if "%DRY%"=="1" (
if not exist "!_subdir!" echo [DRY] mkdir "!_subdir!"
if exist "%scriptDir%NewDaily.bat" echo [DRY] copy "%scriptDir%NewDaily.bat" "!_subdir!\NewDaily.bat"
if exist "%scriptDir%UpdateSequences.bat" echo [DRY] copy "%scriptDir%UpdateSequences.bat" "!_subdir!\UpdateSequences.bat"
if exist "%scriptDir%ZipSeqArchv.bat" echo [DRY] copy "%scriptDir%ZipSeqArchv.bat" "!_subdir!\ZipSeqArchv.bat"
if exist "%scriptDir%UnzipSeqArchv.bat" echo [DRY] copy "%scriptDir%UnzipSeqArchv.bat" "!_subdir!\UnzipSeqArchv.bat"
) else (
if not exist "!_subdir!" mkdir "!_subdir!" >nul 2>&1
if exist "%scriptDir%NewDaily.bat" copy /Y "%scriptDir%NewDaily.bat" "!_subdir!\NewDaily.bat" >nul
if exist "%scriptDir%UpdateSequences.bat" copy /Y "%scriptDir%UpdateSequences.bat" "!_subdir!\UpdateSequences.bat" >nul
if exist "%scriptDir%ZipSeqArchv.bat" copy /Y "%scriptDir%ZipSeqArchv.bat" "!_subdir!\ZipSeqArchv.bat" >nul
if exist "%scriptDir%UnzipSeqArchv.bat" copy /Y "%scriptDir%UnzipSeqArchv.bat" "!_subdir!\UnzipSeqArchv.bat" >nul
)
for /d %%D in ("%%S\daily_*") do (
set "dailyName=%%~nD"