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); }
bool TSystem::doesExistFileOrLevel(const TFilePath &fp) { if (TFileStatus(fp).doesExist()) return true; if (fp.isLevelName()) { const TFilePath &parentDir = fp.getParentDir(); if (!TFileStatus(parentDir).doesExist()) return false; TFilePathSet files; try { files = TSystem::readDirectory(parentDir, false, true, true); } catch (...) { } TFilePathSet::iterator it, end = files.end(); for (it = files.begin(); it != end; ++it) { if (it->getLevelNameW() == fp.getLevelNameW()) return true; } } else if (fp.getType() == "psd") { QString name(QString::fromStdWString(fp.getWideName())); name.append(QString::fromStdString(fp.getDottedType())); int sepPos = name.indexOf("#"); int dotPos = name.indexOf(".", sepPos); int removeChars = dotPos - sepPos; int doubleUnderscorePos = name.indexOf("__", sepPos); if (doubleUnderscorePos > 0) removeChars = doubleUnderscorePos - sepPos; name.remove(sepPos, removeChars); TFilePath psdpath(fp.getParentDir() + TFilePath(name.toStdWString())); if (TFileStatus(psdpath).doesExist()) return true; } return false; }
void TSystem::hideFileOrLevel_throw(const TFilePath &fp) { if (fp.isLevelName()) { TFilePathSet files; files = TSystem::readDirectory(fp.getParentDir(), false); TFilePathSet::iterator it, end = files.end(); for (it = files.begin(); it != end; ++it) { if (it->getLevelNameW() == fp.getLevelNameW()) TSystem::hideFile(*it); } } else TSystem::hideFile(fp); }
void TSystem::copyFileOrLevel_throw(const TFilePath &dst, const TFilePath &src) { if (src.isLevelName()) { TFilePathSet files; files = TSystem::readDirectory(src.getParentDir(), false); TFilePathSet::iterator it, end = files.end(); for (it = files.begin(); it != end; ++it) { if (it->getLevelNameW() == src.getLevelNameW()) { TFilePath src1 = *it; TFilePath dst1 = dst.withFrame(it->getFrame()); TSystem::copyFile(dst1, src1); } } } else TSystem::copyFile(dst, src); }