-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.cpp
47 lines (35 loc) · 1.12 KB
/
Config.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
//
// Created by liam on 17/01/18.
//
#include <rapidjson/document.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include "Config.h"
Config::Config() {
//Do we have a config? If not, create a default one
if (this->file = fopen("tebex_config.cfg", "r+")) {
} else {
this->file = fopen("tebex_config.cfg", "w+");
this->writeFile();
}
char* jsonString = (char *)"";
//read file
fgets(jsonString, 10000, this->file);
rapidjson::Document document;
document.Parse<0>(jsonString);
this->secret = document["secret"].GetString();
this->verbose = document["verbose"].GetBool();
}
bool Config::writeFile() {
rapidjson::Document document;
document.SetObject();
rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
rapidjson::Value secret;
rapidjson::Value verbose;
secret.SetString(this->secret.c_str(), allocator);
verbose.SetBool(this->verbose);
document.AddMember("secret", secret, allocator);
document.AddMember("verbose", verbose, allocator);
fputs(document.GetString(), this->file);
return true;
}