From 29618c651efb66c37e5f1d379d4fe0bc2452d62c Mon Sep 17 00:00:00 2001 From: WuChang <3142324836@qq.com> Date: Tue, 23 Jan 2024 17:26:33 +0800 Subject: [PATCH] Fixed crash handler save path when plugin crashed --- src/crash.cpp | 8 +++++++- src/crash.h | 2 ++ src/main.cpp | 20 ++++++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/crash.cpp b/src/crash.cpp index d6450f16..4db6cc10 100644 --- a/src/crash.cpp +++ b/src/crash.cpp @@ -9,6 +9,8 @@ #include #endif //JUCE_WINDOWS +static std::string hostPath; + std::string getLocalTime() { time_t nowTime; time(&nowTime); @@ -36,7 +38,7 @@ void applicationCrashHandler(void* info) { std::replace(time.begin(), time.end(), ':', '_'); /** Get File Path */ - std::filesystem::path projPath = std::filesystem::current_path(); + std::filesystem::path projPath = std::filesystem::path{ ::hostPath }; std::filesystem::path projHLPath = projPath / (time + ".vshl.dmp"); std::filesystem::path projMLPath = projPath / (time + ".vsml.dmp"); std::filesystem::path projLLPath = projPath / (time + ".vsll.dmp"); @@ -72,3 +74,7 @@ const juce::Array getAllDumpFiles() { return appDir.findChildFiles(juce::File::findFiles, false, "*.vsll.dmp;*.vsml.dmp;*.vshl.dmp", juce::File::FollowSymlinks::no); } + +void initCrashHandler(const juce::String& path) { + ::hostPath = path.toStdString(); +} diff --git a/src/crash.h b/src/crash.h index 757f096a..7a6964b0 100644 --- a/src/crash.h +++ b/src/crash.h @@ -5,3 +5,5 @@ void applicationCrashHandler(void*); const juce::Array getAllDumpFiles(); + +void initCrashHandler(const juce::String& path); diff --git a/src/main.cpp b/src/main.cpp index 3058e278..c7ffff53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,19 @@ class MainApplication : public juce::JUCEApplication { private: std::unique_ptr splash = nullptr; + void initCrashHandler() { + InitTaskList::getInstance()->add( + [splash = Splash::SafePointer(this->splash.get())] { + if (splash) { splash->showMessage("Init Crash Handler..."); } + } + ); + InitTaskList::getInstance()->add( + [] { + ::initCrashHandler(utils::getAppRootDir().getFullPathName()); + } + ); + }; + void loadConfig() { InitTaskList::getInstance()->add( [splash = Splash::SafePointer(this->splash.get())] { @@ -404,7 +417,7 @@ class MainApplication : public juce::JUCEApplication { ); InitTaskList::getInstance()->add( [] { - auto dumpList = getAllDumpFiles(); + auto dumpList = ::getAllDumpFiles(); if (!dumpList.isEmpty()) { juce::String mes = TRANS("Found the following crash dump files. These files take up {DMPSIZE} of storage space, should they be deleted to save disk space?") + "\n"; size_t dumpSize = 0; @@ -476,7 +489,7 @@ class MainApplication : public juce::JUCEApplication { void setCrashHandler() { InitTaskList::getInstance()->add( [] { - juce::SystemStats::setApplicationCrashHandler(applicationCrashHandler); + juce::SystemStats::setApplicationCrashHandler(::applicationCrashHandler); } ); }; @@ -493,6 +506,9 @@ class MainApplication : public juce::JUCEApplication { this->splash = std::make_unique(); this->splash->setVisible(true); + /** Init Crash Handler */ + this->initCrashHandler(); + /** Load Config */ this->loadConfig();