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
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";
36 char *ext_tri = "tri";
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 );
111 if ( !g_pak ) { // copy it
112 sprintf( dest, "%s/%s", g_releasedir, filename );
113 printf( "copying to %s\n", dest );
114 QCopyFile( source, dest );
119 printf( "paking %s\n", filename );
120 if ( strlen( filename ) >= sizeof( pf->name ) ) {
121 Error( "Filename too long for pak: %s", filename );
124 len = LoadFile( source, (void **)&buf );
126 if ( g_compress_pak && len < 4096 * 1024 ) {
128 cblock_t Huffman( cblock_t in );
135 if ( out.count < in.count ) {
136 printf( " compressed from %i to %i\n", in.count, out.count );
146 strcpy( pf->name, filename );
147 pf->filepos = LittleLong( ftell( pakfile ) );
148 pf->filelen = LittleLong( len );
151 SafeWrite( pakfile, buf, len );
162 void FinishPak( void ){
172 pakheader.id[0] = 'P';
173 pakheader.id[1] = 'A';
174 pakheader.id[2] = 'C';
175 pakheader.id[3] = 'K';
176 dirlen = (byte *)pf - (byte *)pfiles;
177 pakheader.dirofs = LittleLong( ftell( pakfile ) );
178 pakheader.dirlen = LittleLong( dirlen );
180 checksum = Com_BlockChecksum( (void *)pfiles, dirlen );
182 SafeWrite( pakfile, pfiles, dirlen );
184 i = ftell( pakfile );
186 fseek( pakfile, 0, SEEK_SET );
187 SafeWrite( pakfile, &pakheader, sizeof( pakheader ) );
191 printf( "%i files packed in %i bytes\n",d, i );
192 printf( "checksum: 0x%x\n", checksum );
200 This is only used to cause a file to be copied during a release
201 build (default.cfg, maps, etc)
204 void Cmd_File( void ){
206 ReleaseFile( token );
217 void PackDirectory_r( char *dir ){
218 struct _finddata_t fileinfo;
220 char dirstring[1024];
223 sprintf( dirstring, "%s%s/*.*", gamedir, dir );
225 handle = _findfirst( dirstring, &fileinfo );
226 if ( handle == -1 ) {
232 sprintf( filename, "%s/%s", dir, fileinfo.name );
233 if ( fileinfo.attrib & _A_SUBDIR ) { // directory
234 if ( fileinfo.name[0] != '.' ) { // don't pak . and ..
235 PackDirectory_r( filename );
239 // copy or pack the file
240 ReleaseFile( filename );
241 } while ( _findnext( handle, &fileinfo ) != -1 );
243 _findclose( handle );
247 #include <sys/types.h>
251 void PackDirectory_r( char *dir ){
253 struct direct **namelist, *ent;
255 struct dirent **namelist, *ent;
262 char dirstring[1024];
265 sprintf( dirstring, "%s%s", gamedir, dir );
266 count = scandir( dirstring, &namelist, NULL, NULL );
268 for ( i = 0 ; i < count ; i++ )
273 if ( name[0] == '.' ) {
277 sprintf( fullname, "%s/%s", dir, name );
278 sprintf( dirstring, "%s%s/%s", gamedir, dir, name );
280 if ( stat( dirstring, &st ) == -1 ) {
281 Error( "fstating %s", pf->name );
283 if ( st.st_mode & S_IFDIR ) { // directory
284 PackDirectory_r( fullname );
288 // copy or pack the file
289 ReleaseFile( fullname );
299 This is only used to cause a directory to be copied during a
300 release build (sounds, etc)
303 void Cmd_Dir( void ){
305 PackDirectory_r( token );
308 //========================================================================
310 #define MAX_RTEX 16384
312 char rtex[MAX_RTEX][64];
314 void ReleaseTexture( char *name ){
318 for ( i = 0 ; i < numrtex ; i++ )
319 if ( !Q_strncasecmp( name, rtex[i], strlen( name ) ) ) {
323 if ( numrtex == MAX_RTEX ) {
324 Error( "numrtex == MAX_RTEX" );
327 strcpy( rtex[i], name );
330 sprintf( path, "textures/%s.wal", name );
338 Only relevent for release and pak files.
339 Releases the .bsp files for the maps, and scans all of the files to
340 build a list of all textures used, which are then released.
343 void Cmd_Maps( void ){
347 while ( TokenAvailable() )
350 sprintf( map, "maps/%s.bsp", token );
357 // get all the texture references
358 sprintf( map, "%smaps/%s.bsp", gamedir, token );
359 LoadBSPFileTexinfo( map );
360 for ( i = 0 ; i < numtexinfo ; i++ )
361 ReleaseTexture( texinfo[i].texture );
366 //==============================================================
373 void ParseScript( void ){
377 { // look for a line starting with a $ command
382 if ( token[0] == '$' ) {
385 while ( TokenAvailable() )
392 if ( !strcmp( token, "$modelname" ) ) {
395 else if ( !strcmp( token, "$base" ) ) {
398 else if ( !strcmp( token, "$cd" ) ) {
401 else if ( !strcmp( token, "$origin" ) ) {
404 else if ( !strcmp( token, "$scale" ) ) {
407 else if ( !strcmp( token, "$frame" ) ) {
410 else if ( !strcmp( token, "$skin" ) ) {
413 else if ( !strcmp( token, "$skinsize" ) ) {
419 else if ( !strcmp( token, "$spritename" ) ) {
422 else if ( !strcmp( token, "$load" ) ) {
425 else if ( !strcmp( token, "$spriteframe" ) ) {
431 else if ( !strcmp( token, "$grab" ) ) {
434 else if ( !strcmp( token, "$raw" ) ) {
437 else if ( !strcmp( token, "$colormap" ) ) {
440 else if ( !strcmp( token, "$mippal" ) ) {
443 else if ( !strcmp( token, "$mipdir" ) ) {
446 else if ( !strcmp( token, "$mip" ) ) {
449 else if ( !strcmp( token, "$environment" ) ) {
455 else if ( !strcmp( token, "$video" ) ) {
461 else if ( !strcmp( token, "$file" ) ) {
464 else if ( !strcmp( token, "$dir" ) ) {
467 else if ( !strcmp( token, "$maps" ) ) {
470 else if ( !strcmp( token, "$alphalight" ) ) {
473 else if ( !strcmp( token, "$inverse16table" ) ) {
474 Cmd_Inverse16Table();
477 Error( "bad command %s\n", token );
482 //=======================================================
489 int main( int argc, char **argv ){
490 static int i; // VC4.2 compiler bug if auto...
493 ExpandWildcards( &argc, &argv );
495 InitPaths( &argc, argv );
497 for ( i = 1 ; i < argc ; i++ )
499 if ( !strcmp( argv[i], "-archive" ) ) {
500 // -archive f:/quake2/release/dump_11_30
502 strcpy( archivedir, argv[i + 1] );
503 printf( "Archiving source to: %s\n", archivedir );
506 else if ( !strcmp( argv[i], "-release" ) ) {
508 strcpy( g_releasedir, argv[i + 1] );
509 printf( "Copy output to: %s\n", g_releasedir );
512 else if ( !strcmp( argv[i], "-compress" ) ) {
513 g_compress_pak = true;
514 printf( "Compressing pakfile\n" );
516 else if ( !strcmp( argv[i], "-pak" ) ) {
519 printf( "Building pakfile: %s\n", argv[i + 1] );
520 BeginPak( argv[i + 1] );
523 else if ( !strcmp( argv[i], "-only" ) ) {
524 strcpy( g_only, argv[i + 1] );
525 printf( "Only grabbing %s\n", g_only );
528 else if ( !strcmp( argv[i], "-3ds" ) ) {
530 printf( "loading .3ds files\n" );
532 else if ( argv[i][0] == '-' ) {
533 Error( "Unknown option \"%s\"", argv[i] );
541 Error( "usage: %s [-archive <directory>] [-release <directory>] [-only <model>] [-3ds] file.qgr", argv[ 0 ] );
545 trifileext = ext_3ds;
548 trifileext = ext_tri;
551 for ( ; i < argc ; i++ )
553 printf( "--------------- %s ---------------\n", argv[i] );
555 strcpy( path, argv[i] );
556 DefaultExtension( path, ".qdt" );
557 SetQdirFromPath( path );
558 LoadScriptFile( ExpandArg( path ) );
565 // write out the last model