Berserk
Classes | Public Types | Public Member Functions | List of all members
FileSystem Class Referencefinal

Target platform file system access and file utils. More...

#include <FileSystem.hpp>

Classes

struct  Entry
 Directory entry. More...
 

Public Types

enum class  EntryType { File , Directory , Link , Unknown }
 Type of directory entry. More...
 

Public Member Functions

BRK_API FileSystem ()
 
BRK_API ~FileSystem ()=default
 
BRK_API std::FILE * OpenFile (const String &filepath, const String &mode)
 Open file by file path and mode. More...
 
BRK_API void CloseFile (std::FILE *file)
 Close opened file. More...
 
BRK_API Ref< DataReadFile (const String &filepath)
 Read file by file path. More...
 
BRK_API void AddSearchPath (String path)
 Add search path. More...
 
BRK_API void SetSearchPaths (std::vector< String > searchPaths)
 Set search paths for paths resolution. More...
 
BRK_API String GetFullFilePath (const String &filename)
 Get full path for specified file. More...
 
BRK_API String GetFullDirPath (const String &dirname)
 Get full path for specified directory. More...
 
BRK_API String GetFileExtension (const String &filename)
 Retrieve file extension. More...
 
BRK_API String GetFileName (const String &filename, bool withoutExtension=false)
 Get file name from file path. More...
 
BRK_API bool IsAbsolutePath (const String &filename)
 Check is passed path is absolute. More...
 
BRK_API bool IsFileExists (const String &filename)
 Check if specified file exists. More...
 
BRK_API bool IsDirExists (const String &dirname)
 Check if specified directory exists. More...
 
BRK_API std::vector< EntryListDir (const String &dir)
 List entries of the specified directory. More...
 
BRK_API const StringGetExecutablePath ()
 Path to the executable file of the application. More...
 
BRK_API String GetExecutableDir () const
 Path to the executable directory where file of the application is located. More...
 

Detailed Description

Target platform file system access and file utils.

Member Enumeration Documentation

◆ EntryType

enum FileSystem::EntryType
strong

Type of directory entry.

Enumerator
File 

Simple file

Directory 

Directory

Link 

Link or hyper-link for a file/directory

Unknown 

Entry has unknown type

Constructor & Destructor Documentation

◆ FileSystem()

BRK_NS_BEGIN FileSystem::FileSystem ( )

InitCore file system

◆ ~FileSystem()

BRK_API FileSystem::~FileSystem ( )
default

Member Function Documentation

◆ AddSearchPath()

void FileSystem::AddSearchPath ( String  path)

Add search path.

Adds search path used to search engine files. New path is added as last path in the list of search paths (with lower priority). Adding new path invalidates previously cached path lookups.

Parameters
pathSearch path to add; must be not empty

◆ CloseFile()

void FileSystem::CloseFile ( std::FILE *  file)

Close opened file.

Parameters
fileFile handle to close

◆ GetExecutableDir()

String FileSystem::GetExecutableDir ( ) const

Path to the executable directory where file of the application is located.

Returns
Path

◆ GetExecutablePath()

const String & FileSystem::GetExecutablePath ( )

Path to the executable file of the application.

Returns
Path

◆ GetFileExtension()

String FileSystem::GetFileExtension ( const String filename)

Retrieve file extension.

Parameters
filenameFile name to get extension
Returns
Extension if present

◆ GetFileName()

String FileSystem::GetFileName ( const String filename,
bool  withoutExtension = false 
)

Get file name from file path.

Get file name from relative or absolute path to the file. This function preserves file extension.

Parameters
filenameRelative or absolute path
withoutExtensionPass true to remove extension
Returns
File name

◆ GetFullDirPath()

String FileSystem::GetFullDirPath ( const String dirname)

Get full path for specified directory.

Attempts to resolve passed relative directory path using configured search paths of the file system class.

Uses cache of resolved entries to speed-up look ups.

Parameters
dirnameRelative or absolute path
Returns
Full path if resolved

◆ GetFullFilePath()

String FileSystem::GetFullFilePath ( const String filename)

Get full path for specified file.

Attempts to resolve passed relative file path using configured search paths of the file system class.

Uses cache of resolved entries to speed-up look ups.

Parameters
filenameRelative or absolute path
Returns
Full path if resolved

◆ IsAbsolutePath()

bool FileSystem::IsAbsolutePath ( const String filename)

Check is passed path is absolute.

Parameters
filenamePath to check
Returns
True if absolute

◆ IsDirExists()

bool FileSystem::IsDirExists ( const String dirname)

Check if specified directory exists.

Note
Uses search path to resolve relative path if passed
Parameters
dirnameRelative or absolute path of the directory
Returns
True if directory exists

◆ IsFileExists()

bool FileSystem::IsFileExists ( const String filename)

Check if specified file exists.

Note
Uses search path to resolve relative path if passed
Parameters
filenameRelative or absolute path of the file
Returns
True if file exists

◆ ListDir()

std::vector< FileSystem::Entry > FileSystem::ListDir ( const String dir)

List entries of the specified directory.

Note
Uses search path to resolve relative path if passed
Parameters
dirRelative or absolute path of the directory
Returns
List of directory entries

◆ OpenFile()

std::FILE * FileSystem::OpenFile ( const String filepath,
const String mode 
)

Open file by file path and mode.

Opens file using provided full absolute file path. Automatically converts string path to required encoding of platform.

Parameters
filepathAbsolute (full) path to file
modeMode to open file
Returns
File handle or null if failed open

◆ ReadFile()

Ref< Data > FileSystem::ReadFile ( const String filepath)

Read file by file path.

Attempts to open and read content of the file, specified by file path. File content is read into allocated data container. If fails to open or read file, returns null.

Parameters
filepathAbsolute (full) path to file
Returns
Data or null if failed read file

◆ SetSearchPaths()

void FileSystem::SetSearchPaths ( std::vector< String searchPaths)

Set search paths for paths resolution.

Uses passed search paths to resolve relative file and directory paths to full paths.

Parameters
searchPathsList of search paths

The documentation for this class was generated from the following files: