[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.
This commit is contained in:
Lukas Brübach 2026-10-18 23:37:44 +02:00
parent f508a4d1bb
commit 0d3750f2be

View file

@ -467,16 +467,18 @@ int main(int argc, char *argv[])
{ {
QString crashDumpDir; QString crashDumpDir;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
// Mirrors the writer's location: %LOCALAPPDATA%/CrashDumps/Cockatrice. When the handler's // Mirrors the writer (CockatriceUnhandledExceptionFilter): it appends CrashDumps/Cockatrice
// known-folder lookup fails it falls back to <temp>/../.., so the scan has to walk up the // to %LOCALAPPDATA%, or, when its known-folder lookup fails, to the temp directory walked up
// same two levels; plain QDir::tempPath() would look in a directory nothing ever writes to. // two parent_path() steps. %LOCALAPPDATA% is this scan's stand-in for FOLDERID_LocalAppData:
crashDumpDir = QString::fromLocal8Bit(qgetenv("LOCALAPPDATA")) + "/CrashDumps/Cockatrice"; // both come from the same profile, so when the lookup fails the variable is normally unset.
if (qgetenv("LOCALAPPDATA").isEmpty()) { QString crashDumpRootPath = QString::fromLocal8Bit(qgetenv("LOCALAPPDATA"));
QDir fallback(QDir::tempPath()); if (crashDumpRootPath.isEmpty()) {
fallback.cdUp(); // The writer's fallback expression, verbatim — QDir::cdUp() is existence-checked and
fallback.cdUp(); // would silently leave the path alone here, parent_path() is not.
crashDumpDir = fallback.absolutePath(); 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 #else
crashDumpDir = QDir::tempPath(); crashDumpDir = QDir::tempPath();
#endif #endif