-
Notifications
You must be signed in to change notification settings - Fork 9
/
settingsmanager.cpp
66 lines (61 loc) · 1.95 KB
/
settingsmanager.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
#include "settingsmanager.h"
#include <QDebug>
QString playerName, minecraftPath, launchMode, javaPath, last;
int maxMemory;
bool loaded, debug;
void SettingsManager::load()
{
QFile f(SettingsManager::d.currentPath() + "/settings.json");
if(f.open(QFile::ReadOnly))
{
QTextStream ts(&f);
QString str, line;
while(!ts.atEnd()) {
line = ts.readLine();
str += line;
}
Json::Reader reader;
Json::Value root;
std::string stdstring = str.toStdString();
reader.parse(stdstring,root);
playerName = QString(root["PlayerName"].asString().c_str());
minecraftPath = QString(root["MinecraftPath"].asString().c_str());
javaPath = QString(root["JavaPath"].asString().c_str());
launchMode = QString(root["LaunchMode"].asString().c_str());
last = QString(root["Last"].asString().c_str());
maxMemory = root["MaxMemory"].asUInt();
debug = root["Debug"].asBool();
loaded = true;
}
else
{
playerName = "Player007";
minecraftPath = FileUtilities::qhome().append("/.minecraft");
maxMemory = SystemManager::getMemorySize() / 2;
debug = false;
last = "";
launchMode = "Normal";
javaPath = "";
loaded = true;
save();
}
}
void SettingsManager::save()
{
if(!loaded) return;
QString path = d.currentPath();
QFile file(path + "/settings.json");
Json::FastWriter writer;
Json::Value root;
root["PlayerName"] = playerName.toStdString();
root["MinecraftPath"] = minecraftPath.toStdString();
root["JavaPath"] = javaPath.toStdString();
root["Last"] = last.toStdString();
root["MaxMemory"] = Json::Value(maxMemory);
root["LaunchMode"] = launchMode.toStdString();
root["Debug"] = debug;
const char *c = (path + "/settings.json").toStdString().c_str();
ofstream fout(c);
fout<<root.toStyledString();
fout.close();
}