Repository navigation
Expand file tree
/
Copy pathPersistentSettings.cpp
More file actions
88 lines (65 loc) · 2.32 KB
/
Copy pathPersistentSettings.cpp
File metadata and controls
88 lines (65 loc) · 2.32 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Persistent Settings
*
* From: https://github.com/PokemonAutomation/
*
*/
#include <QCoreApplication>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/Json/JsonValue.h"
//#include "Common/Cpp/Json/JsonArray.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Logging/Logger.h"
#include "CommonFramework/Options/Environment/PerformanceOptions.h"
#include "PersistentSettings.h"
// #include <iostream>
// using std::cout;
// using std::endl;
namespace PokemonAutomation{
PersistentSettings& PERSISTENT_SETTINGS(){
static PersistentSettings settings;
return settings;
}
PersistentSettings::PersistentSettings(){}
void PersistentSettings::write() const{
JsonObject root;
root["20-GlobalSettings"] = GlobalSettings::instance().to_json();
// root["50-SwitchKeyboardMapping"] = NintendoSwitch::read_keyboard_mapping();
root["99-Panels"] = panels.clone();
try{
root.dump(PROGRAM_SETTING_JSON_PATH());
}catch (FileException&){}
}
void PersistentSettings::read(){
JsonValue json = load_json_file(PROGRAM_SETTING_JSON_PATH());
JsonObject* obj = json.to_object();
if (obj == nullptr){
throw FileException(nullptr, PA_CURRENT_FUNCTION, "Invalid settings file.", PROGRAM_SETTING_JSON_PATH());
}
// Need to load this subset of settings first because they will affect how
// "GlobalSettings" is constructed.
const JsonValue* settings = obj->get_value("20-GlobalSettings");
if (settings){
PreloadSettings::instance().load(*settings);
GlobalSettings::instance().load_json(*settings);
}
// GlobalSettings::instance().PROCESS_PRIORITY0.update_priority_to_option();
GlobalSettings::instance().PERFORMANCE->REALTIME_THREAD_PRIORITY.set_on_this_thread(global_logger_tagged());
#if 0
{
const JsonArray* array = obj->get_array("50-SwitchKeyboardMapping");
if (array){
NintendoSwitch::set_keyboard_mapping(*array);
}
}
#endif
{
JsonObject* value = obj->get_object("99-Panels");
if (value){
// panels = to_QJson(*value).toObject();
panels = std::move(*value);
}
}
}
}