Allow to register additional files for upload in case of crash

This commit is contained in:
Michał Janiszewski 2022-08-04 19:45:19 +02:00
parent b42ff262ef
commit 4243bf0d8e
2 changed files with 34 additions and 13 deletions

View File

@ -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<std::wstring, std::wstring> _uploadFiles;
# define BACKTRACE_TOKEN L"0ca992e20aca116b5e090fd2eaff6e7b5c8225f778fd8f4e77cb077d70329324"
@ -114,8 +115,6 @@ static bool OnCrash(
return succeeded;
}
std::map<std::wstring, std::wstring> 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
}

View File

@ -9,7 +9,11 @@
#pragma once
#include <string>
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);