write porymap settings and log to writeable path

This commit is contained in:
Melody 2018-12-26 20:18:33 -05:00 committed by Marcus Huderle
parent a5ff02c4c9
commit 1ccc8f72df
2 changed files with 20 additions and 2 deletions

View file

@ -10,6 +10,7 @@
#include <QLabel>
#include <QTextStream>
#include <QRegularExpression>
#include <QStandardPaths>
KeyValueConfigBase::~KeyValueConfigBase() {
@ -89,7 +90,14 @@ PorymapConfig porymapConfig;
QString PorymapConfig::getConfigFilepath() {
// porymap config file is in the same directory as porymap itself.
return "porymap.cfg";
QString settingsPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QDir dir(settingsPath);
if (!dir.exists())
dir.mkpath(settingsPath);
QString configPath = dir.absoluteFilePath("porymap.cfg");
return configPath;
}
void PorymapConfig::parseConfigKeyValue(QString key, QString value) {

View file

@ -1,5 +1,7 @@
#include "log.h"
#include <QDateTime>
#include <QDir>
#include <QStandardPaths>
void logInfo(QString message) {
log(message, LogType::LOG_INFO);
@ -30,8 +32,16 @@ void log(QString message, LogType type) {
}
message = QString("%1 %2 %3").arg(now).arg(typeString).arg(message);
QString settingsPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QDir dir(settingsPath);
if (!dir.exists())
dir.mkpath(settingsPath);
QString logPath = dir.absoluteFilePath("porymap.log");
qDebug() << message;
QFile outFile("porymap.log");
QFile outFile(logPath);
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << message << endl;