56 lines
1.1 KiB
C++
56 lines
1.1 KiB
C++
#include "files.h"
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <Log.h>
|
|
|
|
#ifdef WIN32
|
|
#define CACHEPATH "lolautoacceptor/cache/"
|
|
#else
|
|
#define CACHEPATH ".cache/lolautoaccept/"
|
|
#endif
|
|
|
|
#ifdef WIN32
|
|
#include <QDir>
|
|
|
|
bool mkdirs(const std::string& path) {
|
|
return QDir::root().mkpath(QString::fromStdString(path));
|
|
}
|
|
|
|
std::string getHome() {
|
|
const char* homevar = getenv("appdata");
|
|
if(homevar == nullptr) {
|
|
Log::warn << "%appdata% is not set! Defaulting to ./";
|
|
return "./";
|
|
}
|
|
return std::string(homevar) + "/";
|
|
}
|
|
#else
|
|
bool mkdirs(const std::string& path) {
|
|
size_t offset = 0;
|
|
while(offset < path.size()) {
|
|
offset = path.find('/', offset+1);
|
|
int res = mkdir(path.substr(0, offset).c_str(), S_IRWXU | S_IRWXG); // 770
|
|
if(res == -1 && errno != EEXIST) {
|
|
// mkdirs failed
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
std::string getHome() {
|
|
const char* homevar = getenv("HOME");
|
|
if(homevar == nullptr) {
|
|
Log::warn << "$HOME is not set! Defaulting to ./";
|
|
return "./";
|
|
}
|
|
return std::string(homevar) + "/";
|
|
}
|
|
#endif
|
|
|
|
std::string getCache() {
|
|
return getHome() + CACHEPATH;
|
|
}
|