From bad78945ceba425f6a80e3b8dca2414d592970eb Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 2 Aug 2019 20:51:00 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=90=8D=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/modules/asura-utils/IO/FileSystem.h | 112 +++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 source/modules/asura-utils/IO/FileSystem.h (limited to 'source/modules/asura-utils/IO/FileSystem.h') diff --git a/source/modules/asura-utils/IO/FileSystem.h b/source/modules/asura-utils/IO/FileSystem.h new file mode 100644 index 0000000..f0ac6ba --- /dev/null +++ b/source/modules/asura-utils/IO/FileSystem.h @@ -0,0 +1,112 @@ +#ifndef _ASURA_ENGINE_FILESYSTEM_H_ +#define _ASURA_ENGINE_FILESYSTEM_H_ + +#include +#include + +#include "../Scripting/Portable.hpp" +#include "../Singleton.hpp" +#include "../Type.h" + +#include "FileData.h" +#include "File.h" + +namespace AsuraEngine +{ + namespace IO + { + + enum FileType + { + FILE_TYPE_FILE, ///< 文件 + FILE_TYPE_DIRECTORY, ///< 文件夹 + FILE_TYPE_SYMLINK, ///< 链接 + FILE_TYPE_OTHER, ///< 其他 + }; + + struct FileInfo + { + int64 size; + int64 modtime; + FileType type; + }; + + /// + /// 资源管理,负责加载、存储资源,指定根目录等。无论编辑器还是运行时,都需要限制访问的机制,将用户的操作限制在游戏目录 + /// 下,file system就是做这件事的。Filesystem是运行时和编辑器共用的类,AssetDatabase是用来管理资源的类,在framework + /// 里实现,单纯是逻辑处理,读写还是用Filesystem实现,AssetDatabase提供根据文件内容创建对应资源的方法。 + /// + class Filesystem ASURA_FINAL + : public Singleton + , public AEScripting::Portable + { + public: + + LUAX_DECL_SINGLETON(Filesystem); + + ~Filesystem(); + + void Init(const char* arg0); + + /// + /// 当前可执行文件的所在文件夹 + /// + std::string GetWorkingDirectory(); + + bool Mount(const std::string& locpath, const std::string& montpoint = "/", bool prepend = false); + bool Mount(DataBuffer* db, const std::string& archivename, const std::string& mountpoint = "/", bool prepend = false); + + bool Unmount(const std::string& locpath); + bool Unmount(DataBuffer* db); + + bool GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint); + + void SetWriteDirectory(const std::string locpath); + std::string GetWriteDirectory(); + File* NewFile(const std::string& name); + bool NewDirectory(const std::string& path); + bool Write(const std::string& path, ASURA_REF DataBuffer* buffer); + bool Append(const std::string& path, ASURA_REF DataBuffer* buffer); + bool Remove(const std::string& path); + + FileData* Read(const std::string& path); + bool GetFileInfo(const std::string& path, ASURA_OUT FileInfo* info); + + bool GetDirectoryItems(const std::string& path, ASURA_OUT std::vector& items) { return false; }; + + private: + + typedef std::map MountDataMap; + + bool m_Inited; ///< 是否初始化成功 + std::string m_Cwd; ///< 当前执行文件的工作目录 + MountDataMap m_MountData; ///< 从路径到压缩文档的映射 + + LUAX_DECL_METHOD(_Init); + LUAX_DECL_METHOD(_Mount); + LUAX_DECL_METHOD(_Unmount); + LUAX_DECL_METHOD(_GetMountPoint); + + LUAX_DECL_METHOD(_SetWriteDirectory); + LUAX_DECL_METHOD(_GetWriteDirectory); + LUAX_DECL_METHOD(_CreateFile); + LUAX_DECL_METHOD(_CreateDirectory); + + LUAX_DECL_METHOD(_Write); + LUAX_DECL_METHOD(_Append); + LUAX_DECL_METHOD(_Remove); + + LUAX_DECL_METHOD(_Read); + + LUAX_DECL_METHOD(_GetFileInfo); + + LUAX_DECL_METHOD(_GetDirectoryItems); + + }; + + } +} + +namespace AEIO = AsuraEngine::IO; + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0