Blamite Game Engine - Blam (Core)
Blam::Utils::IO Namespace Reference

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

Functions

BLAM bool file_exists (std::string name)
 Checks if the specified file exists. More...
 
BLAM int CreateFile (std::string filename, std::string file_contents)
 Creates a file with the specified contents. More...
 
BLAM int CreateFileFromResource (std::string filename, int res_id, const char *res_type, bool apply_placeholders)
 Creates a file with the contents pulled from the specified application resource. More...
 
BLAM int CreateFileFromHTMLResource (std::string filename, int res_id, bool apply_placeholders)
 Creates a file with the contents pulled from the specified application HTML resource. More...
 
BLAM int CreateFileFromPNGResource (std::string filename, int res_id)
 Creates a file with the contents pulled from the specified application PNG resource. More...
 
BLAM void ValidatePath (std::string path)
 Validates that the specified path exists. More...
 
BLAM void OpenGameDirectory ()
 Opens the engine's game directory in Windows Explorer. More...
 
BLAM std::string GetApplicationDir ()
 Retrieves the application's working directory. More...
 
BLAM HRESULT GetFileAsBinary (std::string path, void *data, DWORD *size)
 Reads a file as raw binary data. More...
 
BLAM std::vector< std::string > GetFileContentsAsLines (std::string path)
 Reads a file as a list of strings. More...
 

Detailed Description

Utilities relating to reading/writing to and from files.

Function Documentation

◆ CreateFile()

int Blam::Utils::IO::CreateFile ( 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.
Todo:
Rename to avoid clashing with the CreateFile macro

◆ CreateFileFromHTMLResource()

int Blam::Utils::IO::CreateFileFromHTMLResource ( std::string  filename,
int  res_id,
bool  apply_placeholders 
)

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 Blam::Utils::IO::CreateFileFromPNGResource ( 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 Blam::Utils::IO::CreateFileFromResource ( std::string  filename,
int  res_id,
const char *  res_type,
bool  apply_placeholders 
)

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.

◆ file_exists()

bool Blam::Utils::IO::file_exists ( 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
Todo:
Rename to have consistent formatting

◆ GetApplicationDir()

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

Retrieves the application's working directory.

Returns
The application's working directory.

◆ GetFileAsBinary()

HRESULT Blam::Utils::IO::GetFileAsBinary ( std::string  path,
void *  data,
DWORD *  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.

◆ GetFileContentsAsLines()

std::vector< std::string > Blam::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.

◆ OpenGameDirectory()

void Blam::Utils::IO::OpenGameDirectory ( )

Opens the engine's game directory in Windows Explorer.

◆ ValidatePath()

void Blam::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.