载入中...
搜索中...
未找到
Filesystem.h
浏览该文件的文档.
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include "common/Module.h"
7#include "common/config.h"
8#include "filesystem/File.h"
10
11#define EVENGINE_APPDATA_PREFIX ""
12#ifdef EVENGINE_WINDOWS
13#define EVENGINE_APPDATA_FOLDER "EVE"
14#define EVENGINE_PATH_SEPARATOR "/"
15#define EVENGINE_MAX_PATH _MAX_PATH
16#else
17#if defined(EVENGINE_MACOSX) || defined(EVENGINE_IOS)
18#define EVENGINE_APPDATA_FOLDER "EVE"
19#elif defined(EVENGINE_LINUX)
20#define EVENGINE_APPDATA_FOLDER "eve"
21#else
22#define EVENGINE_APPDATA_PREFIX "."
23#define EVENGINE_APPDATA_FOLDER "eve"
24#endif
25#define EVENGINE_PATH_SEPARATOR "/"
26#define EVENGINE_MAX_PATH MAXPATHLEN
27#endif
28
29namespace eve::filesystem {
30
31class Filesystem : public Module {
32public:
34
35 struct Info {
36 // Numbers will be -1 if they cannot be determined.
37 int64_t size;
38 int64_t modtime;
39 std::string type; // file, directory, symlink, other
40 };
41
43 virtual ~Filesystem() {}
44
45 virtual void init(const char* arg0) = 0;
46
47 virtual void setFused(bool fused) = 0;
48 virtual bool isFused() const = 0;
49
55 virtual bool setupWriteDirectory() = 0;
56
63 virtual void setAndroidSaveExternal(bool useExternal = false) { this->useExternal = useExternal; }
64
69 virtual bool isAndroidSaveExternal() const { return useExternal; }
70
76 virtual bool setIdentity(std::string ident, bool appendToPath = false) = 0;
77 virtual std::string getIdentity() const = 0;
78
84 virtual bool setSource(std::string source) = 0;
85
94 virtual bool setSourceFromMemory(const void* data, size_t size) = 0;
95
100 virtual std::string getSource() const = 0;
101
102 virtual bool mount(std::string archive, std::string mountpoint, bool appendToPath = false) = 0;
103 virtual bool mount(Data *data, std::string archivename, std::string mountpoint, bool appendToPath = false) = 0;
104
113 virtual bool mountRealDirectory(std::string realDir, std::string mountpoint, bool appendToPath = false) = 0;
114
116 virtual bool unmountRealDirectory(std::string realDir) = 0;
117
118 virtual bool unmount(std::string archive) = 0;
119 virtual bool unmount(Data *data) = 0;
120
124 virtual File *newFile(std::string filename) const = 0;
125
132 virtual FileData *newFileData(const void *data, std::string filename, size_t size) const;
133
137 virtual std::string getWorkingDirectory() = 0;
138
142 virtual std::string getUserDirectory() = 0;
143
149 virtual std::string getAppdataDirectory() = 0;
150
154 virtual std::string getSaveDirectory() = 0;
155
161 virtual std::string getSourceBaseDirectory() const = 0;
162
166 virtual std::string getRealDirectory(std::string filename) const = 0;
167
172 virtual bool getInfo(std::string filepath, Info &info) const = 0;
173
178 virtual bool createDirectory(std::string dir) = 0;
179
184 virtual bool remove(std::string file) = 0;
185
191 virtual FileData *read(std::string filename, int64_t size = File::ALL) const = 0;
192
199 virtual void write(std::string filename, const void *data, int64_t size) const = 0;
200
207 virtual void append(std::string filename, const void *data, int64_t size) const = 0;
208
213 virtual std::vector<std::string> getDirectoryItems(std::string dir) = 0;
214
218 virtual void setSymlinksEnabled(bool enable) = 0;
219
223 virtual bool areSymlinksEnabled() const = 0;
224
225 // Require path accessors
226 // Not const because it's R/W
227 virtual std::vector<std::string> &getRequirePath() = 0;
228 virtual std::vector<std::string> &getCRequirePath() = 0;
229
233 virtual void allowMountingForPath(const std::string &path) = 0;
234
238 virtual bool isRealDirectory(const std::string &path) const;
239
243 virtual std::string getExecutablePath() const;
244
245 // --- File watch (backend-specific; main-thread poll) ---
246
252 virtual bool watch(std::string path) = 0;
253
255 virtual bool unwatch(std::string path) = 0;
256 virtual void unwatchAll() = 0;
257 virtual int getWatchCount() const = 0;
258
263 virtual std::string pollWatch() = 0;
264 virtual std::string getLastWatchPath() const = 0;
265 virtual std::string getLastWatchRealPath() const = 0;
266
267private:
268 // Should we save external or internal for Android
269 bool useExternal = false;
270}; // Filesystem
271
272} // namespace eve::filesystem
filesystem::File * file
V3 dir
Definition TreeMesh.cpp:121
Data buffer paired with a filename (used for type identification).
Definition FileData.h:12
A File interface, providing generic means of reading from and writing to files.
Definition File.h:14
static const int64_t ALL
Used to indicate ALL data in a file.
Definition File.h:19
virtual bool unmount(std::string archive)=0
virtual std::string getSourceBaseDirectory() const =0
Gets the full path to the directory containing the game source. For example if the game source is C:\...
virtual void allowMountingForPath(const std::string &path)=0
Allows a full (OS-dependent) path to be used with Filesystem::mount.
virtual void init(const char *arg0)=0
virtual bool unmount(Data *data)=0
virtual bool isAndroidSaveExternal() const
Gets whether the Android save is external. Returns a bool.
Definition Filesystem.h:69
virtual std::string getUserDirectory()=0
Gets the user home directory.
virtual bool getInfo(std::string filepath, Info &info) const =0
Gets information about the item at the specified filepath. Returns false if nothing exists at the pat...
virtual bool mount(Data *data, std::string archivename, std::string mountpoint, bool appendToPath=false)=0
virtual bool setSource(std::string source)=0
Sets the path to the game source. This can only be set once.
virtual std::string getExecutablePath() const
Gets the full platform-dependent path to the executable.
virtual bool setIdentity(std::string ident, bool appendToPath=false)=0
Sets the name of the save folder.
virtual bool mountRealDirectory(std::string realDir, std::string mountpoint, bool appendToPath=false)=0
virtual std::vector< std::string > & getRequirePath()=0
virtual std::string getLastWatchRealPath() const =0
virtual FileData * newFileData(const void *data, std::string filename, size_t size) const
Creates a new FileData object. Data will be copied.
virtual int getWatchCount() const =0
virtual File * newFile(std::string filename) const =0
Creates a new file.
virtual std::string getWorkingDirectory()=0
Gets the current working directory.
virtual void setFused(bool fused)=0
virtual std::vector< std::string > getDirectoryItems(std::string dir)=0
This "native" method returns a table of all files in a given directory.
virtual std::string pollWatch()=0
Pop next watch event kind: "added"|"removed"|"modified"|"movedFrom"|"movedTo". Empty string if queue ...
virtual void unwatchAll()=0
virtual bool unwatch(std::string path)=0
Stop watching a path previously passed to watch().
virtual std::string getRealDirectory(std::string filename) const =0
Gets the real directory path containing the file.
virtual bool isFused() const =0
virtual std::string getAppdataDirectory()=0
Gets the APPDATA directory. On Windows, this is the folder in the APPDATA% enviroment variable....
virtual std::string getSaveDirectory()=0
Gets the full path of the save folder.
virtual bool isRealDirectory(const std::string &path) const
Gets whether the given full (OS-dependent) path is a directory.
virtual bool setSourceFromMemory(const void *data, size_t size)=0
Loads the game source from a packaged archive (.eve / zip) held entirely in memory and mounts it at "...
virtual std::string getLastWatchPath() const =0
virtual bool remove(std::string file)=0
Removes a file (or directory).
virtual bool mount(std::string archive, std::string mountpoint, bool appendToPath=false)=0
virtual bool createDirectory(std::string dir)=0
Creates a directory. Write dir must be set.
virtual std::string getIdentity() const =0
virtual bool unmountRealDirectory(std::string realDir)=0
virtual bool areSymlinksEnabled() const =0
Gets whether symbolic link support is enabled.
virtual void write(std::string filename, const void *data, int64_t size) const =0
Write data to a file.
virtual bool setupWriteDirectory()=0
This sets up the save directory. If the it is already set up, nothing happens.
virtual FileData * read(std::string filename, int64_t size=File::ALL) const =0
Reads data from a file.
virtual void append(std::string filename, const void *data, int64_t size) const =0
Append data to a file, creating it if it doesn't exist.
virtual void setAndroidSaveExternal(bool useExternal=false)
This sets the save location on Android. False for internal, true for external
Definition Filesystem.h:63
virtual void setSymlinksEnabled(bool enable)=0
Enable or disable symbolic link support in love.filesystem.
virtual std::string getSource() const =0
Gets the path to the game source. Returns a 0-length string if the source has not been set.
virtual std::vector< std::string > & getCRequirePath()=0
virtual bool watch(std::string path)=0
Watch a virtual or absolute OS path (file or directory). File watches monitor the parent directory an...