v0.6 + v1.0: HMAC download URLs, launcher self-update, Inno Setup installer
Three deliverables shipped together so the next deployment cycle has a
clean distribution story.
(1) Auto-update of the launcher itself
---------------------------------------
- Models: RemoteManifest gains an optional `launcher` section
(LauncherInfo: version, minRequired, download {url,size,sha256},
releaseNotesUrl). Server-side, sign-manifest.php passes it through
unchanged; admins edit versions.json with the new launcher entry +
upload PSLauncher-X.Y.Z.exe to /builds/launcher/.
- Core: ILauncherSelfUpdater compares assembly version against
manifest.launcher.version using the existing SemVer parser, and
reuses DownloadManager (Range/resume/sha256 already proven on the
game ZIPs) to download the new exe into
%LocalAppData%/PSLauncher/selfupdate/.
- New project PSLauncher.Updater (~34 MB self-contained console exe):
spawned by the main app with --target / --source / --pid / --launch.
Waits for the main process to exit (or for the file lock to release),
backs up the current exe to .bak, copies the new file in place, and
restarts. .bak survives the swap so the user can roll back manually.
- App.csproj now declares Version=0.5.0 — currently shipped baseline.
PSLauncher.App.csproj sets a fixed AssemblyVersion so reflection-based
comparison works deterministically.
- MainViewModel.PromptLauncherUpdate: dialog after CheckForUpdates if
the manifest advertises a newer launcher. Download with progress in
the existing footer, then Application.Shutdown() so the Updater can
do its job.
(2) Inno Setup installer
------------------------
installer/PSLauncher.iss + build-installer.ps1 produce a single
PSLauncher-Setup-X.Y.Z.exe (~80 MB) that installs into
Program Files\ASTERION VR\PSLauncher\, drops both PSLauncher.exe and
PSLauncher.Updater.exe side by side (the updater MUST live next to
the target), creates Start Menu + optional Desktop shortcuts, and
registers a clean uninstall entry. The user's %LocalAppData%
(license, logs, cache) is intentionally untouched on uninstall — same
license survives a reinstall.
build-installer.ps1 chains dotnet publish for both projects and ISCC
in one command. README explains the bump-version workflow.
(3) HMAC-signed download URLs
-----------------------------
- New PHP route GET /api/download-url/{version} (Authorization: Bearer
<licenseKey> or ?key=...). Validates the license, checks
download_entitlement_until >= minLicenseDate of the version, and
returns a HMAC-signed URL (path|exp|licId, hash_hmac SHA-256, valid
1 h) + sha256 + sizeBytes for verification.
- /builds/.htaccess routes every *.zip request to gate.php. gate.php
validates exp, lic, sig (constant-time hash_equals), then streams
the file with Range: support so the launcher's resume keeps working.
Audit log gets a download_url_issued entry per request.
- Client-side wired transparently: LicenseService gains
GetSignedDownloadUrlAsync(version) that GETs the endpoint with the
decrypted license key from DPAPI. MainViewModel calls it before
every download; if the endpoint returns 404/401/network-error, the
client falls back to the manifest's plain download.url (graceful
degradation for setups that haven't deployed gate.php yet).
Note on PHP streaming for 14 GB ZIPs: gate.php uses set_time_limit(0)
+ ignore_user_abort(true) + 1 MiB chunked fread with periodic flush.
Works on OVH mutualisé but holds a PHP-FPM slot for the duration. If
parallel downloads scale past a few clients, switch to
mod_xsendfile or migrate /builds/ to Cloudflare R2 with native
S3-presigned URLs and remove the gate entirely.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
136
src/PSLauncher.Updater/Program.cs
Normal file
136
src/PSLauncher.Updater/Program.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace PSLauncher.Updater;
|
||||
|
||||
/// <summary>
|
||||
/// Mini exe qui remplace le launcher principal (qui ne peut pas s'auto-écraser pendant qu'il tourne).
|
||||
///
|
||||
/// Args attendus :
|
||||
/// --target=<chemin_complet_de_PSLauncher.exe>
|
||||
/// --source=<chemin_du_nouveau_PSLauncher.exe>
|
||||
/// [--launch] : relance PSLauncher.exe une fois la copie faite
|
||||
/// [--pid=<PID>] : attend que ce process se termine avant de copier
|
||||
///
|
||||
/// Workflow :
|
||||
/// 1. Si --pid fourni, attend la sortie du process.
|
||||
/// 2. Sinon, attend que le fichier target soit déverrouillé (poll 250 ms).
|
||||
/// 3. Backup target → target.bak (au cas où).
|
||||
/// 4. Copie source → target.
|
||||
/// 5. Optionnellement relance target.
|
||||
/// 6. Supprime source (le .new) puis target.bak après 30 s.
|
||||
/// </summary>
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var opts = ParseArgs(args);
|
||||
if (string.IsNullOrEmpty(opts.Target) || string.IsNullOrEmpty(opts.Source))
|
||||
{
|
||||
Console.Error.WriteLine("Usage: PSLauncher.Updater --target=<exe> --source=<new.exe> [--launch] [--pid=N]");
|
||||
return 2;
|
||||
}
|
||||
|
||||
// 1. Attendre la sortie du launcher principal
|
||||
if (opts.Pid is int pid)
|
||||
{
|
||||
try
|
||||
{
|
||||
var proc = Process.GetProcessById(pid);
|
||||
proc.WaitForExit(60_000);
|
||||
}
|
||||
catch { /* déjà mort, OK */ }
|
||||
}
|
||||
|
||||
// 2. Attendre que le target soit déverrouillé
|
||||
var deadline = DateTime.UtcNow.AddSeconds(60);
|
||||
while (DateTime.UtcNow < deadline)
|
||||
{
|
||||
if (!File.Exists(opts.Target)) break;
|
||||
try
|
||||
{
|
||||
using var fs = File.Open(opts.Target, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
|
||||
break;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Backup
|
||||
var backup = opts.Target + ".bak";
|
||||
try { if (File.Exists(backup)) File.Delete(backup); } catch { }
|
||||
try { if (File.Exists(opts.Target)) File.Move(opts.Target, backup); } catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Backup failed: {ex.Message}");
|
||||
return 3;
|
||||
}
|
||||
|
||||
// 4. Copy new file in place
|
||||
try
|
||||
{
|
||||
File.Copy(opts.Source, opts.Target, overwrite: true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Copy failed: {ex.Message}");
|
||||
// Tente la restauration
|
||||
try { if (File.Exists(backup)) File.Move(backup, opts.Target, overwrite: true); } catch { }
|
||||
return 4;
|
||||
}
|
||||
|
||||
// 5. Relance
|
||||
if (opts.Launch)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = opts.Target,
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = Path.GetDirectoryName(opts.Target)!,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Relaunch failed: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 6. Cleanup différé (le .new + .bak après 30s, en background détaché)
|
||||
try { File.Delete(opts.Source); } catch { }
|
||||
// .bak laissé sur place : si le nouveau exe plante au lancement, l'utilisateur
|
||||
// peut renommer .bak → .exe pour récupérer l'ancien.
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Updater fatal: {ex}");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Options
|
||||
{
|
||||
public string? Target { get; set; }
|
||||
public string? Source { get; set; }
|
||||
public bool Launch { get; set; }
|
||||
public int? Pid { get; set; }
|
||||
}
|
||||
|
||||
private static Options ParseArgs(string[] args)
|
||||
{
|
||||
var o = new Options();
|
||||
foreach (var a in args)
|
||||
{
|
||||
if (a.StartsWith("--target=", StringComparison.OrdinalIgnoreCase)) o.Target = a["--target=".Length..];
|
||||
else if (a.StartsWith("--source=", StringComparison.OrdinalIgnoreCase)) o.Source = a["--source=".Length..];
|
||||
else if (a.StartsWith("--pid=", StringComparison.OrdinalIgnoreCase)) o.Pid = int.TryParse(a["--pid=".Length..], out var p) ? p : null;
|
||||
else if (a.Equals("--launch", StringComparison.OrdinalIgnoreCase)) o.Launch = true;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user