Ejemplo n.º 1
0
void TSystem::renameFileOrLevel_throw(const TFilePath &dst,
                                      const TFilePath &src,
                                      bool renamePalette) {
  if (renamePalette && ((src.getType() == "tlv") || (src.getType() == "tzp") ||
                        (src.getType() == "tzu"))) {
    // Special case: since renames cannot be 'grouped' in the UI, palettes are
    // automatically
    // renamed here if required
    const char *type = (src.getType() == "tlv") ? "tpl" : "plt";

    TFilePath srcpltname(src.withNoFrame().withType(type));
    TFilePath dstpltname(dst.withNoFrame().withType(type));

    if (TSystem::doesExistFileOrLevel(src) &&
        TSystem::doesExistFileOrLevel(srcpltname))
      TSystem::renameFile(dstpltname, srcpltname, false);
  }

  if (src.isLevelName()) {
    TFilePathSet files;
    files = TSystem::readDirectory(src.getParentDir(), false);

    for (TFilePathSet::iterator it = files.begin(); it != files.end(); it++) {
      if (it->getLevelName() == src.getLevelName()) {
        TFilePath src1 = *it;
        TFilePath dst1 = dst.withFrame(it->getFrame());

        TSystem::renameFile(dst1, src1);
      }
    }
  } else
    TSystem::renameFile(dst, src);
}
Ejemplo n.º 2
0
void SceneLevel::save()
{
	TFilePath fp = m_oldPath;
	SceneResource::updatePath(fp);
	TFilePath actualFp = m_scene->decodeFilePath(fp);
	actualFp = restorePsdPath(actualFp);
	TFilePath oldActualPath = restorePsdPath(m_oldActualPath);
	assert(actualFp.getWideString() == L"" || actualFp.getWideString()[0] != L'+');
	if (actualFp != oldActualPath || !TSystem::doesExistFileOrLevel(oldActualPath) || m_sl->getProperties()->getDirtyFlag() || (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag())) {
		try {
			TSystem::touchParentDir(actualFp);
			if (actualFp != oldActualPath &&
				TSystem::doesExistFileOrLevel(oldActualPath) &&
				m_sl->getProperties()->getDirtyFlag() == false &&
				(!m_sl->getPalette() || (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag() == false))) {
				try {
					TXshSimpleLevel::copyFiles(actualFp, oldActualPath);
				} catch (...) {
				}
				//Must NOT KEEP FRAMES, it generate a level frames bind necessary to imageBuilder path refresh.
				m_sl->setPath(fp, false);
			} else {
				m_sl->save(actualFp, oldActualPath);

				if ((actualFp.getType() == "tlv" || actualFp.getType() == "pli") &&
					actualFp != oldActualPath &&
					m_oldRefImgPath != TFilePath()) {
					//Devo preoccuparmi dell'eventuale livello colormodel
					TFilePath actualRefImagPath = m_scene->decodeFilePath(m_oldRefImgPath);
					TFilePath actualRefImagPathTpl = actualRefImagPath.withType("tpl");
					TFilePath oldRefImagPathTpl = m_oldActualRefImgPath.withType("tpl");
					TSystem::copyFile(actualRefImagPath, m_oldActualRefImgPath);
					if (actualRefImagPath.getType() == "tlv")
						TSystem::copyFile(actualRefImagPathTpl, oldRefImagPathTpl);
				}

				if (actualFp.getType() == "tif" || actualFp.getType() == "tiff" || actualFp.getType() == "tga" || actualFp.getType() == "tzi") {
					TFilePath clnin = oldActualPath.withNoFrame().withType("cln");
					if (TSystem::doesExistFileOrLevel(clnin))
						TSystem::copyFile(actualFp.withNoFrame().withType("cln"), clnin);
				}
			}
			//Se il livello e' tlv verifico se esiste il corrispondente unpainted ed in caso affermativo lo copio.
			//Questo controllo viene fatto qui e non nella copia o nel salvataggio del livello perche' in generale
			//non si vuole che il livello unpainted venga copiato con il livello.
			if (actualFp.getType() == "tlv") {
				TFilePath oldUnpaintedLevelPath = oldActualPath.getParentDir() + TFilePath(oldActualPath.getName() + "-unpainted." + oldActualPath.getType());
				TFilePath unpaintedLevelPath = actualFp.getParentDir() + TFilePath(actualFp.getName() + "-unpainted." + actualFp.getType());
				if (TSystem::doesExistFileOrLevel(oldUnpaintedLevelPath) && !TSystem::doesExistFileOrLevel(unpaintedLevelPath))
					TSystem::copyFile(unpaintedLevelPath, oldUnpaintedLevelPath);
				TFilePath oldUnpaintedPalettePath = oldUnpaintedLevelPath.withType("tpl");
				TFilePath unpaintedPalettePath = unpaintedLevelPath.withType("tpl");
				if (TSystem::doesExistFileOrLevel(oldUnpaintedPalettePath) && !TSystem::doesExistFileOrLevel(unpaintedPalettePath))
					TSystem::copyFile(unpaintedPalettePath, oldUnpaintedPalettePath);
			}
		} catch (...) {
		}
	}
	fp = m_oldScannedPath;
	if (fp != TFilePath()) {
		SceneResource::updatePath(fp);
		actualFp = m_scene->decodeFilePath(fp);
		if (actualFp != m_oldActualScannedPath &&
			TSystem::doesExistFileOrLevel(m_oldActualScannedPath)) {
			try {
				TSystem::touchParentDir(actualFp);
				TSystem::copyFileOrLevel_throw(actualFp, m_oldActualScannedPath);
				m_sl->clearFrames();
				m_sl->load();
			} catch (...) {
			}
		}
	}
}