Lunaboy
New member
The archive-creation process of my packer can be divided into 6 steps:
1. Scan directory recursively to get info
2. Create headers and save them to archive
3. Allocate memory for nametable, DirInfo-array and FileInfo-array
4. Scan directory again to fill Info-arrays and nametable, and copy filedata to archive
5. Write Info-arrays (DirInfo and FileInfo) to archive
6. Free memory and quit
The packer scans the directory twice, first time to gather information and a second time to add the files to the archive and to make a map of the filesystem. To get unlimited directory-depth it calls the scan-function recursively. First it changes to a specified directory, next it scans through all items inside the directory and before returning, it changes back to the parent directory. When the scan-function hits a directory, it simply calls itself again. Each time the function is called, it will jump one directory deeper and each time it returns, it jumps out of the directory to its parent.
An example of how it works is shown below.
I’ve posted the main.cpp file below.
This file alone will not compile, because it needs my cFile class (I don’t want to release the class yet).
You can use the code as a reference to see how the packer is working.
Because I get an 'Unable to move/copy file' error while uploading the attachment, I'm using RapidShare:
http://rapidshare.de/files/48468383/ArcPack_Src.zip.html
1. Scan directory recursively to get info
2. Create headers and save them to archive
3. Allocate memory for nametable, DirInfo-array and FileInfo-array
4. Scan directory again to fill Info-arrays and nametable, and copy filedata to archive
5. Write Info-arrays (DirInfo and FileInfo) to archive
6. Free memory and quit
The packer scans the directory twice, first time to gather information and a second time to add the files to the archive and to make a map of the filesystem. To get unlimited directory-depth it calls the scan-function recursively. First it changes to a specified directory, next it scans through all items inside the directory and before returning, it changes back to the parent directory. When the scan-function hits a directory, it simply calls itself again. Each time the function is called, it will jump one directory deeper and each time it returns, it jumps out of the directory to its parent.
An example of how it works is shown below.
Code:
void DoScan(char *DirName){
SetCurrentDirectory(DirName);
for(Nr = 0 to NrItemsInDir){
if(Item[Nr].IsDir){
DoScan(Item[Nr].Name);
}else{
GetInfo(Item[Nr]);
}
}
SetCurrentDirectory("..");
}
--------------------------------------
Example directory-structure
--------------------------------------
TestDir
|__Arrow.bti
|__Bow.bti
|__Ilia
| |__Yelia.bdl
| |__Anims
| | |__Walk.bck
| | |__Stand.bck
| |__Yelia.bti
|__Medly
|__Md.bdl
|__Md.bck
--------------------------------------
Function calling
--------------------------------------
DoScan("TestDir"){
SetCurrentDirectory("TestDir");
GetInfo("TestDir\Arrow.bti");
GetInfo("TestDir\Bow.bti");
DoScan("TestDir\Ilia"){
SetCurrentDirectory("Ilia");
GetInfo("TestDir\Ilia\Yelia.bdl");
DoScan("TestDir\Ilia\Anims"){
SetCurrentDirectory("Anims");
GetInfo("TestDir\Ilia\Anims\Walk.bck");
GetInfo("TestDir\Ilia\Anims\Stand.bck");
SetCurrentDirectory("..");
}
GetInfo("TestDir\Ilia\Yelia.bti")
SetCurrentDirectory("..");
}
DoScan("TestDir\Medly"){
SetCurrentDirectory("Medly");
GetInfo("TestDir\Medly\Md.bdl");
GetInfo("TestDir\Medly\Md.bck");
SetCurrentDirectory("..");
}
SetCurrentDirectory("..");
}
I’ve posted the main.cpp file below.
This file alone will not compile, because it needs my cFile class (I don’t want to release the class yet).
You can use the code as a reference to see how the packer is working.
Because I get an 'Unable to move/copy file' error while uploading the attachment, I'm using RapidShare:
http://rapidshare.de/files/48468383/ArcPack_Src.zip.html