2016-05-04 19:24:41 +02:00
|
|
|
/*****************************************************************************
|
2018-06-15 14:07:34 +02:00
|
|
|
* Copyright (c) 2014-2018 OpenRCT2 developers
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
2018-06-15 14:07:34 +02:00
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
2016-05-04 19:24:41 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2018-01-18 13:55:34 +01:00
|
|
|
#include "Crash.h"
|
2016-04-07 00:10:12 +02:00
|
|
|
|
|
|
|
#ifdef USE_BREAKPAD
|
2018-10-09 23:18:15 +02:00
|
|
|
# include <map>
|
2018-07-21 16:17:06 +02:00
|
|
|
# include <memory>
|
|
|
|
# include <stdio.h>
|
|
|
|
|
|
|
|
# if defined(_WIN32)
|
|
|
|
# include <ShlObj.h>
|
2018-07-17 19:19:53 +02:00
|
|
|
# include <client/windows/handler/exception_handler.h>
|
2018-10-09 23:18:15 +02:00
|
|
|
# include <common/windows/http_upload.h>
|
2018-07-21 16:17:06 +02:00
|
|
|
# include <string>
|
|
|
|
# else
|
|
|
|
# error Breakpad support not implemented yet for this platform
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# include "../Version.h"
|
|
|
|
# include "../core/Console.hpp"
|
2018-10-09 23:18:15 +02:00
|
|
|
# include "../core/String.hpp"
|
2018-07-21 16:17:06 +02:00
|
|
|
# include "../localisation/Language.h"
|
|
|
|
# include "../rct2/S6Exporter.h"
|
|
|
|
# include "../scenario/Scenario.h"
|
2018-10-20 23:54:59 +02:00
|
|
|
# include "../util/Util.h"
|
2018-07-21 16:17:06 +02:00
|
|
|
# include "platform.h"
|
|
|
|
|
|
|
|
# define WSZ(x) L"" x
|
|
|
|
|
|
|
|
# ifdef OPENRCT2_COMMIT_SHA1_SHORT
|
2018-06-22 23:04:38 +02:00
|
|
|
const wchar_t* _wszCommitSha1Short = WSZ(OPENRCT2_COMMIT_SHA1_SHORT);
|
2018-07-21 16:17:06 +02:00
|
|
|
# else
|
2018-06-22 23:04:38 +02:00
|
|
|
const wchar_t* _wszCommitSha1Short = WSZ("");
|
2018-07-21 16:17:06 +02:00
|
|
|
# endif
|
2016-08-28 18:17:20 +02:00
|
|
|
|
2016-10-18 13:25:57 +02:00
|
|
|
// OPENRCT2_ARCHITECTURE is required to be defined in version.h
|
2018-06-22 23:04:38 +02:00
|
|
|
const wchar_t* _wszArchitecture = WSZ(OPENRCT2_ARCHITECTURE);
|
|
|
|
|
2018-10-20 23:54:59 +02:00
|
|
|
// Note: uploading gzipped crash dumps manually requires specifying
|
|
|
|
// 'Content-Encoding: gzip' header in HTTP request, but we cannot do that,
|
|
|
|
// so just hope the file name with '.gz' suffix is enough.
|
|
|
|
// For docs on uplading to backtrace.io check
|
|
|
|
// https://documentation.backtrace.io/product_integration_minidump_breakpad/
|
2018-10-24 23:50:03 +02:00
|
|
|
static bool UploadMinidump(const wchar_t* dumpPath, int& error, std::wstring& response)
|
2018-10-09 23:18:15 +02:00
|
|
|
{
|
2018-10-20 23:54:59 +02:00
|
|
|
std::wstring url(L"https://openrct2.sp.backtrace.io:6098/"
|
|
|
|
L"post?format=minidump&token=f9c5e640d498f15dbe902eab3e822e472af9270d5b0cbdc269cee65a926bf306");
|
2018-10-09 23:18:15 +02:00
|
|
|
std::map<std::wstring, std::wstring> parameters;
|
|
|
|
std::map<std::wstring, std::wstring> files;
|
|
|
|
parameters[L"product_name"] = L"openrct2";
|
|
|
|
// In case of releases this can be empty
|
|
|
|
if (wcslen(_wszCommitSha1Short) > 0)
|
|
|
|
{
|
2018-10-20 23:54:59 +02:00
|
|
|
parameters[L"commit"] = _wszCommitSha1Short;
|
2018-10-09 23:18:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-20 23:54:59 +02:00
|
|
|
parameters[L"commit"] = String::ToUtf16(gVersionInfoFull);
|
2018-10-09 23:18:15 +02:00
|
|
|
}
|
|
|
|
files[L"upload_file_minidump"] = dumpPath;
|
|
|
|
int timeout = 10000;
|
|
|
|
bool success = google_breakpad::HTTPUpload::SendRequest(url, parameters, files, &timeout, &response, &error);
|
|
|
|
wprintf(L"Success = %d, error = %d, response = %s\n", success, error, response.c_str());
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:04:38 +02:00
|
|
|
static bool OnCrash(
|
2018-07-21 13:51:54 +02:00
|
|
|
const wchar_t* dumpPath, const wchar_t* miniDumpId, void* context, EXCEPTION_POINTERS* exinfo,
|
|
|
|
MDRawAssertionInfo* assertion, bool succeeded)
|
2016-04-10 00:30:10 +02:00
|
|
|
{
|
|
|
|
if (!succeeded)
|
|
|
|
{
|
2018-07-21 11:50:45 +02:00
|
|
|
constexpr const char* DumpFailedMessage = "Failed to create the dump. Please file an issue with OpenRCT2 on GitHub and "
|
|
|
|
"provide latest save, and provide "
|
|
|
|
"information about what you did before the crash occurred.";
|
2016-04-10 00:30:10 +02:00
|
|
|
printf("%s\n", DumpFailedMessage);
|
2016-05-11 13:25:21 +02:00
|
|
|
if (!gOpenRCT2SilentBreakpad)
|
|
|
|
{
|
2017-08-15 10:07:44 +02:00
|
|
|
MessageBoxA(nullptr, DumpFailedMessage, OPENRCT2_NAME, MB_OK | MB_ICONERROR);
|
2016-05-11 13:25:21 +02:00
|
|
|
}
|
2016-04-10 00:30:10 +02:00
|
|
|
return succeeded;
|
|
|
|
}
|
|
|
|
|
2016-05-02 23:20:36 +02:00
|
|
|
// Get filenames
|
2016-04-10 00:30:10 +02:00
|
|
|
wchar_t dumpFilePath[MAX_PATH];
|
|
|
|
wchar_t saveFilePath[MAX_PATH];
|
2018-10-24 22:56:25 +02:00
|
|
|
swprintf_s(dumpFilePath, sizeof(dumpFilePath), L"%s\\%s.dmp", dumpPath, miniDumpId);
|
|
|
|
swprintf_s(saveFilePath, sizeof(saveFilePath), L"%s\\%s.sv6", dumpPath, miniDumpId);
|
2018-10-20 23:54:59 +02:00
|
|
|
const wchar_t* minidumpToUpload = dumpFilePath;
|
2016-04-10 00:30:10 +02:00
|
|
|
|
2016-05-02 23:20:36 +02:00
|
|
|
wchar_t dumpFilePathNew[MAX_PATH];
|
2018-06-22 23:04:38 +02:00
|
|
|
swprintf_s(
|
2018-10-24 22:56:25 +02:00
|
|
|
dumpFilePathNew, sizeof(dumpFilePathNew), L"%s\\%s(%s_%s).dmp", dumpPath, miniDumpId, _wszCommitSha1Short,
|
2018-06-22 23:04:38 +02:00
|
|
|
_wszArchitecture);
|
2018-10-20 23:54:59 +02:00
|
|
|
|
|
|
|
wchar_t dumpFilePathGZIP[MAX_PATH];
|
|
|
|
swprintf_s(dumpFilePathGZIP, sizeof(dumpFilePathGZIP), L"%s.gz", dumpFilePathNew);
|
|
|
|
|
|
|
|
FILE* input = _wfopen(dumpFilePath, L"rb");
|
|
|
|
FILE* dest = _wfopen(dumpFilePathGZIP, L"wb");
|
|
|
|
|
|
|
|
if (util_gzip_compress(input, dest))
|
|
|
|
{
|
2018-10-26 13:39:25 +02:00
|
|
|
// TODO: enable upload of gzip-compressed dumps once supported on
|
|
|
|
// backtrace.io (uncomment the line below). For now leave compression
|
|
|
|
// on, as GitHub will accept .gz files, even though it does not
|
|
|
|
// advertise it officially.
|
|
|
|
|
|
|
|
/*
|
2018-10-20 23:54:59 +02:00
|
|
|
minidumpToUpload = dumpFilePathGZIP;
|
2018-10-26 13:39:25 +02:00
|
|
|
*/
|
2018-10-20 23:54:59 +02:00
|
|
|
}
|
|
|
|
fclose(input);
|
|
|
|
fclose(dest);
|
|
|
|
|
|
|
|
// Try to rename the files
|
2016-05-02 23:20:36 +02:00
|
|
|
if (_wrename(dumpFilePath, dumpFilePathNew) == 0)
|
|
|
|
{
|
|
|
|
std::wcscpy(dumpFilePath, dumpFilePathNew);
|
|
|
|
}
|
|
|
|
|
2018-10-20 23:54:59 +02:00
|
|
|
// Compress to gzip-compatible stream
|
|
|
|
|
2016-05-02 23:20:36 +02:00
|
|
|
// Log information to output
|
2016-05-02 23:50:43 +02:00
|
|
|
wprintf(L"Dump Path: %s\n", dumpPath);
|
|
|
|
wprintf(L"Dump File Path: %s\n", dumpFilePath);
|
2016-04-10 00:30:10 +02:00
|
|
|
wprintf(L"Dump Id: %s\n", miniDumpId);
|
|
|
|
wprintf(L"Version: %s\n", WSZ(OPENRCT2_VERSION));
|
2016-08-28 18:17:20 +02:00
|
|
|
wprintf(L"Commit: %s\n", _wszCommitSha1Short);
|
2016-04-10 00:30:10 +02:00
|
|
|
|
|
|
|
bool savedGameDumped = false;
|
2018-06-22 23:04:38 +02:00
|
|
|
utf8* saveFilePathUTF8 = widechar_to_utf8(saveFilePath);
|
2017-02-08 23:17:01 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
auto exporter = std::make_unique<S6Exporter>();
|
|
|
|
exporter->Export();
|
|
|
|
exporter->SaveGame(saveFilePathUTF8);
|
2016-04-10 00:30:10 +02:00
|
|
|
savedGameDumped = true;
|
|
|
|
}
|
2018-06-22 23:04:38 +02:00
|
|
|
catch (const std::exception&)
|
2017-02-08 23:17:01 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
free(saveFilePathUTF8);
|
2016-04-10 00:30:10 +02:00
|
|
|
|
2016-05-11 13:25:21 +02:00
|
|
|
if (gOpenRCT2SilentBreakpad)
|
|
|
|
{
|
2018-10-24 23:50:03 +02:00
|
|
|
int error;
|
|
|
|
std::wstring response;
|
|
|
|
UploadMinidump(minidumpToUpload, error, response);
|
2016-05-11 13:25:21 +02:00
|
|
|
return succeeded;
|
|
|
|
}
|
2017-02-08 23:17:01 +01:00
|
|
|
|
2018-07-21 11:50:45 +02:00
|
|
|
constexpr const wchar_t* MessageFormat = L"A crash has occurred and a dump was created at\n%s.\n\nPlease file an issue "
|
|
|
|
L"with OpenRCT2 on GitHub, and provide "
|
2018-10-09 23:18:15 +02:00
|
|
|
L"the dump and saved game there.\n\nVersion: %s\nCommit: %s\n\n"
|
|
|
|
L"We would like to upload the crash dump for automated analysis, do you agree?\n"
|
|
|
|
L"The automated analysis is done by courtesy of https://backtrace.io/";
|
2016-04-10 00:30:10 +02:00
|
|
|
wchar_t message[MAX_PATH * 2];
|
2018-06-22 23:04:38 +02:00
|
|
|
swprintf_s(message, MessageFormat, dumpFilePath, WSZ(OPENRCT2_VERSION), _wszCommitSha1Short);
|
2016-04-10 00:30:10 +02:00
|
|
|
|
|
|
|
// Cannot use platform_show_messagebox here, it tries to set parent window already dead.
|
2018-10-25 23:18:19 +02:00
|
|
|
int answer = MessageBoxW(nullptr, message, WSZ(OPENRCT2_NAME), MB_YESNO | MB_ICONERROR);
|
2018-10-09 23:18:15 +02:00
|
|
|
if (answer == IDYES)
|
|
|
|
{
|
2018-10-24 23:50:03 +02:00
|
|
|
int error;
|
|
|
|
std::wstring response;
|
|
|
|
bool ok = UploadMinidump(minidumpToUpload, error, response);
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
const wchar_t* MessageFormat2 = L"There was a problem while uploading the dump. Please upload it manually to "
|
|
|
|
L"GitHub. It should be highlighted for you once you close this message.\n"
|
|
|
|
L"Please provide following information as well:\n"
|
|
|
|
L"Error code = %d\n"
|
|
|
|
L"Response = %s";
|
|
|
|
swprintf_s(message, MessageFormat2, error, response.c_str());
|
2018-10-25 23:18:19 +02:00
|
|
|
MessageBoxW(nullptr, message, WSZ(OPENRCT2_NAME), MB_OK | MB_ICONERROR);
|
2018-10-24 23:50:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MessageBoxW(nullptr, L"Dump uploaded succesfully.", WSZ(OPENRCT2_NAME), MB_OK | MB_ICONINFORMATION);
|
|
|
|
}
|
2018-10-09 23:18:15 +02:00
|
|
|
}
|
2017-08-15 10:07:44 +02:00
|
|
|
HRESULT coInitializeResult = CoInitialize(nullptr);
|
2016-04-10 00:30:10 +02:00
|
|
|
if (SUCCEEDED(coInitializeResult))
|
|
|
|
{
|
2016-08-28 18:19:13 +02:00
|
|
|
LPITEMIDLIST pidl = ILCreateFromPathW(dumpPath);
|
2018-10-20 23:54:59 +02:00
|
|
|
LPITEMIDLIST files[3];
|
2018-06-20 17:28:51 +02:00
|
|
|
uint32_t numFiles = 0;
|
2016-04-10 00:30:10 +02:00
|
|
|
|
|
|
|
files[numFiles++] = ILCreateFromPathW(dumpFilePath);
|
2018-10-20 23:54:59 +02:00
|
|
|
// There should be no need to check if this file exists, if it doesn't
|
|
|
|
// it simply shouldn't get selected.
|
|
|
|
files[numFiles++] = ILCreateFromPathW(dumpFilePathGZIP);
|
2016-04-10 00:30:10 +02:00
|
|
|
if (savedGameDumped)
|
|
|
|
{
|
|
|
|
files[numFiles++] = ILCreateFromPathW(saveFilePath);
|
|
|
|
}
|
2018-06-22 23:04:38 +02:00
|
|
|
if (pidl != nullptr)
|
|
|
|
{
|
|
|
|
SHOpenFolderAndSelectItems(pidl, numFiles, (LPCITEMIDLIST*)files, 0);
|
2016-04-10 00:30:10 +02:00
|
|
|
ILFree(pidl);
|
2018-06-20 17:28:51 +02:00
|
|
|
for (uint32_t i = 0; i < numFiles; i++)
|
2016-04-10 00:30:10 +02:00
|
|
|
{
|
|
|
|
ILFree(files[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return whether the dump was successful
|
|
|
|
return succeeded;
|
2016-04-09 19:21:40 +02:00
|
|
|
}
|
|
|
|
|
2016-04-10 00:30:10 +02:00
|
|
|
static std::wstring GetDumpDirectory()
|
|
|
|
{
|
|
|
|
char userDirectory[MAX_PATH];
|
2017-08-15 10:07:44 +02:00
|
|
|
platform_get_user_directory(userDirectory, nullptr, sizeof(userDirectory));
|
2016-04-10 00:30:10 +02:00
|
|
|
|
2018-06-22 23:04:38 +02:00
|
|
|
wchar_t* userDirectoryW = utf8_to_widechar(userDirectory);
|
2016-04-10 00:30:10 +02:00
|
|
|
auto result = std::wstring(userDirectoryW);
|
|
|
|
free(userDirectoryW);
|
2016-04-07 00:10:12 +02:00
|
|
|
|
2016-04-10 00:30:10 +02:00
|
|
|
return result;
|
2016-04-07 00:10:12 +02:00
|
|
|
}
|
2016-04-10 00:30:10 +02:00
|
|
|
|
|
|
|
// Using non-null pipe name here lets breakpad try setting OOP crash handling
|
2018-06-22 23:04:38 +02:00
|
|
|
constexpr const wchar_t* PipeName = L"openrct2-bpad";
|
2016-04-10 00:30:10 +02:00
|
|
|
|
2016-10-06 23:32:10 +02:00
|
|
|
#endif // USE_BREAKPAD
|
|
|
|
|
2018-02-01 18:49:14 +01:00
|
|
|
CExceptionHandler crash_init()
|
2016-04-07 00:10:12 +02:00
|
|
|
{
|
|
|
|
#ifdef USE_BREAKPAD
|
2016-04-10 00:30:10 +02:00
|
|
|
// Path must exist and be RW!
|
|
|
|
auto exHandler = new google_breakpad::ExceptionHandler(
|
2018-06-22 23:04:38 +02:00
|
|
|
GetDumpDirectory(), 0, OnCrash, 0, google_breakpad::ExceptionHandler::HANDLER_ALL, MiniDumpWithDataSegs, PipeName, 0);
|
2016-04-10 00:30:10 +02:00
|
|
|
return reinterpret_cast<CExceptionHandler>(exHandler);
|
2018-06-22 23:04:38 +02:00
|
|
|
#else // USE_BREAKPAD
|
2016-04-10 00:30:10 +02:00
|
|
|
return nullptr;
|
2016-04-07 00:10:12 +02:00
|
|
|
#endif // USE_BREAKPAD
|
|
|
|
}
|