Exemplo n.º 1
0
void InitPaths( int *argc, char **argv )
{
	int		i, j, k, len, len2;
	char	temp[ MAX_OS_PATH ];
	
	
	/* note it */
	Sys_FPrintf( SYS_VRB, "--- InitPaths ---\n" );
	
	/* get the install path for backup */
	LokiInitPaths( argv[ 0 ] );
	
	/* set game to default (q3a) */
	game = &games[ 0 ];
	numBasePaths = 0;
	numGamePaths = 0;
	
	/* parse through the arguments and extract those relevant to paths */
	for( i = 0; i < *argc; i++ )
	{
		/* check for null */
		if( argv[ i ] == NULL )
			continue;
		
		/* -game */
		if( strcmp( argv[ i ], "-game" ) == 0 )
		{
			if( ++i >= *argc )
				Error( "Out of arguments: No game specified after %s", argv[ i - 1 ] );
			argv[ i - 1 ] = NULL;
			game = GetGame( argv[ i ] );
			if( game == NULL )
				game = &games[ 0 ];
			argv[ i ] = NULL;
		}

		/* -fs_forbiddenpath */
		else if( strcmp( argv[ i ], "-fs_forbiddenpath" ) == 0 )
		{
			if( ++i >= *argc )
				Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
			argv[ i - 1 ] = NULL;
			if(g_numForbiddenDirs < VFS_MAXDIRS)
			{
				strncpy(g_strForbiddenDirs[g_numForbiddenDirs], argv[i], PATH_MAX);
				g_strForbiddenDirs[g_numForbiddenDirs][PATH_MAX] = 0;
				++g_numForbiddenDirs;
			}
			argv[ i ] = NULL;
		}

		/* -fs_basepath */
		else if( strcmp( argv[ i ], "-fs_basepath" ) == 0 )
		{
			if( ++i >= *argc )
				Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
			argv[ i - 1 ] = NULL;
			AddBasePath( argv[ i ] );
			argv[ i ] = NULL;
		}
		
		/* -fs_game */
		else if( strcmp( argv[ i ], "-fs_game" ) == 0 )
		{
			if( ++i >= *argc )
				Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
			argv[ i - 1 ] = NULL;
			AddGamePath( argv[ i ] );
			argv[ i ] = NULL;
		}
		
		/* -fs_home */
		else if( strcmp( argv[ i ], "-fs_home" ) == 0 )
		{
			if( ++i >= *argc )
				Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
			argv[ i - 1 ] = NULL;
			homePath = argv[i];
			argv[ i ] = NULL;
		}
		
		/* -fs_homebase */
		else if( strcmp( argv[ i ], "-fs_homebase" ) == 0 )
		{
			if( ++i >= *argc )
				Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
			argv[ i - 1 ] = NULL;
			homeBasePath = argv[i];
			argv[ i ] = NULL;
		}

		/* -fs_homepath - sets both of them */
		else if( strcmp( argv[ i ], "-fs_homepath" ) == 0 )
		{
			if( ++i >= *argc )
				Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] );
			argv[ i - 1 ] = NULL;
			homePath = argv[i];
			homeBasePath = ".";
			argv[ i ] = NULL;
		}
	}
	
	/* remove processed arguments */
	for( i = 0, j = 0, k = 0; i < *argc && j < *argc; i++, j++ )
	{
		for( ; j < *argc && argv[ j ] == NULL; j++ );
		argv[ i ] = argv[ j ];
		if( argv[ i ] != NULL )
			k++;
	}
	*argc = k;
	
	/* add standard game path */
	AddGamePath( game->gamePath );
	
	/* if there is no base path set, figure it out */
	if( numBasePaths == 0 )
	{
		/* this is another crappy replacement for SetQdirFromPath() */
		len2 = strlen( game->magic );
		for( i = 0; i < *argc && numBasePaths == 0; i++ )
		{
			/* extract the arg */
			strcpy( temp, argv[ i ] );
			CleanPath( temp );
			len = strlen( temp );
			Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", game->magic, temp, i );
			
			/* this is slow, but only done once */
			for( j = 0; j < (len - len2); j++ )
			{
				/* check for the game's magic word */
				if( Q_strncasecmp( &temp[ j ], game->magic, len2 ) == 0 )
				{
					/* now find the next slash and nuke everything after it */
					while( temp[ ++j ] != '/' && temp[ j ] != '\0' );
					temp[ j ] = '\0';
					
					/* add this as a base path */
					AddBasePath( temp );
					break;
				}
			}
		}
		
		/* add install path */
		if( numBasePaths == 0 )
			AddBasePath( installPath );
		
		/* check again */
		if( numBasePaths == 0 )
			Error( "Failed to find a valid base path." );
	}
	
	/* this only affects unix */
	if(homeBasePath)
		AddHomeBasePath( homeBasePath );
	else
		AddHomeBasePath( game->homeBasePath );
	
	/* initialize vfs paths */
	if( numBasePaths > MAX_BASE_PATHS )
		numBasePaths = MAX_BASE_PATHS;
	if( numGamePaths > MAX_GAME_PATHS )
		numGamePaths = MAX_GAME_PATHS;
	
	/* walk the list of game paths */
	for( j = 0; j < numGamePaths; j++ )
	{
		/* walk the list of base paths */
		for( i = 0; i < numBasePaths; i++ )
		{
			/* create a full path and initialize it */
			sprintf( temp, "%s/%s/", basePaths[ i ], gamePaths[ j ] );
			vfsInitDirectory( temp );
		}
	}
	
	/* done */
	Sys_Printf( "\n" );
}
Exemplo n.º 2
0
/*
==============
main
==============
*/
int main (int argc, char **argv)
{
	static	int		i;		// VC4.2 compiler bug if auto...
	char	path[1024];

  // using GtkRadiant's versioning next to Id's versioning
  printf ("Q3Data      - (c) 1999 Id Software Inc.\n");
  printf ("GtkRadiant  - v" RADIANT_VERSION " " __DATE__ "\n");

	ExpandWildcards (&argc, &argv);

	for (i=1 ; i<argc ; i++)
	{
		if (!strcmp(argv[i], "-archive"))
		{
			archive = qtrue;
			strcpy (archivedir, argv[i+1]);
			printf ("Archiving source to: %s\n", archivedir);
			i++;
		}
		else if (!strcmp(argv[i], "-release"))
		{
			g_release = qtrue;
			strcpy (g_releasedir, argv[i+1]);
			printf ("Copy output to: %s\n", g_releasedir);
			i++;
		}
		else if ( !strcmp( argv[i], "-nostrips" ) )
		{
			g_stripify = qfalse;
			printf( "Not optimizing for strips\n" );
		}
		else if ( !strcmp( argv[i], "-writedir" ) )
		{
			strcpy( writedir, argv[i+1] );
			printf( "Write output to: %s\n", writedir );
			i++;
		}
		else if ( !strcmp( argv[i], "-verbose" ) )
		{
			g_verbose = qtrue;
		}
		else if ( !strcmp( argv[i], "-dump" ) )
		{
			printf( "Dumping contents of: '%s'\n", argv[i+1] );
			if ( strstr( argv[i+1], ".md3" ) )
			{
				MD3_Dump( argv[i+1] );
			}
			else
			{
				Error( "Do not know how to dump the contents of '%s'\n", argv[i+1] );
			}
			i++;
		}
		else if ( !strcmp( argv[i], "-3dsconvert" ) )
		{
      // NOTE TTimo this is broken, tried on a sample .3ds
      // what happens .. it calls the Convert3DStoMD3,
      // which calls the scriptlib function in non initialized state .. and crashes
			printf( "Converting %s.3DS to %s.MD3\n", argv[i+1], argv[i+1] );
			SetQdirFromPath( argv[i+1] );
      vfsInitDirectory( gamedir );
			Convert3DStoMD3( argv[i+1] );
			i++;
		}
		else if (!strcmp(argv[i], "-only"))
		{
			strcpy (g_only, argv[i+1]);
			printf ("Only grabbing %s\n", g_only);
			i++;
		}
		else if (!strcmp(argv[i], "-gamedir"))
		{
			strcpy(gamedir, argv[i+1]);
			i++;
		}
		else if (argv[i][0] == '-')
			Error ("Unknown option \"%s\"", argv[i]);
		else
			break;
	}

	if (i == argc)
		Error ("usage: q3data [-archive <directory>] [-dump <file.md3>] [-release <directory>] [-only <model>] [-3dsconvert <file.3ds>] [-verbose] [file.qdt]");

	for ( ; i<argc ; i++)
	{
		printf ("--------------- %s ---------------\n", argv[i]);
		// load the script
		strcpy (path, argv[i]);
		DefaultExtension (path, ".qdt");
		if(!gamedir[0])
			SetQdirFromPath (path);
    // NOTE TTimo
    // q3data went through a partial conversion to use the vfs
    // it was never actually tested before 1.1.1
    // the code is still mostly using direct file access calls
    vfsInitDirectory( gamedir );
		LoadScriptFile (ExpandArg(path), -1);
		
		//
		// parse it
		//
		ParseScript ();

		// write out the last model
		FinishModel ( TYPE_UNKNOWN );
	}

	return 0;
}
Exemplo n.º 3
0
void QE_InitVFS( void ){
	// VFS initialization -----------------------
	// we will call vfsInitDirectory, giving the directories to look in (for files in pk3's and for standalone files)
	// we need to call in order, the mod ones first, then the base ones .. they will be searched in this order
	// *nix systems have a dual filesystem in ~/.q3a, which is searched first .. so we need to add that too
	Str directory,prefabs;

	// TTimo: let's leave this to HL mode for now
	if ( g_pGameDescription->mGameFile == "hl.game" ) {
		// Hydra: we search the "gametools" path first so that we can provide editor
		// specific pk3's wads and misc files for use by the editor.
		// the relevant map compiler tools will NOT use this directory, so this helps
		// to ensure that editor files are not used/required in release versions of maps
		// it also helps keep your editor files all in once place, with the editor modules,
		// plugins, scripts and config files.
		// it also helps when testing maps, as you'll know your files won't/can't be used
		// by the game engine itself.

		// <gametools>
		directory = g_pGameDescription->mGameToolsPath;
		vfsInitDirectory( directory.GetBuffer() );
	}

	// NOTE TTimo about the mymkdir calls .. this is a bit dirty, but a safe thing on *nix

	// if we have a mod dir
	if ( *ValueForKey( g_qeglobals.d_project_entity, "gamename" ) != '\0' ) {

#if defined ( __linux__ ) || defined ( __APPLE__ )
		// ~/.<gameprefix>/<fs_game>
		directory = g_qeglobals.m_strHomeGame.GetBuffer();
		Q_mkdir( directory.GetBuffer(), 0775 );
		directory += ValueForKey( g_qeglobals.d_project_entity, "gamename" );
		Q_mkdir( directory.GetBuffer(), 0775 );
		vfsInitDirectory( directory.GetBuffer() );
		AddSlash( directory );
		prefabs = directory;
		// also create the maps dir, it will be used as prompt for load/save
		directory += "/maps";
		Q_mkdir( directory, 0775 );
		// and the prefabs dir
		prefabs += "/prefabs";
		Q_mkdir( prefabs, 0775 );

#endif

		// <fs_basepath>/<fs_game>
		directory = g_pGameDescription->mEnginePath;
		directory += ValueForKey( g_qeglobals.d_project_entity, "gamename" );
		Q_mkdir( directory.GetBuffer(), 0775 );
		vfsInitDirectory( directory.GetBuffer() );
		AddSlash( directory );
		prefabs = directory;
		// also create the maps dir, it will be used as prompt for load/save
		directory += "/maps";
		Q_mkdir( directory.GetBuffer(), 0775 );
		// and the prefabs dir
		prefabs += "/prefabs";
		Q_mkdir( prefabs, 0775 );
	}

#if defined ( __linux__ ) || defined ( __APPLE__ )
	// ~/.<gameprefix>/<fs_main>
	directory = g_qeglobals.m_strHomeGame.GetBuffer();
	directory += g_pGameDescription->mBaseGame;
	vfsInitDirectory( directory.GetBuffer() );
#endif

	// <fs_basepath>/<fs_main>
	directory = g_pGameDescription->mEnginePath;
	directory += g_pGameDescription->mBaseGame;
	vfsInitDirectory( directory.GetBuffer() );
}