#pragma once #include #include #include "File.hpp" #include "script/engine/Engine.hpp" #include "utils/angelscript/MixinAsReferenceCount.hpp" /** * Represent a virtual file system path in the Atlas engine * Similar to the pathlib library in Python */ class Path : public atlas::utils::angelscript::MixinAsReferenceCount { public: explicit Path(const vfs::VirtualFileSystem* fileSystem, const std::filesystem::path& virtualPath); // browse /** * Get the parent directory * @return the parent directory */ [[nodiscard]] Path getParent() const; /** * Get the child paths * @return the child paths */ [[nodiscard]] std::vector> getChildrens(bool recursive = false, const std::string& pattern = "*") const; // type /** * Check if the path correspond to a file system entry * @return does the path exists */ [[nodiscard]] bool exists() const; /** * is the current path leading to a file * @return is the current path leading to a file */ [[nodiscard]] bool isFile() const; /** * is the current path leading to a directory * @return is the current path leading to a directory */ [[nodiscard]] bool isDirectory() const; // operation /** * open the path as a file * @return the opened file */ std::shared_ptr open(const std::string& mode, const std::string& encoding = "utf-8"); [[nodiscard]] bool mkdir(bool parents) const; void remove(bool recursive) const; // component /** * get the full path to the file * @return the full path to the file */ [[nodiscard]] std::string getPath() const; /** * get the name of the directory containing the file * @return the name of the directory containing the file */ [[nodiscard]] std::string getDirname() const; /** * get the name of the file * @return the name of the file */ [[nodiscard]] std::string getFilename() const; /** * get the name of the file without the suffix * @return the name of the file without the suffix */ [[nodiscard]] std::string getBasename() const; /** * get the extension of the file * @return the extension of the file */ [[nodiscard]] std::string getSuffix() const; /** * get the extensions of the file * @return the extensions of the file */ [[nodiscard]] std::vector getSuffixes() const; /** * get the components of the path * @return the components of the path */ [[nodiscard]] std::vector getComponents() const; private: /// the JavaScript engine const vfs::VirtualFileSystem* fileSystem; /// the virtual path std::filesystem::path virtualPath; /** * Get the real path on the host file system of the path * @return the real path on the host file system * @throw rvfs::exception::FileNotFoundException if the path does not match with anything on the real file system */ [[nodiscard]] std::filesystem::path getRealPath() const; };