MLIB
|
Class for storing asset files in Windows resource data. More...
#include <asset.h>
Public Member Functions | |
asset (int id_, const std::filesystem::path &name_=std::filesystem::path(), bool persist=false) | |
Constructor for an asset object. | |
~asset () | |
Destructor. Delete asset file if it exists and is not persistent. | |
const void * | data () |
Load asset data and return a pointer to it. | |
size_t | size () |
Return size of asset data or 0 if asset could not be loaded. | |
bool | write (const std::filesystem::path &root_path) |
Write the asset to a folder. | |
bool | remove () |
Delete asset file from disk. | |
Data Fields | |
std::filesystem::path | name |
Relative asset name. | |
Class for storing asset files in Windows resource data.
This class provides a mechanism for embedding different "assets" like those needed by a HTTP server (pages, CSS files, images, etc.), inside a Windows executable or DLL.
Each asset is stored as a user-defined resource of type RESFILE
(defined as 256) and is identified by its ID. An asset can be written to a file. When the asset object goes out of scope the file is deleted.
The resource file (.rc):
Program file:
This has created the file c:\temp\web\index.html
and c:\temp\web\css\main.css
. When the variables page
and css
go out of scope, the two files will be deleted (however, the directory structure remains in place).
|
inline |
Constructor for an asset object.
name_ | asset file name |
id_ | resource ID |
persist | if true do not delete disk file when asset object is destructed |
|
inline |
Load asset data and return a pointer to it.
|
inline |
Delete asset file from disk.
true
if file was deleted false
if file was not written or doesn't exist
|
inline |
Return size of asset data or 0 if asset could not be loaded.
bool mlib::asset::write | ( | const std::filesystem::path & | path | ) |
Write the asset to a folder.
path | root path for asset file |
true
if successful, false
otherwiseAsset filename is obtained by appending the asset name to the root path. For persistent assets, if file already exists, it is not overwritten.