From 6db7f74295efc11dd341d0013f6c26e2323f4044 Mon Sep 17 00:00:00 2001 From: itszn Date: Wed, 30 Sep 2020 21:46:50 -0700 Subject: [PATCH 1/2] Add crash uploading option for breakpad crashes --- Main/include/GameConfig.hpp | 2 ++ Main/src/Application.cpp | 60 +++++++++++++++++++++++++++++++++- Main/src/GameConfig.cpp | 2 ++ Main/src/SettingsScreen.cpp | 1 + Shared/include/Shared/Path.hpp | 2 ++ Shared/src/Unix/Path.cpp | 5 +++ Shared/src/Windows/Path.cpp | 6 ++++ 7 files changed, 77 insertions(+), 1 deletion(-) diff --git a/Main/include/GameConfig.hpp b/Main/include/GameConfig.hpp index cce3397e8..79bc5c4f0 100644 --- a/Main/include/GameConfig.hpp +++ b/Main/include/GameConfig.hpp @@ -159,6 +159,8 @@ DefineEnum(GameConfigKeys, GameplaySettingsDialogLastTab, TransferScoresOnChartUpdate, + ShowCrashUploadPrompt, + // Gameplay options GaugeType, MirrorChart, diff --git a/Main/src/Application.cpp b/Main/src/Application.cpp index 245e6bd35..15ce13b48 100644 --- a/Main/src/Application.cpp +++ b/Main/src/Application.cpp @@ -619,6 +619,62 @@ void Application::m_InitDiscord() Discord_Initialize(DISCORD_APPLICATION_ID, &dhe, 1, nullptr); } +#ifdef _WIN32 +#ifdef CRASHDUMP +bool g_HandleCrash( + const wchar_t* dump_path, + const wchar_t* minidump_id, + void* context, + EXCEPTION_POINTERS*, + MDRawAssertionInfo*, + bool succeeded) +{ + if (!g_gameConfig.GetBool(GameConfigKeys::ShowCrashUploadPrompt)) + return false; + if (!succeeded) + return false; + bool res = g_gameWindow->ShowYesNoMessage("Report USC Crash?", "USC has crashed. Would you like to upload the crash dump?"); + + if (!res) { + g_application->Shutdown(); + return true; + } + std::wstring asciiPath(dump_path); + std::wstring asciiId(minidump_id); + String path = String(asciiPath.begin(), asciiPath.end()) + "\\" + + String(asciiId.begin(), asciiId.end()) + ".dmp"; + + cpr::Response resp = cpr::Post( + cpr::Url{ "http://uscdmp.stackchk.fail/symbolify" }, + //cpr::Url{ "http://192.168.65.128:1338/" }, + cpr::Multipart{ +#ifdef GIT_COMMIT + {"commit", GIT_COMMIT}, +#endif + {"ingame", "true"}, + {"file", cpr::File{ path }} + }); + + if (resp.status_code < 400) + { + for (char c : resp.text) + { + if (!((c >= '0' && c <= '9') + || (c >= 'a' && c <= 'z') + || (c >= 'A' && c <= 'Z'))) + { + g_application->Shutdown(); + return true; + } + } + Path::OpenInBrowser("http://uscdmp.stackchk.fail/"+resp.text); + } + g_application->Shutdown(); + return true; +} +#endif +#endif + bool Application::m_Init() { ProfilerScope $("Application Setup"); @@ -649,7 +705,7 @@ bool Application::m_Init() auto handler = new google_breakpad::ExceptionHandler( L".\\crash_dumps", NULL, - NULL, + g_HandleCrash, NULL, google_breakpad::ExceptionHandler::HANDLER_ALL, MiniDumpNormal, @@ -882,6 +938,8 @@ bool Application::m_Init() return true; } + + void Application::m_MainLoop() { Timer appTimer; diff --git a/Main/src/GameConfig.cpp b/Main/src/GameConfig.cpp index 63afba7c9..c2c184f65 100644 --- a/Main/src/GameConfig.cpp +++ b/Main/src/GameConfig.cpp @@ -181,6 +181,8 @@ void GameConfig::InitDefaults() Set(GameConfigKeys::AutoResetSettings, false); Set(GameConfigKeys::AutoResetToSpeed, 400.0f); Set(GameConfigKeys::SlamThicknessMultiplier, 1.0f); + + Set(GameConfigKeys::ShowCrashUploadPrompt, true); Set(GameConfigKeys::SettingsTreesOpen, 1); diff --git a/Main/src/SettingsScreen.cpp b/Main/src/SettingsScreen.cpp index 7c4bf1c52..d49b55c63 100644 --- a/Main/src/SettingsScreen.cpp +++ b/Main/src/SettingsScreen.cpp @@ -939,6 +939,7 @@ class SettingsScreen_Impl : public SettingsScreen ToggleSetting(GameConfigKeys::MuteUnfocused, "Mute the game when unfocused"); ToggleSetting(GameConfigKeys::CheckForUpdates, "Check for updates on startup"); ToggleSetting(GameConfigKeys::OnlyRelease, "Only check for new release versions"); + ToggleSetting(GameConfigKeys::ShowCrashUploadPrompt, "Ask to upload crash dumps on crash"); EnumSetting(GameConfigKeys::LogLevel, "Logging level"); diff --git a/Shared/include/Shared/Path.hpp b/Shared/include/Shared/Path.hpp index 76cef869c..1a9dd28d1 100644 --- a/Shared/include/Shared/Path.hpp +++ b/Shared/include/Shared/Path.hpp @@ -41,6 +41,8 @@ class Path static bool CopyDir(String srcFolder, String dstFolder); // Go to specified path using the system default file browser static bool ShowInFileBrowser(const String& path); + // Go to specified url using the system default web browser + static void OpenInBrowser(const String& url); // Open external program with specified parameters (used to open charts in editor) static bool Run(const String& programPath, const String& parameters); diff --git a/Shared/src/Unix/Path.cpp b/Shared/src/Unix/Path.cpp index 1011cb140..6bfcd16bc 100644 --- a/Shared/src/Unix/Path.cpp +++ b/Shared/src/Unix/Path.cpp @@ -180,6 +180,11 @@ Vector Path::GetSubDirs(const String& path) closedir(dir); return ret; } +void Path::OpenInBrowser(const String& path) +{ + Log("Path::OpenInBrowser function not implemented yet", Logger::Severity::Error); + return false; +} bool Path::ShowInFileBrowser(const String& path) { Log("Path::ShowInFileBrowser function not implemented yet", Logger::Severity::Error); diff --git a/Shared/src/Windows/Path.cpp b/Shared/src/Windows/Path.cpp index 4d1f7551b..e4548de50 100644 --- a/Shared/src/Windows/Path.cpp +++ b/Shared/src/Windows/Path.cpp @@ -134,6 +134,12 @@ Vector Path::GetSubDirs(const String& path) return res; } +void Path::OpenInBrowser(const String& path) +{ + WString wpath = Utility::ConvertToWString(path); + ShellExecuteW(NULL, L"open", *wpath, NULL, NULL, SW_SHOWNORMAL); +} + bool Path::ShowInFileBrowser(const String& path) { WString wpath = Utility::ConvertToWString(path); From 2c8a659fc9df0cead6e144383d1f00ecbe3895a8 Mon Sep 17 00:00:00 2001 From: itszn Date: Thu, 1 Oct 2020 05:05:23 +0000 Subject: [PATCH 2/2] Fix linux typo --- Shared/src/Unix/Path.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Shared/src/Unix/Path.cpp b/Shared/src/Unix/Path.cpp index 6bfcd16bc..236cbbcc6 100644 --- a/Shared/src/Unix/Path.cpp +++ b/Shared/src/Unix/Path.cpp @@ -183,7 +183,6 @@ Vector Path::GetSubDirs(const String& path) void Path::OpenInBrowser(const String& path) { Log("Path::OpenInBrowser function not implemented yet", Logger::Severity::Error); - return false; } bool Path::ShowInFileBrowser(const String& path) { @@ -195,4 +194,4 @@ bool Path::Run(const String& programPath, const String& parameters) { Log("Path::Run function not implemented yet", Logger::Severity::Error); return false; -} \ No newline at end of file +}