From 1ccc8f72df9fa70797a856037be993438e163c28 Mon Sep 17 00:00:00 2001 From: Melody Date: Wed, 26 Dec 2018 20:18:33 -0500 Subject: [PATCH] write porymap settings and log to writeable path --- src/config.cpp | 10 +++++++++- src/log.cpp | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index be0612fa..0fa7e01e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -10,6 +10,7 @@ #include #include #include +#include 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) { diff --git a/src/log.cpp b/src/log.cpp index 28d33a29..73e29121 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,5 +1,7 @@ #include "log.h" #include +#include +#include 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;