| Main |
| downloads |
|
Resources loader and saver Program rs stores files in one indivisible package (without compression), which are visible for ResLoader programming tool. This can be used for example for hidding program's resources files such as: fonts, graphics, animations, sounds, etc., or just for keeping program in more compact form (especially if there are many small files in program's data). This example will create 'resources' file, which contains all files from 'graphics' directory (searched recursively):>rs +f resources +r +d graphics switches description: +d <dir name> (add specific directory, default is current directory) +r (stand-alone switch turns on recursive mode for adding files, default is turned off) +f <file name> (set output package name, default is "rs_out") +l <file name> (list all files stored in specific package, default is "rs_out") Format of output file is as simple as possible: (ascii chars)<file 1 name> (unsigned int)<file 1 size> (8-bit bytes)<file 1 body> (ascii chars)<file 2 name> (unsigned int)<file 2 size> (8-bit bytes)<file 2 body> . . . (ascii chars)<file N name> (unsigned int)<file N size> (8-bit bytes)<file N body> Structure ResLoader from res_load library provide loading method for such stored files. For example: //... ResLoader rl; uint nrf = rl.set( "resources" ); //nrf contains number of files stored in 'resources' package, or 0 if 'resources' doesn't exist in program's directory // method ResLoader :: set( char *fileName ) reads files names and its sizes from package and stores this information on vector 'files' uint fileSize = rl.open( "graphics/tree.png" ); //after this rl.p (fstream object) will point at 'tree.png' file in 'resource' package, fileSize is "graphics/tree.png" size in bytes int fileIndex = rl.getIndex( "graphics/tree.png" ); //fileIndex contains index of "graphics/tree.png" file on information vector 'files', or -1 if file doesn't exist in package uint endOfFile = rl.files[ fileIndex ].end; //endOfFile contains end position of "graphics/tree.png" file in package 'resources' //... unsigned char *buf; fileSize = rl.loadFile( "graphics/sky.png", &buf ); //after this buf will contain "graphics/sky.png" file body, if that file doesn't exist in package then the same file in program's system directory is opened automatically //... |