starting cloud save
This commit is contained in:
51
sources/configurationmanager.cpp
Normal file
51
sources/configurationmanager.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "configurationmanager.h"
|
||||
|
||||
ConfigurationManager::ConfigurationManager()
|
||||
{
|
||||
if (QFile::exists(GetPath())) {
|
||||
QFile* file = new QFile(GetPath());
|
||||
file->open(QIODevice::ReadOnly);
|
||||
auto json = QString(file->readAll());
|
||||
file->close();
|
||||
delete file;
|
||||
|
||||
QJsonObject obj = QJsonDocument::fromJson(json.toUtf8()).object();
|
||||
this->s = Settings::FromJSON(obj);
|
||||
} else {
|
||||
this->s = new Settings();
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationManager::~ConfigurationManager()
|
||||
{
|
||||
delete s;
|
||||
}
|
||||
|
||||
Settings *ConfigurationManager::GetConfiguration()
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
QString ConfigurationManager::GetPath() {
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
if (!QDir(path).exists()) {
|
||||
QDir().mkpath(path);
|
||||
}
|
||||
path += "/";
|
||||
if (!QDir(path).exists()) {
|
||||
QDir().mkpath(path);
|
||||
}
|
||||
path += FILENAME;
|
||||
return path;
|
||||
}
|
||||
|
||||
void ConfigurationManager::Save() {
|
||||
QJsonDocument doc(s->ToJSON());
|
||||
QFile *f = new QFile(GetPath());
|
||||
if (f->open(QIODevice::WriteOnly)) {
|
||||
f->write(doc.toJson());
|
||||
f->close();
|
||||
}
|
||||
delete f;
|
||||
}
|
||||
Reference in New Issue
Block a user