OpenCPN Partial API docs
Loading...
Searching...
No Matches
safe_mode.cpp
1#include <cstdio>
2#include <string>
3#include <fstream>
4
5#include <wx/dialog.h>
6#include <wx/filename.h>
7#include <wx/sizer.h>
8
9#include "base_platform.h"
10#include "ocpn_utils.h"
11#include "gui_lib.h"
12
13#include "safe_mode.h"
14
15extern BasePlatform* g_BasePlatform;
16extern bool g_bdisable_opengl;
17
18namespace safe_mode {
19
20static const char* LAST_RUN_ERROR_MSG =
21 _("The last opencpn run seems to have failed. Do you want to run\n"
22 "in safe mode without plugins and other possibly problematic\n"
23 "features?\n");
24
25#ifdef _WIN32
26static std::string SEP("\\");
27#else
28static std::string SEP("/");
29#endif
30
31static const int TIMEOUT_SECONDS = 15;
32
33static bool safe_mode = false;
34
35static std::string check_file_path() {
36 std::string path = g_BasePlatform->GetPrivateDataDir().ToStdString();
37 path += SEP;
38 path += "startcheck.dat";
39 return path;
40}
41
42void set_mode(bool mode) {
43 safe_mode = mode;
44 g_bdisable_opengl = g_bdisable_opengl || mode;
45}
46
47bool get_mode() { return safe_mode; }
48
54 std::string path = check_file_path();
55 if (!ocpn::exists(path)) {
56 std::ofstream dest(path, std::ios::binary);
57 dest << "Internal opencpn use" << std::endl;
58 dest.close();
59 return;
60 }
61 long style = wxYES | wxNO | wxNO_DEFAULT | wxICON_QUESTION;
62 auto dlg = new OCPN_TimedHTMLMessageDialog(0, LAST_RUN_ERROR_MSG,
63 _("Safe restart"), TIMEOUT_SECONDS,
64 style, false, wxDefaultPosition);
65 int reply = dlg->ShowModal();
66 safe_mode = reply == wxID_YES;
67 dlg->Destroy();
68}
69
71void clear_check() { remove(check_file_path().c_str()); }
72
73} // namespace safe_mode
Safe mode handling.
Definition: console.cpp:178
void check_last_start()
Check if the last start failed, possibly invoke user dialog and set safe mode state.
Definition: safe_mode.cpp:53
void clear_check()
Mark last run as successful.
Definition: safe_mode.cpp:71