NODE Software
Back to the main page
Using The Virtual File System
Both the WPK and FAM units require the Zanthos library, which is also available in the latest source release.
These files must be placed in a source directory accessible by Delphi, either your global repository or a project directory.
The FAM system uses a unified data stream for both native OS files and WPK files, meaning that you never have to worry about where your file is coming from, as all data operating methods are the same.
NOTE: The unified data stream class does not allow writing to WPK files. To write to WPK files, you should use the WPKC utility provided. The latest release of this utility can be found here.
Setting up the files
Before we start using the file system, we need to create two files, one called "test.txt", and one called "test.wpk".
Creating the test.txt is easy, simply write a couple of lines using your favourite text editor and save the file in the directory of your projects executable.
Next, we need to create the test.wpk file, for this we need to create a compile script, which WPKC will use to create our file.
The text for this:
lcd|C:\WPKFiles
add|test2.txt|test2.txt
NOTE: You will obviously have to create the C:\WPKFiles directory for this script to work, you can either modify the script or add the directory, its up to you, the reason I did it this way is to prevent confusion.
ANOTHER NOTE: The script does not count spaces as parse breakpoints, instead it uses the pipe "|".
And save this file as test.scl in the directory of your projects executable. Drag this file onto the WPKC executable, then set the output file to your projects executable directory path + "test.wpk", and click "Compile".
A WPK file should now appear(as if by magic :), in the project directory.
Now we can start to use these files...
Using the files
The WPK unit is not used directly in projects, instead, the FAM unit is accessed, which gives us multiple WPK file support and automatic switching between packaged files and native file system files.
An instance of the FAM system is automatically created when you include the unit as part of your project or declare it in a "uses".
From a look at the code, you can see that there are two parts to the system, the actual FAM class, and a FAM stream. The stream class contains a small amount of support code to manage both packaged and non-packaged files.
The FAM automatically sets the current directory as that of the applications exe path(this can be see in the class constructor).
NOTE: In WPK files, the top most level directory is called "/root".
In order to use the test2.txt file which is inside the test.wpk file, we need to first..
1. Tell the FAM a list of all the WPK files we're using, at the moment, the only file is test.wpk.
2. Open the file using the FileOpen function, this should return a valid stream if the file is accessible or nil if the file cannot be found or is inaccessible.
3. Once we've finished using the file, release the memory used by the stream class.
g_FAM.IncludeWPK('test.wpk');
streamTestFile := g_FAM.FileOpen('test2.txt',False);
// do stuff...
myDataStream.Free;
You may have noticed the last parameter of the FileOpen function, and may be wondering what thats used for, well, I'll explain :)
The file access system searches the available WPK files and the OS directory structure for the file specified, if the last paramter is set to True, then if a file cannot be found in a WPK, then no file stream is returned. This ensures that overriding of data files is not accomplished by simply putting the modified file outside of a WPK.
The WPK system also supports directories, and are created using the following WPKC script commands:
mkdir|parentdir|newdirname
eg, mkdir|root/|audio
chdir|newdir|
eg, chdir|root/audio
Comments can also be put inside script files by starting the line with ";"