SPK File Format Library

This is the main library used to manipulate the new SPK File format, this is mainly for other programs who wish to use SPK files in thier programs, or who want to just learn about the file format itself.



Download (Spk Version: 4.00):

Download spk.tar.gz

Download spk.zip




The SPK file format has been changed since its original release. The change gives many advantages over the original format.

The original version was simply a plain text file that was compressed. The major drawbacks of this, was that the whole file had to be uncompressed then the whole thing had to be read in, which can be slow, and limits what you can do with the file.

The new file format has seperate headers for the data that follows. The first line in the file is the main header, this has the type of file, the version, the side of the next block, and the compression type used. The next block is the value block, this is compressed seperatly to the rest of the file, and contains all the settings for the plugin, ie the Name, Author, Version, etc.

After this, is the File Header line, which contains the size of the next block, the compression type and number of files. The next block is the file details, it lists all the files inside, thier size and type, this data block is also compressed seperatly. Finally is the file data that follow one by one, each file is compressed seperalty, and each file is capable of having seperate compression type.


Advantages of New Format:

Disadvantages of New Format:



SPK Library Files

ansi7zip directory contains all the files for the Ansi C versions of the 7Zip decoder, this is used for the Linux version only, note, this doesn't include the encoder. Only 7Decoder.cpp and 7Decoder.h were created by me.

ansi7zip/7Decoder.cpp - Contains the function to decompress 7Zip data stream

7zip directory contains the 7zip library used for the windows version, includes both encoder and decoder, note, your should use either ansi7zip or 7zip files, no need to use both. Only 7zipDataStream.cpp and 7zipDataStream.h were created by me

7zip/7zipDataStream.cpp -Created to allow in data compression/decompression rather than using files
7zip/Windows/FileIO.cpp - Needed for file to file encode/decoding only, used for large files that are too big to fit in memory
/7zip/7zip/Common/FileStreams.cpp - Used for file to file ecode/decoding only, otherwise 7ZipDataSream.cpp is used. This is used for large files where data stream failes

zlib directory contrains all the files needed for the ZLIB library, used to compress and decompress ZLIB compression, main compression used for headers, and Linux version files. All files are from the ZLIB library


Rest of the files are the main SPK Library files that hand everything to do with the files other than compression, all these files are created by me

File.cpp -This class holds each of the individual file data, ie each Script, Text, etc, file in the package will be in this class. It controls reading and writing of file, as well as the compression and uncompression
File.h - Main header for File class, contains enums for compression and file type as well, and includes all files need for 7zip and ZLIB compression
lists.h - Link List class, all files in the SpkFile are stored in a link list.
MultiSpkFile.cpp - Main class for handling opening, reading, writing and creating of Multi-SPK Packages
MultiSpkFile.h - Main file to include when handling Multi-SPK packages.
spkcmdprogress.h - Used to print the encode/decode progress of files to the command prompt
SpkFile.cpp - Main class, used to read, write and edit SPK Packages
SpkFile.h - Main Header file, needs to be included to use the library, includes everything else it needs
String.h - String class, the Library uses its own String library, includes storage, checking and manipulaing of Classes



Included Examples

I have includes the source for the tool SPKTool, this is used as an example on how to use the library. The program itself doesn't actually do much, it is simply a front end of the library, all the fucntionality of the program is handled directly by the SPK Library.

I originally made it to test the library and find any extra functions that i needed to add, and works as a good example on how to include the functionality into your own programs. The program should compile under both linux and windows, the Visual Studio 6 Project files have been included, as have the Linux Makefiles. The linux version was created and compiled in KDevelop.

SPKTool only uses one file, spktool.cpp, along with the rest of the SPK Library. It can handle both normal SPK Packages, and Multi-SPK Packages.



Function Definations


Compression enums - Used for the type of compression used.

SPKCOMPRESS_NONE - No compression, file data is in its raw form

SPKCOMPRESS_7ZIP - The default compression for files, uses the 7-Zip Compression library (Note: These dont work in Linux, can only uncompress, not compress)

SPKCOMPRESS_ZLIB - The default compression for linuz, and for the settings string. Uses the ZLIB compression libries, ie Zip.

Filetype enums - Used in the CFile object for the different file types in the package

FILETYPE_SCRIPT - A script file, these will be installed in the "Scripts" directory, these are usually XML or PCK files

FILETYPE_TEXT - A Text file, used to load different languages into the game, goes into the "t" directory. These are usually XML or PCK files.

FILETYPE_README - A text readme file for users to read so they know what the package does. Installs in the Readme/$scriptname directory. Readmes can be set to a specifc language id so they can be defaulted to the correct language when reading. Readme are TXT files.

FILETYPE_MAP - A Map file, this is for the different universe maps, usually in XML files.

FILETYPE_MOD - Mod files, should have both CAT and DAT pairs, used for either normal mod files or fake patchs. Fake patchs are automatically defined by the filename as a number.

FILETYPE_UNINSTALL - Uninstall Scripts, these are standard script files that dont get installed as normal, isntead go in the Uninstall directory until the package is uninstalled, then they become active.

FILETYPE_SOUND - Sound track files, these are the files used for the in sector music, and are MP3 files.

FILETYPE_EXTRA - Extra files are any other files that are dont match with the current file types. These can have a directory set and installed to different locations.

FILETYPE_SCREEN - Screenshot files, usually JPG files, and are used as loading screens in the game, goes into the loadscr directory.

FILETYPE_BACKUP - Any backup files that are made, ie when installing patchs, a backup of the old files will be placed with this type.

FILETYPE_MISSION - Any mission directory files (Not currently supported)

FILETYPE_MAX - This is the current number of file types available, can be used if the type is out of range.

SPK Read Error enums - When reading/writing spk files, if any errors occur, the error will be set to one of these flags, this allows you to test what went wrong

SPKERR_NONE - No error, the operation was successful.

SPKERR_MALLOC - A problem trying to allocate the memory space for reading the file to memory

SPKERR_FILEOPEN - Unable to open the file, might mean it doesn't exist, this is when fopen() fails.

SPKERR_FILEREAD - Unable to read the file, when fread() fails.

SPKERR_UNCOMPRESS - Unable to uncompress the file, if the uncompress functions fail.

SPKERR_WRITEFILE - Unable to write the file, if the file couldn't be wrriten to disk

SPKERR_CREATEDIRECTORY - If the CreateDirectory function returns false.

SPKERR_FILEMISMATCH - If the number of files in the SPK header does not match the amount of files that was read in.

SPK Read enums - Used to specify the type of file reading when open SPK Files

SPKREAD_ALL - Reads the whole file into memory

SPKREAD_NODATA - Reads all but the files data. It will read the file headers so it knows what files are inside, but wont read the actual file data.

SPKREAD_VALUES - Skips the file reading altoghter, ie, doesn't read the file data nor the files header. Using this would mean the spk file wont know what files are inside. Useful if you only want certain settings, ie the Package name, author, etc. This is used when checking if the package can be installed, without spending extra time reading the files.

SPKREAD_HEADER - Just reads the Header, simply to what the static function CSpkFile::CheckFile does.


Static/Global Functions:

static int CSpkFile::CheckFile ( String filename, float *version )

This is one of the most useful functions, it checks the header flags in the file to see what type of file it is. It only needs to read the first line, so its quick and easy. The filename is a String of the filename to open. It returns an interger of the type of file.

There are 3 defines setup for what it returns.

SPKFILE_INVALID - Returns if the file type is invalid, ie not a true SPK file, it could be the old format that doesn't have the header.

SPKFILE_SINGLE - A Single spk file, you can use the CSpkFile object to open and read it.

SPKFILE_MULTI - A Multi spk file, one that contains multi spk files together, you can use the CMultiSpkFile object to open and read it.

the float *version returns the file version of the file, this can be used to check if the file your opening is of the correct version. IE, if you program is using an older version of the SPK Library, and it trys to open a newer version, it might have trouble. So you can check this and display an error. If you set it to NULL, it will be skipped.

String GetFileTypeString ( int type );

This function converts the interger file type enum to a String. Can be converted back to the interger using the function below.

int GetFileTypeFromString ( String type );

This fucntion converts a String to the file type enum, can be used when trying in the file type, instead of having to type in the number. This is not case sensitive.

bool CreateDirectory ( String dir );

This function will create the specificed directory, this is used when extract files, so that the directory exists when extracting to it. It will create every directory that does exists, if you specify "c:/dir1/dir2/dir3" Then dir1, dir2 and dir3 will be created if they dont exist, you dont have to try to create one at a time. You can also specify the directory as a relative path.

This will return true or false, if it was successful.


The CSpkFile object is contained in the SPK/SpkFile.h and SPK/SpkFile.cpp files. It handles the main SPK file functions, ie, opening, reading, writing, etc.

Data Functions (Used for getting and setting the data values):

String GetName () - Returns the name of the package

String GetAuthor () -Returns the author of the package

String GetVersion () - Returns the version string of the current package

String GetOtherName () - Returns the name of its parent if it requires another package.

String GetOtherAuthor () - Returns the author of its parent if it requires another package.

String GetCreationDate () - Returns the data of when the package was created.

String GetDescription () - Returns the package description.

String GetWebSite () - Returns the web site of the package

String GetWebAddress () - Returns the primary web update address

String GetMirror1 () - Returns the first mirror for the web update

String GetMirror2 () - Returns the second mirror for the web update

String GetScriptType () - Returns the type of package.

String GetEmail () - Returns the email address for the Author.

String GetNameValidFile () - Returns the package name, but removes any invalid characters, ie, any characters that can not be in file names. This is used to create a directory of the package name.

String GetInstallAfterText ( String lang ) - Returns the Install After text of specific language, calls the function GetAfterText.

String GetInstallBeforeText ( String lang ) - Returns the Install Before text of specific language, calls the function GetBeforeText.

String GetUninstallAfterText ( String lang ) - Returns the Uninstall After text of specific language, calls the function GetAfterText.

String GetUninstallBeforeText ( String lang ) - Returns the Uninstall Before text of specific language, calls the function GetBeforeText.

String GetScriptName ( String lang ) - Returns the name of the package in a specific language, if it doesn't find a match language, returns GetName().

CFile *GetIcon () - Returns the file object pointer for the current icon if it exists, otherwise returns NULL.

String GetIconExt () - Returns the icon extension, ie PNG, JPG, ICO, etc.

CSpkFile *GetParent () - Returns the pointer to the parent if it exists.

CLinkList<CFile> *GetFileList () - Returns the pointer to the file list, its a Link List of type CFile.

CLinkList<SWares> *GetWaresList () - Returns the pointer to the wares list, its a Link List of type SWares.

CLinkList<SNames> *GetNamesList () - Returns the pointer to the names list, its a Link List of type SNames. These are the names of the package in different languages.

int GetDataCompression () - Returns the default compression for the file data. Note, each individual files can use different compression methods.

float GetFileVersion () - Returns the SPK File format version of the current spk files.

int GetGameVersion () - Returns the game version, ie the version of what game is required to install the package, 0 is for all versions.

bool IsSigned () - Returns if the package is signed or not, use the UpdateSigned() function to set this correctly.

bool IsCustomStart () - Returns if the package is a Custom Start.



The CFile object is contained in the SPK/File.h and SPK/File.cpp files. It handles the files inside the package themselves, ie the script, text, map, readme, and other files type



The CMultiSpkFile object is contained in SPK/MultiSpkFile.h and SPK/MultiSpkFile.cpp files. It handles the Multi-Spk files, adding/remove spk files, creating, etc.