Change location for crash data (e.g. %AppData%/Aseprite/crashdb)

This commit is contained in:
David Capello 2021-09-22 19:48:44 -03:00
parent 8b215235c7
commit 024cd73f62
2 changed files with 72 additions and 25 deletions

67
src/app/sentry_wrapper.h Normal file
View File

@ -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

View File

@ -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.
{