Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/sceneresources.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/tproject.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelset.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshpalettelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/levelproperties.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsoundlevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/namebuilder.h"
Toshihiro Shimizu 890ddd
#include "toonz/childstack.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "tlogger.h"
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// se path e' della forma +folder/<oldsavepath>/name.type</oldsavepath>
Toshihiro Shimizu 890ddd
// allora sostituisce oldSavePath con newSavePath e ritorna true
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool changeSavePath(TFilePath &path, TFilePath oldSavePath, TFilePath newSavePath)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (oldSavePath == newSavePath)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	TFilePath fp = path.getParentDir();
Shinya Kitaoka 3bfa54
	std::wstring head;
Toshihiro Shimizu 890ddd
	TFilePath tail;
Toshihiro Shimizu 890ddd
	fp.split(head, tail);
Toshihiro Shimizu 890ddd
	if (head != L"" && tail == oldSavePath) {
Toshihiro Shimizu 890ddd
		path = path.withParentDir(TFilePath(head) + newSavePath);
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	} else
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//From ../../../filename#type.psd to ../../../filename.psd
Toshihiro Shimizu 890ddd
TFilePath restorePsdPath(const TFilePath &fp)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString path = QString::fromStdWString(fp.getWideString());
Toshihiro Shimizu 890ddd
	if (fp.getType() != "psd" || !path.contains("#"))
Toshihiro Shimizu 890ddd
		return fp;
Toshihiro Shimizu 890ddd
	int from = path.indexOf("#");
Toshihiro Shimizu 890ddd
	int to = path.lastIndexOf(".");
Toshihiro Shimizu 890ddd
	path.remove(from, to - from);
Toshihiro Shimizu 890ddd
	return TFilePath(path.toStdWString());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool makePathUnique(ToonzScene *scene, TFilePath &path)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 3bfa54
	std::wstring name = path.getWideName();
Toshihiro Shimizu 890ddd
	int id = 2;
Toshihiro Shimizu 890ddd
	int i = name.length() - 1;
Toshihiro Shimizu 890ddd
	int num = 0, p = 1;
Toshihiro Shimizu 890ddd
	while (i >= 0 && L'0' <= name[i] && name[i] <= L'9') {
Toshihiro Shimizu 890ddd
		num += p * (name[i] - L'0');
Toshihiro Shimizu 890ddd
		p *= 10;
Toshihiro Shimizu 890ddd
		i--;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (i >= 0 && name[i] == L'_') {
Toshihiro Shimizu 890ddd
		id = num + 1;
Toshihiro Shimizu 890ddd
		name = name.substr(0, i);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool ret = false;
Toshihiro Shimizu 890ddd
	while (TSystem::doesExistFileOrLevel(scene->decodeFilePath(path))) {
Toshihiro Shimizu 890ddd
		ret = true;
Toshihiro Shimizu 890ddd
		path = path.withName(name + L"_" + toWideString(id));
Toshihiro Shimizu 890ddd
		id++;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool getCollectedPath(ToonzScene *scene, TFilePath &path)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!path.isAbsolute() || path.getWideString()[0] == L'+')
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath collectedPath = scene->getImportedLevelPath(path);
Toshihiro Shimizu 890ddd
	if (path == collectedPath)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath actualCollectedPath = scene->decodeFilePath(collectedPath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (makePathUnique(scene, actualCollectedPath))
Toshihiro Shimizu 890ddd
		collectedPath = collectedPath.withName(actualCollectedPath.getName());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	path = collectedPath;
Toshihiro Shimizu 890ddd
	return true;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// ResourceImportStrategy
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ResourceImportStrategy::ResourceImportStrategy(int strategy)
Toshihiro Shimizu 890ddd
	: m_childFolderEnabled(false), m_strategy(strategy)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setChildFolderEnabled(Preferences::instance()->isSubsceneFolderEnabled());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFilePath ResourceImportStrategy::process(ToonzScene *scene, ToonzScene *srcScene, TFilePath srcPath)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath srcActualPath = srcScene->decodeFilePath(srcPath);
Toshihiro Shimizu 890ddd
	if (!scene->isExternPath(srcActualPath) || m_strategy == DONT_IMPORT)
Toshihiro Shimizu 890ddd
		return srcPath;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath dstPath;
Toshihiro Shimizu 890ddd
	if (srcPath.getWideString().find(L'+') == 0)
Toshihiro Shimizu 890ddd
		dstPath = srcPath;
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		dstPath = scene->getImportedLevelPath(srcPath);
Toshihiro Shimizu 890ddd
	TFilePath actualDstPath = scene->decodeFilePath(dstPath);
Toshihiro Shimizu 890ddd
	assert(actualDstPath != TFilePath());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_strategy == IMPORT_AND_OVERWRITE) {
Toshihiro Shimizu 890ddd
		//bool overwritten = false;
Toshihiro Shimizu 890ddd
		if (TSystem::doesExistFileOrLevel(actualDstPath)) {
Toshihiro Shimizu 890ddd
			TSystem::removeFileOrLevel(actualDstPath);
Toshihiro Shimizu 890ddd
			//  overwritten = true;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		if (TSystem::doesExistFileOrLevel(srcPath))
Toshihiro Shimizu 890ddd
			TXshSimpleLevel::copyFiles(actualDstPath, srcPath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return dstPath;
Toshihiro Shimizu 890ddd
	} else if (m_strategy == IMPORT_AND_RENAME) {
Toshihiro Shimizu 890ddd
		std::wstring levelName = srcPath.getWideName();
Toshihiro Shimizu 890ddd
		TLevelSet *parentLevelSet = scene->getLevelSet();
Toshihiro Shimizu 890ddd
		NameModifier nm(levelName);
Shinya Kitaoka 3bfa54
		std::wstring newName;
Toshihiro Shimizu 890ddd
		for (;;) {
Toshihiro Shimizu 890ddd
			newName = nm.getNext();
Toshihiro Shimizu 890ddd
			if (!parentLevelSet->hasLevel(newName))
Toshihiro Shimizu 890ddd
				break;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		dstPath = dstPath.withName(newName);
Toshihiro Shimizu 890ddd
		actualDstPath = scene->decodeFilePath(dstPath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (TSystem::doesExistFileOrLevel(actualDstPath))
Toshihiro Shimizu 890ddd
			TSystem::removeFileOrLevel(actualDstPath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (TSystem::doesExistFileOrLevel(srcActualPath)) {
Toshihiro Shimizu 890ddd
			TXshSimpleLevel::copyFiles(actualDstPath, srcActualPath);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		return dstPath;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return srcPath;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// SceneResource
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SceneResource::SceneResource(ToonzScene *scene)
Toshihiro Shimizu 890ddd
	: m_scene(scene), m_untitledScene(scene->isUntitled()), m_oldSavePath(scene->getSavePath())
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SceneResource::~SceneResource()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneResource::updatePath(TFilePath &fp)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_untitledScene)
Toshihiro Shimizu 890ddd
		changeSavePath(fp, m_oldSavePath, m_scene->getSavePath());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// SceneLevel
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SceneLevel::SceneLevel(ToonzScene *scene, TXshSimpleLevel *sl)
Toshihiro Shimizu 890ddd
	: SceneResource(scene), m_sl(sl), m_oldPath(sl->getPath()), m_oldActualPath(scene->decodeFilePath(sl->getPath())), m_oldScannedPath(sl->getScannedPath()), m_oldRefImgPath(), m_oldActualRefImgPath()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_oldScannedPath != TFilePath())
Toshihiro Shimizu 890ddd
		m_oldActualScannedPath = m_scene->decodeFilePath(m_oldScannedPath);
Toshihiro Shimizu 890ddd
	if ((sl->getPath().getType() == "tlv" || sl->getPath().getType() == "pli") && sl->getPalette()) {
Toshihiro Shimizu 890ddd
		m_oldRefImgPath = sl->getPalette()->getRefImgPath();
Toshihiro Shimizu 890ddd
		m_oldActualRefImgPath = m_scene->decodeFilePath(m_oldRefImgPath);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneLevel::save()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath fp = m_oldPath;
Toshihiro Shimizu 890ddd
	SceneResource::updatePath(fp);
Toshihiro Shimizu 890ddd
	TFilePath actualFp = m_scene->decodeFilePath(fp);
Toshihiro Shimizu 890ddd
	actualFp = restorePsdPath(actualFp);
Toshihiro Shimizu 890ddd
	TFilePath oldActualPath = restorePsdPath(m_oldActualPath);
Toshihiro Shimizu 890ddd
	assert(actualFp.getWideString() == L"" || actualFp.getWideString()[0] != L'+');
Toshihiro Shimizu 890ddd
	if (actualFp != oldActualPath || !TSystem::doesExistFileOrLevel(oldActualPath) || m_sl->getProperties()->getDirtyFlag() || (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag())) {
Toshihiro Shimizu 890ddd
		try {
Toshihiro Shimizu 890ddd
			TSystem::touchParentDir(actualFp);
Toshihiro Shimizu 890ddd
			if (actualFp != oldActualPath &&
Toshihiro Shimizu 890ddd
				TSystem::doesExistFileOrLevel(oldActualPath) &&
Toshihiro Shimizu 890ddd
				m_sl->getProperties()->getDirtyFlag() == false &&
Toshihiro Shimizu 890ddd
				(!m_sl->getPalette() || (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag() == false))) {
Toshihiro Shimizu 890ddd
				try {
Toshihiro Shimizu 890ddd
					TXshSimpleLevel::copyFiles(actualFp, oldActualPath);
Toshihiro Shimizu 890ddd
				} catch (...) {
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
				//Must NOT KEEP FRAMES, it generate a level frames bind necessary to imageBuilder path refresh.
Toshihiro Shimizu 890ddd
				m_sl->setPath(fp, false);
Toshihiro Shimizu 890ddd
			} else {
Toshihiro Shimizu 890ddd
				m_sl->save(actualFp, oldActualPath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				if ((actualFp.getType() == "tlv" || actualFp.getType() == "pli") &&
Toshihiro Shimizu 890ddd
					actualFp != oldActualPath &&
Toshihiro Shimizu 890ddd
					m_oldRefImgPath != TFilePath()) {
Toshihiro Shimizu 890ddd
					//Devo preoccuparmi dell'eventuale livello colormodel
Toshihiro Shimizu 890ddd
					TFilePath actualRefImagPath = m_scene->decodeFilePath(m_oldRefImgPath);
Toshihiro Shimizu 890ddd
					TFilePath actualRefImagPathTpl = actualRefImagPath.withType("tpl");
Toshihiro Shimizu 890ddd
					TFilePath oldRefImagPathTpl = m_oldActualRefImgPath.withType("tpl");
Toshihiro Shimizu 890ddd
					TSystem::copyFile(actualRefImagPath, m_oldActualRefImgPath);
Toshihiro Shimizu 890ddd
					if (actualRefImagPath.getType() == "tlv")
Toshihiro Shimizu 890ddd
						TSystem::copyFile(actualRefImagPathTpl, oldRefImagPathTpl);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
				if (actualFp.getType() == "tif" || actualFp.getType() == "tiff" || actualFp.getType() == "tga" || actualFp.getType() == "tzi") {
Toshihiro Shimizu 890ddd
					TFilePath clnin = oldActualPath.withNoFrame().withType("cln");
Toshihiro Shimizu 890ddd
					if (TSystem::doesExistFileOrLevel(clnin))
Toshihiro Shimizu 890ddd
						TSystem::copyFile(actualFp.withNoFrame().withType("cln"), clnin);
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			//Se il livello e' tlv verifico se esiste il corrispondente unpainted ed in caso affermativo lo copio.
Toshihiro Shimizu 890ddd
			//Questo controllo viene fatto qui e non nella copia o nel salvataggio del livello perche' in generale
Toshihiro Shimizu 890ddd
			//non si vuole che il livello unpainted venga copiato con il livello.
Toshihiro Shimizu 890ddd
			if (actualFp.getType() == "tlv") {
Toshihiro Shimizu 890ddd
				TFilePath oldUnpaintedLevelPath = oldActualPath.getParentDir() + TFilePath(oldActualPath.getName() + "-unpainted." + oldActualPath.getType());
Toshihiro Shimizu 890ddd
				TFilePath unpaintedLevelPath = actualFp.getParentDir() + TFilePath(actualFp.getName() + "-unpainted." + actualFp.getType());
Toshihiro Shimizu 890ddd
				if (TSystem::doesExistFileOrLevel(oldUnpaintedLevelPath) && !TSystem::doesExistFileOrLevel(unpaintedLevelPath))
Toshihiro Shimizu 890ddd
					TSystem::copyFile(unpaintedLevelPath, oldUnpaintedLevelPath);
Toshihiro Shimizu 890ddd
				TFilePath oldUnpaintedPalettePath = oldUnpaintedLevelPath.withType("tpl");
Toshihiro Shimizu 890ddd
				TFilePath unpaintedPalettePath = unpaintedLevelPath.withType("tpl");
Toshihiro Shimizu 890ddd
				if (TSystem::doesExistFileOrLevel(oldUnpaintedPalettePath) && !TSystem::doesExistFileOrLevel(unpaintedPalettePath))
Toshihiro Shimizu 890ddd
					TSystem::copyFile(unpaintedPalettePath, oldUnpaintedPalettePath);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} catch (...) {
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	fp = m_oldScannedPath;
Toshihiro Shimizu 890ddd
	if (fp != TFilePath()) {
Toshihiro Shimizu 890ddd
		SceneResource::updatePath(fp);
Toshihiro Shimizu 890ddd
		actualFp = m_scene->decodeFilePath(fp);
Toshihiro Shimizu 890ddd
		if (actualFp != m_oldActualScannedPath &&
Toshihiro Shimizu 890ddd
			TSystem::doesExistFileOrLevel(m_oldActualScannedPath)) {
Toshihiro Shimizu 890ddd
			try {
Toshihiro Shimizu 890ddd
				TSystem::touchParentDir(actualFp);
Toshihiro Shimizu 890ddd
				TSystem::copyFileOrLevel_throw(actualFp, m_oldActualScannedPath);
Toshihiro Shimizu 890ddd
				m_sl->clearFrames();
Toshihiro Shimizu 890ddd
				m_sl->load();
Toshihiro Shimizu 890ddd
			} catch (...) {
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneLevel::updatePath()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_untitledScene)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TFilePath fp = m_oldPath;
Toshihiro Shimizu 890ddd
	SceneResource::updatePath(fp);
Toshihiro Shimizu 890ddd
	m_sl->setPath(fp, true);
Toshihiro Shimizu 890ddd
	fp = m_oldScannedPath;
Toshihiro Shimizu 890ddd
	SceneResource::updatePath(fp);
Toshihiro Shimizu 890ddd
	m_sl->setScannedPath(fp);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneLevel::rollbackPath()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_untitledScene)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_sl->setPath(m_oldPath, true);
Toshihiro Shimizu 890ddd
	m_sl->setScannedPath(m_oldScannedPath);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool SceneLevel::isDirty()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_sl->getProperties()->getDirtyFlag() ||
Toshihiro Shimizu 890ddd
		(m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag()))
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QString SceneLevel::getResourceName()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString string;
Toshihiro Shimizu 890ddd
	bool levelIsDirty = false;
Toshihiro Shimizu 890ddd
	if (m_sl->getProperties()->getDirtyFlag()) {
Toshihiro Shimizu 890ddd
		string += QString::fromStdString(m_sl->getPath().getLevelName());
Toshihiro Shimizu 890ddd
		levelIsDirty = true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	if (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag()) {
Toshihiro Shimizu 890ddd
		if (levelIsDirty)
Toshihiro Shimizu 890ddd
			string += " and ";
Toshihiro Shimizu 890ddd
		if (m_sl->getPath().getType() == "pli")
Toshihiro Shimizu 890ddd
			string += QString::fromStdWString(m_sl->getPalette()->getPaletteName()) + ".pli (palette)";
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			string += QString::fromStdWString(m_sl->getPalette()->getPaletteName()) + ".tpl";
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return string;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// ScenePalette
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ScenePalette::ScenePalette(ToonzScene *scene, TXshPaletteLevel *pl)
Toshihiro Shimizu 890ddd
	: SceneResource(scene), m_pl(pl), m_oldPath(pl->getPath()), m_oldActualPath(scene->decodeFilePath(pl->getPath()))
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ScenePalette::save()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_oldPath != TFilePath());
Toshihiro Shimizu 890ddd
	TFilePath fp = m_oldPath;
Toshihiro Shimizu 890ddd
	SceneResource::updatePath(fp);
Toshihiro Shimizu 890ddd
	TFilePath actualFp = m_scene->decodeFilePath(fp);
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		TSystem::touchParentDir(actualFp);
Toshihiro Shimizu 890ddd
		if (actualFp != m_oldActualPath && TSystem::doesExistFileOrLevel(m_oldActualPath)) {
Toshihiro Shimizu 890ddd
			TSystem::copyFile(actualFp, m_oldActualPath);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		m_pl->save(); // actualFp non so perche' era cosi'
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
		TLogger::error() << "Can't save " << actualFp;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ScenePalette::updatePath()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath fp = m_oldPath;
Toshihiro Shimizu 890ddd
	SceneResource::updatePath(fp);
Toshihiro Shimizu 890ddd
	if (fp != m_oldPath)
Toshihiro Shimizu 890ddd
		m_pl->setPath(fp);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ScenePalette::rollbackPath()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_pl->setPath(m_oldPath);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool ScenePalette::isDirty()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_pl->getPalette()->getDirtyFlag();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QString ScenePalette::getResourceName()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return QString::fromStdString(m_pl->getPath().getLevelName());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// SceneSound
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SceneSound::SceneSound(ToonzScene *scene, TXshSoundLevel *sl)
Toshihiro Shimizu 890ddd
	: SceneResource(scene), m_sl(sl), m_oldPath(sl->getPath()), m_oldActualPath(scene->decodeFilePath(sl->getPath()))
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneSound::save()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	assert(m_oldPath != TFilePath());
Toshihiro Shimizu 890ddd
	TFilePath fp = m_oldPath;
Toshihiro Shimizu 890ddd
	SceneResource::updatePath(fp);
Toshihiro Shimizu 890ddd
	TFilePath actualFp = m_scene->decodeFilePath(fp);
Toshihiro Shimizu 890ddd
	try {
Toshihiro Shimizu 890ddd
		TSystem::touchParentDir(actualFp);
Toshihiro Shimizu 890ddd
		if (!TSystem::doesExistFileOrLevel(m_oldActualPath)) {
Toshihiro Shimizu 890ddd
			m_sl->save(actualFp);
Toshihiro Shimizu 890ddd
		} else if (actualFp != m_oldActualPath) {
Toshihiro Shimizu 890ddd
			TSystem::copyFile(actualFp, m_oldActualPath);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	} catch (...) {
Toshihiro Shimizu 890ddd
		TLogger::error() << "Can't save " << actualFp;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneSound::updatePath()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath fp = m_oldPath;
Toshihiro Shimizu 890ddd
	SceneResource::updatePath(fp);
Toshihiro Shimizu 890ddd
	if (fp != m_oldPath)
Toshihiro Shimizu 890ddd
		m_sl->setPath(fp);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneSound::rollbackPath()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_sl->setPath(m_oldPath);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// SceneResources
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SceneResources::SceneResources(ToonzScene *scene, TXsheet *subXsheet)
Toshihiro Shimizu 890ddd
	: m_scene(scene), m_commitDone(false), m_wasUntitled(scene->isUntitled()), m_subXsheet(subXsheet)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	getResources();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SceneResources::~SceneResources()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_commitDone)
Toshihiro Shimizu 890ddd
		rollbackPaths();
Toshihiro Shimizu 890ddd
	clearPointerContainer(m_resources);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneResources::getResources()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ToonzScene *scene = m_scene;
Toshihiro Shimizu 890ddd
	std::vector<txshlevel *=""> levels;</txshlevel>
Toshihiro Shimizu 890ddd
	scene->getLevelSet()->listLevels(levels);
Toshihiro Shimizu 890ddd
	std::vector<txshlevel *="">::iterator it;</txshlevel>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	for (it = levels.begin(); it != levels.end(); ++it) {
Toshihiro Shimizu 890ddd
		TXshSimpleLevel *sl = (*it)->getSimpleLevel();
Toshihiro Shimizu 890ddd
		if (sl)
Toshihiro Shimizu 890ddd
			m_resources.push_back(new SceneLevel(scene, sl));
Toshihiro Shimizu 890ddd
		TXshPaletteLevel *pl = (*it)->getPaletteLevel();
Toshihiro Shimizu 890ddd
		if (pl)
Toshihiro Shimizu 890ddd
			m_resources.push_back(new ScenePalette(scene, pl));
Toshihiro Shimizu 890ddd
		TXshSoundLevel *sdl = (*it)->getSoundLevel();
Toshihiro Shimizu 890ddd
		if (sdl)
Toshihiro Shimizu 890ddd
			m_resources.push_back(new SceneSound(scene, sdl));
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneResources::save(const TFilePath newScenePath)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath oldScenePath = m_scene->getScenePath();
Toshihiro Shimizu 890ddd
	m_scene->setScenePath(newScenePath);
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)m_resources.size(); i++)
Toshihiro Shimizu 890ddd
		m_resources[i]->save();
Toshihiro Shimizu 890ddd
	m_scene->setScenePath(oldScenePath);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneResources::updatePaths()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)m_resources.size(); i++)
Toshihiro Shimizu 890ddd
		m_resources[i]->updatePath();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneResources::rollbackPaths()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)m_resources.size(); i++)
Toshihiro Shimizu 890ddd
		m_resources[i]->rollbackPath();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void SceneResources::accept(ResourceProcessor *processor, bool autoCommit)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)m_resources.size() && !processor->aborted(); i++)
Toshihiro Shimizu 890ddd
		m_resources[i]->accept(processor);
Toshihiro Shimizu 890ddd
	if (autoCommit)
Toshihiro Shimizu 890ddd
		commit();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
//return the name list of dirty resources
Toshihiro Shimizu 890ddd
void SceneResources::getDirtyResources(std::vector<qstring> &dirtyResources)</qstring>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)m_resources.size(); i++)
Toshihiro Shimizu 890ddd
		if (m_resources[i]->isDirty()) {
Toshihiro Shimizu 890ddd
			dirtyResources.push_back(m_resources[i]->getResourceName());
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// ResourceImporter
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ResourceImporter::ResourceImporter(
Toshihiro Shimizu 890ddd
	ToonzScene *scene,
Toshihiro Shimizu 890ddd
	TProject *dstProject,
Toshihiro Shimizu 890ddd
	ResourceImportStrategy &importStrategy)
Toshihiro Shimizu 890ddd
	: m_scene(scene), m_dstProject(dstProject), m_dstScene(new ToonzScene()), m_importStrategy(importStrategy)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_dstScene->setProject(dstProject);
Toshihiro Shimizu 890ddd
	TFilePath newFp =
Toshihiro Shimizu 890ddd
		dstProject->getScenesPath() + (scene->getScenePath() - scene->getProject()->getScenesPath());
Toshihiro Shimizu 890ddd
	makeUnique(newFp);
Toshihiro Shimizu 890ddd
	m_dstScene->setScenePath(newFp);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ResourceImporter::~ResourceImporter()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	delete m_dstScene;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool ResourceImporter::makeUnique(TFilePath &path)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return makePathUnique(m_dstScene, path);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFilePath ResourceImporter::getImportedScenePath() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_dstScene->getScenePath();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFilePath ResourceImporter::codePath(const TFilePath &oldPath, const TFilePath &newActualPath)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return oldPath.withName(newActualPath.getName());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
std::string ResourceImporter::extractPsdSuffix(TFilePath &path)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (path.getType() != "psd")
Toshihiro Shimizu 890ddd
		return "";
Shinya Kitaoka 3bfa54
	std::string name = path.getName();
Toshihiro Shimizu 890ddd
	int i = name.find("#");
Shinya Kitaoka 3bfa54
	if (i == std::string::npos)
Toshihiro Shimizu 890ddd
		return "";
Shinya Kitaoka 3bfa54
	std::string suffix = name.substr(i);
Toshihiro Shimizu 890ddd
	path = path.withName(name.substr(0, i));
Toshihiro Shimizu 890ddd
	return suffix;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 3bfa54
TFilePath ResourceImporter::buildPsd(const TFilePath &basePath, const std::string &suffix)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return basePath.withName(basePath.getName() + suffix);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ResourceImporter::process(TXshSimpleLevel *sl)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (sl->getPath().isAbsolute())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TFilePath newPath;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath slPath = sl->getPath();
Shinya Kitaoka 3bfa54
	std::string suffix = extractPsdSuffix(slPath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath imgRefPath;
Toshihiro Shimizu 890ddd
	if (sl->getPalette())
Toshihiro Shimizu 890ddd
		imgRefPath = sl->getPalette()->getRefImgPath();
Toshihiro Shimizu 890ddd
	newPath = m_importStrategy.process(m_dstScene, m_scene, slPath);
Toshihiro Shimizu 890ddd
	if (imgRefPath != TFilePath() && !m_dstScene->isExternPath(m_dstScene->decodeFilePath(imgRefPath)))
Toshihiro Shimizu 890ddd
		m_importStrategy.process(m_dstScene, m_scene, imgRefPath);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (suffix != "")
Toshihiro Shimizu 890ddd
		newPath = buildPsd(newPath, suffix);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	sl->setPath(newPath);
Toshihiro Shimizu 890ddd
	if (sl->getScannedPath() != TFilePath()) {
Toshihiro Shimizu 890ddd
		newPath = m_importStrategy.process(m_dstScene, m_scene, sl->getScannedPath());
Toshihiro Shimizu 890ddd
		sl->setScannedPath(newPath);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	sl->setDirtyFlag(false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ResourceImporter::process(TXshPaletteLevel *pl)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (pl->getPath().isAbsolute())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TFilePath newPath;
Toshihiro Shimizu 890ddd
	newPath = m_importStrategy.process(m_dstScene, m_scene, pl->getPath());
Toshihiro Shimizu 890ddd
	pl->setPath(newPath);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ResourceImporter::process(TXshSoundLevel *sl)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (sl->getPath().isAbsolute())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TFilePath newPath;
Toshihiro Shimizu 890ddd
	newPath = m_importStrategy.process(m_dstScene, m_scene, sl->getPath());
Toshihiro Shimizu 890ddd
	sl->setPath(newPath);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// ResourceCollector
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ResourceCollector::ResourceCollector(ToonzScene *scene)
Toshihiro Shimizu 890ddd
	: m_scene(scene), m_count(0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ResourceCollector::~ResourceCollector()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool ResourceCollector::makeUnique(TFilePath &path)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return makePathUnique(m_scene, path);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ResourceCollector::process(TXshSimpleLevel *sl)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath path = sl->getPath();
Toshihiro Shimizu 890ddd
	std::string suffix = ResourceImporter::extractPsdSuffix(path);
Toshihiro Shimizu 890ddd
	std::map<tfilepath, tfilepath="">::iterator it = m_collectedFiles.find(path);</tfilepath,>
Toshihiro Shimizu 890ddd
	if (it != m_collectedFiles.end()) {
Toshihiro Shimizu 890ddd
		TFilePath destPath = it->second;
Toshihiro Shimizu 890ddd
		if (suffix != "")
Toshihiro Shimizu 890ddd
			destPath = ResourceImporter::buildPsd(destPath, suffix);
Toshihiro Shimizu 890ddd
		sl->setPath(destPath);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		TFilePath collectedPath = path;
Toshihiro Shimizu 890ddd
		if (getCollectedPath(m_scene, collectedPath)) {
Toshihiro Shimizu 890ddd
			TFilePath actualCollectedPath = m_scene->decodeFilePath(collectedPath);
Toshihiro Shimizu 890ddd
			if (actualCollectedPath != path && TSystem::doesExistFileOrLevel(path) &&
Toshihiro Shimizu 890ddd
				!TSystem::doesExistFileOrLevel(actualCollectedPath)) {
Toshihiro Shimizu 890ddd
				try {
Toshihiro Shimizu 890ddd
					TSystem::touchParentDir(actualCollectedPath);
Toshihiro Shimizu 890ddd
					TXshSimpleLevel::copyFiles(actualCollectedPath, path);
Toshihiro Shimizu 890ddd
				} catch (...) {
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			++m_count;
Toshihiro Shimizu 890ddd
			TFilePath destPath = collectedPath;
Toshihiro Shimizu 890ddd
			if (suffix != "")
Toshihiro Shimizu 890ddd
				destPath = ResourceImporter::buildPsd(destPath, suffix);
Toshihiro Shimizu 890ddd
			sl->setPath(destPath);
Toshihiro Shimizu 890ddd
			m_collectedFiles[path] = collectedPath;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (sl->getScannedPath() != TFilePath()) {
Toshihiro Shimizu 890ddd
		path = sl->getScannedPath();
Toshihiro Shimizu 890ddd
		TFilePath collectedPath = path;
Toshihiro Shimizu 890ddd
		if (getCollectedPath(m_scene, collectedPath)) {
Toshihiro Shimizu 890ddd
			TFilePath actualCollectedPath = m_scene->decodeFilePath(collectedPath);
Toshihiro Shimizu 890ddd
			if (actualCollectedPath != path && TSystem::doesExistFileOrLevel(path)) {
Toshihiro Shimizu 890ddd
				try {
Toshihiro Shimizu 890ddd
					TSystem::touchParentDir(actualCollectedPath);
Toshihiro Shimizu 890ddd
					TXshSimpleLevel::copyFiles(actualCollectedPath, path);
Toshihiro Shimizu 890ddd
				} catch (...) {
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			sl->setScannedPath(collectedPath);
Toshihiro Shimizu 890ddd
			m_count++;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	sl->setDirtyFlag(false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ResourceCollector::process(TXshSoundLevel *sl)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath path = sl->getPath();
Toshihiro Shimizu 890ddd
	TFilePath collectedPath = path;
Toshihiro Shimizu 890ddd
	if (!getCollectedPath(m_scene, collectedPath))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath actualCollectedPath = m_scene->decodeFilePath(collectedPath);
Toshihiro Shimizu 890ddd
	if (actualCollectedPath != path && TSystem::doesExistFileOrLevel(path)) {
Toshihiro Shimizu 890ddd
		try {
Toshihiro Shimizu 890ddd
			TSystem::touchParentDir(actualCollectedPath);
Toshihiro Shimizu 890ddd
			TXshSimpleLevel::copyFiles(actualCollectedPath, path);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		} catch (...) {
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	sl->setPath(collectedPath);
Toshihiro Shimizu 890ddd
	m_count++;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ResourceCollector::process(TXshPaletteLevel *pl)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TFilePath path = pl->getPath();
Toshihiro Shimizu 890ddd
	TFilePath collectedPath = path;
Toshihiro Shimizu 890ddd
	if (!getCollectedPath(m_scene, collectedPath))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TFilePath actualCollectedPath = m_scene->decodeFilePath(collectedPath);
Toshihiro Shimizu 890ddd
	if (actualCollectedPath != path && TSystem::doesExistFileOrLevel(path)) {
Toshihiro Shimizu 890ddd
		try {
Toshihiro Shimizu 890ddd
			TSystem::touchParentDir(actualCollectedPath);
Toshihiro Shimizu 890ddd
			TXshSimpleLevel::copyFiles(actualCollectedPath, path);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		} catch (...) {
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	pl->setPath(collectedPath);
Toshihiro Shimizu 890ddd
	m_count++;
Toshihiro Shimizu 890ddd
}