From 4243bf0d8ef7f12747683cde30083e97c0644583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Thu, 4 Aug 2022 19:45:19 +0200 Subject: [PATCH] Allow to register additional files for upload in case of crash --- src/openrct2/platform/Crash.cpp | 43 +++++++++++++++++++++++---------- src/openrct2/platform/Crash.h | 4 +++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index 130a6e2349..b88157d805 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -47,13 +47,14 @@ # define WSZ(x) L"" x # ifdef OPENRCT2_COMMIT_SHA1_SHORT -const wchar_t* _wszCommitSha1Short = WSZ(OPENRCT2_COMMIT_SHA1_SHORT); +static const wchar_t* _wszCommitSha1Short = WSZ(OPENRCT2_COMMIT_SHA1_SHORT); # else -const wchar_t* _wszCommitSha1Short = WSZ(""); +static const wchar_t* _wszCommitSha1Short = WSZ(""); # endif // OPENRCT2_ARCHITECTURE is required to be defined in version.h -const wchar_t* _wszArchitecture = WSZ(OPENRCT2_ARCHITECTURE); +static const wchar_t* _wszArchitecture = WSZ(OPENRCT2_ARCHITECTURE); +static std::map _uploadFiles; # define BACKTRACE_TOKEN L"0ca992e20aca116b5e090fd2eaff6e7b5c8225f778fd8f4e77cb077d70329324" @@ -114,8 +115,6 @@ static bool OnCrash( return succeeded; } - std::map uploadFiles; - // Get filenames wchar_t dumpFilePath[MAX_PATH]; wchar_t saveFilePath[MAX_PATH]; @@ -147,7 +146,7 @@ static bool OnCrash( // advertise it officially. /* - uploadFiles[L"upload_file_minidump"] = dumpFilePathGZIP; + _uploadFiles[L"upload_file_minidump"] = dumpFilePathGZIP; */ } fclose(input); @@ -161,7 +160,7 @@ static bool OnCrash( { std::wcscpy(dumpFilePath, dumpFilePathNew); } - uploadFiles[L"upload_file_minidump"] = dumpFilePath; + _uploadFiles[L"upload_file_minidump"] = dumpFilePath; // Compress to gzip-compatible stream @@ -195,13 +194,13 @@ static bool OnCrash( // Compress the save if (savedGameDumped) { - uploadFiles[L"attachment_park.park"] = saveFilePath; + _uploadFiles[L"attachment_park.park"] = saveFilePath; } auto configFilePathUTF8 = String::ToUtf8(configFilePath); if (config_save(configFilePathUTF8)) { - uploadFiles[L"attachment_config.ini"] = configFilePath; + _uploadFiles[L"attachment_config.ini"] = configFilePath; } // janisozaur: https://github.com/OpenRCT2/OpenRCT2/pull/17634 @@ -219,7 +218,7 @@ static bool OnCrash( if (!screenshotPath.empty()) { auto screenshotPathW = String::ToWideChar(screenshotPath.c_str()); - uploadFiles[L"attachment_screenshot.png"] = screenshotPathW; + _uploadFiles[L"attachment_screenshot.png"] = screenshotPathW; } } @@ -229,7 +228,7 @@ static bool OnCrash( bool record_copied = CopyFileW(parkReplayPathW.c_str(), recordFilePathNew, true); if (record_copied) { - uploadFiles[L"attachment_replay.parkrep"] = recordFilePathNew; + _uploadFiles[L"attachment_replay.parkrep"] = recordFilePathNew; } else { @@ -242,7 +241,7 @@ static bool OnCrash( printf("Uploading minidump in silent mode...\n"); int error; std::wstring response; - UploadMinidump(uploadFiles, error, response); + UploadMinidump(_uploadFiles, error, response); return succeeded; } @@ -260,7 +259,7 @@ static bool OnCrash( { int error; std::wstring response; - bool ok = UploadMinidump(uploadFiles, error, response); + bool ok = UploadMinidump(_uploadFiles, error, response); if (!ok) { const wchar_t* MessageFormat2 = L"There was a problem while uploading the dump. Please upload it manually to " @@ -340,3 +339,21 @@ CExceptionHandler crash_init() return nullptr; #endif // USE_BREAKPAD } + +void crash_register_additional_file(const std::string& key, const std::string& path) +{ +#ifdef USE_BREAKPAD + _uploadFiles[String::ToWideChar(key.c_str())] = String::ToWideChar(path.c_str()); +#endif // USE_BREAKPAD +} + +void crash_unregister_additional_file(const std::string& key) +{ +#ifdef USE_BREAKPAD + auto it = _uploadFiles.find(String::ToWideChar(key.c_str())); + if (it != _uploadFiles.end()) + { + _uploadFiles.erase(it); + } +#endif // USE_BREAKPAD +} diff --git a/src/openrct2/platform/Crash.h b/src/openrct2/platform/Crash.h index 46c4a1c966..51caa4237f 100644 --- a/src/openrct2/platform/Crash.h +++ b/src/openrct2/platform/Crash.h @@ -9,7 +9,11 @@ #pragma once +#include + using CExceptionHandler = void*; extern bool gOpenRCT2SilentBreakpad; CExceptionHandler crash_init(); +void crash_register_additional_file(const std::string& key, const std::string& path); +void crash_unregister_additional_file(const std::string& key);