3#include <Foundation/Basics.h>
4#include <Foundation/Communication/Event.h>
5#include <Foundation/IO/FileEnums.h>
6#include <Foundation/Strings/String.h>
7#include <Foundation/Strings/StringBuilder.h>
8#include <Foundation/Threading/AtomicInteger.h>
9#include <Foundation/Threading/Mutex.h>
10#include <Foundation/Time/Timestamp.h>
14#if PL_ENABLED(PL_USE_POSIX_FILE_API)
15# include <Foundation/IO/Implementation/Posix/OSFileDeclarations_posix.h>
16#elif PL_ENABLED(PL_PLATFORM_WINDOWS)
17# include <Foundation/IO/Implementation/Win/OSFileDeclarations_win.h>
53 plUInt64 m_uiFileSize = 0;
56 bool m_bIsDirectory =
false;
59#if PL_ENABLED(PL_SUPPORTS_FILE_ITERATORS) || defined(PL_DOCS)
61struct plFileIterationData;
65 using StorageType = plUInt8;
69 Recursive = PL_BIT(0),
70 ReportFiles = PL_BIT(1),
71 ReportFolders = PL_BIT(2),
73 ReportFilesRecursive = Recursive | ReportFiles,
74 ReportFoldersRecursive = Recursive | ReportFolders,
75 ReportFilesAndFoldersRecursive = Recursive | ReportFiles | ReportFolders,
77 Default = ReportFilesAndFoldersRecursive,
82 StorageType Recursive : 1;
83 StorageType ReportFiles : 1;
84 StorageType ReportFolders : 1;
142 plInt32 InternalNext();
153 plFileIterationData m_Data;
157 plUInt32 m_uiCurrentStartFolder = 0;
171 PL_DISALLOW_COPY_AND_ASSIGN(
plOSFile);
187 plResult Write(
const void* pBuffer, plUInt64 uiBytes);
190 plUInt64 Read(
void* pBuffer, plUInt64 uiBytes);
199 plUInt64 GetFilePosition()
const;
205 plUInt64 GetFileSize()
const;
251#if PL_ENABLED(PL_SUPPORTS_FILE_STATS) || defined(PL_DOCS)
255# if (PL_ENABLED(PL_SUPPORTS_CASE_INSENSITIVE_PATHS) && PL_ENABLED(PL_SUPPORTS_UNRESTRICTED_FILE_ACCESS)) || defined(PL_DOCS)
262#if (PL_ENABLED(PL_SUPPORTS_FILE_ITERATORS) && PL_ENABLED(PL_SUPPORTS_FILE_STATS)) || defined(PL_DOCS)
339 plInt32 m_iFileID = 0;
351 bool m_bSuccess =
true;
357 plUInt64 m_uiBytesAccessed = 0;
370 static Event s_FileEvents;
375 void InternalClose();
376 plResult InternalWrite(
const void* pBuffer, plUInt64 uiBytes);
377 plUInt64 InternalRead(
void* pBuffer, plUInt64 uiBytes);
378 plUInt64 InternalGetFilePosition()
const;
382 static bool InternalExistsDirectory(
plStringView sDirectory);
388#if PL_ENABLED(PL_SUPPORTS_FILE_STATS)
398 bool m_bRetryOnSharingViolation =
true;
407 plOSFileData m_FileData;
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition DynamicArray.h:81
An plFileSystemIterator allows to iterate over all files in a certain directory.
Definition OSFile.h:94
bool IsValid() const
Returns true if the iterator currently points to a valid file entry.
void StartMultiFolderSearch(plArrayPtr< plString > startFolders, plStringView sSearchTerm, plBitflags< plFileSystemIteratorFlags > flags=plFileSystemIteratorFlags::Default)
The same as StartSearch() but executes the same search on multiple folders.
void StartSearch(plStringView sSearchTerm, plBitflags< plFileSystemIteratorFlags > flags=plFileSystemIteratorFlags::Default)
Starts a search at the given folder. Use * and ? as wildcards.
void Next()
Advances the iterator to the next file object. Might recurse into sub-folders.
const plFileStats & GetStats() const
Returns the file stats of the current object that the iterator points to.
Definition OSFile.h:130
const plStringView GetCurrentSearchTerm() const
Returns the search string with which StartSearch() was called.
Definition OSFile.h:122
void SkipFolder()
The same as 'Next' only that the current folder will not be recursed into.
const plStringBuilder & GetCurrentPath() const
Returns the current path in which files are searched. Changes when 'Next' moves in or out of a sub-fo...
Definition OSFile.h:127
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
This is an abstraction for the most important file operations.
Definition OSFile.h:170
static void GatherAllItemsInFolder(plDynamicArray< plFileStats > &out_itemList, plStringView sFolder, plBitflags< plFileSystemIteratorFlags > flags=plFileSystemIteratorFlags::Default)
Returns the plFileStats for all files and folders in the given folder.
static plStringView GetApplicationPath()
Returns the full path to the application binary.
static plResult GetFileCasing(plStringView sFileOrFolder, plStringBuilder &out_sCorrectSpelling)
Useful on systems that are not strict about the casing of file names. Determines the correct name of ...
static plResult GetFileStats(plStringView sFileOrFolder, plFileStats &out_stats)
Gets the stats about the given file or folder. Returns false, if the stats could not be determined.
static plString GetUserDocumentsFolder(plStringView sSubFolder={})
Returns the folder into which the user may want to store documents. Append a sub-folder for your appl...
static plString GetTempDataFolder(plStringView sSubFolder={})
Returns the folder into which temp data may be written.
const plOSFileData & GetFileData() const
This will return the platform specific file data (handles etc.), if you really want to be able to wre...
Definition OSFile.h:208
static const plString GetCurrentWorkingDirectory()
Returns the processes current working directory (CWD).
static plResult DeleteFolder(plStringView sFolder)
Deletes all files recursively in szFolder.
static void RemoveEventHandler(Event::Handler handler)
Unregisters a previously registered receiver. It is an error to unregister a receiver that was not re...
Definition OSFile.h:366
static plResult CopyFolder(plStringView sSourceFolder, plStringView sDestinationFolder, plDynamicArray< plString > *out_pFilesCopied=nullptr)
Copies szSourceFolder to szDestinationFolder. Overwrites existing files.
static plString GetUserDataFolder(plStringView sSubFolder={})
Returns the folder into which user data may be safely written. Append a sub-folder for your applicati...
static void AddEventHandler(Event::Handler handler)
Allows to register a function as an event receiver. All receivers will be notified in the order that ...
Definition OSFile.h:363
plStringView GetOpenFileName() const
Returns the name of the file that is currently opened. Returns an empty string, if no file is open.
Definition OSFile.h:196
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
The timestamp class encapsulates a date in time as microseconds since Unix epoch.
Definition Timestamp.h:23
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
Defines in which mode to open a file.
Definition OSFile.h:22
Enum
Definition OSFile.h:24
@ Append
Open file for appending (writing, but always only at the end, already existing data is preserved).
Definition OSFile.h:28
@ Write
Open file for writing (already existing data is discarded).
Definition OSFile.h:27
@ None
None, only used internally.
Definition OSFile.h:25
@ Read
Open file for reading.
Definition OSFile.h:26
Enum
Definition FileEnums.h:18
Enum
Definition FileEnums.h:7
@ Default
Results in 'Exclusive' when requesting write access and 'SharedReads' when requesting read access....
Definition FileEnums.h:8
Holds the stats for a file.
Definition OSFile.h:34
plString m_sName
The name of the file or folder that the stats are for. Does not include the parent path to it....
Definition OSFile.h:47
plStringBuilder m_sParentPath
Path to the parent folder. Append m_sName to m_sParentPath to obtain the full path.
Definition OSFile.h:43
plTimestamp m_LastModificationTime
The last modification time as an UTC timestamp since Unix epoch.
Definition OSFile.h:50
The data that is sent through the event interface.
Definition OSFile.h:333
plTime m_Duration
How long the operation took.
Definition OSFile.h:354
plStringView m_sFile
The name of the file that was operated upon.
Definition OSFile.h:342
plStringView m_sFile2
If a second file was operated upon (FileCopy), that is the second file name.
Definition OSFile.h:345
Describes the types of events that plOSFile sends.
Definition OSFile.h:313
Enum
Definition OSFile.h:315
@ MakeDir
A path has been created (recursive directory creation).
Definition OSFile.h:324
@ FileCopy
A file has been copied to another location.
Definition OSFile.h:325
@ FileExists
A check whether a file exists has been done.
Definition OSFile.h:319
@ FileRead
From an open file data was read.
Definition OSFile.h:322
@ FileCasing
The exact spelling of a file/path is requested.
Definition OSFile.h:327
@ FileDelete
A file was attempted to be deleted.
Definition OSFile.h:321
@ FileClose
An open file has been closed.
Definition OSFile.h:318
@ FileStat
The stats of a file are queried.
Definition OSFile.h:326
@ FileOpen
A file has been (attempted) to open.
Definition OSFile.h:317
@ DirectoryExists
A check whether a directory exists has been done.
Definition OSFile.h:320
@ FileWrite
Data was written to an open file.
Definition OSFile.h:323
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12