paysages3d/src/core/CacheFile.cpp

53 lines
1.2 KiB
C++

#include "CacheFile.h"
#include "DataFile.h"
#include <sstream>
CacheFile::CacheFile(const string &module, const string &ext, const string &tag1, int tag2, int tag3, int tag4,
int tag5, int tag6) {
ostringstream buf;
buf << "cache/" << module << "-" << tag1 << "-" << tag2 << "-" << tag3 << "-" << tag4 << "-" << tag5 << "-" << tag6 << "." << ext;
filepath = buf.str();
}
bool CacheFile::isReadable() {
FILE *f = fopen(filepath.c_str(), "rb");
if (f) {
fclose(f);
return true;
} else {
string datapath = DataFile::findFile(filepath);
if (datapath.empty()) {
return false;
} else {
FILE *f = fopen(datapath.c_str(), "rb");
if (f) {
fclose(f);
return true;
} else {
return false;
}
}
}
}
bool CacheFile::isWritable() {
FILE *f = fopen("cache/.test", "wb");
if (f) {
fclose(f);
return true;
} else {
return false;
}
}
string CacheFile::getPath() {
string datapath = DataFile::findFile(filepath);
if (datapath.empty()) {
return filepath;
} else {
return datapath;
}
}