2 Copyright (C) 1999-2006 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
26 qboolean g_compress_pak;
27 qboolean g_release; // don't grab, copy output data to new tree
28 qboolean g_pak; // if true, copy to pak instead of release
29 char g_releasedir[1024]; // c:\quake2\baseq2, etc
30 qboolean g_archive; // don't grab, copy source data to new tree
32 char g_only[256]; // if set, only grab this cd
33 qboolean g_skipmodel; // set true when a cd is not g_only
35 char *ext_3ds = "3ds";
39 char game[64] = "quake2";
41 void InitPaths( int *argc, char **argv );
44 =======================================================
48 =======================================================
64 packfile_t pfiles[16384];
67 packheader_t pakheader;
76 void BeginPak (char *outname)
81 pakfile = SafeOpenWrite (outname);
83 // leave space for header
84 SafeWrite (pakfile, &pakheader, sizeof(pakheader));
94 Filename should be gamedir reletive.
95 Either copies the file to the release dir, or adds it to
99 void ReleaseFile (char *filename)
109 sprintf (source, "%s%s", gamedir, filename);
113 sprintf (dest, "%s/%s", g_releasedir, filename);
114 printf ("copying to %s\n", dest);
115 QCopyFile (source, dest);
120 printf ("paking %s\n", filename);
121 if (strlen(filename) >= sizeof(pf->name))
122 Error ("Filename too long for pak: %s", filename);
124 len = LoadFile (source, (void **)&buf);
126 if (g_compress_pak && len < 4096*1024 )
129 cblock_t Huffman (cblock_t in);
136 if (out.count < in.count)
138 printf (" compressed from %i to %i\n", in.count, out.count);
147 strcpy (pf->name, filename);
148 pf->filepos = LittleLong(ftell(pakfile));
149 pf->filelen = LittleLong(len);
152 SafeWrite (pakfile, buf, len);
163 void FinishPak (void)
173 pakheader.id[0] = 'P';
174 pakheader.id[1] = 'A';
175 pakheader.id[2] = 'C';
176 pakheader.id[3] = 'K';
177 dirlen = (byte *)pf - (byte *)pfiles;
178 pakheader.dirofs = LittleLong(ftell(pakfile));
179 pakheader.dirlen = LittleLong(dirlen);
181 checksum = Com_BlockChecksum ( (void *)pfiles, dirlen );
183 SafeWrite (pakfile, pfiles, dirlen);
187 fseek (pakfile, 0, SEEK_SET);
188 SafeWrite (pakfile, &pakheader, sizeof(pakheader));
192 printf ("%i files packed in %i bytes\n",d, i);
193 printf ("checksum: 0x%x\n", checksum);
201 This is only used to cause a file to be copied during a release
202 build (default.cfg, maps, etc)
219 void PackDirectory_r (char *dir)
221 struct _finddata_t fileinfo;
223 char dirstring[1024];
226 sprintf (dirstring, "%s%s/*.*", gamedir, dir);
228 handle = _findfirst (dirstring, &fileinfo);
234 sprintf (filename, "%s/%s", dir, fileinfo.name);
235 if (fileinfo.attrib & _A_SUBDIR)
237 if (fileinfo.name[0] != '.') // don't pak . and ..
238 PackDirectory_r (filename);
241 // copy or pack the file
242 ReleaseFile (filename);
243 } while (_findnext( handle, &fileinfo ) != -1);
249 #include <sys/types.h>
252 void PackDirectory_r (char *dir)
255 struct direct **namelist, *ent;
257 struct dirent **namelist, *ent;
264 char dirstring[1024];
267 sprintf (dirstring, "%s%s", gamedir, dir);
268 count = scandir(dirstring, &namelist, NULL, NULL);
270 for (i=0 ; i<count ; i++)
278 sprintf (fullname, "%s/%s", dir, name);
279 sprintf (dirstring, "%s%s/%s", gamedir, dir, name);
281 if (stat (dirstring, &st) == -1)
282 Error ("fstating %s", pf->name);
283 if (st.st_mode & S_IFDIR)
285 PackDirectory_r (fullname);
289 // copy or pack the file
290 ReleaseFile (fullname);
300 This is only used to cause a directory to be copied during a
301 release build (sounds, etc)
307 PackDirectory_r (token);
310 //========================================================================
312 #define MAX_RTEX 16384
314 char rtex[MAX_RTEX][64];
316 void ReleaseTexture (char *name)
321 for (i=0 ; i<numrtex ; i++)
322 if (!Q_strncasecmp(name, rtex[i], strlen(name)))
325 if (numrtex == MAX_RTEX)
326 Error ("numrtex == MAX_RTEX");
328 strcpy (rtex[i], name);
331 sprintf (path, "textures/%s.wal", name);
339 Only relevent for release and pak files.
340 Releases the .bsp files for the maps, and scans all of the files to
341 build a list of all textures used, which are then released.
349 while (TokenAvailable ())
352 sprintf (map, "maps/%s.bsp", token);
358 // get all the texture references
359 sprintf (map, "%smaps/%s.bsp", gamedir, token);
360 LoadBSPFileTexinfo (map);
361 for (i=0 ; i<numtexinfo ; i++)
362 ReleaseTexture (texinfo[i].texture);
367 //==============================================================
374 void ParseScript (void)
379 { // look for a line starting with a $ command
385 while (TokenAvailable())
392 if (!strcmp (token, "$modelname"))
394 else if (!strcmp (token, "$base"))
396 else if (!strcmp (token, "$cd"))
398 else if (!strcmp (token, "$origin"))
400 else if (!strcmp (token, "$scale"))
402 else if (!strcmp (token, "$frame"))
404 else if (!strcmp (token, "$skin"))
406 else if (!strcmp (token, "$skinsize"))
411 else if (!strcmp (token, "$spritename"))
413 else if (!strcmp (token, "$load"))
415 else if (!strcmp (token, "$spriteframe"))
420 else if (!strcmp (token, "$grab"))
422 else if (!strcmp (token, "$raw"))
424 else if (!strcmp (token, "$colormap"))
426 else if (!strcmp (token, "$mippal"))
428 else if (!strcmp (token, "$mipdir"))
430 else if (!strcmp (token, "$mip"))
432 else if (!strcmp (token, "$environment"))
437 else if (!strcmp (token, "$video"))
442 else if (!strcmp (token, "$file"))
444 else if (!strcmp (token, "$dir"))
446 else if (!strcmp (token, "$maps"))
448 else if (!strcmp (token, "$alphalight"))
450 else if (!strcmp (token, "$inverse16table" ))
451 Cmd_Inverse16Table();
453 Error ("bad command %s\n", token);
457 //=======================================================
464 int main (int argc, char **argv)
466 static int i; // VC4.2 compiler bug if auto...
469 ExpandWildcards (&argc, &argv);
471 InitPaths( &argc, argv );
473 for (i=1 ; i<argc ; i++)
475 if (!strcmp(argv[i], "-archive"))
477 // -archive f:/quake2/release/dump_11_30
479 strcpy (archivedir, argv[i+1]);
480 printf ("Archiving source to: %s\n", archivedir);
483 else if (!strcmp(argv[i], "-release"))
486 strcpy (g_releasedir, argv[i+1]);
487 printf ("Copy output to: %s\n", g_releasedir);
490 else if (!strcmp(argv[i], "-compress"))
492 g_compress_pak = true;
493 printf ("Compressing pakfile\n");
495 else if (!strcmp(argv[i], "-pak"))
499 printf ("Building pakfile: %s\n", argv[i+1]);
500 BeginPak (argv[i+1]);
503 else if (!strcmp(argv[i], "-only"))
505 strcpy (g_only, argv[i+1]);
506 printf ("Only grabbing %s\n", g_only);
509 else if (!strcmp(argv[i], "-3ds"))
512 printf ("loading .3ds files\n");
514 else if (argv[i][0] == '-')
515 Error ("Unknown option \"%s\"", argv[i]);
521 Error ("usage: %s [-archive <directory>] [-release <directory>] [-only <model>] [-3ds] file.qgr", argv[ 0 ] );
524 trifileext = ext_3ds;
526 trifileext = ext_tri;
528 for ( ; i<argc ; i++)
530 printf ("--------------- %s ---------------\n", argv[i]);
532 strcpy (path, argv[i]);
533 DefaultExtension (path, ".qdt");
534 SetQdirFromPath (path);
535 LoadScriptFile (ExpandArg(path));
542 // write out the last model