2 Copyright (C) 2005 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 int dirs = 0, files = 0;
29 FileData *fileData = NULL;
44 void countFiles(const char *dirName)
48 dirp = opendir(dirName);
51 while ((dfile = readdir(dirp)))
53 if (dfile->d_name[0] == '.')
58 snprintf(filename, sizeof filename, "%s/%s", dirName, dfile->d_name);
60 if (strlen(filename) > PAK_MAX_FILENAME - 1)
62 printf("\nERROR - '%s' exceeds maximum defined file length of %d\n", filename, PAK_MAX_FILENAME);
66 dirp2 = opendir(filename);
79 fileData = new FileData[totalFiles];
82 void recurseDirectory(const char *dirName)
93 dirp = opendir(dirName);
97 printf("%s: Directory does not exist or is not accessable\n", dirName);
104 while ((dfile = readdir(dirp)))
106 if (dfile->d_name[0] == '.')
111 snprintf(filename, sizeof filename, "%s/%s", dirName, dfile->d_name);
113 dirp2 = opendir(filename);
118 recurseDirectory(filename);
122 infile = fopen(filename, "rb");
125 printf("Couldn't open %s for reading!\n", filename);
131 fseek(infile, SEEK_SET, SEEK_END);
133 filesize = ftell(infile);
143 buffer = new unsigned char[filesize];
151 output = new unsigned char[(int)(filesize * 1.01) + 12];
153 fp = gzopen(filename, "rb");
157 printf("Couldn't open %s for reading!\n", filename);
164 fSize = gzread(fp, buffer, filesize);
167 cSize = (uLongf)((fSize * 1.01) + 12);
168 compress2(output, &cSize, buffer, fSize, 9);
170 fileData[files].set(filename, fSize, cSize, ftell(pak));
172 fwrite(output, 1, cSize, pak);
177 percentage /= totalFiles;
180 printf("\b\b\b\b%3.0f%%", percentage);
191 int main(int argc, char *argv[])
195 printf("Usage : pak <directory names> <outputname>\n");
196 printf("Example : pak data music gfx sound data.pak\n");
200 pak = fopen(argv[argc - 1], "wb");
202 for (int i = 1 ; i < (argc - 1) ; i++)
207 printf("Paking...000%%");
215 for (int i = 1 ; i < (argc - 1) ; i++)
217 recurseDirectory(argv[i]);
220 unsigned int pos = ftell(pak);
222 for (int i = 0 ; i < files ; i++)
224 if (fileData[i].fSize == 0)
229 fwrite(&fileData[i], sizeof(FileData), 1, pak);
232 unsigned int numberOfFiles = totalFiles;
234 fwrite(&pos, sizeof(unsigned int), 1, pak);
235 fwrite(&numberOfFiles, sizeof(unsigned int), 1, pak);
239 printf("\nPak: All Done. Added %d files\n", numberOfFiles);