Elaztek Developer Hub
Blamite Game Engine - Strings  00309.02.03.21.0044.blamite
A library containing general purpose utilities and classes for use in multiple projects.
BlamStrings::Utils::IO Namespace Reference

Utilities relating to reading/writing to and from files. More...

Functions

STRINGS_API bool FileExists (std::string name)
 Checks if the specified file exists. More...
 
STRINGS_API int CreateNewFile (std::string filename, std::string file_contents)
 Creates a file with the specified contents. More...
 
STRINGS_API int CreateFileFromResource (HMODULE module_handle, std::string filename, int res_id, const char *res_type)
 Creates a file with the contents pulled from the specified application resource. More...
 
STRINGS_API int CreateFileFromHTMLResource (HMODULE module_handle, std::string filename, int res_id)
 Creates a file with the contents pulled from the specified application HTML resource. More...
 
STRINGS_API int CreateFileFromPNGResource (HMODULE module_handle, std::string filename, int res_id)
 Creates a file with the contents pulled from the specified application PNG resource. 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 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...
 

Detailed Description

Utilities relating to reading/writing to and from files.

Function Documentation

◆ CreateFileFromHTMLResource()

int BlamStrings::Utils::IO::CreateFileFromHTMLResource ( HMODULE  module_handle,
std::string  filename,
int  res_id 
)

Creates a file with the contents pulled from the specified application HTML resource.

Parameters
filename- The path to the file to create.
res_id- The ID of the HTML resource to load the contents from.
apply_placeholders- Whether or not to apply placeholders to the file contents before writing.
Returns
0
Todo:
Make return code useful or change return type to void.

◆ CreateFileFromPNGResource()

int BlamStrings::Utils::IO::CreateFileFromPNGResource ( HMODULE  module_handle,
std::string  filename,
int  res_id 
)

Creates a file with the contents pulled from the specified application PNG resource.

Parameters
filename- The path to the file to create.
res_id- The ID of the PNG resource to load the contents from.
Returns
0 on success, -1 on failure.

◆ CreateFileFromResource()

int BlamStrings::Utils::IO::CreateFileFromResource ( HMODULE  module_handle,
std::string  filename,
int  res_id,
const char *  res_type 
)

Creates a file with the contents pulled from the specified application resource.

Parameters
filename- The path to the file to create.
res_id- The ID of the resource to load the contents from.
res_type- The type of resource that res_id is.
apply_placeholders- Whether or not to apply placeholders to the file contents before writing.
Returns
0
Todo:
Make return code useful or change return type to void.

◆ CreateNewFile()

int BlamStrings::Utils::IO::CreateNewFile ( std::string  filename,
std::string  file_contents 
)

Creates a file with the specified contents.

Parameters
filename- The path to the file to create.
file_contents- The contents to write to the file.
Returns
0
Todo:
Make return code useful or change return type to void.

◆ FileExists()

bool BlamStrings::Utils::IO::FileExists ( std::string  name)

Checks if the specified file exists.

Parameters
name- The path to the file.
Returns
true if the file exists, false if it does not

◆ GetApplicationDir()

std::string BlamStrings::Utils::IO::GetApplicationDir ( )

Retrieves the application's working directory.

Returns
The application's working directory.

◆ GetDirectoryList()

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.

Parameters
path- The path of the folder to locate folders from.
Returns
A list of strings, with each string being the name of a folder.

◆ GetFileContentsAsLines()

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.

Parameters
path- The path of the file to read from.
Returns
A list of strings, with each string representing a line in the file.

◆ GetFileContentsAsString()

std::string BlamStrings::Utils::IO::GetFileContentsAsString ( std::string  path)

Reads a file as a string.

Parameters
path- The path of the file to read from.
Returns
The file contents, represented as a string.

◆ GetFileList()

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.

Parameters
path- The path of the folder to locate files from.
Returns
A list of strings, with each string being the name of a file.

◆ OpenGameDirectory()

void BlamStrings::Utils::IO::OpenGameDirectory ( )

Opens the engine's game directory in Windows Explorer.

◆ ReadBinaryFile()

bool BlamStrings::Utils::IO::ReadBinaryFile ( std::string  path,
void *  data,
int64_t *  size 
)

Reads a file as raw binary data.

Parameters
path- The path of the file to read from.
data- Address to write data to.
size- Pointer of the size of the resource.
Returns
S_OK if the file was read without error, E_FAIL if the file could not be read.

◆ ValidatePath()

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.

Parameters
path- The path to validate.