From 024cd73f624486aba389d2b676f67d0169e11d06 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 22 Sep 2021 19:48:44 -0300 Subject: [PATCH] Change location for crash data (e.g. %AppData%/Aseprite/crashdb) --- src/app/sentry_wrapper.h | 67 ++++++++++++++++++++++++++++++++++++++++ src/main/main.cpp | 30 +++--------------- 2 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 src/app/sentry_wrapper.h diff --git a/src/app/sentry_wrapper.h b/src/app/sentry_wrapper.h new file mode 100644 index 000000000..3eb9805f0 --- /dev/null +++ b/src/app/sentry_wrapper.h @@ -0,0 +1,67 @@ +// Aseprite +// Copyright (C) 2021 Igara Studio S.A. +// +// This program is distributed under the terms of +// the End-User License Agreement for Aseprite. + +#ifndef APP_SENTRY_WRAPPER_H +#define APP_SENTRY_WRAPPER_H + +#if !ENABLE_SENTRY + #error ENABLE_SENTRY must be defined +#endif + +#include "app/resource_finder.h" +#include "base/string.h" + +#include "sentry.h" + +namespace app { + +class Sentry { +public: + void init() + { + sentry_options_t* options = sentry_options_new(); + sentry_options_set_dsn(options, SENTRY_DNS); + + std::string release = "aseprite@"; + release += get_app_version(); + sentry_options_set_release(options, release.c_str()); + +#if _DEBUG + sentry_options_set_debug(options, 1); +#endif + + setupDirs(options); + + if (sentry_init(options) == 0) + m_init = true; + } + + ~Sentry() + { + if (m_init) + sentry_close(); + } + +private: + void setupDirs(sentry_options_t* options) + { + ResourceFinder rf; + rf.includeUserDir("crashdb"); + std::string dir = rf.getFirstOrCreateDefault(); + +#if SENTRY_PLATFORM_WINDOWS + sentry_options_set_database_pathw(options, base::from_utf8(dir).c_str()); +#else + sentry_options_set_database_path(options, dir.c_str()); +#endif + } + + bool m_init = false; +}; + +} // namespace app + +#endif // APP_SENTRY_WRAPPER_H diff --git a/src/main/main.cpp b/src/main/main.cpp index c8af5c2a1..e7940e7c2 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -22,7 +22,7 @@ #include "ver/info.h" #if ENABLE_SENTRY - #include "sentry.h" + #include "app/sentry_wrapper.h" #else #include "base/memory_dump.h" #endif @@ -65,28 +65,6 @@ namespace { }; #endif -#if ENABLE_SENTRY - class Sentry { - public: - Sentry() { - sentry_options_t* options = sentry_options_new(); - sentry_options_set_dsn(options, SENTRY_DNS); - - std::string release = "aseprite@"; - release += get_app_version(); - sentry_options_set_release(options, release.c_str()); - -#if _DEBUG - sentry_options_set_debug(options, 1); -#endif - sentry_init(options); - } - ~Sentry() { - sentry_close(); - } - }; -#endif - } // Aseprite entry point. (Called from "os" library.) @@ -107,7 +85,7 @@ int app_main(int argc, char* argv[]) try { #if ENABLE_SENTRY - Sentry sentry; + app::Sentry sentry; #else base::MemoryDump memoryDump; #endif @@ -117,7 +95,9 @@ int app_main(int argc, char* argv[]) os::SystemRef system(os::make_system()); app::App app; -#if !ENABLE_SENTRY +#if ENABLE_SENTRY + sentry.init(); +#else // Change the memory dump filename to save on disk (.dmp // file). Note: Only useful on Windows. {