With some DIRection from IanM (thanks!) I now have a solution:
Packages created by DIRBLOCK have the following structure:
1). First 4 bytes make up an integer = the # of files in the package
- These bytes need to be READ to advance the READ command's byte index
2). The next block of the package must be read with READ FILEBLOCK and will contain the name of the first file in the package.
- I imagine we could read the text in this first file and use it to name our first extracted file. I tried just reading it with READ STRING and it did not work. Might be able to do READ BYTE and put those bytes together to make up the string for the filename.
3).Now when we run READ FILEBLOCK again we will finally get our first file.
4).Repeat steps 2 and 3 for how ever many files you want to extract.
open to read 1,"d:\backup.pak"
read byte 1,c
read byte 1,d
read byte 1,d
read byte 1,d
print c," files contained in d:\backup.pak"
read fileblock 1,"d:\test\filename1.txt"
read fileblock 1,"d:\GreenSpace.jpg"
read fileblock 1,"d:\test\filename2.txt"
read fileblock 1,"d:\test\It-Came-From-Above.jpg"
read fileblock 1,"d:\test\filename3.txt"
read fileblock 1,"d:\test\mmm.jpg"
close file 1
print "extraction done"
wait key
end
Note that you do not need to reference the original directory structure or the original filename.
I imagine I could create from this a sort of random access algorithm for getting to just the file I need. Though it seems I would have a lot of files that would be created and then need to be deleted.
Although I enjoy Jesse Redman's article I'm concerned that putting files in a DIRBLOCK is not the best method of protecting files. Any DB Pro user should be able to get to them with the above method. However I suppose if you name the files with incorrect extensions then it will make it a little tougher to figure out what is what. Also if they had your game they could simply know to look for the files while the game is running.
I guess if I want better protection I'd need to create some sort of encryption algorithm to scramble the data in the DIRBLOCK file. A bit beyond me right now, so I will stick with DIRBLOCK.
Thanks to you both for the help.
I've learned much from this!
~Napland Games~