1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

IVCMIDirs::userExtractedPath() created

This commit is contained in:
krs
2022-11-24 22:15:46 +02:00
parent 6130776fe4
commit 9b3cab1181
5 changed files with 51 additions and 46 deletions

View File

@@ -638,7 +638,7 @@ void processCommand(const std::string &message)
std::cout << "Command accepted.\t"; std::cout << "Command accepted.\t";
const bfs::path outPath = const bfs::path outPath =
VCMIDirs::get().userCachePath() / "extracted"; VCMIDirs::get().userExtractedPath();
bfs::create_directories(outPath); bfs::create_directories(outPath);
@@ -671,7 +671,7 @@ void processCommand(const std::string &message)
std::cout << "Command accepted.\t"; std::cout << "Command accepted.\t";
const bfs::path outPath = const bfs::path outPath =
VCMIDirs::get().userCachePath() / "extracted" / "configuration"; VCMIDirs::get().userExtractedPath() / "configuration";
bfs::create_directories(outPath); bfs::create_directories(outPath);
@@ -712,7 +712,7 @@ void processCommand(const std::string &message)
std::cout << "Command accepted.\t"; std::cout << "Command accepted.\t";
const bfs::path outPath = const bfs::path outPath =
VCMIDirs::get().userCachePath() / "extracted" / "scripts"; VCMIDirs::get().userExtractedPath() / "scripts";
bfs::create_directories(outPath); bfs::create_directories(outPath);
@@ -735,7 +735,7 @@ void processCommand(const std::string &message)
std::cout << "Command accepted.\t"; std::cout << "Command accepted.\t";
const bfs::path outPath = const bfs::path outPath =
VCMIDirs::get().userCachePath() / "extracted"; VCMIDirs::get().userExtractedPath();
auto list = CResourceHandler::get()->getFilteredFiles([](const ResourceID & ident) auto list = CResourceHandler::get()->getFilteredFiles([](const ResourceID & ident)
{ {
@@ -851,7 +851,7 @@ void processCommand(const std::string &message)
readed >> URI; readed >> URI;
std::unique_ptr<CAnimation> anim = make_unique<CAnimation>(URI); std::unique_ptr<CAnimation> anim = make_unique<CAnimation>(URI);
anim->preload(); anim->preload();
anim->exportBitmaps(VCMIDirs::get().userCachePath() / "extracted"); anim->exportBitmaps(VCMIDirs::get().userExtractedPath());
} }
else if(cn == "extract") else if(cn == "extract")
{ {
@@ -860,7 +860,7 @@ void processCommand(const std::string &message)
if (CResourceHandler::get()->existsResource(ResourceID(URI))) 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(); auto data = CResourceHandler::get()->load(ResourceID(URI))->readAll();

View File

@@ -23,6 +23,8 @@ bfs::path IVCMIDirs::userLogsPath() const { return userCachePath(); }
bfs::path IVCMIDirs::userSavePath() const { return userDataPath() / "Saves"; } 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 bfs::path IVCMIDirs::fullLibraryPath(const std::string &desiredFolder, const std::string &baseLibName) const
{ {
return libraryPath() / desiredFolder / libraryName(baseLibName); return libraryPath() / desiredFolder / libraryName(baseLibName);
@@ -36,15 +38,16 @@ std::string IVCMIDirs::genHelpString() const
const auto gdStringA = boost::algorithm::join(tempVec, ":"); const auto gdStringA = boost::algorithm::join(tempVec, ":");
return return
" game data: " + gdStringA + "\n" " game data: " + gdStringA + "\n"
" libraries: " + libraryPath().string() + "\n" " libraries: " + libraryPath().string() + "\n"
" server: " + serverPath().string() + "\n" " server: " + serverPath().string() + "\n"
"\n" "\n"
" user data: " + userDataPath().string() + "\n" " user data: " + userDataPath().string() + "\n"
" user cache: " + userCachePath().string() + "\n" " user cache: " + userCachePath().string() + "\n"
" user config: " + userConfigPath().string() + "\n" " user config: " + userConfigPath().string() + "\n"
" user logs: " + userLogsPath().string() + "\n" " user logs: " + userLogsPath().string() + "\n"
" user saves: " + userSavePath().string() + "\n"; // Should end without new-line? " user saves: " + userSavePath().string() + "\n";
" user extracted: " + userExtractedPath().string() + "\n"; // Should end without new-line?
} }
void IVCMIDirs::init() void IVCMIDirs::init()
@@ -148,24 +151,24 @@ bool StartBatchCopyDataProgram(
class VCMIDirsWIN32 final : public IVCMIDirs class VCMIDirsWIN32 final : public IVCMIDirs
{ {
public: public:
boost::filesystem::path userDataPath() const override; bfs::path userDataPath() const override;
boost::filesystem::path userCachePath() const override; bfs::path userCachePath() const override;
boost::filesystem::path userConfigPath() const override; bfs::path userConfigPath() const override;
std::vector<boost::filesystem::path> dataPaths() const override; std::vector<bfs::path> dataPaths() const override;
boost::filesystem::path clientPath() const override; bfs::path clientPath() const override;
boost::filesystem::path serverPath() const override; bfs::path serverPath() const override;
boost::filesystem::path libraryPath() const override; bfs::path libraryPath() const override;
boost::filesystem::path binaryPath() const override; bfs::path binaryPath() const override;
std::string libraryName(const std::string& basename) const override; std::string libraryName(const std::string& basename) const override;
void init() override; void init() override;
protected: protected:
boost::filesystem::path oldUserDataPath() const; bfs::path oldUserDataPath() const;
boost::filesystem::path oldUserSavePath() const; bfs::path oldUserSavePath() const;
}; };
void VCMIDirsWIN32::init() void VCMIDirsWIN32::init()
@@ -355,8 +358,8 @@ std::string VCMIDirsWIN32::libraryName(const std::string& basename) const { retu
class IVCMIDirsUNIX : public IVCMIDirs class IVCMIDirsUNIX : public IVCMIDirs
{ {
public: public:
boost::filesystem::path clientPath() const override; bfs::path clientPath() const override;
boost::filesystem::path serverPath() const override; bfs::path serverPath() const override;
virtual bool developmentMode() const; virtual bool developmentMode() const;
}; };
@@ -427,14 +430,14 @@ bfs::path VCMIDirsIOS::binaryPath() const { return {iOS_utils::bundlePath()}; }
class VCMIDirsOSX final : public VCMIDirsApple class VCMIDirsOSX final : public VCMIDirsApple
{ {
public: public:
boost::filesystem::path userDataPath() const override; bfs::path userDataPath() const override;
boost::filesystem::path userCachePath() const override; bfs::path userCachePath() const override;
boost::filesystem::path userLogsPath() const override; bfs::path userLogsPath() const override;
std::vector<boost::filesystem::path> dataPaths() const override; std::vector<bfs::path> dataPaths() const override;
boost::filesystem::path libraryPath() const override; bfs::path libraryPath() const override;
boost::filesystem::path binaryPath() const override; bfs::path binaryPath() const override;
void init() override; void init() override;
}; };
@@ -464,12 +467,12 @@ void VCMIDirsOSX::init()
for (bfs::directory_iterator file(from); file != bfs::directory_iterator(); ++file) for (bfs::directory_iterator file(from); file != bfs::directory_iterator(); ++file)
{ {
const boost::filesystem::path& srcFilePath = file->path(); const bfs::path& srcFilePath = file->path();
const boost::filesystem::path dstFilePath = to / srcFilePath.filename(); const bfs::path dstFilePath = to / srcFilePath.filename();
// TODO: Aplication should ask user what to do when file exists: // TODO: Aplication should ask user what to do when file exists:
// replace/ignore/stop process/replace all/ignore all // replace/ignore/stop process/replace all/ignore all
if (!boost::filesystem::exists(dstFilePath)) if (!bfs::exists(dstFilePath))
bfs::rename(srcFilePath, dstFilePath); bfs::rename(srcFilePath, dstFilePath);
} }
@@ -526,14 +529,14 @@ bfs::path VCMIDirsOSX::binaryPath() const { return "."; }
class VCMIDirsXDG : public IVCMIDirsUNIX class VCMIDirsXDG : public IVCMIDirsUNIX
{ {
public: public:
boost::filesystem::path userDataPath() const override; bfs::path userDataPath() const override;
boost::filesystem::path userCachePath() const override; bfs::path userCachePath() const override;
boost::filesystem::path userConfigPath() const override; bfs::path userConfigPath() const override;
std::vector<boost::filesystem::path> dataPaths() const override; std::vector<bfs::path> dataPaths() const override;
boost::filesystem::path libraryPath() const override; bfs::path libraryPath() const override;
boost::filesystem::path binaryPath() const override; bfs::path binaryPath() const override;
std::string libraryName(const std::string& basename) const override; std::string libraryName(const std::string& basename) const override;
}; };

View File

@@ -29,6 +29,9 @@ public:
// Path to saved games // Path to saved games
virtual boost::filesystem::path userSavePath() const; 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 // Paths to global system-wide data directories. First items have higher priority
virtual std::vector<boost::filesystem::path> dataPaths() const = 0; virtual std::vector<boost::filesystem::path> dataPaths() const = 0;

View File

@@ -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 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::path extractedFilePath = extractionFolderPath / entryName;
bfs::create_directories(extractionFolderPath); bfs::create_directories(extractionFolderPath);

View File

@@ -29,7 +29,7 @@ void doConvertPcxToPng(bool deleteOriginals)
{ {
std::string filename; std::string filename;
bfs::path imagesPath = VCMIDirs::get().userCachePath() / "extracted" / "IMAGES"; bfs::path imagesPath = VCMIDirs::get().userExtractedPath() / "IMAGES";
bfs::directory_iterator end_iter; bfs::directory_iterator end_iter;
for(bfs::directory_iterator dir_itr(imagesPath); dir_itr != end_iter; ++dir_itr) 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<Animation> anim = make_unique<Animation>(fileName); std::unique_ptr<Animation> anim = make_unique<Animation>(fileName);
anim->preload(); anim->preload();
anim->exportBitmaps(pathToQString(VCMIDirs::get().userCachePath() / "extracted")); anim->exportBitmaps(pathToQString(VCMIDirs::get().userExtractedPath()));
if(deleteOriginals) if(deleteOriginals)
bfs::remove(spritesPath / fileName); 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) // hero speciality small icons, hero speciality large icons)
void splitDefFiles(bool deleteOriginals) void splitDefFiles(bool deleteOriginals)
{ {
bfs::path extractedPath = VCMIDirs::get().userDataPath() / "extracted"; bfs::path spritesPath = VCMIDirs::get().userExtractedPath() / "SPRITES";
bfs::path spritesPath = extractedPath / "SPRITES";
for(std::string defFilename : {"TwCrPort.def", "CPRSMALL.def", "FlagPort.def", "ITPA.def", "ITPt.def", "Un32.def", "Un44.def"}) for(std::string defFilename : {"TwCrPort.def", "CPRSMALL.def", "FlagPort.def", "ITPA.def", "ITPt.def", "Un32.def", "Un44.def"})
splitDefFile(defFilename, spritesPath, deleteOriginals); splitDefFile(defFilename, spritesPath, deleteOriginals);