From 0d3750f2beb643057d4a2c22ae6bd2a12a02862f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sun, 18 Oct 2026 23:37:44 +0200 Subject: [PATCH] [CrashReporting] Complete the dump-scan fallback path The previous commit walked the scan's fallback up two levels but dropped the CrashDumps/Cockatrice suffix that the writer appends unconditionally, so a dump written through the fallback was still invisible to the scan. Evaluate the writer's expression verbatim rather than mirroring it with QDir: cdUp() is existence-checked and silently leaves the path alone when the directory is missing, parent_path() is not, and QDir::absoluteFilePath() joins the shared suffix without risking a doubled separator when the walk lands on a root. Verified by compiling the block verbatim against Qt 6 with -Wextra -Werror and comparing it with the writer's join for both the normal and the fallback case. Also record that %LOCALAPPDATA% is the scan's stand-in for FOLDERID_LocalAppData and why the two normally agree. --- cockatrice/src/main.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index 081711e89..38ec3d137 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -467,16 +467,18 @@ int main(int argc, char *argv[]) { QString crashDumpDir; #ifdef Q_OS_WIN - // Mirrors the writer's location: %LOCALAPPDATA%/CrashDumps/Cockatrice. When the handler's - // known-folder lookup fails it falls back to /../.., so the scan has to walk up the - // same two levels; plain QDir::tempPath() would look in a directory nothing ever writes to. - crashDumpDir = QString::fromLocal8Bit(qgetenv("LOCALAPPDATA")) + "/CrashDumps/Cockatrice"; - if (qgetenv("LOCALAPPDATA").isEmpty()) { - QDir fallback(QDir::tempPath()); - fallback.cdUp(); - fallback.cdUp(); - crashDumpDir = fallback.absolutePath(); + // Mirrors the writer (CockatriceUnhandledExceptionFilter): it appends CrashDumps/Cockatrice + // to %LOCALAPPDATA%, or, when its known-folder lookup fails, to the temp directory walked up + // two parent_path() steps. %LOCALAPPDATA% is this scan's stand-in for FOLDERID_LocalAppData: + // both come from the same profile, so when the lookup fails the variable is normally unset. + QString crashDumpRootPath = QString::fromLocal8Bit(qgetenv("LOCALAPPDATA")); + if (crashDumpRootPath.isEmpty()) { + // The writer's fallback expression, verbatim — QDir::cdUp() is existence-checked and + // would silently leave the path alone here, parent_path() is not. + const std::filesystem::path fallback = std::filesystem::temp_directory_path().parent_path().parent_path(); + crashDumpRootPath = QString::fromStdWString(fallback.wstring()); } + crashDumpDir = QDir(crashDumpRootPath).absoluteFilePath(QStringLiteral("CrashDumps/Cockatrice")); #else crashDumpDir = QDir::tempPath(); #endif