载入中...
搜索中...
未找到
Filesystem.h
浏览该文件的文档.
1#pragma once
2
3#include <cstdlib>
4#include <cstring>
5#include <map>
6#include <memory>
7#include <mutex>
8#include <string>
9#include <vector>
10
13
14namespace eve {
15namespace filesystem {
16namespace physfs {
17
20public:
21 Filesystem();
22 ~Filesystem() override;
23
24 void init(const char* arg0) override;
25
26 void setFused(bool fused) override;
27 bool isFused() const override;
28
29 bool setupWriteDirectory() override;
30
31 bool setIdentity(std::string ident, bool appendToPath = false) override;
32 std::string getIdentity() const override;
33
34 bool setSource(std::string source) override;
35 bool setSourceFromMemory(const void* data, size_t size) override;
36
37 std::string getSource() const override;
38
39 bool mount(std::string archive, std::string mountpoint, bool appendToPath = false) override;
40 bool mount(Data *data, std::string archivename, std::string mountpoint, bool appendToPath = false) override;
41 bool mountRealDirectory(std::string realDir, std::string mountpoint, bool appendToPath = false) override;
42 bool unmountRealDirectory(std::string realDir) override;
43
44 bool unmount(std::string archive) override;
45 bool unmount(Data *data) override;
46
47 filesystem::File *newFile(std::string filename) const override;
48
49 std::string getWorkingDirectory() override;
50 std::string getUserDirectory() override;
51 std::string getAppdataDirectory() override;
52 std::string getSaveDirectory() override;
53 std::string getSourceBaseDirectory() const override;
54
55 std::string getRealDirectory(std::string filename) const override;
56
57 bool getInfo(std::string filepath, Info &info) const override;
58
59 bool createDirectory(std::string dir) override;
60
61 bool remove(std::string file) override;
62
63 FileData *read(std::string filename, int64_t size = File::ALL) const override;
64 void write(std::string filename, const void *data, int64_t size) const override;
65 void append(std::string filename, const void *data, int64_t size) const override;
66
67 std::vector<std::string> getDirectoryItems(std::string dir) override;
68
69 void setSymlinksEnabled(bool enable) override;
70 bool areSymlinksEnabled() const override;
71
72 std::vector<std::string> &getRequirePath() override;
73 std::vector<std::string> &getCRequirePath() override;
74
75 void allowMountingForPath(const std::string &path) override;
76
77 bool watch(std::string path) override;
78 bool unwatch(std::string path) override;
79 void unwatchAll() override;
80 int getWatchCount() const override;
81 std::string pollWatch() override;
82 std::string getLastWatchPath() const override;
83 std::string getLastWatchRealPath() const override;
84
85private:
86 bool resolveWatchTarget(const std::string &path, std::string &realDir, std::string &filterName,
87 std::string &reportPath);
88 FileWatch &watchers();
89
90 // Contains the current working directory (UTF8).
91 std::string cwd;
92
93 // %APPDATA% on Windows.
94 std::string appdata;
95
96 // This name will be used to create the folder
97 // in the appdata/userdata folder.
98 std::string save_identity;
99
100 // Full and relative paths of the game save folder.
101 // (Relative to the %APPDATA% folder, meaning that the
102 // relative string will look something like: ./LOVE/game)
103 std::string save_path_relative, save_path_full;
104
105 // The full path to the source of the game.
106 std::string game_source;
107
108 // Allow saving outside of the LOVE_APPDATA_FOLDER
109 // for release 'builds'
110 bool fused;
111 bool fusedSet;
112
113 // Search path for require
114 std::vector<std::string> requirePath;
115 std::vector<std::string> cRequirePath;
116
117 std::vector<std::string> allowedMountPaths;
118
119 std::map<std::string, Data*> mountedData;
120
121 std::unique_ptr<FileWatch> fileWatch_;
122 std::string lastWatchPath_;
123 std::string lastWatchRealPath_;
124
125 // Real directories mounted as virtual overlays (see mountRealDirectory).
126 std::vector<std::string> mountedRealDirs_;
127 std::mutex mountMu_;
128
129 // Owns the bytes backing a memory-mounted game archive (see setSourceFromMemory).
130 void* memoryArchive_ = nullptr;
131
132}; // Filesystem
133
134} // namespace physfs
135} // namespace filesystem
136} // namespace eve
filesystem::File * file
Light2D::Data * data
V3 dir
Definition TreeMesh.cpp:121
Data buffer paired with a filename (used for type identification).
Definition FileData.h:12
OS directory watch with a main-thread event queue. Desktop/mobile: backed by Poco::DirectoryWatcher (...
Definition FileWatch.h:23
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
PhysFS 文件系统后端实现(挂载/解挂、读写、热重载)。
Definition Filesystem.h:19
std::string getSaveDirectory() override
Gets the full path of the save folder.
void append(std::string filename, const void *data, int64_t size) const override
Append data to a file, creating it if it doesn't exist.
bool setSource(std::string source) override
Sets the path to the game source. This can only be set once.
bool setIdentity(std::string ident, bool appendToPath=false) override
Sets the name of the save folder.
std::string getRealDirectory(std::string filename) const override
Gets the real directory path containing the file.
bool setSourceFromMemory(const void *data, size_t size) override
Loads the game source from a packaged archive (.eve / zip) held entirely in memory and mounts it at "...
void setFused(bool fused) override
bool watch(std::string path) override
Watch a virtual or absolute OS path (file or directory). File watches monitor the parent directory an...
std::string getSource() const override
Gets the path to the game source. Returns a 0-length string if the source has not been set.
filesystem::File * newFile(std::string filename) const override
Creates a new file.
std::string getUserDirectory() override
Gets the user home directory.
bool createDirectory(std::string dir) override
Creates a directory. Write dir must be set.
bool remove(std::string file) override
Removes a file (or directory).
std::vector< std::string > getDirectoryItems(std::string dir) override
This "native" method returns a table of all files in a given directory.
bool unmount(std::string archive) override
std::string pollWatch() override
Pop next watch event kind: "added"|"removed"|"modified"|"movedFrom"|"movedTo". Empty string if queue ...
std::string getLastWatchRealPath() const override
bool mountRealDirectory(std::string realDir, std::string mountpoint, bool appendToPath=false) override
bool unwatch(std::string path) override
Stop watching a path previously passed to watch().
bool mount(std::string archive, std::string mountpoint, bool appendToPath=false) override
std::string getIdentity() const override
void init(const char *arg0) override
bool setupWriteDirectory() override
This sets up the save directory. If the it is already set up, nothing happens.
std::vector< std::string > & getCRequirePath() override
std::string getWorkingDirectory() override
Gets the current working directory.
FileData * read(std::string filename, int64_t size=File::ALL) const override
Reads data from a file.
bool unmountRealDirectory(std::string realDir) override
void allowMountingForPath(const std::string &path) override
Allows a full (OS-dependent) path to be used with Filesystem::mount.
void write(std::string filename, const void *data, int64_t size) const override
Write data to a file.
void setSymlinksEnabled(bool enable) override
Enable or disable symbolic link support in love.filesystem.
bool getInfo(std::string filepath, Info &info) const override
Gets information about the item at the specified filepath. Returns false if nothing exists at the pat...
bool areSymlinksEnabled() const override
Gets whether symbolic link support is enabled.
std::vector< std::string > & getRequirePath() override
std::string getSourceBaseDirectory() const override
Gets the full path to the directory containing the game source. For example if the game source is C:\...
std::string getAppdataDirectory() override
Gets the APPDATA directory. On Windows, this is the folder in the APPDATA% enviroment variable....
std::string getLastWatchPath() const override
Definition Build.cpp:11