|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tsystem.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tiio.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcontenthistory.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// STD includes
|
|
Toshihiro Shimizu |
890ddd |
#include <map></map>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qdir></qdir>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tlevel_io.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace std;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DEFINE_CLASS_CODE(TLevelReader, 8)
|
|
Toshihiro Shimizu |
890ddd |
DEFINE_CLASS_CODE(TLevelWriter, 9)
|
|
Toshihiro Shimizu |
890ddd |
//DEFINE_CLASS_CODE(TLevelReaderWriter, 25) //brutto
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
typedef std::pair<qstring, int=""> LevelReaderKey;</qstring,>
|
|
Toshihiro Shimizu |
890ddd |
std::map<levelreaderkey, *="" tlevelreadercreateproc=""> LevelReaderTable;</levelreaderkey,>
|
|
Toshihiro Shimizu |
890ddd |
std::map<qstring, *,="" bool="" std::pair<tlevelwritercreateproc="">> LevelWriterTable;</qstring,>
|
|
Shinya Kitaoka |
3bfa54 |
//std::map<std::string, tlevelreaderwritercreateproc*=""> LevelReaderWriterTable;</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TLevelReader::TLevelReader(const TFilePath &path)
|
|
Toshihiro Shimizu |
890ddd |
: TSmartObject(m_classCode), m_info(0), m_path(path), m_contentHistory(0), m_frameFormat(TFrameId::FOUR_ZEROS)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TLevelReader::~TLevelReader()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_contentHistory;
|
|
Toshihiro Shimizu |
890ddd |
delete m_info;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TLevelReaderP::TLevelReaderP(const TFilePath &path, int reader)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString extension = QString::fromStdString(toLower(path.getType()));
|
|
Toshihiro Shimizu |
890ddd |
LevelReaderKey key(extension, reader);
|
|
Toshihiro Shimizu |
890ddd |
std::map<levelreaderkey, *="" tlevelreadercreateproc="">::iterator it;</levelreaderkey,>
|
|
Toshihiro Shimizu |
890ddd |
it = LevelReaderTable.find(key);
|
|
Toshihiro Shimizu |
890ddd |
if (it != LevelReaderTable.end()) {
|
|
Toshihiro Shimizu |
890ddd |
m_pointer = it->second(path);
|
|
Toshihiro Shimizu |
890ddd |
assert(m_pointer);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_pointer = new TLevelReader(path);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_pointer->addRef();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool myLess(const TFilePath &l, const TFilePath &r)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return l.getFrame() < r.getFrame();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const TImageInfo *TLevelReader::getImageInfo(TFrameId fid)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_info)
|
|
Toshihiro Shimizu |
890ddd |
return m_info;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TImageReaderP frameReader = getFrameReader(fid);
|
|
Toshihiro Shimizu |
890ddd |
if (!frameReader)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const TImageInfo *fInfo = frameReader->getImageInfo();
|
|
Toshihiro Shimizu |
890ddd |
if (!fInfo)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_info = new TImageInfo(*fInfo);
|
|
Toshihiro Shimizu |
890ddd |
if (m_info->m_properties)
|
|
Toshihiro Shimizu |
890ddd |
m_info->m_properties = m_info->m_properties->clone();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return m_info;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const TImageInfo *TLevelReader::getImageInfo()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_info)
|
|
Toshihiro Shimizu |
890ddd |
return m_info;
|
|
Toshihiro Shimizu |
890ddd |
TLevelP level = loadInfo();
|
|
Toshihiro Shimizu |
890ddd |
if (level->getFrameCount() == 0)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
return getImageInfo(level->begin()->first);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TLevelP TLevelReader::loadInfo()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TFilePath parentDir = m_path.getParentDir();
|
|
Toshihiro Shimizu |
890ddd |
TFilePath levelName(m_path.getLevelName());
|
|
Toshihiro Shimizu |
890ddd |
// cout << "Parent dir = '" << parentDir << "'" << endl;
|
|
Toshihiro Shimizu |
890ddd |
// cout << "Level name = '" << levelName << "'" << endl;
|
|
Toshihiro Shimizu |
890ddd |
TFilePathSet files;
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
files = TSystem::readDirectory(parentDir, false, true, true);
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
throw TImageException(m_path, "unable to read directory content");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TLevelP level;
|
|
Toshihiro Shimizu |
890ddd |
vector<tfilepath> data;</tfilepath>
|
|
Toshihiro Shimizu |
890ddd |
for (TFilePathSet::iterator it = files.begin(); it != files.end(); it++) {
|
|
Toshihiro Shimizu |
890ddd |
TFilePath ln(it->getLevelName());
|
|
Toshihiro Shimizu |
890ddd |
// cout << "try " << *it << " " << it->getLevelName() << endl;
|
|
Toshihiro Shimizu |
890ddd |
if (levelName == TFilePath(it->getLevelName())) {
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
level->setFrame(it->getFrame(), TImageP());
|
|
Toshihiro Shimizu |
890ddd |
data.push_back(*it);
|
|
Toshihiro Shimizu |
890ddd |
} catch (string msg) {
|
|
Toshihiro Shimizu |
890ddd |
throw msg;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (!data.empty()) {
|
|
Toshihiro Shimizu |
890ddd |
std::vector<tfilepath>::iterator it = std::min_element(data.begin(), data.end(), myLess);</tfilepath>
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fr = (*it).withoutParentDir().withName("").withType("");
|
|
Toshihiro Shimizu |
890ddd |
wstring ws = fr.getWideString();
|
|
Toshihiro Shimizu |
890ddd |
if (ws.length() == 5) {
|
|
Toshihiro Shimizu |
890ddd |
if (ws.rfind(L'_') == (int)wstring::npos)
|
|
Toshihiro Shimizu |
890ddd |
m_frameFormat = TFrameId::FOUR_ZEROS;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_frameFormat = TFrameId::UNDERSCORE_FOUR_ZEROS;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (ws.rfind(L'_') == (int)wstring::npos)
|
|
Toshihiro Shimizu |
890ddd |
m_frameFormat = TFrameId::NO_PAD;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_frameFormat = TFrameId::UNDERSCORE_NO_PAD;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
m_frameFormat = TFrameId::FOUR_ZEROS;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return level;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageReaderP TLevelReader::getFrameReader(TFrameId fid)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return TImageReaderP(m_path.withFrame(fid, m_frameFormat));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TLevelReader::getSupportedFormats(QStringList &names)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (std::map<levelreaderkey, *="" tlevelreadercreateproc="">::iterator it = LevelReaderTable.begin();</levelreaderkey,>
|
|
Toshihiro Shimizu |
890ddd |
it != LevelReaderTable.end();
|
|
Toshihiro Shimizu |
890ddd |
++it) {
|
|
Toshihiro Shimizu |
890ddd |
names.push_back(it->first.first);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TSoundTrack *TLevelReader::loadSoundTrack()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TLevelWriter::TLevelWriter(const TFilePath &path, TPropertyGroup *prop)
|
|
Toshihiro Shimizu |
890ddd |
: TSmartObject(m_classCode), m_path(path), m_properties(prop), m_contentHistory(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
string ext = path.getType();
|
|
Toshihiro Shimizu |
890ddd |
if (!prop)
|
|
Toshihiro Shimizu |
890ddd |
m_properties = Tiio::makeWriterProperties(ext);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TLevelWriter::~TLevelWriter()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_properties;
|
|
Toshihiro Shimizu |
890ddd |
delete m_contentHistory;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TLevelWriterP::TLevelWriterP(const TFilePath &path, TPropertyGroup *winfo)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString type = QString::fromStdString(toLower(path.getType()));
|
|
Toshihiro Shimizu |
890ddd |
std::map<qstring, *,="" bool="" std::pair<tlevelwritercreateproc="">>::iterator it;</qstring,>
|
|
Toshihiro Shimizu |
890ddd |
it = LevelWriterTable.find(type);
|
|
Toshihiro Shimizu |
890ddd |
if (it != LevelWriterTable.end())
|
|
Toshihiro Shimizu |
890ddd |
m_pointer = it->second.first(path, winfo ? winfo->clone() : Tiio::makeWriterProperties(path.getType()));
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
m_pointer = new TLevelWriter(path, winfo ? winfo->clone() : Tiio::makeWriterProperties(path.getType()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(m_pointer);
|
|
Toshihiro Shimizu |
890ddd |
m_pointer->addRef();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TLevelWriter::save(const TLevelP &level)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (TLevel::Iterator it = level->begin(); it != level->end(); it++) {
|
|
Toshihiro Shimizu |
890ddd |
if (it->second)
|
|
Toshihiro Shimizu |
890ddd |
getFrameWriter(it->first)->save(it->second);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TLevelWriter::saveSoundTrack(TSoundTrack *)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
throw TException("The level format doesn't support soundtracks");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TLevelWriter::setFrameRate(double fps)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_frameRate = fps;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TLevelWriter::getSupportedFormats(QStringList &names, bool onlyRenderFormats)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
for (std::map<qstring, *,="" bool="" std::pair<tlevelwritercreateproc="">>::iterator it = LevelWriterTable.begin();</qstring,>
|
|
Toshihiro Shimizu |
890ddd |
it != LevelWriterTable.end();
|
|
Toshihiro Shimizu |
890ddd |
++it) {
|
|
Toshihiro Shimizu |
890ddd |
if (!onlyRenderFormats || it->second.second)
|
|
Toshihiro Shimizu |
890ddd |
names.push_back(it->first);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TImageWriterP TLevelWriter::getFrameWriter(TFrameId fid)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TImageWriterP iw(m_path.withFrame(fid));
|
|
Toshihiro Shimizu |
890ddd |
iw->setProperties(m_properties);
|
|
Toshihiro Shimizu |
890ddd |
return iw;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TLevelWriter::setContentHistory(TContentHistory *contentHistory)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (contentHistory != m_contentHistory) {
|
|
Toshihiro Shimizu |
890ddd |
delete m_contentHistory;
|
|
Toshihiro Shimizu |
890ddd |
m_contentHistory = contentHistory;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TLevelWriter::renumberFids(const std::map<tframeid, tframeid=""> &table)</tframeid,>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
typedef std::map<tframeid, tframeid=""> Table;</tframeid,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
struct locals {
|
|
Toshihiro Shimizu |
890ddd |
static inline QString qstring(const TFilePath &fp)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return QString::fromStdWString(fp.getWideString());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
static inline QString temp(const QString &str)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return str + QString("_");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_path.getDots() == "..") {
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
// Extract all image file paths of the level
|
|
Toshihiro Shimizu |
890ddd |
QDir parentDir(QString::fromStdWString(m_path.getParentDir().getWideString()));
|
|
Toshihiro Shimizu |
890ddd |
parentDir.setFilter(QDir::Files);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QStringList nameFilters(
|
|
Toshihiro Shimizu |
890ddd |
QString::fromStdWString(m_path.getWideName()) +
|
|
Toshihiro Shimizu |
890ddd |
".*." +
|
|
Toshihiro Shimizu |
890ddd |
QString::fromStdString(m_path.getType()));
|
|
Toshihiro Shimizu |
890ddd |
parentDir.setNameFilters(nameFilters);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePathSet fpset;
|
|
Toshihiro Shimizu |
890ddd |
TSystem::readDirectory(fpset, parentDir, false); // Could throw
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Traverse each file, trying to match it with a table entry
|
|
Toshihiro Shimizu |
890ddd |
std::vector<qstring> storedDstPaths;</qstring>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePathSet::iterator st, sEnd(fpset.end());
|
|
Toshihiro Shimizu |
890ddd |
for (st = fpset.begin(); st != sEnd; ++st) {
|
|
Toshihiro Shimizu |
890ddd |
const QString &src = locals::qstring(*st);
|
|
Toshihiro Shimizu |
890ddd |
const TFrameId &fid = st->getFrame(); // Could throw ! (and I'm quite appalled of that o.o')
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Table::const_iterator dt(table.find(fid));
|
|
Toshihiro Shimizu |
890ddd |
if (dt == table.end()) {
|
|
Toshihiro Shimizu |
890ddd |
// The frame must be removed
|
|
Toshihiro Shimizu |
890ddd |
QFile::remove(src);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (fid == dt->second)
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// The frame must be renumbered
|
|
Toshihiro Shimizu |
890ddd |
const QString &dst = locals::qstring(st->withFrame(dt->second));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!QFile::rename(src, dst)) {
|
|
Toshihiro Shimizu |
890ddd |
// Use a temporary file rename to ensure that other frames to be renumbered
|
|
Toshihiro Shimizu |
890ddd |
// are not overwritten.
|
|
Toshihiro Shimizu |
890ddd |
if (QFile::rename(locals::qstring(*st), locals::temp(dst)))
|
|
Toshihiro Shimizu |
890ddd |
storedDstPaths.push_back(dst);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// If the second rename did not happen, the problem was not on dst, but on src.
|
|
Toshihiro Shimizu |
890ddd |
// Alas, it means that rename on source is not possible - skip.
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// At this point, temporaries should be restored to originals. In case the
|
|
Toshihiro Shimizu |
890ddd |
// rename of one of those files cannot be finalized, leave the temporary - as
|
|
Toshihiro Shimizu |
890ddd |
// it may be impossible to roll back (another frame could have been renumbered
|
|
Toshihiro Shimizu |
890ddd |
// to the would-roll-back frame) !
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::vector<qstring>::iterator dt, dEnd(storedDstPaths.end());</qstring>
|
|
Toshihiro Shimizu |
890ddd |
for (dt = storedDstPaths.begin(); dt != dEnd; ++dt)
|
|
Toshihiro Shimizu |
890ddd |
QFile::rename(locals::temp(*dt), *dt);
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
// Could not read the directory - skip silently
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//============================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TLevelReader::define(
|
|
Toshihiro Shimizu |
890ddd |
QString extension,
|
|
Toshihiro Shimizu |
890ddd |
int reader,
|
|
Toshihiro Shimizu |
890ddd |
TLevelReaderCreateProc *proc)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
LevelReaderKey key(extension, reader);
|
|
Toshihiro Shimizu |
890ddd |
LevelReaderTable[key] = proc;
|
|
Toshihiro Shimizu |
890ddd |
//cout << "LevelReader " << extension << " registred" << endl;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TLevelWriter::define(
|
|
Toshihiro Shimizu |
890ddd |
QString extension,
|
|
Toshihiro Shimizu |
890ddd |
TLevelWriterCreateProc *proc, bool isRenderFormat)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
LevelWriterTable[extension] = std::pair<tlevelwritercreateproc *,="" bool="">(proc, isRenderFormat);</tlevelwritercreateproc>
|
|
Toshihiro Shimizu |
890ddd |
//cout << "LevelWriter " << extension << " registred" << endl;
|
|
Toshihiro Shimizu |
890ddd |
}
|