1 // Aseprite
2 // Copyright (C) 2001-2018  David Capello
3 //
4 // This program is distributed under the terms of
5 // the End-User License Agreement for Aseprite.
6 
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10 
11 #include "app/send_crash.h"
12 
13 #include "app/app.h"
14 #include "app/console.h"
15 #include "app/i18n/strings.h"
16 #include "app/resource_finder.h"
17 #include "base/bind.h"
18 #include "base/fs.h"
19 #include "base/launcher.h"
20 #include "ui/alert.h"
21 
22 #include "send_crash.xml.h"
23 
24 namespace app {
25 
search()26 void SendCrash::search()
27 {
28 #ifdef _WIN32
29   m_dumpFilename = memory_dump_filename();
30 
31   if (base::is_file(m_dumpFilename)) {
32     App::instance()->showNotification(this);
33   }
34 #endif
35 }
36 
notificationText()37 std::string SendCrash::notificationText()
38 {
39   return "Report last crash";
40 }
41 
notificationClick()42 void SendCrash::notificationClick()
43 {
44   if (m_dumpFilename.empty()) {
45     ui::Alert::show(Strings::alerts_nothing_to_report());
46     return;
47   }
48 
49   app::gen::SendCrash dlg;
50 
51   // The current version is a "development" version if the VERSION
52   // macro contains the "dev" word.
53   bool isDev = (std::string(VERSION).find("dev") != std::string::npos);
54   if (isDev) {
55     dlg.official()->setVisible(false);
56     dlg.devFilename()->setText(m_dumpFilename);
57     dlg.devFilename()->Click.connect(base::Bind(&SendCrash::onClickDevFilename, this));
58   }
59   else {
60     dlg.dev()->setVisible(false);
61     dlg.filename()->setText(m_dumpFilename);
62     dlg.filename()->Click.connect(base::Bind(&SendCrash::onClickFilename, this));
63   }
64 
65   dlg.openWindowInForeground();
66   if (dlg.closer() == dlg.deleteFile()) {
67     try {
68       base::delete_file(m_dumpFilename);
69       m_dumpFilename = "";
70     }
71     catch (const std::exception& ex) {
72       Console::showException(ex);
73     }
74   }
75 }
76 
onClickFilename()77 void SendCrash::onClickFilename()
78 {
79   base::launcher::open_folder(m_dumpFilename);
80 }
81 
onClickDevFilename()82 void SendCrash::onClickDevFilename()
83 {
84   base::launcher::open_file(m_dumpFilename);
85 }
86 
87 } // namespace app
88