refactor engine_paths

This commit is contained in:
alexei-zebra
2024-08-06 15:32:56 +03:00
parent c7ce9a939f
commit 62c98b8420
2 changed files with 130 additions and 105 deletions
+31 -26
View File
@@ -8,7 +8,6 @@
#include "../content/ContentPack.hpp"
namespace fs = std::filesystem;
class files_access_error : public std::runtime_error {
public:
@@ -17,51 +16,57 @@ public:
};
class EnginePaths {
fs::path userfiles {"."};
fs::path resources {"res"};
fs::path worldFolder;
std::vector<ContentPack>* contentPacks = nullptr;
public:
void prepare();
fs::path getUserfiles() const;
fs::path getResources() const;
void setUserFilesFolder(std::filesystem::path folder);
std::filesystem::path getUserFilesFolder() const;
fs::path getScreenshotFile(const std::string& ext);
fs::path getWorldsFolder();
fs::path getWorldFolder();
fs::path getWorldFolder(const std::string& name);
fs::path getControlsFile();
fs::path getSettingsFile();
bool isWorldNameUsed(const std::string& name);
void setResourcesFolder(std::filesystem::path folder);
std::filesystem::path getResourcesFolder() const;
std::filesystem::path getWorldsFolder();
std::filesystem::path getWorldFolderByName(const std::string& name);
void setCurrentWorldFolder(std::filesystem::path folder);
std::filesystem::path getCurrentWorldFolder();
std::filesystem::path getNewScreenshotFile(const std::string& ext);
std::filesystem::path getControlsFile();
std::filesystem::path getSettingsFile();
void setUserfiles(fs::path folder);
void setResources(fs::path folder);
void setContentPacks(std::vector<ContentPack>* contentPacks);
void setWorldFolder(fs::path folder);
std::vector<fs::path> scanForWorlds();
std::vector<std::filesystem::path> scanForWorlds();
fs::path resolve(const std::string& path, bool throwErr = true);
std::filesystem::path resolve(const std::string& path, bool throwErr = true);
private:
std::filesystem::path userFilesFolder {"."};
std::filesystem::path resourcesFolder {"res"};
std::filesystem::path currentWorldFolder;
std::vector<ContentPack>* contentPacks = nullptr;
};
struct PathsRoot {
std::string name;
fs::path path;
std::filesystem::path path;
};
class ResPaths {
fs::path mainRoot;
std::vector<PathsRoot> roots;
public:
ResPaths(fs::path mainRoot, std::vector<PathsRoot> roots);
ResPaths(std::filesystem::path mainRoot, std::vector<PathsRoot> roots);
fs::path find(const std::string& filename) const;
std::filesystem::path find(const std::string& filename) const;
std::string findRaw(const std::string& filename) const;
std::vector<fs::path> listdir(const std::string& folder) const;
std::vector<std::filesystem::path> listdir(const std::string& folder) const;
std::vector<std::string> listdirRaw(const std::string& folder) const;
const fs::path& getMainRoot() const;
const std::filesystem::path& getMainRoot() const;
private:
std::filesystem::path mainRoot;
std::vector<PathsRoot> roots;
};
#endif // FILES_ENGINE_PATHS_HPP_