-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitquit.cpp
73 lines (53 loc) · 1.5 KB
/
initquit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "stdafx.h"
#include "json.hpp"
#include <fstream>
// Sample initquit implementation. See also: initquit class documentation in relevant header.
extern static_api_ptr_t<playback_control> *g_playback_control;
//extern callInMainThreadHelper *mtHelper;
extern UINT_PTR g_timer;
extern nlohmann::json *json_intervals;
CStringA wctomb(CString s);
CString mbtowc(CStringA s);
extern cfg_string cfg_bogoSetting1;
void save_track_db();
void load_track_db();
class myinitquit : public initquit {
public:
void on_init() {
console::print("Rehearsal component: on_init() begin");
g_playback_control = new static_api_ptr_t<playback_control>();
//mtHelper = new callInMainThreadHelper();
json_intervals = new nlohmann::json();
load_track_db();
console::print("Rehearsal component: on_init() end");
}
void on_quit() {
if (g_timer) {
::KillTimer(NULL, g_timer);
}
save_track_db();
delete json_intervals;
console::print("Rehearsal component: on_quit()");
}
};
static initquit_factory_t<myinitquit> g_myinitquit_factory;
void save_track_db() {
CStringA text(cfg_bogoSetting1);
CString path = mbtowc(text);
wchar_t path_w[500];
ExpandEnvironmentStrings(path, path_w, 500);
std::ofstream of(path_w);
of << (*json_intervals);
of.close();
}
void load_track_db() {
CStringA text(cfg_bogoSetting1);
CString path = mbtowc(text);
wchar_t path_w[500];
ExpandEnvironmentStrings(path, path_w, 500);
std::ifstream of(path_w);
if (of.is_open()) {
of >> (*json_intervals);
}
of.close();
}