paysages3d/src/system/CacheFile.cpp

68 lines
1.4 KiB
C++
Raw Normal View History

#include "CacheFile.h"
2014-09-18 09:39:36 +00:00
#include <QString>
#include "DataFile.h"
2014-09-18 09:39:36 +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)
{
2014-09-18 09:39:36 +00:00
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();
}
bool CacheFile::isReadable()
{
2014-09-18 09:39:36 +00:00
FILE* f = fopen(filepath.c_str(), "rb");
if (f)
{
fclose(f);
return true;
}
else
{
2014-09-18 09:39:36 +00:00
std::string datapath = DataFile::findFile(filepath);
if (datapath.empty())
{
2014-09-18 09:39:36 +00:00
return false;
}
else
{
2014-09-18 09:39:36 +00:00
FILE* f = fopen(datapath.c_str(), "rb");
if (f)
{
fclose(f);
return true;
}
else
{
return false;
}
}
}
}
bool CacheFile::isWritable()
{
2014-09-18 09:39:36 +00:00
FILE* f = fopen("cache/.test", "wb");
if (f)
{
fclose(f);
return true;
}
else
{
return false;
}
}
2014-09-18 09:39:36 +00:00
std::string CacheFile::getPath()
{
2014-09-18 09:39:36 +00:00
std::string datapath = DataFile::findFile(filepath);
if (datapath.empty())
{
2014-09-18 09:39:36 +00:00
return filepath;
}
else
{
2014-09-18 09:39:36 +00:00
return datapath;
}
}