-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
48 lines (37 loc) · 1.21 KB
/
utils.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
#include "utils.h"
QString readFile(QString path){
QString output = "";
QFile file(path);
file.open(QIODevice::ReadWrite);
QTextStream in(&file);
output.append(in.readAll());
file.close();
return output;
}
void writeFile(QString path, QString value){
QFile file(path);
file.open(QIODevice::ReadWrite);
file.write(value.toUtf8());
file.close();
}
Config::Config(){
defaultConfigPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/AugSteam";
}
void Config::load(){
if (!QDir().exists(defaultConfigPath)){
QDir().mkpath(defaultConfigPath);
}
if (!QDir().exists(defaultConfigPath+"/config.json")){
this->save();
}
QString configValue = readFile(defaultConfigPath+"/config.json");
QJsonObject configObj = QJsonDocument::fromJson(configValue.toUtf8()).object();
this->maFilesPath = configObj["maFilesPath"].toString();
this->nickname = configObj["nickname"].toString();
}
void Config::save(){
QJsonObject configObj;
configObj["maFilesPath"] = this->maFilesPath;
configObj["nickname"] = this->nickname;
writeFile(defaultConfigPath+"/config.json", QString(QJsonDocument(configObj).toJson()));
}