.dat file creation help
I've made a program that keeps lots of files into one *.dat file. My question is, I would like to make directories inside the file, such as: "Sounds\Buildings\collapse01.wav" and "Images\Sprites\MainCharacter\walknorth.jpg", what would be the best way to approach this?
[edited by - Faze on October 16, 2002 11:06:46 PM]
Look for a zip library and store all your data files in a zipfile, from which you extract files at runtime. Inside the zip you can have your directory structure.
You could have a header or a footer that holds the directory information. Each entry is either a folder or a file name, and has a length and a pointer to a block of binary data in the file that holds the data. The length for a folder, I suppose is the length of all the filenames so you know where to stop.
So each entry in the index is:
name
type (folder or file)
location in file
length in bytes
The first few bytes of the .dat file should be constant and tell you where the index actually starts and what the length of the root folder is.
You could instead make the last filename two zeroes so the parser knows not to go any farther within a given folder.
It would be wise to load the directory structure into memory with all the pointers and lengths stored so you don't have to search the whole directory in the file to find the data you're looking for.
Just one possibility.
This also serves well for making additional .dat files to override data in the main .dat file. Your program could load in the directory for the main .dat file, then load in the secondary .dat file and overwrite in memory everything that has a duplicate name (you would have to store a file handle in memory as well so your program knows which file to open!)
Get the idea?
[edited by - Waverider on October 17, 2002 6:39:08 PM]
So each entry in the index is:
name
type (folder or file)
location in file
length in bytes
The first few bytes of the .dat file should be constant and tell you where the index actually starts and what the length of the root folder is.
You could instead make the last filename two zeroes so the parser knows not to go any farther within a given folder.
It would be wise to load the directory structure into memory with all the pointers and lengths stored so you don't have to search the whole directory in the file to find the data you're looking for.
Just one possibility.
This also serves well for making additional .dat files to override data in the main .dat file. Your program could load in the directory for the main .dat file, then load in the secondary .dat file and overwrite in memory everything that has a duplicate name (you would have to store a file handle in memory as well so your program knows which file to open!)
Get the idea?
[edited by - Waverider on October 17, 2002 6:39:08 PM]
webjunkie: It''s set up so that it looks like this:
*Begin*
ABC.gif
// binary code here
*End*
*Begin*
Sound.wav
// binary code here
*End*
Waverider: I understand what you mean, I''ll give it a shot.
When I''m totally finished with everything, I''ll add a very tight encryption on it, and pull the files when I need them. Thanks for the help.
*Begin*
ABC.gif
// binary code here
*End*
*Begin*
Sound.wav
// binary code here
*End*
Waverider: I understand what you mean, I''ll give it a shot.
When I''m totally finished with everything, I''ll add a very tight encryption on it, and pull the files when I need them. Thanks for the help.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement