[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;
#ifdef Q_OS_WIN
// Mirrors the writer's location: %LOCALAPPDATA%/CrashDumps/Cockatrice. When the handler's
// known-folder lookup fails it falls back to <temp>/../.., 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