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";
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>
250 void PackDirectory_r( char *dir ){
252 struct direct **namelist, *ent;
254 struct dirent **namelist, *ent;
261 char dirstring[1024];
264 sprintf( dirstring, "%s%s", gamedir, dir );
265 count = scandir( dirstring, &namelist, NULL, NULL );
267 for ( i = 0 ; i < count ; i++ )
272 if ( name[0] == '.' ) {
276 sprintf( fullname, "%s/%s", dir, name );
277 sprintf( dirstring, "%s%s/%s", gamedir, dir, name );
279 if ( stat( dirstring, &st ) == -1 ) {
280 Error( "fstating %s", pf->name );
282 if ( st.st_mode & S_IFDIR ) { // directory
283 PackDirectory_r( fullname );
287 // copy or pack the file
288 ReleaseFile( fullname );
298 This is only used to cause a directory to be copied during a
299 release build (sounds, etc)
302 void Cmd_Dir( void ){
304 PackDirectory_r( token );
307 //========================================================================
309 #define MAX_RTEX 16384
311 char rtex[MAX_RTEX][64];
313 void ReleaseTexture( char *name ){
317 for ( i = 0 ; i < numrtex ; i++ )
318 if ( !Q_strncasecmp( name, rtex[i], strlen( name ) ) ) {
322 if ( numrtex == MAX_RTEX ) {
323 Error( "numrtex == MAX_RTEX" );
326 strcpy( rtex[i], name );
329 sprintf( path, "textures/%s.wal", name );
337 Only relevent for release and pak files.
338 Releases the .bsp files for the maps, and scans all of the files to
339 build a list of all textures used, which are then released.
342 void Cmd_Maps( void ){
346 while ( TokenAvailable() )
349 sprintf( map, "maps/%s.bsp", token );
356 // get all the texture references
357 sprintf( map, "%smaps/%s.bsp", gamedir, token );
358 LoadBSPFileTexinfo( map );
359 for ( i = 0 ; i < numtexinfo ; i++ )
360 ReleaseTexture( texinfo[i].texture );
365 //==============================================================
372 void ParseScript( void ){
376 { // look for a line starting with a $ command
381 if ( token[0] == '$' ) {
384 while ( TokenAvailable() )
391 if ( !strcmp( token, "$modelname" ) ) {
394 else if ( !strcmp( token, "$base" ) ) {
397 else if ( !strcmp( token, "$cd" ) ) {
400 else if ( !strcmp( token, "$origin" ) ) {
403 else if ( !strcmp( token, "$scale" ) ) {
406 else if ( !strcmp( token, "$frame" ) ) {
409 else if ( !strcmp( token, "$skin" ) ) {
412 else if ( !strcmp( token, "$skinsize" ) ) {
418 else if ( !strcmp( token, "$spritename" ) ) {
421 else if ( !strcmp( token, "$load" ) ) {
424 else if ( !strcmp( token, "$spriteframe" ) ) {
430 else if ( !strcmp( token, "$grab" ) ) {
433 else if ( !strcmp( token, "$raw" ) ) {
436 else if ( !strcmp( token, "$colormap" ) ) {
439 else if ( !strcmp( token, "$mippal" ) ) {
442 else if ( !strcmp( token, "$mipdir" ) ) {
445 else if ( !strcmp( token, "$mip" ) ) {
448 else if ( !strcmp( token, "$environment" ) ) {
454 else if ( !strcmp( token, "$video" ) ) {
460 else if ( !strcmp( token, "$file" ) ) {
463 else if ( !strcmp( token, "$dir" ) ) {
466 else if ( !strcmp( token, "$maps" ) ) {
469 else if ( !strcmp( token, "$alphalight" ) ) {
472 else if ( !strcmp( token, "$inverse16table" ) ) {
473 Cmd_Inverse16Table();
476 Error( "bad command %s\n", token );
481 //=======================================================
488 int main( int argc, char **argv ){
489 static int i; // VC4.2 compiler bug if auto...
492 ExpandWildcards( &argc, &argv );
494 InitPaths( &argc, argv );
496 for ( i = 1 ; i < argc ; i++ )
498 if ( !strcmp( argv[i], "-archive" ) ) {
499 // -archive f:/quake2/release/dump_11_30
501 strcpy( archivedir, argv[i + 1] );
502 printf( "Archiving source to: %s\n", archivedir );
505 else if ( !strcmp( argv[i], "-release" ) ) {
507 strcpy( g_releasedir, argv[i + 1] );
508 printf( "Copy output to: %s\n", g_releasedir );
511 else if ( !strcmp( argv[i], "-compress" ) ) {
512 g_compress_pak = true;
513 printf( "Compressing pakfile\n" );
515 else if ( !strcmp( argv[i], "-pak" ) ) {
518 printf( "Building pakfile: %s\n", argv[i + 1] );
519 BeginPak( argv[i + 1] );
522 else if ( !strcmp( argv[i], "-only" ) ) {
523 strcpy( g_only, argv[i + 1] );
524 printf( "Only grabbing %s\n", g_only );
527 else if ( !strcmp( argv[i], "-3ds" ) ) {
529 printf( "loading .3ds files\n" );
531 else if ( argv[i][0] == '-' ) {
532 Error( "Unknown option \"%s\"", argv[i] );
540 Error( "usage: %s [-archive <directory>] [-release <directory>] [-only <model>] [-3ds] file.qgr", argv[ 0 ] );
544 trifileext = ext_3ds;
547 trifileext = ext_tri;
550 for ( ; i < argc ; i++ )
552 printf( "--------------- %s ---------------\n", argv[i] );
554 strcpy( path, argv[i] );
555 DefaultExtension( path, ".qdt" );
556 SetQdirFromPath( path );
557 LoadScriptFile( ExpandArg( path ) );
564 // write out the last model