forked from MrBesen/lolautoaccept
files.h
This commit is contained in:
parent
24425de9e8
commit
e9e2712fdc
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
// stuff required for file handling
|
||||
|
||||
#include <string>
|
||||
|
||||
// create a directory and its parents
|
||||
bool mkdirs(const std::string& path);
|
||||
|
||||
// get $HOME or a useful default value
|
||||
std::string getHome();
|
|
@ -26,6 +26,7 @@ SOURCES += \
|
|||
src/datadragon.cpp \
|
||||
src/datadragonimagecache.cpp \
|
||||
src/fakescreen.cpp \
|
||||
src/files.cpp \
|
||||
src/lolautoaccept.cpp \
|
||||
src/main.cpp \
|
||||
src/mainwindow.cpp \
|
||||
|
@ -42,6 +43,7 @@ HEADERS += \
|
|||
include/datadragon.h \
|
||||
include/datadragonimagecache.h \
|
||||
include/fakescreen.h \
|
||||
include/files.h \
|
||||
include/lolautoaccept.h \
|
||||
include/mainwindow.h \
|
||||
include/matcher.h \
|
||||
|
|
|
@ -1,32 +1,14 @@
|
|||
#include "datadragonimagecache.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <Log.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <QFile>
|
||||
|
||||
static 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;
|
||||
}
|
||||
#include "files.h"
|
||||
|
||||
DataDragonImageCache::DataDragonImageCache(const std::string& folderextra, const std::string& imageext) : imageext(imageext) {
|
||||
// init cache dir
|
||||
const char* homevar = getenv("HOME");
|
||||
if(homevar == nullptr) {
|
||||
Log::warn << "$HOME is not set! Defaulting to ./";
|
||||
homevar = "./";
|
||||
}
|
||||
cacheDir = std::string(homevar) + "/.cache/lolautoaccept/" + folderextra + "/";
|
||||
cacheDir = getHome() + "/.cache/lolautoaccept/" + folderextra + "/";
|
||||
|
||||
mkdirs(cacheDir);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
#include "files.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <Log.h>
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue