write porymap settings and log to writeable path
This commit is contained in:
parent
a5ff02c4c9
commit
1ccc8f72df
2 changed files with 20 additions and 2 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
KeyValueConfigBase::~KeyValueConfigBase() {
|
KeyValueConfigBase::~KeyValueConfigBase() {
|
||||||
|
|
||||||
|
@ -89,7 +90,14 @@ PorymapConfig porymapConfig;
|
||||||
|
|
||||||
QString PorymapConfig::getConfigFilepath() {
|
QString PorymapConfig::getConfigFilepath() {
|
||||||
// porymap config file is in the same directory as porymap itself.
|
// 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) {
|
void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
|
||||||
|
|
12
src/log.cpp
12
src/log.cpp
|
@ -1,5 +1,7 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
void logInfo(QString message) {
|
void logInfo(QString message) {
|
||||||
log(message, LogType::LOG_INFO);
|
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);
|
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;
|
qDebug() << message;
|
||||||
QFile outFile("porymap.log");
|
QFile outFile(logPath);
|
||||||
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
|
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
|
||||||
QTextStream ts(&outFile);
|
QTextStream ts(&outFile);
|
||||||
ts << message << endl;
|
ts << message << endl;
|
||||||
|
|
Loading…
Reference in a new issue