summaryrefslogtreecommitdiff
path: root/Source/modules/asura-base/FileSystem/FileManager.h
blob: 282032171ef00fe72bce06637e616b9bfd5244fa (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
#ifndef _ASURA_ENGINE_FILESYSTEM_H_
#define _ASURA_ENGINE_FILESYSTEM_H_

#include <map>
#include <string>

#include "../Scripting/Scripting.h"
#include "../Singleton.hpp"
#include "../Type.h"

#include "FileData.h"
#include "File.h"

namespace_begin(AsuraEngine)
namespace_begin(FileSystem)

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µġFileManagerʱͱ༭õ࣬AssetDatabaseԴ࣬framework
/// ʵ֣߼дFileManagerʵ֣AssetDatabaseṩļݴӦԴķ
///
class FileManager ASURA_FINAL
	: public Singleton<FileManager>
	, public AEScripting::Portable<FileManager>
{
public:

	LUAX_DECL_SINGLETON(FileManager);

	~FileManager();

	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_end
namespace_end

namespace AEFileSystem = AsuraEngine::FileSystem;

#endif