-
Notifications
You must be signed in to change notification settings - Fork 23
/
SystemConfig.cpp
62 lines (57 loc) · 2.22 KB
/
SystemConfig.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
#include "SystemConfig.h"
#include "FPSciAnyTableReader.h"
SystemConfig::SystemConfig(const Any& any) {
FPSciAnyTableReader reader(any);
int settingsVersion = 1;
reader.getIfPresent("settingsVersion", settingsVersion);
switch (settingsVersion) {
case 1:
reader.getIfPresent("hasLatencyLogger", hasLogger);
if (hasLogger) {
reader.get("loggerComPort", loggerComPort, "Logger COM port must be provided if \"hasLogger\" = true!");
}
else {
reader.getIfPresent("loggerComPort", loggerComPort);
}
reader.getIfPresent("hasLatencyLoggerSync", hasSync);
if (hasSync) {
reader.get("loggerSyncComPort", syncComPort, "Logger sync COM port must be provided if \"hasLoggerSync\" = true!");
}
else {
reader.getIfPresent("loggerSyncComPort", syncComPort);
}
break;
default:
debugPrintf("Settings version '%d' not recognized in SystemConfig.\n", settingsVersion);
break;
}
}
SystemConfig SystemConfig::load(String filename, bool saveJSON) {
if (filename.empty()) { filename = "systemconfig.Any"; }
// Create default UserConfig file
if (!FileSystem::exists(System::findDataFile(filename, false))) { // if file not found, generate a default user config table
SystemConfig defConfig = SystemConfig();
defConfig.toAny().save(filename, saveJSON); // Save the .any file
return defConfig;
}
return Any::fromFile(System::findDataFile(filename));
}
Any SystemConfig::toAny(const bool forceAll) const {
Any a(Any::TABLE);
SystemConfig def;
if (forceAll || def.hasLogger != hasLogger) a["hasLatencyLogger"] = hasLogger;
if (forceAll || def.loggerComPort != loggerComPort) a["loggerComPort"] = loggerComPort;
if (forceAll || def.hasSync != hasSync) a["hasLatencyLoggerSync"] = hasSync;
if (forceAll || def.syncComPort != syncComPort) a["loggerSyncComPort"] = syncComPort;
return a;
}
void SystemConfig::printToLog() {
const String loggerComStr = hasLogger ? loggerComPort : "None";
const String syncComStr = hasSync ? syncComPort : "None";
logPrintf("-------------------\nLDAT-R Config:\n-------------------\n\tLogger Present: %s\n\tLogger COM Port: %s\n\tSync Card Present: %s\n\tSync COM Port: %s\n\n",
hasLogger ? "True" : "False",
loggerComStr.c_str(),
hasSync ? "True" : "False",
syncComStr.c_str()
);
}