Skip to content

FileSystem

class FileSystem

Base class for files and resources loaders.

The FileSystem class is used by the engine as an interface to load files and other resources. It provides basic functionalities needed by a file system.

You are able to implement your own FileSystem subclass to fit your needs, for example, reading files from a network drive or a custom storage system.

Functions

Name Description
~FileSystem Default destructor.
SetBasePath Changes the file system base path.
GetBasePath Returns the base path of the file system.
ResolvePath Resolves a relative path from the file system base path.
Exists Checks if an item (file or folder) exists on the file system.
IsDirectory Checks if an item (file or folder) is a directory.
Join Merge the given parts of the path into a single path, by joining them with the file system's path separator.
OpenFile Opens the file at the given path.
StartOpenFileSystem Opens the FileSystem.
TryFinalizeOpenFileSystem Checks if the FileSystem is loaded.
StartCloseFileSystem Stops the FileSystem.
TryFinalizeCloseFileSystem Checks if the FileSystem is stopped.

Function Details

Exists

[[nodiscard]] virtual bool Exists(const AmOsString& path) const = 0

Checks if an item (file or folder) exists on the file system.

Parameter path
The path to the item.
Return
true if the file exists, false otherwise.

GetBasePath

[[nodiscard]] virtual const AmOsString& GetBasePath() const = 0

Returns the base path of the file system.

Return
The base path for resolving relative paths from which the engine will load resources.

IsDirectory

[[nodiscard]] virtual bool IsDirectory(const AmOsString& path) const = 0

Checks if an item (file or folder) is a directory.

Parameter path
The path to the item.
Return
true if the file is a directory, false otherwise.

Join

[[nodiscard]] virtual AmOsString Join(const std::vector<AmOsString>& parts) const = 0

Merge the given parts of the path into a single path, by joining them with the file system's path separator.

Parameter parts
The parts of the path.
Return
A path concatenated with the given parts and the file system path separator.

OpenFile

[[nodiscard]] virtual std::shared_ptr<File> OpenFile(const AmOsString& path, eFileOpenMode mode = eFileOpenMode_Read) const = 0

Opens the file at the given path.

Parameter path
The path to the file to open.
Parameter mode
The file open mode.
Return
The opened file. The returned File implementation depends on the FileSystem implementation.

ResolvePath

[[nodiscard]] virtual AmOsString ResolvePath(const AmOsString& path) const = 0

Resolves a relative path from the file system base path.

Return
The resolved path.

SetBasePath

virtual void SetBasePath(const AmOsString& basePath) = 0

Changes the file system base path.

That path is interpreted by the implementation and doesn't necessarily have to be a real path on disk. It's just used as the base path for resolving relative paths from which the engine will load resources.

Parameter basePath
The file system base path.

StartCloseFileSystem

virtual void StartCloseFileSystem() = 0

Stops the FileSystem.

This function MUST be called when the FileSystem is no longer needed. It is used to stop the file system (eg: unmounting an archive).

Tip

For implementations, it is recommended to process the stopping in a separate thread.

The implementation is free to ignore this if not needed.

StartOpenFileSystem

virtual void StartOpenFileSystem() = 0

Opens the FileSystem.

This function MUST be called before any other actions in the file system. It is used to initialize the file system (eg: mounting an archive).

Tip

For implementations, It is recommended to process the initialization in a separate thread.

The implementation is free to ignore this if not needed.

TryFinalizeCloseFileSystem

virtual bool TryFinalizeCloseFileSystem() = 0

Checks if the FileSystem is stopped.

Since the StartCloseFileSystem() function is designed to be asynchronous, this function is used to check if the FileSystem has been successfully stopped.

Return
true if the FileSystem has been fully stopped, false otherwise.

TryFinalizeOpenFileSystem

virtual bool TryFinalizeOpenFileSystem() = 0

Checks if the FileSystem is loaded.

Since the StartOpenFileSystem() function is designed to be asynchronous, this function is used to check if the FileSystem has been successfully initialized.

Return
true if the FileSystem has been fully loaded, false otherwise.

~FileSystem

virtual ~FileSystem() = default

Default destructor.