TDME2  1.9.200
FileSystemInterface.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
9 
11 
12 using std::string;
13 using std::vector;
14 
17 
18 /**
19  * File system interface
20  * @author Andreas Drewke
21  */
23 {
24  /**
25  * Public destructor
26  */
27  virtual ~FileSystemInterface() {}
28 
29  /**
30  * Compose URI from path name and file name
31  * @param pathName path name
32  * @param fileName file name
33  * @return complete file URI with path name and file name
34  */
35  virtual const string composeURI(const string& pathName, const string& fileName) = 0;
36 
37  /**
38  * Return file size of given file
39  * @param pathName path name
40  * @param fileName file name
41  * @return file size
42  * @throws tdme::os::filesystem::FileSystemException
43  */
44  virtual uint64_t getFileSize(const string& pathName, const string& fileName) = 0;
45 
46  /**
47  * Get content as string
48  * @param pathName path name
49  * @param fileName file name
50  * @return string
51  * @throws tdme::os::filesystem::FileSystemException
52  */
53  virtual const string getContentAsString(const string& pathName, const string& fileName) = 0;
54 
55  /**
56  * Set content from string
57  * @param pathName path name
58  * @param fileName file name
59  * @param content content string
60  * @throws tdme::os::filesystem::FileSystemException
61  */
62  virtual void setContentFromString(const string& pathName, const string& fileName, const string& content) = 0;
63 
64  /**
65  * Get file content
66  * @param pathName path name
67  * @param fileName file name
68  * @param content content vector
69  * @throws tdme::os::filesystem::FileSystemException
70  */
71  virtual void getContent(const string& pathName, const string& fileName, vector<uint8_t>& content) = 0;
72 
73  /**
74  * Set file content
75  * @param pathName path name
76  * @param fileName file name
77  * @param content content vector
78  * @throws tdme::os::filesystem::FileSystemException
79  */
80  virtual void setContent(const string& pathName, const string& fileName, const vector<uint8_t>& content) = 0;
81 
82  /**
83  * Get file content as string array
84  * @param pathName path name
85  * @param fileName file name
86  * @param content content vector
87  * @throws tdme::os::filesystem::FileSystemException
88  */
89  virtual void getContentAsStringArray(const string& pathName, const string& fileName, vector<string>& content) = 0;
90 
91  /**
92  * Set file content as string array
93  * @param pathName path name
94  * @param fileName file name
95  * @param content string array
96  * @return byte array
97  * @throws tdme::os::filesystem::FileSystemException
98  */
99  virtual void setContentFromStringArray(const string& pathName, const string& fileName, const vector<string>& content) = 0;
100 
101  /**
102  * List files for given path and filter by a file name filter if not null
103  * @param pathName path name
104  * @param files files
105  * @param filter filter or null, this filter can be created on stack as ownership will not be taken over
106  * @param addDrives add drives to list(applies to Microsoft Windows only)
107  * @return file names
108  * @throws tdme::os::filesystem::FileSystemException
109  */
110  virtual void list(const string& pathName, vector<string>& files, FileNameFilter* filter = nullptr, bool addDrives = false) = 0;
111 
112  /**
113  * Check if file is a path
114  * @param uri uniform resource identifier
115  * @return if file is a path
116  * @throws tdme::os::filesystem::FileSystemException
117  */
118  virtual bool isPath(const string& uri) = 0;
119 
120  /**
121  * Check if file is a drive (applies to Microsoft Windows only)
122  * @param uri uniform resource identifier
123  * @return if file is a drive
124  */
125  virtual bool isDrive(const string& uri) = 0;
126 
127  /**
128  * Check if file exists
129  * @param uri uniform resource identifier
130  * @return bool if file exists
131  * @throws tdme::os::filesystem::FileSystemException
132  */
133  virtual bool exists(const string& uri) = 0;
134 
135  /**
136  * Returns if file is a executable file
137  * @param pathName path name
138  * @param fileName file name
139  * @return is executable
140  */
141  virtual bool isExecutable(const string& pathName, const string& fileName) = 0;
142 
143  /**
144  * Set up file to be an executable file
145  * @param pathName path name
146  * @param fileName file name
147  * @return success
148  * @throws tdme::os::filesystem::FileSystemException
149  */
150  virtual void setExecutable(const string& pathName, const string& fileName) = 0;
151 
152  /**
153  * Get canonical URI from given path name and file name
154  * @param pathName path name
155  * @param fileName file name
156  * @return canonical URI
157  */
158  virtual const string getCanonicalURI(const string& pathName, const string& fileName) = 0;
159 
160  /**
161  * Get current working path name
162  * @return current working path
163  * @throws tdme::os::filesystem::FileSystemException
164  */
165  virtual const string getCurrentWorkingPathName() = 0;
166 
167  /**
168  * Change path
169  * @param pathName path name
170  * @throws tdme::os::filesystem::FileSystemException
171  */
172  virtual void changePath(const string& pathName) = 0;
173 
174  /**
175  * Get path name
176  * @param uri uniform resource identifier
177  * @return canonical path
178  */
179  virtual const string getPathName(const string& uri) = 0;
180 
181  /**
182  * Get file name
183  * @param uri uniform resource identifier
184  * @return canonical path
185  */
186  virtual const string getFileName(const string& uri) = 0;
187 
188  /**
189  * Remove file extension, e.g. .dae, .fbx, ...
190  * @param fileName file name
191  * @return file name
192  */
193  virtual const string removeFileExtension(const string& fileName) = 0;
194 
195  /**
196  * Create path
197  * @param pathName path name
198  * @throws tdme::os::filesystem::FileSystemException
199  */
200  virtual void createPath(const string& pathName) = 0;
201 
202  /**
203  * Remove path
204  * @param pathName path name
205  * @param recursive remove recursive
206  * @return success
207  * @throws tdme::os::filesystem::FileSystemException
208  */
209  virtual void removePath(const string& pathName, bool recursive) = 0;
210 
211  /**
212  * Remove file
213  * @param pathName path name
214  * @param fileName file name
215  * @return success
216  * @throws tdme::os::filesystem::FileSystemException
217  */
218  virtual void removeFile(const string& pathName, const string& fileName) = 0;
219 
220  /**
221  * Rename file
222  * @param fileNameFrom file name from
223  * @param fileNameTo file name to
224  * @throws tdme::os::filesystem::FileSystemException
225  */
226  virtual void rename(const string& fileNameFrom, const string& fileNameTo) = 0;
227 
228  /**
229  * Reads a thumbnail attachment from binary file
230  * @param pathName path name
231  * @param fileName file name
232  * @param thumbnailAttachmentContent thumbnail attachment content
233  * @return attachment available
234  */
235  virtual bool getThumbnailAttachment(const string& pathName, const string& fileName, vector<uint8_t>& thumbnailAttachmentContent) = 0;
236 
237  /**
238  * Reads a thumbnail attachment from data vector
239  * @param content content
240  * @param thumbnailAttachmentContent thumbnail attachment content
241  * @return attachment available
242  */
243  virtual bool getThumbnailAttachment(const vector<uint8_t>& content, vector<uint8_t>& thumbnailAttachmentContent) = 0;
244 };
File system file name filter interface.
virtual bool isExecutable(const string &pathName, const string &fileName)=0
Returns if file is a executable file.
virtual void setContentFromStringArray(const string &pathName, const string &fileName, const vector< string > &content)=0
Set file content as string array.
virtual const string getPathName(const string &uri)=0
Get path name.
virtual void list(const string &pathName, vector< string > &files, FileNameFilter *filter=nullptr, bool addDrives=false)=0
List files for given path and filter by a file name filter if not null.
virtual void setExecutable(const string &pathName, const string &fileName)=0
Set up file to be an executable file.
virtual void getContent(const string &pathName, const string &fileName, vector< uint8_t > &content)=0
Get file content.
virtual const string getContentAsString(const string &pathName, const string &fileName)=0
Get content as string.
virtual bool isDrive(const string &uri)=0
Check if file is a drive (applies to Microsoft Windows only)
virtual void setContent(const string &pathName, const string &fileName, const vector< uint8_t > &content)=0
Set file content.
virtual bool exists(const string &uri)=0
Check if file exists.
virtual bool isPath(const string &uri)=0
Check if file is a path.
virtual uint64_t getFileSize(const string &pathName, const string &fileName)=0
Return file size of given file.
virtual void rename(const string &fileNameFrom, const string &fileNameTo)=0
Rename file.
virtual void changePath(const string &pathName)=0
Change path.
virtual void removeFile(const string &pathName, const string &fileName)=0
Remove file.
virtual const string getFileName(const string &uri)=0
Get file name.
virtual const string composeURI(const string &pathName, const string &fileName)=0
Compose URI from path name and file name.
virtual ~FileSystemInterface()
Public destructor.
virtual void setContentFromString(const string &pathName, const string &fileName, const string &content)=0
Set content from string.
virtual void removePath(const string &pathName, bool recursive)=0
Remove path.
virtual const string removeFileExtension(const string &fileName)=0
Remove file extension, e.g.
virtual const string getCurrentWorkingPathName()=0
Get current working path name.
virtual void getContentAsStringArray(const string &pathName, const string &fileName, vector< string > &content)=0
Get file content as string array.
virtual bool getThumbnailAttachment(const string &pathName, const string &fileName, vector< uint8_t > &thumbnailAttachmentContent)=0
Reads a thumbnail attachment from binary file.
virtual void createPath(const string &pathName)=0
Create path.
virtual bool getThumbnailAttachment(const vector< uint8_t > &content, vector< uint8_t > &thumbnailAttachmentContent)=0
Reads a thumbnail attachment from data vector.
virtual const string getCanonicalURI(const string &pathName, const string &fileName)=0
Get canonical URI from given path name and file name.