2013-12-09 21:16:00 +00:00
|
|
|
#include "CacheFile.h"
|
|
|
|
|
2014-09-18 09:39:36 +00:00
|
|
|
#include <QString>
|
|
|
|
#include "DataFile.h"
|
2013-12-09 21:16:00 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
CacheFile::CacheFile(const std::string &module, const std::string &ext, const std::string &tag1, int tag2, int tag3,
|
|
|
|
int tag4, int tag5, int tag6) {
|
|
|
|
filepath = QString("cache/%1-%2-%3-%4-%5-%6-%7.%8")
|
|
|
|
.arg(QString::fromStdString(module))
|
|
|
|
.arg(QString::fromStdString(tag1))
|
|
|
|
.arg(tag2)
|
|
|
|
.arg(tag3)
|
|
|
|
.arg(tag4)
|
|
|
|
.arg(tag5)
|
|
|
|
.arg(tag6)
|
|
|
|
.arg(QString::fromStdString(ext))
|
|
|
|
.toStdString();
|
2013-12-09 21:16:00 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
bool CacheFile::isReadable() {
|
|
|
|
FILE *f = fopen(filepath.c_str(), "rb");
|
|
|
|
if (f) {
|
2013-12-09 21:16:00 +00:00
|
|
|
fclose(f);
|
|
|
|
return true;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2014-09-18 09:39:36 +00:00
|
|
|
std::string datapath = DataFile::findFile(filepath);
|
2015-11-09 21:30:46 +00:00
|
|
|
if (datapath.empty()) {
|
2014-09-18 09:39:36 +00:00
|
|
|
return false;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
|
|
|
FILE *f = fopen(datapath.c_str(), "rb");
|
|
|
|
if (f) {
|
2014-09-18 09:39:36 +00:00
|
|
|
fclose(f);
|
|
|
|
return true;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2014-09-18 09:39:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-12-09 21:16:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
bool CacheFile::isWritable() {
|
|
|
|
FILE *f = fopen("cache/.test", "wb");
|
|
|
|
if (f) {
|
2013-12-09 21:16:00 +00:00
|
|
|
fclose(f);
|
|
|
|
return true;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2013-12-09 21:16:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
std::string CacheFile::getPath() {
|
2014-09-18 09:39:36 +00:00
|
|
|
std::string datapath = DataFile::findFile(filepath);
|
2015-11-09 21:30:46 +00:00
|
|
|
if (datapath.empty()) {
|
2014-09-18 09:39:36 +00:00
|
|
|
return filepath;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2014-09-18 09:39:36 +00:00
|
|
|
return datapath;
|
2013-12-09 21:16:00 +00:00
|
|
|
}
|
|
|
|
}
|