Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FileManager.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Containers/UnrealString.h"
7#include "Misc/DateTime.h"
8#include "GenericPlatform/GenericPlatformFile.h"
9
10// Maximum length of any filename. For now, we have no restriction. We would probably use shortening rules if we have to.
11#define MAX_UNREAL_FILENAME_LENGTH_DEPRECATED (PLATFORM_MAX_FILEPATH_LENGTH_DEPRECATED)
12
13
15{
22 FILEWRITE_Silent = 0x20
23};
24
25
27{
32};
33
34
36{
37 COPY_OK = 0x00,
38 COPY_Fail = 0x01,
40};
41
42
44{
45 virtual bool Poll( float Fraction )=0;
46};
47
48
50{
51 IO_READ = 0x01, // Open for reading
52 IO_WRITE = 0x02, // Open for writing
53 IO_APPEND = 0x40, // When writing, keep the existing data, set the filepointer to the end of the existing data
54};
55
56
58{
59protected:
60
61 /** Construtor. */
63
64public:
65
66 /** Singleton access, platform specific, also calls PreInit() **/
67 static IFileManager& Get();
68
69 /** Allow the file manager to handle the commandline */
70 virtual void ProcessCommandLineOptions() = 0;
71
72 /** Enables/disables the sandbox, if it is being used */
73 virtual void SetSandboxEnabled(bool bInEnabled) = 0;
74 /** Returns whether the sandbox is enabled or not */
75 virtual bool IsSandboxEnabled() const = 0;
76
77 /**
78 * Opens a file for reading and create an FArchive which can be used to read from it.
79 *
80 * @param Filename Path to the file to open
81 * @param ReadFlags An optional bitfield of optional flags. For flag values see @See EFileRead
82 *
83 * @return Returns a pointer to an FArchive when successful and a nullptr if the operation failed.
84 * Note that it is up to the caller to delete the FArchive when done.
85 */
86 virtual FArchive* CreateFileReader( const TCHAR* Filename, uint32 ReadFlags=0 )=0;
87
88 /**
89 * Opens a file for writing and create an FArchive which can be used to write to it.
90 *
91 * @param Filename Path to the desired location of the file
92 * @param WriteFlags An optional bitfield of optional flags. For flag values see @See EFileWrite
93 *
94 * @return Returns a pointer to an FArchive when successful and a nullptr if the operation failed.
95 * Note that it is up to the caller to delete the FArchive when done.
96 */
97 virtual FArchive* CreateFileWriter( const TCHAR* Filename, uint32 WriteFlags=0 )=0;
98
99 // If you're writing to a debug file, you should use CreateDebugFileWriter, and wrap the calling code in #if ALLOW_DEBUG_FILES.
102#endif
103
104 /** Checks if a file is read-only. */
105 virtual bool IsReadOnly( const TCHAR* Filename )=0;
106
107 /** Deletes a file. */
108 virtual bool Delete( const TCHAR* Filename, bool RequireExists=0, bool EvenReadOnly=0, bool Quiet=0 )=0;
109
110 /** Copies a file. */
111 virtual uint32 Copy( const TCHAR* Dest, const TCHAR* Src, bool Replace=1, bool EvenIfReadOnly=0, bool Attributes=0, FCopyProgress* Progress = nullptr, EFileRead ReadFlags=FILEREAD_None, EFileWrite WriteFlags=FILEWRITE_None)=0; // utility
112
113 /** Moves/renames a file. */
114 virtual bool Move( const TCHAR* Dest, const TCHAR* Src, bool Replace=1, bool EvenIfReadOnly=0, bool Attributes=0, bool bDoNotRetryOrError=0 )=0;
115
116 /** Checks if a file exists */
117 virtual bool FileExists( const TCHAR* Filename )=0;
118
119 /** Checks if a directory exists. */
120 virtual bool DirectoryExists( const TCHAR* InDirectory )=0;
121
122 /** Creates a directory. */
123 virtual bool MakeDirectory( const TCHAR* Path, bool Tree=0 )=0;
124
125 /** Deletes a directory. */
126 virtual bool DeleteDirectory( const TCHAR* Path, bool RequireExists=0, bool Tree=0 )=0;
127
128 /** Return the stat data for the given file or directory. Check the FFileStatData::bIsValid member before using the returned data */
129 virtual FFileStatData GetStatData(const TCHAR* FilenameOrDirectory) = 0;
130
131 /** Finds file or directories. */
132 virtual void FindFiles( TArray<FString>& FileNames, const TCHAR* Filename, bool Files, bool Directories)=0;
133
134 /**
135 * Finds all the files within the given directory, with optional file extension filter.
136 *
137 * @param[out] FoundFiles All the files that matched the optional FileExtension filter, or all files if none was specified.
138 *
139 * @param[in] Directory The absolute path to the directory to search. Ex: "C:\UE4\Pictures"
140 *
141 * @param[in] FileExtension If FileExtension is NULL, or an empty string "" then all files are found.
142 * Otherwise FileExtension can be of the form .EXT or just EXT and only files with that extension will be returned.
143 */
144 virtual void FindFiles(TArray<FString>& FoundFiles, const TCHAR* Directory, const TCHAR* FileExtension = nullptr) = 0;
145
146 /** Finds file or directories recursively. */
147 virtual void FindFilesRecursive( TArray<FString>& FileNames, const TCHAR* StartDirectory, const TCHAR* Filename, bool Files, bool Directories, bool bClearFileNames=true) = 0; // utility
148
149 /**
150 * Call the Visit function of the visitor once for each file or directory in a single directory. This function does not explore subdirectories.
151 * @param Directory The directory to iterate the contents of.
152 * @param Visitor Visitor to call for each element of the directory
153 * @return false if the directory did not exist or if the visitor returned false.
154 **/
155 virtual bool IterateDirectory(const TCHAR* Directory, IPlatformFile::FDirectoryVisitor& Visitor) = 0;
156
157 /**
158 * Call the visitor once for each file or directory in a single directory. This function does not explore subdirectories.
159 * @param Directory The directory to iterate the contents of.
160 * @param Visitor Visitor to call for each element of the directory (see FDirectoryVisitor::Visit for the signature)
161 * @return false if the directory did not exist or if the visitor returned false.
162 **/
163 virtual bool IterateDirectory(const TCHAR* Directory, IPlatformFile::FDirectoryVisitorFunc Visitor) = 0;
164
165 /**
166 * Call the Visit function of the visitor once for each file or directory in a directory tree. This function explores subdirectories.
167 * @param Directory The directory to iterate the contents of, recursively.
168 * @param Visitor Visitor to call for each element of the directory and each element of all subdirectories.
169 * @return false if the directory did not exist or if the visitor returned false.
170 **/
171 virtual bool IterateDirectoryRecursively(const TCHAR* Directory, IPlatformFile::FDirectoryVisitor& Visitor) = 0;
172
173 /**
174 * Call the Visit function of the visitor once for each file or directory in a directory tree. This function explores subdirectories.
175 * @param Directory The directory to iterate the contents of, recursively.
176 * @param Visitor Visitor to call for each element of the directory and each element of all subdirectories (see FDirectoryVisitor::Visit for the signature).
177 * @return false if the directory did not exist or if the visitor returned false.
178 **/
179 virtual bool IterateDirectoryRecursively(const TCHAR* Directory, IPlatformFile::FDirectoryVisitorFunc Visitor) = 0;
180
181 /**
182 * Call the Visit function of the visitor once for each file or directory in a single directory. This function does not explore subdirectories.
183 * @param Directory The directory to iterate the contents of.
184 * @param Visitor Visitor to call for each element of the directory
185 * @return false if the directory did not exist or if the visitor returned false.
186 **/
187 virtual bool IterateDirectoryStat(const TCHAR* Directory, IPlatformFile::FDirectoryStatVisitor& Visitor) = 0;
188
189 /**
190 * Call the visitor once for each file or directory in a single directory. This function does not explore subdirectories.
191 * @param Directory The directory to iterate the contents of.
192 * @param Visitor Visitor to call for each element of the directory (see FDirectoryStatVisitor::Visit for the signature)
193 * @return false if the directory did not exist or if the visitor returned false.
194 **/
195 virtual bool IterateDirectoryStat(const TCHAR* Directory, IPlatformFile::FDirectoryStatVisitorFunc Visitor) = 0;
196
197 /**
198 * Call the Visit function of the visitor once for each file or directory in a directory tree. This function explores subdirectories.
199 * @param Directory The directory to iterate the contents of, recursively.
200 * @param Visitor Visitor to call for each element of the directory and each element of all subdirectories.
201 * @return false if the directory did not exist or if the visitor returned false.
202 **/
203 virtual bool IterateDirectoryStatRecursively(const TCHAR* Directory, IPlatformFile::FDirectoryStatVisitor& Visitor) = 0;
204
205 /**
206 * Call the Visit function of the visitor once for each file or directory in a directory tree. This function explores subdirectories.
207 * @param Directory The directory to iterate the contents of, recursively.
208 * @param Visitor Visitor to call for each element of the directory and each element of all subdirectories (see FDirectoryStatVisitor::Visit for the signature).
209 * @return false if the directory did not exist or if the visitor returned false.
210 **/
211 virtual bool IterateDirectoryStatRecursively(const TCHAR* Directory, IPlatformFile::FDirectoryStatVisitorFunc Visitor) = 0;
212
213 /** Gets the age of a file measured in seconds. */
214 virtual double GetFileAgeSeconds( const TCHAR* Filename )=0;
215
216 /**
217 * @return the modification time of the given file (or FDateTime::MinValue() on failure)
218 */
219 virtual FDateTime GetTimeStamp( const TCHAR* Path ) = 0;
220
221 /**
222 * @param[in] PathA The first given file
223 * @param[in] PathB The second given file
224 * @param[out] OutTimeStampA the modification time of the first given file (or FDateTime::MinValue() on failure)
225 * @param[out] OutTimeStampB the modification time of the second given file (or FDateTime::MinValue() on failure)
226 */
227 virtual void GetTimeStampPair(const TCHAR* PathA, const TCHAR* PathB, FDateTime& OutTimeStampA, FDateTime& OutTimeStampB) = 0;
228
229 /**
230 * Sets the modification time of the given file
231 */
232 virtual bool SetTimeStamp( const TCHAR* Path, FDateTime TimeStamp ) = 0;
233
234 /**
235 * @return the last access time of the given file (or FDateTime::MinValue() on failure)
236 */
237 virtual FDateTime GetAccessTimeStamp( const TCHAR* Filename ) = 0;
238
239 /**
240 * Converts passed in filename to use a relative path.
241 *
242 * @param Filename filename to convert to use a relative path
243 *
244 * @return filename using relative path
245 */
246 virtual FString ConvertToRelativePath( const TCHAR* Filename ) = 0;
247
248 /**
249 * Converts passed in filename to use an absolute path (for reading)
250 *
251 * @param Filename filename to convert to use an absolute path, safe to pass in already using absolute path
252 *
253 * @return filename using absolute path
254 */
255 virtual FString ConvertToAbsolutePathForExternalAppForRead( const TCHAR* Filename ) = 0;
256
257 /**
258 * Converts passed in filename to use an absolute path (for writing)
259 *
260 * @param Filename filename to convert to use an absolute path, safe to pass in already using absolute path
261 *
262 * @return filename using absolute path
263 */
264 virtual FString ConvertToAbsolutePathForExternalAppForWrite( const TCHAR* Filename ) = 0;
265
266 /**
267 * Returns the size of a file. (Thread-safe)
268 *
269 * @param Filename Platform-independent Unreal filename.
270 * @return File size in bytes or INDEX_NONE if the file didn't exist.
271 **/
272 virtual int64 FileSize( const TCHAR* Filename )=0;
273
274 /**
275 * Sends a message to the file server, and will block until it's complete. Will return
276 * immediately if the file manager doesn't support talking to a server.
277 *
278 * @param Message The string message to send to the server
279 *
280 * @return true if the message was sent to server and it returned success, or false if there is no server, or the command failed
281 */
282 virtual bool SendMessageToServer(const TCHAR* Message, IPlatformFile::IFileServerMessageHandler* Handler)=0;
283
284 /**
285 * For case insensitive filesystems, returns the full path of the file with the same case as in the filesystem.
286 *
287 * @param Filename Filename to query
288 *
289 * @return Filename with the same case as in the filesystem.
290 */
291 virtual FString GetFilenameOnDisk(const TCHAR* Filename) = 0;
292};
#define ALLOW_DEBUG_FILES
Definition Build.h:320
ECopyResult
Definition Enums.h:13954
EFileOpenFlags
Definition Enums.h:11741
EFileWrite
Definition Enums.h:6335
EFileRead
Definition Enums.h:6327
@ COPY_OK
Definition FileManager.h:37
@ COPY_Canceled
Definition FileManager.h:39
@ COPY_Fail
Definition FileManager.h:38
@ FILEWRITE_Append
Definition FileManager.h:20
@ FILEWRITE_AllowRead
Definition FileManager.h:21
@ FILEWRITE_NoFail
Definition FileManager.h:17
@ FILEWRITE_None
Definition FileManager.h:16
@ FILEWRITE_EvenIfReadOnly
Definition FileManager.h:19
@ FILEWRITE_NoReplaceExisting
Definition FileManager.h:18
@ FILEWRITE_Silent
Definition FileManager.h:22
@ FILEREAD_None
Definition FileManager.h:28
@ FILEREAD_NoFail
Definition FileManager.h:29
@ FILEREAD_AllowWrite
Definition FileManager.h:31
@ FILEREAD_Silent
Definition FileManager.h:30
@ IO_APPEND
Definition FileManager.h:53
@ IO_WRITE
Definition FileManager.h:52
@ IO_READ
Definition FileManager.h:51
#define PLATFORM_MAX_FILEPATH_LENGTH_DEPRECATED
Definition Platform.h:289
virtual FArchive * CreateFileWriter(const TCHAR *Filename, uint32 WriteFlags=0)=0
virtual void FindFiles(TArray< FString > &FoundFiles, const TCHAR *Directory, const TCHAR *FileExtension=nullptr)=0
virtual FDateTime GetTimeStamp(const TCHAR *Path)=0
virtual void ProcessCommandLineOptions()=0
virtual FString ConvertToRelativePath(const TCHAR *Filename)=0
virtual bool IterateDirectoryRecursively(const TCHAR *Directory, IPlatformFile::FDirectoryVisitorFunc Visitor)=0
virtual bool Move(const TCHAR *Dest, const TCHAR *Src, bool Replace=1, bool EvenIfReadOnly=0, bool Attributes=0, bool bDoNotRetryOrError=0)=0
virtual FArchive * CreateFileReader(const TCHAR *Filename, uint32 ReadFlags=0)=0
virtual bool IterateDirectoryStatRecursively(const TCHAR *Directory, IPlatformFile::FDirectoryStatVisitorFunc Visitor)=0
virtual bool IterateDirectoryStat(const TCHAR *Directory, IPlatformFile::FDirectoryStatVisitorFunc Visitor)=0
virtual bool IterateDirectory(const TCHAR *Directory, IPlatformFile::FDirectoryVisitorFunc Visitor)=0
virtual bool MakeDirectory(const TCHAR *Path, bool Tree=0)=0
virtual bool DeleteDirectory(const TCHAR *Path, bool RequireExists=0, bool Tree=0)=0
virtual FString ConvertToAbsolutePathForExternalAppForWrite(const TCHAR *Filename)=0
virtual uint32 Copy(const TCHAR *Dest, const TCHAR *Src, bool Replace=1, bool EvenIfReadOnly=0, bool Attributes=0, FCopyProgress *Progress=nullptr, EFileRead ReadFlags=FILEREAD_None, EFileWrite WriteFlags=FILEWRITE_None)=0
static IFileManager & Get()
virtual bool DirectoryExists(const TCHAR *InDirectory)=0
virtual void SetSandboxEnabled(bool bInEnabled)=0
virtual FString GetFilenameOnDisk(const TCHAR *Filename)=0
virtual bool FileExists(const TCHAR *Filename)=0
virtual FDateTime GetAccessTimeStamp(const TCHAR *Filename)=0
virtual FFileStatData GetStatData(const TCHAR *FilenameOrDirectory)=0
virtual bool IterateDirectoryStatRecursively(const TCHAR *Directory, IPlatformFile::FDirectoryStatVisitor &Visitor)=0
virtual double GetFileAgeSeconds(const TCHAR *Filename)=0
virtual bool SetTimeStamp(const TCHAR *Path, FDateTime TimeStamp)=0
virtual bool IterateDirectoryRecursively(const TCHAR *Directory, IPlatformFile::FDirectoryVisitor &Visitor)=0
virtual FString ConvertToAbsolutePathForExternalAppForRead(const TCHAR *Filename)=0
virtual int64 FileSize(const TCHAR *Filename)=0
virtual void FindFiles(TArray< FString > &FileNames, const TCHAR *Filename, bool Files, bool Directories)=0
virtual bool IsReadOnly(const TCHAR *Filename)=0
virtual void GetTimeStampPair(const TCHAR *PathA, const TCHAR *PathB, FDateTime &OutTimeStampA, FDateTime &OutTimeStampB)=0
virtual bool IsSandboxEnabled() const =0
virtual bool IterateDirectoryStat(const TCHAR *Directory, IPlatformFile::FDirectoryStatVisitor &Visitor)=0
virtual void FindFilesRecursive(TArray< FString > &FileNames, const TCHAR *StartDirectory, const TCHAR *Filename, bool Files, bool Directories, bool bClearFileNames=true)=0
virtual bool IterateDirectory(const TCHAR *Directory, IPlatformFile::FDirectoryVisitor &Visitor)=0
virtual bool SendMessageToServer(const TCHAR *Message, IPlatformFile::IFileServerMessageHandler *Handler)=0
virtual bool Delete(const TCHAR *Filename, bool RequireExists=0, bool EvenReadOnly=0, bool Quiet=0)=0
TFunctionRef< bool(const TCHAR *, const FFileStatData &) FDirectoryStatVisitorFunc)
TFunctionRef< bool(const TCHAR *, bool) FDirectoryVisitorFunc)
virtual bool Poll(float Fraction)=0