demo knacksicherer: edition im code + launcher prüft dateien
- edition.json entfällt; die Edition steckt als Marker im Code (const BUILD_EDITION). build.ps1 -Demo flippt ihn nur in der gestagten Kopie auf 'demo'; die Quelle bleibt 'full'. Keine lösch-/editierbare Extra-Datei mehr. - Launcher: beim Auspacken wird ein Fingerabdruck (SHA-256 über server.js, package.json, lib\, public\, tools\) in .ok gespeichert und bei JEDEM Start neu geprüft. Wurde im entpackten App-Ordner etwas geändert oder gelöscht (z. B. der Demo-Marker zurückgesetzt), wird automatisch das Original neu ausgepackt. node_modules/node bleiben aussen vor (gross, nicht Teil der Demo-Logik → schneller Start). Getestet: Marker im entpackten server.js auf 'full' gepatcht → nach Neustart wieder 'full'->'demo', Server meldet wieder Demo. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
11
build.ps1
11
build.ps1
@@ -11,7 +11,7 @@
|
||||
# Needs the .NET 8+ SDK (and Node.js on this PC, which is copied into the release exe).
|
||||
#
|
||||
# powershell -ExecutionPolicy Bypass -File build.ps1 -Demo -> release\ProjectDashboard-Demo.exe (+ -Demo-Setup.exe)
|
||||
# the free demo: at most 6 projects (edition.json in the payload). The full build is not touched.
|
||||
# the free demo: at most 6 projects (edition marker in server.js). The full build is not touched.
|
||||
param([switch]$Release, [switch]$Demo)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if ($Demo) { $Release = [switch]$true }
|
||||
@@ -73,9 +73,14 @@ Enthaltene Software:
|
||||
- Lucide Icons (ISC) - node_modules\lucide-static\LICENSE
|
||||
"@
|
||||
|
||||
# demo edition: server.js reads edition.json (WriteAllText = UTF-8 without BOM)
|
||||
# demo edition: flip the marker in the STAGED server.js only (the source stays 'full')
|
||||
if ($Demo) {
|
||||
[IO.File]::WriteAllText((Join-Path $payload 'edition.json'), '{ "demo": true, "limit": 6, "buyUrl": "https://sn09.itch.io/project-dashboard" }')
|
||||
$sf = Join-Path $payload 'server.js'
|
||||
$txt = [IO.File]::ReadAllText($sf)
|
||||
$flip = $txt.Replace("const BUILD_EDITION = 'full'", "const BUILD_EDITION = 'demo'")
|
||||
if ($flip -eq $txt) { throw "Demo-Marker nicht gefunden in server.js (const BUILD_EDITION = 'full')" }
|
||||
[IO.File]::WriteAllText($sf, $flip, (New-Object Text.UTF8Encoding $false))
|
||||
Write-Host ' edition: demo'
|
||||
}
|
||||
|
||||
Write-Host '2/3 Packen ...'
|
||||
|
||||
@@ -343,8 +343,33 @@ sealed class MainForm : Form
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Unpacks the embedded payload.zip once per version to <DataDir>\app\<hash>
|
||||
// and removes older versions. Returns the app folder.
|
||||
// App files whose change would alter the app logic or unlock the demo. node_modules and node.exe
|
||||
// are third-party and large, so they're left out: the edition marker and the demo limits live only
|
||||
// in these. ".ok" is the stored fingerprint and is never part of it.
|
||||
static readonly string[] CheckFiles = { "server.js", "package.json" };
|
||||
static readonly string[] CheckDirs = { "lib", "public", "tools" };
|
||||
|
||||
// Hash of the integrity-relevant files (path + contents), stable regardless of file order.
|
||||
static string Fingerprint(string dir)
|
||||
{
|
||||
var files = new List<string>();
|
||||
foreach (var f in CheckFiles) { var p = Path.Combine(dir, f); if (File.Exists(p)) files.Add(p); }
|
||||
foreach (var d in CheckDirs) { var p = Path.Combine(dir, d); if (Directory.Exists(p)) files.AddRange(Directory.GetFiles(p, "*", SearchOption.AllDirectories)); }
|
||||
var items = files
|
||||
.Select(f => (key: Path.GetRelativePath(dir, f).Replace('\\', '/').ToLowerInvariant(), path: f))
|
||||
.OrderBy(x => x.key, StringComparer.Ordinal);
|
||||
using var ih = IncrementalHash.CreateHash(HashAlgorithmName.SHA256);
|
||||
foreach (var (key, path) in items)
|
||||
{
|
||||
ih.AppendData(System.Text.Encoding.UTF8.GetBytes(key + "\n"));
|
||||
ih.AppendData(File.ReadAllBytes(path));
|
||||
}
|
||||
return Convert.ToHexString(ih.GetHashAndReset()).ToLowerInvariant();
|
||||
}
|
||||
|
||||
// Unpacks the embedded payload.zip once per version to <DataDir>\app\<hash> and removes older
|
||||
// versions. On every start the unpacked files are re-checked against their fingerprint (stored in
|
||||
// ".ok"); if anything was changed or removed, the originals are unpacked again. Returns the app folder.
|
||||
string UnpackPayload()
|
||||
{
|
||||
var asm = Assembly.GetExecutingAssembly();
|
||||
@@ -354,14 +379,16 @@ sealed class MainForm : Form
|
||||
using (var sha = SHA256.Create()) hash = Convert.ToHexString(sha.ComputeHash(res))[..12].ToLowerInvariant();
|
||||
var appsRoot = Path.Combine(DataDir, "app");
|
||||
var target = Path.Combine(appsRoot, hash);
|
||||
if (File.Exists(Path.Combine(target, ".ok"))) return target;
|
||||
var okFile = Path.Combine(target, ".ok");
|
||||
// valid only if the files still match what was unpacked (tamper-evident)
|
||||
try { if (File.Exists(okFile) && File.ReadAllText(okFile) == Fingerprint(target)) return target; } catch { }
|
||||
|
||||
Directory.CreateDirectory(appsRoot);
|
||||
var tmp = target + ".tmp";
|
||||
if (Directory.Exists(tmp)) Directory.Delete(tmp, true);
|
||||
res.Position = 0;
|
||||
using (var zip = new ZipArchive(res, ZipArchiveMode.Read)) zip.ExtractToDirectory(tmp);
|
||||
File.WriteAllText(Path.Combine(tmp, ".ok"), DateTime.Now.ToString("s"));
|
||||
File.WriteAllText(Path.Combine(tmp, ".ok"), Fingerprint(tmp));
|
||||
if (Directory.Exists(target)) Directory.Delete(target, true);
|
||||
Directory.Move(tmp, target);
|
||||
foreach (var old in Directory.GetDirectories(appsRoot))
|
||||
|
||||
14
server.js
14
server.js
@@ -50,12 +50,14 @@ const HOST = '127.0.0.1'
|
||||
const PORT = Number(process.env.DASHBOARD_PORT) || 4848
|
||||
const ALLOWED_HOSTS = new Set([`localhost:${PORT}`, `127.0.0.1:${PORT}`])
|
||||
|
||||
// Edition: the demo build ships an edition.json next to this file (build.ps1 -Release -Demo).
|
||||
// The demo shows at most DEMO_LIMIT projects; everything else works. DASHBOARD_DEMO=1 tests it from source.
|
||||
const EDITION = (() => { try { return JSON.parse(fs.readFileSync(path.join(__dirname, 'edition.json'), 'utf8').replace(/^\uFEFF/, '')) } catch { return {} } })()
|
||||
const DEMO = EDITION.demo === true || process.env.DASHBOARD_DEMO === '1'
|
||||
const DEMO_LIMIT = Number(EDITION.limit) > 0 ? Number(EDITION.limit) : 6
|
||||
const BUY_URL = typeof EDITION.buyUrl === 'string' && EDITION.buyUrl ? EDITION.buyUrl : 'https://sn09.itch.io/project-dashboard'
|
||||
// Edition is baked into the code, not a separate file (which anyone could delete). build.ps1 -Demo
|
||||
// rewrites 'full' -> 'demo' in the staged copy only; the launcher re-checks the unpacked files on every
|
||||
// start, so editing this back out doesn't stick. DASHBOARD_DEMO=1 tests the demo from the source folder.
|
||||
// Keep the next line in this exact single-line form \u2013 the build's text replace matches it literally.
|
||||
const BUILD_EDITION = 'full'
|
||||
const DEMO = BUILD_EDITION === 'demo' || process.env.DASHBOARD_DEMO === '1'
|
||||
const DEMO_LIMIT = 6
|
||||
const BUY_URL = 'https://sn09.itch.io/project-dashboard'
|
||||
let demoTotal = 0 // all project folders found (the demo shows DEMO_LIMIT of them)
|
||||
|
||||
const STATUSES = ['idea', 'active', 'paused', 'done', 'archived']
|
||||
|
||||
Reference in New Issue
Block a user