From 2ad92f142ddf3b1274e3549911cfce620fdc2799 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 22:35:55 +0200 Subject: [PATCH] feat: remove standalone logs on graceful exit, retain on crash or debug opt-in --- README.md | 4 ++++ build.ps1 | 14 +++++++++++++- src/AzimuthRPC.App/Program.cs | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 632a8ba..ea71088 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,10 @@ Compatibility can vary with Azimuth and FH2ML versions or other mods. If somethi Both the standalone EXE and the FH2ML DLL write `%LOCALAPPDATA%\\AzimuthRPC\\logs\\AzimuthRPC.log` (paste that path into Windows Explorer). The native DLL now logs as soon as `FH2ML_Initialize` is called, including rejected host API versions or unsupported game-image checks. If no log is created, first verify the executable actually started or the loader called the DLL initializer; an absent log alone does **not** prove that car offsets changed. Logs can contain runtime telemetry, memory probe values, loaded module names and Discord IPC status, so **review the log before uploading it publicly**. +The **standalone EXE automatically removes `AzimuthRPC.log` and its rotated `.1` log after a normal exit** (tray `Exit`). If it crashes or is force-terminated, logs are kept for troubleshooting. To preserve logs while testing, launch the standalone with `--keep-logs`; copy the log before exiting if you need to share it. Cleanup is best-effort if another process keeps the file open. + +The FH2ML native DLL still retains logs: it has no safe, guaranteed shutdown callback, and attempting deletion inside `DllMain` during process teardown could cause instability. Don't run the standalone and native DLL at the same time. + AzimuthRPC does not ask for your Discord password or token. No game files, saves or raw memory captures are included in this repository. ## Build from source diff --git a/build.ps1 b/build.ps1 index e4eb036..1c2a718 100644 --- a/build.ps1 +++ b/build.ps1 @@ -15,7 +15,7 @@ try { if ($SmokeTest) { $exe = Join-Path $PSScriptRoot 'src/AzimuthRPC.App/bin/Release/net8.0-windows/AzimuthRPC.exe' - $process = Start-Process -FilePath $exe -ArgumentList '--smoke-test' -WindowStyle Hidden -PassThru + $process = Start-Process -FilePath $exe -ArgumentList '--smoke-test', '--keep-logs' -WindowStyle Hidden -PassThru if (-not $process.WaitForExit(15000)) { throw 'Public tray smoke test timed out' } if ($process.ExitCode -ne 0) { throw "Public tray smoke test failed: $($process.ExitCode)" } # A zero exit code is not enough: confirm the EXE actually wrote its @@ -25,10 +25,12 @@ try { (Join-Path ([IO.Path]::GetTempPath()) 'AzimuthRPC\AzimuthRPC.log') ) $startupLogged = $false + $verifiedLog = $null foreach ($candidate in $candidates) { if ((Test-Path -LiteralPath $candidate) -and ((Get-Content -LiteralPath $candidate -Raw) -match 'standalone started \(smoke test\)')) { $startupLogged = $true + $verifiedLog = $candidate Write-Host "Verified standalone startup log at: $candidate" break } @@ -37,5 +39,15 @@ try { throw "Public tray smoke test did not create a startup log in either AppData or TEMP" } + # Run a normal clean exit and verify the active/rotated files vanish. + $cleanupProcess = Start-Process -FilePath $exe -ArgumentList '--smoke-test' -WindowStyle Hidden -PassThru + if (-not $cleanupProcess.WaitForExit(15000)) { throw 'Public tray cleanup smoke test timed out' } + if ($cleanupProcess.ExitCode -ne 0) { throw "Public tray cleanup smoke test failed: $($cleanupProcess.ExitCode)" } + foreach ($candidate in $candidates) { + if ($candidate -eq $verifiedLog -and ((Test-Path -LiteralPath $candidate) -or (Test-Path -LiteralPath "$candidate.1"))) { + throw "Public tray clean exit left log files behind: $candidate" + } + } + Write-Host "Verified clean shutdown removed standalone active/rotated logs." } } finally { Pop-Location } diff --git a/src/AzimuthRPC.App/Program.cs b/src/AzimuthRPC.App/Program.cs index 8477528..f76eb15 100644 --- a/src/AzimuthRPC.App/Program.cs +++ b/src/AzimuthRPC.App/Program.cs @@ -13,6 +13,7 @@ private static void Main(string[] args) ApplicationConfiguration.Initialize(); bool smokeTest = args.Contains("--smoke-test", StringComparer.OrdinalIgnoreCase); + bool keepLogs = args.Contains("--keep-logs", StringComparer.OrdinalIgnoreCase); using var mutex = new Mutex(true, @"Local\AzimuthRPC", out bool firstInstance); if (!firstInstance) { @@ -48,11 +49,13 @@ private static void Main(string[] args) "AzimuthRPC log fallback", MessageBoxButtons.OK, MessageBoxIcon.Warning); } + bool exitedNormally = false; try { var config = new AppConfig { Offline = smokeTest }; using var context = new TrayApplicationContext(config, smokeTest, log); Application.Run(context); + exitedNormally = true; } catch (Exception e) { @@ -65,6 +68,9 @@ private static void Main(string[] args) finally { log.Write("AzimuthRPC standalone stopped"); + // Leave diagnostics behind if startup fails or the process crashes. + // Only clean files after the normal tray/smoke-test shutdown. + log.DeleteOnDispose = exitedNormally && !keepLogs; } } } @@ -232,6 +238,7 @@ private FileLog(string path, StreamWriter writer) internal string FilePath { get; } internal string? FallbackReason { get; private set; } + internal bool DeleteOnDispose { get; set; } internal static FileLog Open() { @@ -281,7 +288,19 @@ public void Dispose() { lock (_gate) { + // Close the writer first; Windows otherwise retains the file handle. _writer.Dispose(); + if (!DeleteOnDispose) + return; + + // Delete only our known log files, never user files or the folder. + // Cleanup is best-effort if antivirus/another process has a file open. + foreach (string path in new[] { FilePath, FilePath + ".1" }) + { + try { File.Delete(path); } + catch (IOException) { } + catch (UnauthorizedAccessException) { } + } } } }