예제 #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);
}
예제 #2
0
TLevelP TLevelReader::loadInfo()
{
	TFilePath parentDir = m_path.getParentDir();
	TFilePath levelName(m_path.getLevelName());
	//  cout << "Parent dir = '" << parentDir << "'" << endl;
	//  cout << "Level name = '" << levelName << "'" << endl;
	TFilePathSet files;
	try {
		files = TSystem::readDirectory(parentDir, false, true, true);
	} catch (...) {
		throw TImageException(m_path, "unable to read directory content");
	}
	TLevelP level;
	vector<TFilePath> data;
	for (TFilePathSet::iterator it = files.begin(); it != files.end(); it++) {
		TFilePath ln(it->getLevelName());
		// cout << "try " << *it << "  " << it->getLevelName() <<  endl;
		if (levelName == TFilePath(it->getLevelName())) {
			try {
				level->setFrame(it->getFrame(), TImageP());
				data.push_back(*it);
			} catch (string msg) {
				throw msg;
			}
		}
	}
	if (!data.empty()) {
		std::vector<TFilePath>::iterator it = std::min_element(data.begin(), data.end(), myLess);
		TFilePath fr = (*it).withoutParentDir().withName("").withType("");
		wstring ws = fr.getWideString();
		if (ws.length() == 5) {
			if (ws.rfind(L'_') == (int)wstring::npos)
				m_frameFormat = TFrameId::FOUR_ZEROS;
			else
				m_frameFormat = TFrameId::UNDERSCORE_FOUR_ZEROS;
		} else {
			if (ws.rfind(L'_') == (int)wstring::npos)
				m_frameFormat = TFrameId::NO_PAD;
			else
				m_frameFormat = TFrameId::UNDERSCORE_NO_PAD;
		}

	} else
		m_frameFormat = TFrameId::FOUR_ZEROS;

	return level;
}