starting cloud save

This commit is contained in:
Aurélie Delhaie
2022-01-09 21:21:18 +01:00
parent c49966b47c
commit ffebb3c7d7
26 changed files with 983 additions and 213 deletions

View 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;
}