summaryrefslogtreecommitdiff
path: root/source/modules/asura-utils/io/file_system.h
blob: 9b4c4be38dd2bf6d8a4ef0cd05a5d3164a0d27ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef __ASURA_ENGINE_FILESYSTEM_H__
#define __ASURA_ENGINE_FILESYSTEM_H__

#include <map>
#include <string>

#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;
		};

		///
		/// Դء洢ԴָĿ¼ȡ۱༭ʱҪƷʵĻƣûIJϷĿ¼
		/// £file systemµġFilesystemʱͱ༭õ࣬AssetDatabaseԴ࣬framework
		/// ʵ֣߼дFilesystemʵ֣AssetDatabaseṩļݴӦԴķ
		///
		class Filesystem ASURA_FINAL
			: public Singleton<Filesystem>
			, public AEScripting::Portable<Filesystem>
		{
		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<std::string>& items) { return false; };

		private:

			typedef std::map<std::string, DataBuffer*> 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