lolautoaccept/src/files.cpp

44 lines
737 B
C++
Raw Permalink Normal View History

2022-04-23 22:35:44 +02:00
#include "files.h"
#include <sys/stat.h>
2023-05-31 22:22:23 +02:00
#include <QDir>
2022-04-23 22:35:44 +02:00
#include <Log.h>
2022-08-24 16:12:03 +02:00
#ifdef WIN32
#define CACHEPATH "lolautoacceptor/cache/"
#else
#define CACHEPATH ".cache/lolautoaccept/"
#endif
#ifdef WIN32
2023-05-31 22:22:23 +02:00
QString getHome() {
2022-08-24 16:12:03 +02:00
const char* homevar = getenv("appdata");
if(homevar == nullptr) {
2023-05-31 22:22:23 +02:00
qWarning() << "%appdata% is not set! Defaulting to ./";
2022-08-24 16:12:03 +02:00
return "./";
}
2023-05-31 22:22:23 +02:00
return QString(homevar) + "/";
2022-08-24 16:12:03 +02:00
}
#else
2022-04-23 22:35:44 +02:00
2023-05-31 22:22:23 +02:00
QString getHome() {
2022-04-23 22:35:44 +02:00
const char* homevar = getenv("HOME");
if(homevar == nullptr) {
2023-05-31 22:22:23 +02:00
qWarning() << "$HOME is not set! Defaulting to ./";
2022-04-23 22:35:44 +02:00
return "./";
}
2023-05-31 22:22:23 +02:00
return QString(homevar) + "/";
2022-07-05 23:45:28 +02:00
}
2022-08-24 16:12:03 +02:00
#endif
2022-07-05 23:45:28 +02:00
2023-05-31 22:22:23 +02:00
bool mkdirs(const QString& path) {
return QDir::root().mkpath(path);
}
QString getCache() {
2022-08-24 16:12:03 +02:00
return getHome() + CACHEPATH;
}