From 5feabfacc838aef2b5e9fadaa641e6b853253ae7 Mon Sep 17 00:00:00 2001 From: Bennik2000 Date: Mon, 16 Mar 2020 22:39:17 +0100 Subject: [PATCH] UI: Fix wrong path in the crash message dialog Closes obsproject/obs-studio#2290 --- UI/obs-app.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index b6f0b7d59..1504da761 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -49,6 +49,7 @@ #ifdef _WIN32 #include +#include #else #include #include @@ -1888,8 +1889,7 @@ static int run_program(fstream &logFile, int argc, char *argv[]) #define CRASH_MESSAGE \ "Woops, OBS has crashed!\n\nWould you like to copy the crash log " \ - "to the clipboard? (Crash logs will still be saved to the " \ - "%appdata%\\obs-studio\\crashes directory)" + "to the clipboard? The crash log will still be saved to:\n\n%s" static void main_crash_handler(const char *format, va_list args, void *param) { @@ -1898,10 +1898,12 @@ static void main_crash_handler(const char *format, va_list args, void *param) vsnprintf(text, MAX_CRASH_REPORT_SIZE, format, args); text[MAX_CRASH_REPORT_SIZE - 1] = 0; - delete_oldest_file(true, "obs-studio/crashes"); + string crashFilePath = "obs-studio/crashes"; - string name = "obs-studio/crashes/Crash "; - name += GenerateTimeDateFilename("txt"); + delete_oldest_file(true, crashFilePath.c_str()); + + string name = crashFilePath + "/"; + name += "Crash " + GenerateTimeDateFilename("txt"); BPtr path(GetConfigPathPtr(name.c_str())); @@ -1919,7 +1921,26 @@ static void main_crash_handler(const char *format, va_list args, void *param) file << text; file.close(); - int ret = MessageBoxA(NULL, CRASH_MESSAGE, "OBS has crashed!", + string pathString(path.Get()); + +#ifdef _WIN32 + std::replace(pathString.begin(), pathString.end(), '/', '\\'); +#endif + + string absolutePath = + canonical(filesystem::path(pathString)).u8string(); + + size_t size = snprintf(nullptr, 0, CRASH_MESSAGE, absolutePath.c_str()); + + unique_ptr message_buffer(new char[size + 1]); + + snprintf(message_buffer.get(), size + 1, CRASH_MESSAGE, + absolutePath.c_str()); + + string finalMessage = + string(message_buffer.get(), message_buffer.get() + size); + + int ret = MessageBoxA(NULL, finalMessage.c_str(), "OBS has crashed!", MB_YESNO | MB_ICONERROR | MB_TASKMODAL); if (ret == IDYES) {