From 250e30d73f09e9da2b5a81d0fbae63744ae12a73 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 2 Apr 2019 08:47:15 +0800 Subject: *misc --- source/libs/asura-lib-utils/io/file_system.h | 112 +++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 source/libs/asura-lib-utils/io/file_system.h (limited to 'source/libs/asura-lib-utils/io/file_system.h') diff --git a/source/libs/asura-lib-utils/io/file_system.h b/source/libs/asura-lib-utils/io/file_system.h new file mode 100644 index 0000000..849cbb6 --- /dev/null +++ b/source/libs/asura-lib-utils/io/file_system.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 "file_data.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 mInited; ///< 是否初始化成功 + std::string mCwd; ///< 当前执行文件的工作目录 + MountDataMap mMountData; ///< 从路径到压缩文档的映射 + + 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