diff --git a/client/CMT.cpp b/client/CMT.cpp index 26459e815..00cb02622 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -638,7 +638,7 @@ void processCommand(const std::string &message) std::cout << "Command accepted.\t"; const bfs::path outPath = - VCMIDirs::get().userCachePath() / "extracted"; + VCMIDirs::get().userExtractedPath(); bfs::create_directories(outPath); @@ -671,7 +671,7 @@ void processCommand(const std::string &message) std::cout << "Command accepted.\t"; const bfs::path outPath = - VCMIDirs::get().userCachePath() / "extracted" / "configuration"; + VCMIDirs::get().userExtractedPath() / "configuration"; bfs::create_directories(outPath); @@ -712,7 +712,7 @@ void processCommand(const std::string &message) std::cout << "Command accepted.\t"; const bfs::path outPath = - VCMIDirs::get().userCachePath() / "extracted" / "scripts"; + VCMIDirs::get().userExtractedPath() / "scripts"; bfs::create_directories(outPath); @@ -735,7 +735,7 @@ void processCommand(const std::string &message) std::cout << "Command accepted.\t"; const bfs::path outPath = - VCMIDirs::get().userCachePath() / "extracted"; + VCMIDirs::get().userExtractedPath(); auto list = CResourceHandler::get()->getFilteredFiles([](const ResourceID & ident) { @@ -851,7 +851,7 @@ void processCommand(const std::string &message) readed >> URI; std::unique_ptr anim = make_unique(URI); anim->preload(); - anim->exportBitmaps(VCMIDirs::get().userCachePath() / "extracted"); + anim->exportBitmaps(VCMIDirs::get().userExtractedPath()); } else if(cn == "extract") { @@ -860,7 +860,7 @@ void processCommand(const std::string &message) if (CResourceHandler::get()->existsResource(ResourceID(URI))) { - const bfs::path outPath = VCMIDirs::get().userCachePath() / "extracted" / URI; + const bfs::path outPath = VCMIDirs::get().userExtractedPath() / URI; auto data = CResourceHandler::get()->load(ResourceID(URI))->readAll(); diff --git a/lib/VCMIDirs.cpp b/lib/VCMIDirs.cpp index b9c99507b..f56a6549b 100644 --- a/lib/VCMIDirs.cpp +++ b/lib/VCMIDirs.cpp @@ -23,6 +23,8 @@ bfs::path IVCMIDirs::userLogsPath() const { return userCachePath(); } bfs::path IVCMIDirs::userSavePath() const { return userDataPath() / "Saves"; } +bfs::path IVCMIDirs::userExtractedPath() const { return userCachePath() / "extracted"; } + bfs::path IVCMIDirs::fullLibraryPath(const std::string &desiredFolder, const std::string &baseLibName) const { return libraryPath() / desiredFolder / libraryName(baseLibName); @@ -36,15 +38,16 @@ std::string IVCMIDirs::genHelpString() const const auto gdStringA = boost::algorithm::join(tempVec, ":"); return - " game data: " + gdStringA + "\n" - " libraries: " + libraryPath().string() + "\n" - " server: " + serverPath().string() + "\n" + " game data: " + gdStringA + "\n" + " libraries: " + libraryPath().string() + "\n" + " server: " + serverPath().string() + "\n" "\n" - " user data: " + userDataPath().string() + "\n" - " user cache: " + userCachePath().string() + "\n" - " user config: " + userConfigPath().string() + "\n" - " user logs: " + userLogsPath().string() + "\n" - " user saves: " + userSavePath().string() + "\n"; // Should end without new-line? + " user data: " + userDataPath().string() + "\n" + " user cache: " + userCachePath().string() + "\n" + " user config: " + userConfigPath().string() + "\n" + " user logs: " + userLogsPath().string() + "\n" + " user saves: " + userSavePath().string() + "\n"; + " user extracted: " + userExtractedPath().string() + "\n"; // Should end without new-line? } void IVCMIDirs::init() @@ -148,24 +151,24 @@ bool StartBatchCopyDataProgram( class VCMIDirsWIN32 final : public IVCMIDirs { public: - boost::filesystem::path userDataPath() const override; - boost::filesystem::path userCachePath() const override; - boost::filesystem::path userConfigPath() const override; + bfs::path userDataPath() const override; + bfs::path userCachePath() const override; + bfs::path userConfigPath() const override; - std::vector dataPaths() const override; + std::vector dataPaths() const override; - boost::filesystem::path clientPath() const override; - boost::filesystem::path serverPath() const override; + bfs::path clientPath() const override; + bfs::path serverPath() const override; - boost::filesystem::path libraryPath() const override; - boost::filesystem::path binaryPath() const override; + bfs::path libraryPath() const override; + bfs::path binaryPath() const override; std::string libraryName(const std::string& basename) const override; void init() override; protected: - boost::filesystem::path oldUserDataPath() const; - boost::filesystem::path oldUserSavePath() const; + bfs::path oldUserDataPath() const; + bfs::path oldUserSavePath() const; }; void VCMIDirsWIN32::init() @@ -355,8 +358,8 @@ std::string VCMIDirsWIN32::libraryName(const std::string& basename) const { retu class IVCMIDirsUNIX : public IVCMIDirs { public: - boost::filesystem::path clientPath() const override; - boost::filesystem::path serverPath() const override; + bfs::path clientPath() const override; + bfs::path serverPath() const override; virtual bool developmentMode() const; }; @@ -427,14 +430,14 @@ bfs::path VCMIDirsIOS::binaryPath() const { return {iOS_utils::bundlePath()}; } class VCMIDirsOSX final : public VCMIDirsApple { public: - boost::filesystem::path userDataPath() const override; - boost::filesystem::path userCachePath() const override; - boost::filesystem::path userLogsPath() const override; + bfs::path userDataPath() const override; + bfs::path userCachePath() const override; + bfs::path userLogsPath() const override; - std::vector dataPaths() const override; + std::vector dataPaths() const override; - boost::filesystem::path libraryPath() const override; - boost::filesystem::path binaryPath() const override; + bfs::path libraryPath() const override; + bfs::path binaryPath() const override; void init() override; }; @@ -464,12 +467,12 @@ void VCMIDirsOSX::init() for (bfs::directory_iterator file(from); file != bfs::directory_iterator(); ++file) { - const boost::filesystem::path& srcFilePath = file->path(); - const boost::filesystem::path dstFilePath = to / srcFilePath.filename(); + const bfs::path& srcFilePath = file->path(); + const bfs::path dstFilePath = to / srcFilePath.filename(); // TODO: Aplication should ask user what to do when file exists: // replace/ignore/stop process/replace all/ignore all - if (!boost::filesystem::exists(dstFilePath)) + if (!bfs::exists(dstFilePath)) bfs::rename(srcFilePath, dstFilePath); } @@ -526,14 +529,14 @@ bfs::path VCMIDirsOSX::binaryPath() const { return "."; } class VCMIDirsXDG : public IVCMIDirsUNIX { public: - boost::filesystem::path userDataPath() const override; - boost::filesystem::path userCachePath() const override; - boost::filesystem::path userConfigPath() const override; + bfs::path userDataPath() const override; + bfs::path userCachePath() const override; + bfs::path userConfigPath() const override; - std::vector dataPaths() const override; + std::vector dataPaths() const override; - boost::filesystem::path libraryPath() const override; - boost::filesystem::path binaryPath() const override; + bfs::path libraryPath() const override; + bfs::path binaryPath() const override; std::string libraryName(const std::string& basename) const override; }; diff --git a/lib/VCMIDirs.h b/lib/VCMIDirs.h index 791f07483..50b385f5d 100644 --- a/lib/VCMIDirs.h +++ b/lib/VCMIDirs.h @@ -29,6 +29,9 @@ public: // Path to saved games virtual boost::filesystem::path userSavePath() const; + // Path to "extracted" directory, used to temporarily hold extracted Original H3 files + virtual boost::filesystem::path userExtractedPath() const; + // Paths to global system-wide data directories. First items have higher priority virtual std::vector dataPaths() const = 0; diff --git a/lib/filesystem/CArchiveLoader.cpp b/lib/filesystem/CArchiveLoader.cpp index e2751e69f..65bf8bd9a 100644 --- a/lib/filesystem/CArchiveLoader.cpp +++ b/lib/filesystem/CArchiveLoader.cpp @@ -236,7 +236,7 @@ void CArchiveLoader::extractToFolder(const std::string & outputSubFolder, const bfs::path createExtractedFilePath(const std::string & outputSubFolder, const std::string & entryName) { - bfs::path extractionFolderPath = VCMIDirs::get().userCachePath() / "extracted" / outputSubFolder; + bfs::path extractionFolderPath = VCMIDirs::get().userExtractedPath() / outputSubFolder; bfs::path extractedFilePath = extractionFolderPath / entryName; bfs::create_directories(extractionFolderPath); diff --git a/mapeditor/resourceExtractor/ResourceConverter.cpp b/mapeditor/resourceExtractor/ResourceConverter.cpp index f03154c39..cdebe9300 100644 --- a/mapeditor/resourceExtractor/ResourceConverter.cpp +++ b/mapeditor/resourceExtractor/ResourceConverter.cpp @@ -29,7 +29,7 @@ void doConvertPcxToPng(bool deleteOriginals) { std::string filename; - bfs::path imagesPath = VCMIDirs::get().userCachePath() / "extracted" / "IMAGES"; + bfs::path imagesPath = VCMIDirs::get().userExtractedPath() / "IMAGES"; bfs::directory_iterator end_iter; for(bfs::directory_iterator dir_itr(imagesPath); dir_itr != end_iter; ++dir_itr) @@ -68,7 +68,7 @@ void splitDefFile(const std::string & fileName, const bfs::path & spritesPath, b { std::unique_ptr anim = make_unique(fileName); anim->preload(); - anim->exportBitmaps(pathToQString(VCMIDirs::get().userCachePath() / "extracted")); + anim->exportBitmaps(pathToQString(VCMIDirs::get().userExtractedPath())); if(deleteOriginals) bfs::remove(spritesPath / fileName); @@ -82,8 +82,7 @@ void splitDefFile(const std::string & fileName, const bfs::path & spritesPath, b // hero speciality small icons, hero speciality large icons) void splitDefFiles(bool deleteOriginals) { - bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted"; - bfs::path spritesPath = extractedPath / "SPRITES"; + bfs::path spritesPath = VCMIDirs::get().userExtractedPath() / "SPRITES"; for(std::string defFilename : {"TwCrPort.def", "CPRSMALL.def", "FlagPort.def", "ITPA.def", "ITPt.def", "Un32.def", "Un44.def"}) splitDefFile(defFilename, spritesPath, deleteOriginals);