forked from MrBesen/lolautoaccept
36 lines
944 B
C++
36 lines
944 B
C++
#include "datadragonimagecache.h"
|
|
|
|
#include <QFile>
|
|
#include <QPixmap>
|
|
|
|
#include <Log.h>
|
|
|
|
#include "files.h"
|
|
|
|
DataDragonImageCache::DataDragonImageCache(const QString& folderextra, const QString& imageext) : imageext(imageext) {
|
|
// init cache dir
|
|
cacheDir = getCache() + folderextra + "/";
|
|
|
|
mkdirs(cacheDir);
|
|
}
|
|
DataDragonImageCache::~DataDragonImageCache() {}
|
|
|
|
bool DataDragonImageCache::hasImage(const QString& name) {
|
|
QFile file(getFilepath(name));
|
|
return file.size() > 1024; // a image with less than 1KiB? assume it would be readable (r-Permissions)
|
|
}
|
|
|
|
QPixmap DataDragonImageCache::getImage(const QString& name) {
|
|
return QPixmap(getFilepath(name));
|
|
}
|
|
|
|
void DataDragonImageCache::addImageRaw(const QByteArray& arr, const QString& name) {
|
|
QFile file(getFilepath(name));
|
|
file.open(QIODevice::WriteOnly);
|
|
file.write(arr);
|
|
}
|
|
|
|
QString DataDragonImageCache::getFilepath(const QString& name) const {
|
|
return cacheDir + name + imageext;
|
|
}
|