59 lines
2.8 KiB
Batchfile
59 lines
2.8 KiB
Batchfile
|
|
@echo off
|
||
|
|
setlocal
|
||
|
|
set "BDIR=%~dp0"
|
||
|
|
echo.
|
||
|
|
echo === VI3 DGL-Planung: Code aktualisieren (Sync-Transfer) ===
|
||
|
|
echo.
|
||
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command "$m='### PS'+'CODE ###';$me=[IO.File]::ReadAllText('%~f0');$p=$me.IndexOf($m);$nl=$me.IndexOf([char]10,$p);Invoke-Expression $me.Substring($nl+1)"
|
||
|
|
echo.
|
||
|
|
pause
|
||
|
|
exit /b
|
||
|
|
### PSCODE ###
|
||
|
|
$ErrorActionPreference = 'Stop'
|
||
|
|
# Diese BAT liegt IM Kit-Ordner SyncJob\. Bundles werden von HIER gelesen,
|
||
|
|
# der Code wird in die PORTAL-WURZEL (eine Ebene hoeher) geschrieben. Die
|
||
|
|
# data\*.json (Live-Daten) sind NIE im Bundle und werden NIE angefasst.
|
||
|
|
$here = $env:BDIR
|
||
|
|
$root = Split-Path -Parent ($here.TrimEnd('\'))
|
||
|
|
if (-not (Test-Path -LiteralPath (Join-Path $root 'index.html'))) {
|
||
|
|
Write-Host ('FEHLER: ' + $root + ' ist nicht die Portal-Wurzel (keine index.html).') -ForegroundColor Red
|
||
|
|
Write-Host 'Den Ordner SyncJob in die Portal-Wurzel legen (neben index.html) und erneut starten.' -ForegroundColor Red
|
||
|
|
return
|
||
|
|
}
|
||
|
|
Write-Host ('Ziel (Portal-Wurzel): ' + $root)
|
||
|
|
$bundles = Get-ChildItem -LiteralPath $here -Filter 'sync-bundle-*.txt' | Sort-Object Name
|
||
|
|
if (-not $bundles) { Write-Host 'FEHLER: keine sync-bundle-*.txt neben der BAT gefunden.' -ForegroundColor Red; return }
|
||
|
|
Write-Host ('Bundles: ' + $bundles.Count)
|
||
|
|
$flush = {
|
||
|
|
param($d, $rel, $expLen, $b64)
|
||
|
|
if (-not $rel) { return $null }
|
||
|
|
$bytes = [Convert]::FromBase64String($b64)
|
||
|
|
$full = Join-Path $d ($rel -replace '/', '\')
|
||
|
|
$pd = Split-Path -Parent $full
|
||
|
|
if (-not (Test-Path -LiteralPath $pd)) { New-Item -ItemType Directory -Path $pd -Force | Out-Null }
|
||
|
|
[IO.File]::WriteAllBytes($full, $bytes)
|
||
|
|
return ($bytes.Length -eq $expLen)
|
||
|
|
}
|
||
|
|
$ok = 0; $bad = 0; $rel = $null; $expLen = 0; $sb = New-Object System.Text.StringBuilder
|
||
|
|
foreach ($b in $bundles) {
|
||
|
|
Write-Host ('-> ' + $b.Name)
|
||
|
|
foreach ($line in [IO.File]::ReadAllLines($b.FullName)) {
|
||
|
|
if ($line.StartsWith('### FILE: ')) {
|
||
|
|
$r = & $flush $root $rel $expLen $sb.ToString()
|
||
|
|
if ($r -eq $true) { $ok++ } elseif ($r -eq $false) { $bad++ }
|
||
|
|
$meta = $line.Substring(10); $k = $meta.LastIndexOf(' | ')
|
||
|
|
$rel = $meta.Substring(0, $k); $expLen = [int]$meta.Substring($k + 3); $sb = New-Object System.Text.StringBuilder
|
||
|
|
} elseif ($line.StartsWith('###')) { continue }
|
||
|
|
elseif ($line.Length -gt 0) { [void]$sb.Append($line) }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$r = & $flush $root $rel $expLen $sb.ToString()
|
||
|
|
if ($r -eq $true) { $ok++ } elseif ($r -eq $false) { $bad++ }
|
||
|
|
Write-Host ''
|
||
|
|
if ($bad -eq 0) {
|
||
|
|
Write-Host ('FERTIG: ' + $ok + ' Dateien aktualisiert.') -ForegroundColor Green
|
||
|
|
Write-Host 'Jetzt server.ps1 neu starten und zur Kontrolle sync-check.html oeffnen.' -ForegroundColor Green
|
||
|
|
} else {
|
||
|
|
Write-Host ('FERTIG mit Warnungen: ' + $ok + ' ok, ' + $bad + ' mit falscher Laenge.') -ForegroundColor Yellow
|
||
|
|
}
|