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