![]() |
Blamite Game Engine - Strings
00427.01.12.25.2146.blamite
A library containing general purpose utilities and classes for use in multiple projects.
|
Utilities relating to reading/writing to and from files. More...
Functions | |
STRINGS_API bool | FileExists (std::string name) |
Checks if the specified file or directory exists. More... | |
STRINGS_API bool | IsFile (std::string path) |
Checks if a given path refers to a regular file. More... | |
STRINGS_API bool | IsDirectory (std::string path) |
Checks if a given path refers to a directory. More... | |
STRINGS_API bool | CreateNewFile (std::string filename, std::string file_contents) |
Creates a file with the specified contents, or overwrites an existing file if it already exists. More... | |
STRINGS_API void | ValidatePath (std::string path) |
Validates that the specified path exists. More... | |
STRINGS_API void | OpenGameDirectory () |
Opens the engine's game directory in Windows Explorer. More... | |
STRINGS_API std::string | GetApplicationDir () |
Retrieves the application's working directory. More... | |
STRINGS_API bool | ReadBinaryFile (std::string path, void **data, int64_t *size) |
Reads a file as raw binary data. More... | |
STRINGS_API bool | ReadFile (std::string path, void **data, int64_t *size) |
Reads a file as text data, with a NULL byte placed at the end of the file contents. More... | |
STRINGS_API std::vector< std::string > | GetFileContentsAsLines (std::string path) |
Reads a file as a list of strings. More... | |
STRINGS_API std::string | GetFileContentsAsString (std::string path) |
Reads a file as a string. More... | |
STRINGS_API std::vector< std::string > | GetFileList (std::string path) |
Retrieves the list of all files in a given directory. More... | |
STRINGS_API std::vector< std::string > | GetDirectoryList (std::string path) |
Retrieves the list of all folders in the root of a given directory. More... | |
STRINGS_API std::vector< std::string > | GetDeepFileList (std::string path) |
Retrieves the list of all files within a given directory. More... | |
STRINGS_API std::string | NormalizePath (std::string path) |
Normalizes a path string. More... | |
STRINGS_API std::string | GetFileName (std::string path) |
Retrieves the name of the file or folder that a given path refers to. More... | |
STRINGS_API std::string | GetFileNameWithoutExtension (std::string path) |
Retrieves the name of the file or folder that a given path refers to, excluding the file's extension (if applicable). More... | |
STRINGS_API std::string | GetFileExtension (std::string path) |
Retrieves the extension of a file. More... | |
STRINGS_API std::string | GetFileExtension (std::string path, bool skip_file_check) |
Retrieves the extension of a file. More... | |
STRINGS_API std::string | GetContainingFolder (std::string path) |
Retrieves the containing folder of a given file or directory. More... | |
STRINGS_API std::string | GetContainingFolder (std::string path, bool require_exists) |
Retrieves the containing folder of a given file or directory. More... | |
STRINGS_API std::string | GetEngineDataRoot () |
Retrieves the root folder for all game engine and editing kit user data files. More... | |
STRINGS_API void | ExploreDirectory (std::string path) |
Opens a directory within the system file explorer. More... | |
STRINGS_API std::string | GetAbsolutePathFromRelative (std::string relative_path) |
Converts a relative path to an absolute file path. More... | |
STRINGS_API std::string | GetRelativePathFromAbsolute (std::string absolute_path) |
Converts an absolute path to a relative file path. More... | |
STRINGS_API bool | WriteBinaryFile (std::string file_path, void *data, int64_t size) |
Creates a file with the specified contents, or overwrites an existing file if it already exists. More... | |
STRINGS_API void | OpenFile (std::string file_path) |
Opens a file with its default application. More... | |
STRINGS_API std::string | GetModuleFilePath (HMODULE module_handle) |
Retrieves the file path for a given module (ie, a DLL or executable). More... | |
STRINGS_API uint64_t | GetFileSize (std::string file_path) |
Retrives the size of a file, in bytes. More... | |
Utilities relating to reading/writing to and from files.
bool BlamStrings::Utils::IO::CreateNewFile | ( | std::string | filename, |
std::string | file_contents | ||
) |
Creates a file with the specified contents, or overwrites an existing file if it already exists.
filename | - The path to the file to create. |
file_contents | - The contents to write to the file. |
true
if the file was created successfully, otherwise returns false
. void BlamStrings::Utils::IO::ExploreDirectory | ( | std::string | path | ) |
Opens a directory within the system file explorer.
bool BlamStrings::Utils::IO::FileExists | ( | std::string | name | ) |
Checks if the specified file or directory exists.
name | - The path to the file or directory. |
true
if the file exists, false
if it does not std::string BlamStrings::Utils::IO::GetAbsolutePathFromRelative | ( | std::string | relative_path | ) |
Converts a relative path to an absolute file path.
relative_path | - The relative path to the file, relative to the application directory. |
@retruns The absolute path to the file. If an error occurred, this will return an empty string.
std::string BlamStrings::Utils::IO::GetApplicationDir | ( | ) |
Retrieves the application's working directory.
std::string BlamStrings::Utils::IO::GetContainingFolder | ( | std::string | path | ) |
Retrieves the containing folder of a given file or directory.
In the event that path
refers to a file (ie, C:/Windows/system32/moricons.dll
), this would return the path with the filename omitted (C:/Windows/system32/
). In the event that path
refers to a directory (ie, C:/Windows/system32/
), this would return the path with the last directory excluded (C:/Windows/
).
If the specified path could not be found (or if the path refers to neither a file nor directory), an empty string is returned.
path | - The path to retrieve the containing folder for. |
std::string BlamStrings::Utils::IO::GetContainingFolder | ( | std::string | path, |
bool | require_exists | ||
) |
Retrieves the containing folder of a given file or directory.
In the event that path
refers to a file (ie, C:/Windows/system32/moricons.dll
), this would return the path with the filename omitted (C:/Windows/system32/
). In the event that path
refers to a directory (ie, C:/Windows/system32/
), this would return the path with the last directory excluded (C:/Windows/
).
If the specified path could not be found (or if the path refers to neither a file nor directory), an empty string is returned.
path | - The path to retrieve the containing folder for. |
require_exists | - If true, will perform extra checks and require that the path exists. |
std::vector< std::string > BlamStrings::Utils::IO::GetDeepFileList | ( | std::string | path | ) |
Retrieves the list of all files within a given directory.
This will search through ALL subdirectories and build a complete list of all files. This list will ONLY contain files, any directories are excluded.
path | - The path of the folder to locate files from. |
std::vector< std::string > BlamStrings::Utils::IO::GetDirectoryList | ( | std::string | path | ) |
Retrieves the list of all folders in the root of a given directory.
This list will ONLY contain directories/folders, any files are excluded.
path | - The path of the folder to locate folders from. |
std::string BlamStrings::Utils::IO::GetEngineDataRoot | ( | ) |
Retrieves the root folder for all game engine and editing kit user data files.
On Windows, this value is set to APPDATA%/Elaztek Studios/Blamite/
.
std::vector< std::string > BlamStrings::Utils::IO::GetFileContentsAsLines | ( | std::string | path | ) |
Reads a file as a list of strings.
Can be used to easily read a set of lines from a plain text file.
path | - The path of the file to read from. |
std::string BlamStrings::Utils::IO::GetFileContentsAsString | ( | std::string | path | ) |
Reads a file as a string.
path | - The path of the file to read from. |
std::string BlamStrings::Utils::IO::GetFileExtension | ( | std::string | path | ) |
Retrieves the extension of a file.
For instance, using this function on C:/Windows/explorer.exe
would return exe
. Running this function on a directory or file with no extension would return an empty string.
path | - The path to retrieve the extension for. |
std::string BlamStrings::Utils::IO::GetFileExtension | ( | std::string | path, |
bool | skip_file_check | ||
) |
Retrieves the extension of a file.
For instance, using this function on C:/Windows/explorer.exe
would return exe
. Running this function on a directory or file with no extension would return an empty string.
path | - The path to retrieve the extension for. |
skip_file_check | - If true , the check for whether the path refers to a valid folder or file on disk is skipped. This can allow for non-file path strings to be checked (such as tag paths), but if checking an actual file path, then incorrect results may be returned (such as removing part of a directory name if it contains a period). |
std::vector< std::string > BlamStrings::Utils::IO::GetFileList | ( | std::string | path | ) |
Retrieves the list of all files in a given directory.
This list will ONLY contain files, any directories are excluded.
path | - The path of the folder to locate files from. |
std::string BlamStrings::Utils::IO::GetFileName | ( | std::string | path | ) |
Retrieves the name of the file or folder that a given path refers to.
For instance, using this function on C:/Windows/explorer.exe
would return explorer.exe
. Running this function on C:/Program Files (x86)/Microsoft Games/Halo
would return Halo
.
path | - The path to retrieve the file name for. |
std::string BlamStrings::Utils::IO::GetFileNameWithoutExtension | ( | std::string | path | ) |
Retrieves the name of the file or folder that a given path refers to, excluding the file's extension (if applicable).
For instance, using this function on C:/Windows/explorer.exe
would return explorer
. Running this function on C:/Program Files (x86)/Microsoft Games/Halo
would return Halo
.
path | - The path to retrieve the file name for. |
uint64_t BlamStrings::Utils::IO::GetFileSize | ( | std::string | file_path | ) |
Retrives the size of a file, in bytes.
file_path | - The path to the file. |
std::string BlamStrings::Utils::IO::GetModuleFilePath | ( | HMODULE | module_handle | ) |
Retrieves the file path for a given module (ie, a DLL or executable).
module_handle | - The HMODULE to retrieve the file path of. |
std::string BlamStrings::Utils::IO::GetRelativePathFromAbsolute | ( | std::string | absolute_path | ) |
Converts an absolute path to a relative file path.
relative_path | - The absolute path to the file. |
@retruns The relative path to the file, relative to the application directory. If an error occurred, this will return an empty string.
bool BlamStrings::Utils::IO::IsDirectory | ( | std::string | path | ) |
Checks if a given path refers to a directory.
path | - The path to check. |
true
if the given path refers to a directory. If the path does not exist or does not refer to a directory, then this will return false
. bool BlamStrings::Utils::IO::IsFile | ( | std::string | path | ) |
Checks if a given path refers to a regular file.
path | - The path to check. |
true
if the given path refers to a regular file. If the path does not exist or does not refer to a regular file, then this will return false
. std::string BlamStrings::Utils::IO::NormalizePath | ( | std::string | path | ) |
Normalizes a path string.
This function will take a file path, and ensure it is consistent prior to being interpreted by other code within the engine. Primarily, it will replace \\
with /
.
path | - The path to normalize. |
void BlamStrings::Utils::IO::OpenFile | ( | std::string | file_path | ) |
Opens a file with its default application.
file_path | - The path to the file to open. |
void BlamStrings::Utils::IO::OpenGameDirectory | ( | ) |
Opens the engine's game directory in Windows Explorer.
bool BlamStrings::Utils::IO::ReadBinaryFile | ( | std::string | path, |
void ** | data, | ||
int64_t * | size | ||
) |
Reads a file as raw binary data.
Upon successful reading, the data pointer must be freed by the caller.
path | - The path of the file to read from. |
data | - Address to write data to. |
size | - Pointer of the size of the resource. |
S_OK
if the file was read without error, E_FAIL
if the file could not be read. bool BlamStrings::Utils::IO::ReadFile | ( | std::string | path, |
void ** | data, | ||
int64_t * | size | ||
) |
Reads a file as text data, with a NULL
byte placed at the end of the file contents.
Upon successful reading, the data pointer must be freed by the caller.
path | - The path of the file to read from. |
data | - Address to write data to. |
size | - Pointer of the size of the resource. |
S_OK
if the file was read without error, E_FAIL
if the file could not be read. void BlamStrings::Utils::IO::ValidatePath | ( | std::string | path | ) |
Validates that the specified path exists.
The path can be any relative or absolute path. The function will automatically create any and all required subdirectories to ensure that the path can be written to.
path | - The path to validate. |
bool BlamStrings::Utils::IO::WriteBinaryFile | ( | std::string | file_path, |
void * | data, | ||
int64_t | size | ||
) |
Creates a file with the specified contents, or overwrites an existing file if it already exists.
filename | - The path to the file to create. |
data | - The contents to write to the file. |
size | - The size of the data being written to the file. |
true
if the file was created successfully, otherwise returns false
.