2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 qboolean g_compress_pak;
26 qboolean g_release; // don't grab, copy output data to new tree
27 qboolean g_pak; // if true, copy to pak instead of release
28 char g_releasedir[1024]; // c:\quake2\baseq2, etc
29 qboolean g_archive; // don't grab, copy source data to new tree
31 char g_only[256]; // if set, only grab this cd
32 qboolean g_skipmodel; // set true when a cd is not g_only
34 char *ext_3ds = "3ds";
38 char game[64] = "quake2";
40 void InitPaths( int *argc, char **argv );
43 =======================================================
47 =======================================================
50 unsigned Com_BlockChecksum (void *buffer, int length);
65 packfile_t pfiles[16384];
68 packheader_t pakheader;
77 void BeginPak (char *outname)
82 pakfile = SafeOpenWrite (outname);
84 // leave space for header
85 SafeWrite (pakfile, &pakheader, sizeof(pakheader));
95 Filename should be gamedir reletive.
96 Either copies the file to the release dir, or adds it to
100 void ReleaseFile (char *filename)
110 sprintf (source, "%s%s", gamedir, filename);
114 sprintf (dest, "%s/%s", g_releasedir, filename);
115 printf ("copying to %s\n", dest);
116 QCopyFile (source, dest);
121 printf ("paking %s\n", filename);
122 if (strlen(filename) >= sizeof(pf->name))
123 Error ("Filename too long for pak: %s", filename);
125 len = LoadFile (source, (void **)&buf);
127 if (g_compress_pak && len < 4096*1024 )
130 cblock_t Huffman (cblock_t in);
137 if (out.count < in.count)
139 printf (" compressed from %i to %i\n", in.count, out.count);
148 strcpy (pf->name, filename);
149 pf->filepos = LittleLong(ftell(pakfile));
150 pf->filelen = LittleLong(len);
153 SafeWrite (pakfile, buf, len);
164 void FinishPak (void)
174 pakheader.id[0] = 'P';
175 pakheader.id[1] = 'A';
176 pakheader.id[2] = 'C';
177 pakheader.id[3] = 'K';
178 dirlen = (byte *)pf - (byte *)pfiles;
179 pakheader.dirofs = LittleLong(ftell(pakfile));
180 pakheader.dirlen = LittleLong(dirlen);
182 checksum = Com_BlockChecksum ( (void *)pfiles, dirlen );
184 SafeWrite (pakfile, pfiles, dirlen);
188 fseek (pakfile, 0, SEEK_SET);
189 SafeWrite (pakfile, &pakheader, sizeof(pakheader));
193 printf ("%i files packed in %i bytes\n",d, i);
194 printf ("checksum: 0x%x\n", checksum);
202 This is only used to cause a file to be copied during a release
203 build (default.cfg, maps, etc)
220 void PackDirectory_r (char *dir)
222 struct _finddata_t fileinfo;
224 char dirstring[1024];
227 sprintf (dirstring, "%s%s/*.*", gamedir, dir);
229 handle = _findfirst (dirstring, &fileinfo);
235 sprintf (filename, "%s/%s", dir, fileinfo.name);
236 if (fileinfo.attrib & _A_SUBDIR)
238 if (fileinfo.name[0] != '.') // don't pak . and ..
239 PackDirectory_r (filename);
242 // copy or pack the file
243 ReleaseFile (filename);
244 } while (_findnext( handle, &fileinfo ) != -1);
250 #include <sys/types.h>
253 void PackDirectory_r (char *dir)
256 struct direct **namelist, *ent;
258 struct dirent **namelist, *ent;
265 char dirstring[1024];
268 sprintf (dirstring, "%s%s", gamedir, dir);
269 count = scandir(dirstring, &namelist, NULL, NULL);
271 for (i=0 ; i<count ; i++)
279 sprintf (fullname, "%s/%s", dir, name);
280 sprintf (dirstring, "%s%s/%s", gamedir, dir, name);
282 if (stat (dirstring, &st) == -1)
283 Error ("fstating %s", pf->name);
284 if (st.st_mode & S_IFDIR)
286 PackDirectory_r (fullname);
290 // copy or pack the file
291 ReleaseFile (fullname);
301 This is only used to cause a directory to be copied during a
302 release build (sounds, etc)
308 PackDirectory_r (token);
311 //========================================================================
313 #define MAX_RTEX 16384
315 char rtex[MAX_RTEX][64];
317 void ReleaseTexture (char *name)
322 for (i=0 ; i<numrtex ; i++)
323 if (!Q_strncasecmp(name, rtex[i], strlen(name)))
326 if (numrtex == MAX_RTEX)
327 Error ("numrtex == MAX_RTEX");
329 strcpy (rtex[i], name);
332 sprintf (path, "textures/%s.wal", name);
340 Only relevent for release and pak files.
341 Releases the .bsp files for the maps, and scans all of the files to
342 build a list of all textures used, which are then released.
350 while (TokenAvailable ())
353 sprintf (map, "maps/%s.bsp", token);
359 // get all the texture references
360 sprintf (map, "%smaps/%s.bsp", gamedir, token);
361 LoadBSPFileTexinfo (map);
362 for (i=0 ; i<numtexinfo ; i++)
363 ReleaseTexture (texinfo[i].texture);
368 //==============================================================
375 void ParseScript (void)
380 { // look for a line starting with a $ command
386 while (TokenAvailable())
393 if (!strcmp (token, "$modelname"))
395 else if (!strcmp (token, "$base"))
397 else if (!strcmp (token, "$cd"))
399 else if (!strcmp (token, "$origin"))
401 else if (!strcmp (token, "$scale"))
403 else if (!strcmp (token, "$frame"))
405 else if (!strcmp (token, "$skin"))
407 else if (!strcmp (token, "$skinsize"))
412 else if (!strcmp (token, "$spritename"))
414 else if (!strcmp (token, "$load"))
416 else if (!strcmp (token, "$spriteframe"))
421 else if (!strcmp (token, "$grab"))
423 else if (!strcmp (token, "$raw"))
425 else if (!strcmp (token, "$colormap"))
427 else if (!strcmp (token, "$mippal"))
429 else if (!strcmp (token, "$mipdir"))
431 else if (!strcmp (token, "$mip"))
433 else if (!strcmp (token, "$environment"))
438 else if (!strcmp (token, "$video"))
443 else if (!strcmp (token, "$file"))
445 else if (!strcmp (token, "$dir"))
447 else if (!strcmp (token, "$maps"))
449 else if (!strcmp (token, "$alphalight"))
451 else if (!strcmp (token, "$inverse16table" ))
452 Cmd_Inverse16Table();
454 Error ("bad command %s\n", token);
458 //=======================================================
465 int main (int argc, char **argv)
467 static int i; // VC4.2 compiler bug if auto...
470 ExpandWildcards (&argc, &argv);
472 InitPaths( &argc, argv );
474 for (i=1 ; i<argc ; i++)
476 if (!strcmp(argv[i], "-archive"))
478 // -archive f:/quake2/release/dump_11_30
480 strcpy (archivedir, argv[i+1]);
481 printf ("Archiving source to: %s\n", archivedir);
484 else if (!strcmp(argv[i], "-release"))
487 strcpy (g_releasedir, argv[i+1]);
488 printf ("Copy output to: %s\n", g_releasedir);
491 else if (!strcmp(argv[i], "-compress"))
493 g_compress_pak = true;
494 printf ("Compressing pakfile\n");
496 else if (!strcmp(argv[i], "-pak"))
500 printf ("Building pakfile: %s\n", argv[i+1]);
501 BeginPak (argv[i+1]);
504 else if (!strcmp(argv[i], "-only"))
506 strcpy (g_only, argv[i+1]);
507 printf ("Only grabbing %s\n", g_only);
510 else if (!strcmp(argv[i], "-3ds"))
513 printf ("loading .3ds files\n");
515 else if (argv[i][0] == '-')
516 Error ("Unknown option \"%s\"", argv[i]);
522 Error ("usage: %s [-archive <directory>] [-release <directory>] [-only <model>] [-3ds] file.qgr", argv[ 0 ] );
525 trifileext = ext_3ds;
527 trifileext = ext_tri;
529 for ( ; i<argc ; i++)
531 printf ("--------------- %s ---------------\n", argv[i]);
533 strcpy (path, argv[i]);
534 DefaultExtension (path, ".qdt");
535 SetQdirFromPath (path);
536 LoadScriptFile (ExpandArg(path));
543 // write out the last model