(This is quite complicated by the way)
Have a look at pak_creator.c
http://legendofedgar.svn.sourceforge.net/viewvc/legendofedgar/trunk/src/pak_creator.c?revision=947&view=markup
This program recurses through one or more directories and appends file that it finds to a resource file. So you might have
gfx/player_stand.png (64k)
gfx/player_fire.png (90k)
sound/pistol.ogg (6k)
First, I get the size of the file and the size of the resource file, which will be 0 initially. Next, I add this information to a structure. So, I’ll have the following:
fileData[0].name = “gfx/player_stand.png”; /* The name of the file we’re about to add /
fileData[0].size = 64000; / Its size in bytes /
fileData[0].offset = 0; / The current size of the resource file */
Now I use fwrite to append this file to the resource file, then I get the next file:
fileData[1].name = “gfx/player_fire.png”; /* The name of the file we’re about to add /
fileData[1].size = 90000; / Its size in bytes /
fileData[1].offset = 64000; / The current size of the resource file */
As you’ll see, the size of the resource file is 64,000. That’s because we previously added that image. Now we add the next file and move to the next one:
fileData[2].name = “sound/pistol.ogg”; /* The name of the file we’re about to add /
fileData[2].size = 6000; / Its size in bytes /
fileData[2].offset = 154000; / The current size of the resource file */
Once we have added all of the files, we’ll have a resource file and a structure array that tells us where each file is and how big it is. So, if we wanted to find gfx/player_fire.png, we would loop through our structure and a string compare on the fileData[i].name until we find it. Once we find it, we can find out how big it is and where it lives in the resource file.
Does this make sense so far?