示例#1
0
bool CBaseGameStats::SaveToFileNOW( bool bForceSyncWrite /* = false */ )
{
	if ( !StatsTrackingIsFullyEnabled() )
		return false;

	// this code path is only for old format stats.  Products that use new format take a different path.
	if ( !gamestats->UseOldFormat() )
		return false;

	CUtlBuffer buf;
	buf.PutShort( GAMESTATS_FILE_VERSION );
	buf.Put( s_szPseudoUniqueID, 16 );

	if( ShouldTrackStandardStats() )
		m_BasicStats.SaveToBuffer( buf ); 
	else
		buf.PutInt( GAMESTATS_STANDARD_NOT_SAVED );

	gamestats->AppendCustomDataToSaveBuffer( buf );

	char fullpath[ 512 ] = { 0 };
	if ( filesystem->FileExists( GetStatSaveFileName(), GAMESTATS_PATHID ) )
	{
		filesystem->RelativePathToFullPath( GetStatSaveFileName(), GAMESTATS_PATHID, fullpath, sizeof( fullpath ) );
	}
	else
	{
		// filename is local to game dir for Steam, so we need to prepend game dir for regular file save
		char gamePath[256];
		engine->GetGameDir( gamePath, 256 );
		Q_StripTrailingSlash( gamePath );
		Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", gamePath, GetStatSaveFileName() );
		Q_strlower( fullpath );
		Q_FixSlashes( fullpath );
	}

	// StatsLog( "SaveToFileNOW '%s'\n", fullpath );

	if( CBGSDriver.m_bShuttingDown || bForceSyncWrite ) //write synchronously
	{
		filesystem->WriteFile( fullpath, GAMESTATS_PATHID, buf );

		StatsLog( "Shut down wrote to '%s'\n", fullpath );
	}
	else
	{
		// Allocate memory for async system to use (and free afterward!!!)
		size_t nBufferSize = buf.TellPut();
		void *pMem = malloc(nBufferSize);
		CUtlBuffer statsBuffer( pMem, nBufferSize );
		statsBuffer.Put( buf.Base(), nBufferSize );

		// Write data async
		filesystem->AsyncWrite( fullpath, statsBuffer.Base(), statsBuffer.TellPut(), true, false );
	}

	return true;
}
示例#2
0
//-----------------------------------------------------------------------------
// Purpose: 
// Output : const char
//-----------------------------------------------------------------------------
const char *GetBaseDirectory( void )
{
	static char path[MAX_PATH] = {0};
	if ( path[0] == 0 )
	{
		GetModuleFileName( (HMODULE)GetAppInstance(), path, sizeof( path ) );
		Q_StripLastDir( path, sizeof( path ) );	// Get rid of the filename.
		Q_StripTrailingSlash( path );
	}
	return path;
}
//-----------------------------------------------------------------------------
// Adds the platform folder to the search path.
//-----------------------------------------------------------------------------
void FileSystem_AddSearchPath_Platform( IFileSystem *pFileSystem, const char *szGameInfoPath )
{
	char platform[MAX_PATH];
	if ( pFileSystem->IsSteam() )
	{
		// Steam doesn't support relative paths
		Q_strncpy( platform, "platform", MAX_PATH );
	}
	else
	{
		if ( !Sys_GetExecutableName( platform, sizeof( platform ) ) )
		{
			// fall back to old method if we can't get the executable name
			Q_strncpy( platform, szGameInfoPath, MAX_PATH );
			Q_StripTrailingSlash( platform );
			Q_strncat( platform, "/../platform", MAX_PATH, MAX_PATH );
		}
		else
		{
			Q_StripFilename( platform );
			Q_StripTrailingSlash( platform );
			Q_FixSlashes( platform );

			// remove bin folder if necessary
			int nLen = Q_strlen( platform );
			if ( ( nLen > 4 )
					&& platform[ nLen - 4 ] == CORRECT_PATH_SEPARATOR
					&& !Q_stricmp( "bin", platform + ( nLen - 3 ) )
				)
			{
				Q_StripLastDir( platform, sizeof( platform ) );
				Q_StripTrailingSlash( platform );
			}
			// go into platform folder
			Q_strncat( platform, "/platform", MAX_PATH, MAX_PATH );
		}
	}

	pFileSystem->AddSearchPath( platform, "PLATFORM" );
}
//-----------------------------------------------------------------------------
// Adds the platform folder to the search path.
//-----------------------------------------------------------------------------
void FileSystem_AddSearchPath_Platform( IFileSystem *pFileSystem, const char *szGameInfoPath )
{
	char platform[MAX_PATH];
	if ( pFileSystem->IsSteam() )
	{
		// Steam doesn't support relative paths
		Q_strncpy( platform, "platform", MAX_PATH );
	}
	else
	{
		Q_strncpy( platform, szGameInfoPath, MAX_PATH );
		Q_StripTrailingSlash( platform );
		Q_strncat( platform, "/../platform", MAX_PATH, MAX_PATH );
	}

	pFileSystem->AddSearchPath( platform, "PLATFORM" );
}
示例#5
0
//-----------------------------------------------------------------------------
// Computes a full directory
//-----------------------------------------------------------------------------
static void ComputeFullPath( const char *pRelativeDir, char *pFullPath, int nBufLen )
{
	if ( !Q_IsAbsolutePath( pRelativeDir ) )
	{
		char pDir[MAX_PATH];
		if ( g_pFullFileSystem->GetCurrentDirectory( pDir, sizeof(pDir) ) )
		{
			Q_ComposeFileName( pDir, pRelativeDir, pFullPath, nBufLen );
		}
	}
	else
	{
		Q_strncpy( pFullPath, pRelativeDir, nBufLen );
	}

	Q_StripTrailingSlash( pFullPath );

	// Ensure the output directory exists
	g_pFullFileSystem->CreateDirHierarchy( pFullPath );
}
示例#6
0
//-----------------------------------------------------------------------------
// Purpose: Add a new configuration with proper defaults to a keyvalue block
//-----------------------------------------------------------------------------
bool AddConfig( int configID )
{
	// Find the games block of the keyvalues
	KeyValues *gameBlock = g_ConfigManager.GetGameBlock();
	
	if ( gameBlock == NULL )
	{
		Assert( 0 );
		return false;
	}

	// Set to defaults
	defaultConfigInfo_t newInfo;
	memset( &newInfo, 0, sizeof( newInfo ) );

	// Data for building the new configuration
	const char *pModName = g_Configs[configID]->m_Name.Base();
	const char *pModDirectory = g_Configs[configID]->m_ModDir.Base();
	
	// Mod name
	Q_strncpy( newInfo.gameName, pModName, sizeof( newInfo.gameName ) );
	
	// FGD
	Q_strncpy( newInfo.FGD, "base.fgd", sizeof( newInfo.FGD ) );

	// Get the base directory
	Q_FileBase( pModDirectory, newInfo.gameDir, sizeof( newInfo.gameDir ) );

	// Default executable
	Q_strncpy( newInfo.exeName, "hl2.exe", sizeof( newInfo.exeName ) );

	char szPath[MAX_PATH];
	Q_strncpy( szPath, pModDirectory, sizeof( szPath ) );
	Q_StripLastDir( szPath, sizeof( szPath ) );
	Q_StripTrailingSlash( szPath );

	char fullDir[MAX_PATH];
	g_ConfigManager.GetRootGameDirectory( fullDir, sizeof( fullDir ), g_ConfigManager.GetRootDirectory(), "half-life 2" );
	
	return g_ConfigManager.AddDefaultConfig( newInfo, gameBlock, szPath, fullDir );
}
FSReturnCode_t FileSystem_LoadSearchPaths( CFSSearchPathsInit &initInfo )
{
	if ( !initInfo.m_pFileSystem || !initInfo.m_pDirectoryName )
		return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_LoadSearchPaths: Invalid parameters specified." );

	KeyValues *pMainFile, *pFileSystemInfo, *pSearchPaths;
	FSReturnCode_t retVal = LoadGameInfoFile( initInfo.m_pDirectoryName, pMainFile, pFileSystemInfo, pSearchPaths );
	if ( retVal != FS_OK )
		return retVal;
	
	// All paths except those marked with |gameinfo_path| are relative to the base dir.
	char baseDir[MAX_PATH];
	if ( !FileSystem_GetBaseDir( baseDir, sizeof( baseDir ) ) )
		return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetBaseDir failed." );

	initInfo.m_ModPath[0] = 0;

	#define GAMEINFOPATH_TOKEN		"|gameinfo_path|"
	#define BASESOURCEPATHS_TOKEN	"|all_source_engine_paths|"

	bool bLowViolence = IsLowViolenceBuild();
	bool bFirstGamePath = true;
	
	for ( KeyValues *pCur=pSearchPaths->GetFirstValue(); pCur; pCur=pCur->GetNextValue() )
	{
		const char *pPathID = pCur->GetName();
		const char *pLocation = pCur->GetString();
		
		if ( Q_stristr( pLocation, GAMEINFOPATH_TOKEN ) == pLocation )
		{
			pLocation += strlen( GAMEINFOPATH_TOKEN );
			FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, initInfo.m_pDirectoryName, pLocation, bLowViolence );
		}
		else if ( Q_stristr( pLocation, BASESOURCEPATHS_TOKEN ) == pLocation )
		{
			// This is a special identifier that tells it to add the specified path for all source engine versions equal to or prior to this version.
			// So in Orange Box, if they specified:
			//		|all_source_engine_paths|hl2
			// it would add the ep2\hl2 folder and the base (ep1-era) hl2 folder.
			//
			// We need a special identifier in the gameinfo.txt here because the base hl2 folder exists in different places.
			// In the case of a game or a Steam-launched dedicated server, all the necessary prior engine content is mapped in with the Steam depots,
			// so we can just use the path as-is.

			// In the case of an hldsupdatetool dedicated server, the base hl2 folder is "..\..\hl2" (since we're up in the 'orangebox' folder).
												   
			pLocation += strlen( BASESOURCEPATHS_TOKEN );

			// Add the Orange-box path (which also will include whatever the depots mapped in as well if we're 
			// running a Steam-launched app).
			FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, pLocation, bLowViolence );

			if ( FileSystem_IsHldsUpdateToolDedicatedServer() )
			{			
				// If we're using the hldsupdatetool dedicated server, then go up a directory to get the ep1-era files too.
				char ep1EraPath[MAX_PATH];
				V_snprintf( ep1EraPath, sizeof( ep1EraPath ), "..%c%s", CORRECT_PATH_SEPARATOR, pLocation );
				FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, ep1EraPath, bLowViolence );
			}
		}
		else
		{
			FileSystem_AddLoadedSearchPath( initInfo, pPathID, &bFirstGamePath, baseDir, pLocation, bLowViolence );
		}
	}

	pMainFile->deleteThis();

	//
	// Set up search paths for add-ons
	//
	if ( IsPC() )
	{
#ifdef ENGINE_DLL
		FileSystem_UpdateAddonSearchPaths( initInfo.m_pFileSystem );
#endif
	}

	// these specialized tool paths are not used on 360 and cause a costly constant perf tax, so inhibited
	if ( IsPC() )
	{
		// Create a content search path based on the game search path
		const char *pGameRoot = getenv( GAMEROOT_TOKEN );
		const char *pContentRoot = getenv( CONTENTROOT_TOKEN );

		if ( pGameRoot && pContentRoot )
		{
			int nLen = initInfo.m_pFileSystem->GetSearchPath( "GAME", false, NULL, 0 );
			char *pSearchPath = (char*)stackalloc( nLen * sizeof(char) );
			initInfo.m_pFileSystem->GetSearchPath( "GAME", false, pSearchPath, nLen );
			char *pPath = pSearchPath;
			while( pPath )
			{
				char *pSemiColon = strchr( pPath, ';' );
				if ( pSemiColon )
				{
					*pSemiColon = 0;
				}

				Q_StripTrailingSlash( pPath );
				Q_FixSlashes( pPath );

				const char *pCurPath = pPath;
				pPath = pSemiColon ? pSemiColon + 1 : NULL;

				char pRelativePath[MAX_PATH];
				char pContentPath[MAX_PATH];
				if ( !Q_MakeRelativePath( pCurPath, pGameRoot, pRelativePath, sizeof(pRelativePath) ) )
					continue;

				Q_ComposeFileName( pContentRoot, pRelativePath, pContentPath, sizeof(pContentPath) );
				initInfo.m_pFileSystem->AddSearchPath( pContentPath, "CONTENT" );
			}

			// Add the "platform" directory as a game searchable path
			char pPlatformPath[MAX_PATH];
			Q_ComposeFileName( pGameRoot, "platform", pPlatformPath, sizeof(pPlatformPath) );
			initInfo.m_pFileSystem->AddSearchPath( pPlatformPath, "GAME", PATH_ADD_TO_TAIL );

			initInfo.m_pFileSystem->AddSearchPath( pContentRoot, "CONTENTROOT" );
			initInfo.m_pFileSystem->AddSearchPath( pGameRoot, "GAMEROOT" );
		}
		else
		{
			// Come up with some reasonable default
			int nLen = initInfo.m_pFileSystem->GetSearchPath( "MOD", false, NULL, 0 );
			char *pSearchPath = (char*)stackalloc( nLen * sizeof(char) );
			initInfo.m_pFileSystem->GetSearchPath( "MOD", false, pSearchPath, nLen );
			char *pSemiColon = strchr( pSearchPath, ';' );
			if ( pSemiColon )
			{
				*pSemiColon = 0;
			}

			char pGameRootPath[MAX_PATH];
			Q_strncpy( pGameRootPath, pSearchPath, sizeof(pGameRootPath) );
			Q_StripTrailingSlash( pGameRootPath );
			Q_StripFilename( pGameRootPath );

			char pContentRootPath[MAX_PATH];
			Q_strncpy( pContentRootPath, pGameRootPath, sizeof(pContentRootPath) );
			char *pGame = Q_stristr( pContentRootPath, "game" );

			if ( pGame )
			{
				Q_strcpy( pGame, "content" );
			}

			initInfo.m_pFileSystem->AddSearchPath( pContentRootPath, "CONTENTROOT" );
			initInfo.m_pFileSystem->AddSearchPath( pGameRootPath, "GAMEROOT" );
		}

		// Also, mark specific path IDs as "by request only". That way, we won't waste time searching in them
		// when people forget to specify a search path.
		initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "contentroot", true );
		initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "gameroot", true );
		initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "content", true );
	}

	// Also, mark specific path IDs as "by request only". That way, we won't waste time searching in them
	// when people forget to specify a search path.
	initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "executable_path", true );
	initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "gamebin", true );
	initInfo.m_pFileSystem->MarkPathIDByRequestOnly( "mod", true );

	// Add the write path last.
	if ( initInfo.m_ModPath[0] != 0 )
	{
		initInfo.m_pFileSystem->AddSearchPath( initInfo.m_ModPath, "DEFAULT_WRITE_PATH", PATH_ADD_TO_TAIL );
	}

#ifdef _DEBUG	
	initInfo.m_pFileSystem->PrintSearchPaths();
#endif

#if defined( ENABLE_RUNTIME_STACK_TRANSLATION ) && !defined( _X360 )
	//copy search paths to stack tools so it can grab pdb's from all over. But only on P4 or Steam Beta builds
	if( (CommandLine()->FindParm( "-steam" ) == 0) || //not steam
		(CommandLine()->FindParm( "-internalbuild" ) != 0) ) //steam beta is ok
	{
		char szSearchPaths[4096];
		//int CBaseFileSystem::GetSearchPath( const char *pathID, bool bGetPackFiles, char *pPath, int nMaxLen )
		int iLength1 = initInfo.m_pFileSystem->GetSearchPath( "EXECUTABLE_PATH", false, szSearchPaths, 4096 );
		if( iLength1 == 1 )
			iLength1 = 0;

		int iLength2 = initInfo.m_pFileSystem->GetSearchPath( "GAMEBIN", false, szSearchPaths + iLength1, 4096 - iLength1 );
		if( (iLength2 > 1) && (iLength1 > 1) )
		{
			szSearchPaths[iLength1 - 1] = ';'; //replace first null terminator
		}

		const char *szAdditionalPath = CommandLine()->ParmValue( "-AdditionalPDBSearchPath" );
		if( szAdditionalPath && szAdditionalPath[0] )
		{
			int iLength = iLength1;
			if( iLength2 > 1 )
				iLength += iLength2;

			if( iLength != 0 )
			{
				szSearchPaths[iLength - 1] = ';'; //replaces null terminator
			}
			V_strncpy( &szSearchPaths[iLength], szAdditionalPath, 4096 - iLength );			
		}

		//Append the perforce symbol server last. Documentation says that "srv*\\perforce\symbols" should work, but it doesn't.
		//"symsrv*symsrv.dll*\\perforce\symbols" which the docs say is the same statement, works.
		{
			V_strncat( szSearchPaths, ";symsrv*symsrv.dll*\\\\perforce\\symbols", 4096 );
		}

		SetStackTranslationSymbolSearchPath( szSearchPaths );
		//MessageBox( NULL, szSearchPaths, "Search Paths", 0 );
	}
#endif

	return FS_OK;
}
示例#8
0
//-----------------------------------------------------------------------------
// Purpose: extracts the list of defines and includes used for this config
//-----------------------------------------------------------------------------
bool CVCProjConvert::ExtractIncludes( IXMLDOMElement *pDoc, CConfiguration & config )
{
	config.ResetDefines();
	config.ResetIncludes();
	
	if (!pDoc)
	{
		return false;
	}

#ifdef _WIN32
	CComPtr<IXMLDOMNodeList> pTools;
	pDoc->getElementsByTagName( _bstr_t("Tool"), &pTools);
	if (pTools)
	{
		long len = 0;
		pTools->get_length(&len);
		for ( int i=0; i<len; i++ )
		{
			CComPtr<IXMLDOMNode> pNode;
			pTools->get_item( i, &pNode );
			if (pNode)
			{
				CComQIPtr<IXMLDOMElement> pElem( pNode );
				CUtlSymbol toolName = GetXMLAttribValue( pElem, "Name" );
				if ( toolName == "VCCLCompilerTool" )
				{
					CUtlSymbol defines = GetXMLAttribValue( pElem, "PreprocessorDefinitions" );
					char *str = (char *)_alloca( Q_strlen( defines.String() ) + 1 );
					Assert( str );
					Q_strcpy( str, defines.String() );
					// now tokenize the string on the ";" char
					char *delim = strchr( str, ';' );
					char *curpos = str;
					while ( delim )
					{
						*delim = 0;
						delim++;
						if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" )  &&  
							 Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines
						{
							config.AddDefine( curpos );
						}
						curpos = delim;
						delim = strchr( delim, ';' );
					}
					if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" )  &&  
						 Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines
					{
						config.AddDefine( curpos );
					}

					CUtlSymbol includes = GetXMLAttribValue( pElem, "AdditionalIncludeDirectories" );
					char *str2 = (char *)_alloca( Q_strlen( includes.String() ) + 1 );
					Assert( str2 );
					Q_strcpy( str2, includes.String() );
					// now tokenize the string on the ";" char
					delim = strchr( str2, ',' );
					curpos = str2;
					while ( delim )
					{
						*delim = 0;
						delim++;
						config.AddInclude( curpos );
						curpos = delim;
						delim = strchr( delim, ',' );
					}
					config.AddInclude( curpos );
				}
			}
		}
	}
#elif _LINUX
	DOMNodeList *nodes= pDoc->getElementsByTagName( _bstr_t("Tool"));
	if (nodes)
	{
		int len = nodes->getLength();
		for ( int i=0; i<len; i++ )
		{
			DOMNode *node = nodes->item(i);
			if (node)
			{
				CUtlSymbol toolName = GetXMLAttribValue( node, "Name" );
				if ( toolName == "VCCLCompilerTool" )
				{
					CUtlSymbol defines = GetXMLAttribValue( node, "PreprocessorDefinitions" );
					char *str = (char *)_alloca( Q_strlen( defines.String() ) + 1 );
					Assert( str );
					Q_strcpy( str, defines.String() );
					// now tokenize the string on the ";" char
					char *delim = strchr( str, ';' );
					char *curpos = str;
					while ( delim )
					{
						*delim = 0;
						delim++;
						if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" )  &&  
							 Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines
						{
							config.AddDefine( curpos );
						}
						curpos = delim;
						delim = strchr( delim, ';' );
					}
					if ( Q_stricmp( curpos, "WIN32" ) && Q_stricmp( curpos, "_WIN32" )  &&  
						 Q_stricmp( curpos, "_WINDOWS") && Q_stricmp( curpos, "WINDOWS")) // don't add WIN32 defines
					{
						config.AddDefine( curpos );
					}

					CUtlSymbol includes = GetXMLAttribValue( node, "AdditionalIncludeDirectories" );
					char *str2 = (char *)_alloca( Q_strlen( includes.String() ) + 1 );
					Assert( str2 );
					Q_strcpy( str2, includes.String() );
					// now tokenize the string on the ";" char
					char token = ',';
					delim = strchr( str2, token );
					if ( !delim )
					{
						token = ';';
						delim = strchr( str2, token );
					}
					curpos = str2;
					while ( delim )
					{
						*delim = 0;
						delim++;
						Q_FixSlashes( curpos );
						Q_strlower( curpos );
						char fullPath[ MAX_PATH ];
						Q_snprintf( fullPath, sizeof(fullPath), "%s/%s", m_BaseDir.String(), curpos );
						Q_StripTrailingSlash( fullPath );
						config.AddInclude( fullPath );
						curpos = delim;
						delim = strchr( delim, token );
					}
					Q_FixSlashes( curpos );
					Q_strlower( curpos );
					char fullPath[ MAX_PATH ];
					Q_snprintf( fullPath, sizeof(fullPath), "%s/%s", m_BaseDir.String(), curpos );
					Q_StripTrailingSlash( fullPath );
					config.AddInclude( fullPath );
				}
			}
		}
	}

#endif
	return true;
}
示例#9
0
//-----------------------------------------------------------------------------
// Purpose: load up a project and parse it
//-----------------------------------------------------------------------------
bool CVCProjConvert::LoadProject( const char *project )
{
#ifdef _WIN32
	HRESULT hr;
	IXMLDOMDocument *pXMLDoc=NULL;

	hr = ::CoCreateInstance(CLSID_DOMDocument, 
							NULL, 
							CLSCTX_INPROC_SERVER, 
							IID_IXMLDOMDocument, 
							(void**)&pXMLDoc);

	if (FAILED(hr))
	{
		Msg ("Cannot instantiate msxml2.dll\n");
		Msg ("Please download the MSXML run-time (url below)\n");
		Msg ("http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/766/msdncompositedoc.xml\n");
		return false;
	}

	VARIANT_BOOL vtbool;
	_variant_t bstrProject(project);

	pXMLDoc->put_async( VARIANT_BOOL(FALSE) );
	hr = pXMLDoc->load(bstrProject,&vtbool);
	if (FAILED(hr) || vtbool==VARIANT_FALSE)
	{
		Msg ("Could not open %s.\n", bstrProject);
		pXMLDoc->Release();
		return false;
	} 
#elif _LINUX
	XercesDOMParser* parser = new XercesDOMParser();
        parser->setValidationScheme(XercesDOMParser::Val_Always);    // optional.
        parser->setDoNamespaces(true);    // optional

        ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
        parser->setErrorHandler(errHandler);

        try {
            parser->parse(project);
        }
        catch (const XMLException& toCatch) {
            char* message = XMLString::transcode(toCatch.getMessage());
            Error( "Exception message is: %s\n", message );    
            XMLString::release(&message);
            return;
        }
        catch (const DOMException& toCatch) {
            char* message = XMLString::transcode(toCatch.msg);
            Error( "Exception message is: %s\n", message );    
            XMLString::release(&message);
            return;
        }
        catch (...) {
            Error( "Unexpected Exception \n" );
            return;
        }
	
	DOMDocument *pXMLDoc = parser->getDocument();
#endif

	ExtractProjectName( pXMLDoc );
	if ( !m_Name.IsValid() )
	{
		Msg( "Failed to extract project name\n" );
		return false;
	}
	char baseDir[ MAX_PATH ];
	Q_ExtractFilePath( project, baseDir, sizeof(baseDir) );
	Q_StripTrailingSlash( baseDir );
	m_BaseDir = baseDir;

	ExtractConfigurations( pXMLDoc );
	if ( m_Configurations.Count() == 0 )
	{
		Msg( "Failed to find any configurations to load\n" );
		return false;
	}

	ExtractFiles( pXMLDoc );

#ifdef _WIN32
	pXMLDoc->Release();
#elif _LINUX
	delete pXMLDoc;
	delete errHandler;
#endif

	m_bProjectLoaded = true;
	return true;
}
示例#10
0
int main( int argc, char **argv )
{
	if( argc < 2 )
	{
		Usage();
	}
	MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
	InitDefaultFileSystem();

	int i = 1;
	while( i < argc )
	{
		if( stricmp( argv[i], "-quiet" ) == 0 )
		{
			i++;
			g_Quiet = true;
			g_NoPause = true; // no point in pausing if we aren't going to print anything out.
		}
		if( stricmp( argv[i], "-nopause" ) == 0 )
		{
			i++;
			g_NoPause = true;
		}
		else
		{
			break;
		}
	}

	char pCurrentDirectory[MAX_PATH];
	if ( _getcwd( pCurrentDirectory, sizeof(pCurrentDirectory) ) == NULL )
	{
		fprintf( stderr, "Unable to get the current directory\n" );
		return -1;
	}

	Q_FixSlashes( pCurrentDirectory );
	Q_StripTrailingSlash( pCurrentDirectory );

	for( ; i < argc; i++ )
	{
		static char normalFileNameWithoutExtension[1024];
		char *pFileName;
		if ( !Q_IsAbsolutePath( argv[i] ) )
		{
			Q_snprintf( normalFileNameWithoutExtension, sizeof(normalFileNameWithoutExtension), "%s\\%s", pCurrentDirectory, argv[i] );
			pFileName = normalFileNameWithoutExtension;
		}
		else
		{
			pFileName = argv[i];
		}

		if( !g_Quiet )
		{
			printf( "file: %s\n", pFileName );
		}
		float bumpScale = -1.0f;
		int startFrame = -1;
		int endFrame = -1;
		LoadConfigFile( pFileName, &bumpScale, &startFrame, &endFrame );
		if( bumpScale == -1.0f )
		{
			fprintf( stderr, "Must specify \"bumpscale\" in config file\n" );
			Pause();
			continue;
		}
		if( ( startFrame == -1 && endFrame != -1 ) ||
			( startFrame != -1 && endFrame == -1 ) )
		{
			fprintf( stderr, "ERROR: If you use startframe, you must use endframe, and vice versa.\n" );
			Pause();
			continue;
		}
		if( !g_Quiet )
		{
			printf( "\tbumpscale: %f\n", bumpScale );
		}
		
		Q_StripExtension( pFileName, normalFileNameWithoutExtension, sizeof( normalFileNameWithoutExtension ) );
		ProcessFiles( normalFileNameWithoutExtension,
					  startFrame, endFrame,
					  bumpScale );
	}
	return 0;
}
示例#11
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : argc - 
//			argv[] - 
// Output : int
//-----------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
	SpewOutputFunc( SpewFunc );

	int i = 1;
	for (i ; i<argc ; i++)
	{
		if ( argv[ i ][ 0 ] == '-' )
		{
			switch( argv[ i ][ 1 ] )
			{
			case 'l':
				uselogfile = true;
				break;
			case 'v':
				verbose = true;
				break;
			case 'a':
				checkani = true;
				break;
			default:
				printusage();
				break;
			}
		}
	}

	if ( argc < 3 || ( i != argc ) )
	{
		vprint( 0, "Valve Software - mdlcheck.exe (%s)\n", __DATE__ );
		vprint( 0, "--- Source Model Consistency Checker ---\n" );

		printusage();
	}

	CheckLogFile();

	vprint( 0, "Valve Software - mdlcheck.exe (%s)\n", __DATE__ );
	vprint( 0, "--- Source Model Consistency Checker ---\n" );

	vprint( 0, "    Looking for messed up .qc and .mdl files...\n" );

	char modelsources[ 256 ];
	strcpy( modelsources, argv[ i - 2 ] );
	char modelsdir[ 256 ];
	strcpy( modelsdir, argv[ i - 1 ] );

	if ( !strstr( modelsdir, "models" ) )
	{
		vprint( 0, "Models dir %s looks invalid (format:  u:/tf2/hl2/models)\n", modelsdir );
		return 0;
	}

	Q_StripTrailingSlash( modelsources );
	Q_StripTrailingSlash( modelsdir );

	ProcessSourceDirectory( modelsources );
	ProcessModelsDirectory( modelsdir );
	CheckForUnbuiltModels( );

	return 0;
}
示例#12
0
int main( int argc, char **argv )
{
	SpewOutputFunc( VTF2TGAOutputFunc );
	CommandLine()->CreateCmdLine( argc, argv );
	MathLib_Init( 2.2f, 2.2f, 0.0f, 1.0f, false, false, false, false );
	InitDefaultFileSystem();

	const char *pVTFFileName = CommandLine()->ParmValue( "-i" );
	const char *pTGAFileName = CommandLine()->ParmValue( "-o" );
	bool bGenerateMipLevels = CommandLine()->CheckParm( "-mip" ) != NULL;
	if ( !pVTFFileName )
	{
		Usage();
	}

	if ( !pTGAFileName )
	{
		pTGAFileName = pVTFFileName;
	}

	char pCurrentDirectory[MAX_PATH];
	if ( _getcwd( pCurrentDirectory, sizeof(pCurrentDirectory) ) == NULL )
	{
		fprintf( stderr, "Unable to get the current directory\n" );
		return -1;
	}
	Q_StripTrailingSlash( pCurrentDirectory );

	char pBuf[MAX_PATH];
	if ( !Q_IsAbsolutePath( pTGAFileName ) )
	{
		Q_snprintf( pBuf, sizeof(pBuf), "%s\\%s", pCurrentDirectory, pTGAFileName );
	}
	else
	{
		Q_strncpy( pBuf, pTGAFileName, sizeof(pBuf) );
	}
	Q_FixSlashes( pBuf );

	char pOutFileNameBase[MAX_PATH];
	Q_StripExtension( pBuf, pOutFileNameBase, MAX_PATH );

	char pActualVTFFileName[MAX_PATH];
	Q_strncpy( pActualVTFFileName, pVTFFileName, MAX_PATH );
	if ( !Q_strstr( pActualVTFFileName, ".vtf" ) )
	{
		Q_strcat( pActualVTFFileName, ".vtf", MAX_PATH ); 
	}

	FILE *vtfFp = fopen( pActualVTFFileName, "rb" );
	if( !vtfFp )
	{
		Error( "Can't open %s\n", pActualVTFFileName );
		exit( -1 );
	}

	fseek( vtfFp, 0, SEEK_END );
	int srcVTFLength = ftell( vtfFp );
	fseek( vtfFp, 0, SEEK_SET );

	CUtlBuffer buf;
	buf.EnsureCapacity( srcVTFLength );
	int nBytesRead = fread( buf.Base(), 1, srcVTFLength, vtfFp );
	fclose( vtfFp );
	buf.SeekPut( CUtlBuffer::SEEK_HEAD, nBytesRead );

	IVTFTexture *pTex = CreateVTFTexture();
	if (!pTex->Unserialize( buf ))
	{
		Error( "*** Error reading in .VTF file %s\n", pActualVTFFileName );
		exit(-1);
	}
	
	Msg( "vtf width: %d\n", pTex->Width() );
	Msg( "vtf height: %d\n", pTex->Height() );
	Msg( "vtf numFrames: %d\n", pTex->FrameCount() );

	Msg( "TEXTUREFLAGS_POINTSAMPLE=%s\n", ( pTex->Flags() & TEXTUREFLAGS_POINTSAMPLE ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_TRILINEAR=%s\n", ( pTex->Flags() & TEXTUREFLAGS_TRILINEAR ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_CLAMPS=%s\n", ( pTex->Flags() & TEXTUREFLAGS_CLAMPS ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_CLAMPT=%s\n", ( pTex->Flags() & TEXTUREFLAGS_CLAMPT ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_CLAMPU=%s\n", ( pTex->Flags() & TEXTUREFLAGS_CLAMPU ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_BORDER=%s\n", ( pTex->Flags() & TEXTUREFLAGS_BORDER ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_ANISOTROPIC=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ANISOTROPIC ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_HINT_DXT5=%s\n", ( pTex->Flags() & TEXTUREFLAGS_HINT_DXT5 ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_SRGB=%s\n", ( pTex->Flags() & TEXTUREFLAGS_SRGB ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_NORMAL=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NORMAL ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_NOMIP=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NOMIP ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_NOLOD=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NOLOD ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_ALL_MIPS=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ALL_MIPS ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_PROCEDURAL=%s\n", ( pTex->Flags() & TEXTUREFLAGS_PROCEDURAL ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_ONEBITALPHA=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ONEBITALPHA ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_EIGHTBITALPHA=%s\n", ( pTex->Flags() & TEXTUREFLAGS_EIGHTBITALPHA ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_ENVMAP=%s\n", ( pTex->Flags() & TEXTUREFLAGS_ENVMAP ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_RENDERTARGET=%s\n", ( pTex->Flags() & TEXTUREFLAGS_RENDERTARGET ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_DEPTHRENDERTARGET=%s\n", ( pTex->Flags() & TEXTUREFLAGS_DEPTHRENDERTARGET ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_NODEBUGOVERRIDE=%s\n", ( pTex->Flags() & TEXTUREFLAGS_NODEBUGOVERRIDE ) ? "true" : "false" );
	Msg( "TEXTUREFLAGS_SINGLECOPY=%s\n", ( pTex->Flags() & TEXTUREFLAGS_SINGLECOPY ) ? "true" : "false" );
	
	Vector vecReflectivity = pTex->Reflectivity();
	Msg( "vtf reflectivity: %f %f %f\n", vecReflectivity[0], vecReflectivity[1], vecReflectivity[2] );
	Msg( "transparency: " );
	if( pTex->Flags() & TEXTUREFLAGS_EIGHTBITALPHA )
	{
		Msg( "eightbitalpha\n" );
	}
	else if( pTex->Flags() & TEXTUREFLAGS_ONEBITALPHA )
	{
		Msg( "onebitalpha\n" );
	}
	else
	{
		Msg( "noalpha\n" );
	}
	ImageFormat srcFormat = pTex->Format();
	Msg( "vtf format: %s\n", ImageLoader::GetName( srcFormat ) );
		
	int iTGANameLen = Q_strlen( pOutFileNameBase );

	int iFaceCount = pTex->FaceCount();
	int nFrameCount = pTex->FrameCount();
	bool bIsCubeMap = pTex->IsCubeMap();

	int iLastMipLevel = bGenerateMipLevels ? pTex->MipCount() - 1 : 0;
	for( int iFrame = 0; iFrame < nFrameCount; ++iFrame )
	{
		for ( int iMipLevel = 0; iMipLevel <= iLastMipLevel; ++iMipLevel )
		{
			int iWidth, iHeight, iDepth;
			pTex->ComputeMipLevelDimensions( iMipLevel, &iWidth, &iHeight, &iDepth );

			for (int iCubeFace = 0; iCubeFace < iFaceCount; ++iCubeFace)
			{
				for ( int z = 0; z < iDepth; ++z )
				{
					// Construct output filename
					char *pTempNameBuf = (char *)stackalloc( iTGANameLen + 13 );
					Q_strncpy( pTempNameBuf, pOutFileNameBase, iTGANameLen + 1 );
					char *pExt = Q_strrchr( pTempNameBuf, '.' );
					if ( pExt )
					{
						pExt = 0;
					}

					if ( bIsCubeMap )
					{
						Assert( pTex->Depth() == 1 ); // shouldn't this be 1 instead of 0?
						static const char *pCubeFaceName[7] = { "rt", "lf", "bk", "ft", "up", "dn", "sph" };
						Q_strcat( pTempNameBuf, pCubeFaceName[iCubeFace], iTGANameLen + 13 ); 
					}

					if ( nFrameCount > 1 )
					{
						char pTemp[4];
						Q_snprintf( pTemp, 4, "%03d", iFrame );
						Q_strcat( pTempNameBuf, pTemp, iTGANameLen + 13 ); 
					}

					if ( iLastMipLevel != 0 )
					{
						char pTemp[8];
						Q_snprintf( pTemp, 8, "_mip%d", iMipLevel );
						Q_strcat( pTempNameBuf, pTemp, iTGANameLen + 13 ); 
					}

					if ( pTex->Depth() > 1 )
					{
						char pTemp[6];
						Q_snprintf( pTemp, 6, "_z%03d", z );
						Q_strcat( pTempNameBuf, pTemp, iTGANameLen + 13 ); 
					}

					if( srcFormat == IMAGE_FORMAT_RGBA16161616F )
					{
						Q_strcat( pTempNameBuf, ".pfm", iTGANameLen + 13 ); 
					}
					else
					{
						Q_strcat( pTempNameBuf, ".tga", iTGANameLen + 13 ); 
					}

					unsigned char *pSrcImage = pTex->ImageData( iFrame, iCubeFace, iMipLevel, 0, 0, z );

					ImageFormat dstFormat;
					if( srcFormat == IMAGE_FORMAT_RGBA16161616F )
					{
						dstFormat = IMAGE_FORMAT_RGB323232F;
					}
					else
					{
						if( ImageLoader::IsTransparent( srcFormat ) || (srcFormat == IMAGE_FORMAT_ATI1N ) || (srcFormat == IMAGE_FORMAT_ATI2N ))
						{
							dstFormat = IMAGE_FORMAT_BGRA8888;
						}
						else
						{
							dstFormat = IMAGE_FORMAT_BGR888;
						}
					}
				//	dstFormat = IMAGE_FORMAT_RGBA8888;
				//	dstFormat = IMAGE_FORMAT_RGB888;
				//	dstFormat = IMAGE_FORMAT_BGRA8888;
				//	dstFormat = IMAGE_FORMAT_BGR888;
				//	dstFormat = IMAGE_FORMAT_BGRA5551;
				//	dstFormat = IMAGE_FORMAT_BGR565;
				//	dstFormat = IMAGE_FORMAT_BGRA4444;
				//	printf( "dstFormat: %s\n", ImageLoader::GetName( dstFormat ) );
					unsigned char *pDstImage = new unsigned char[ImageLoader::GetMemRequired( iWidth, iHeight, 1, dstFormat, false )];
					if( !ImageLoader::ConvertImageFormat( pSrcImage, srcFormat, 
						pDstImage, dstFormat, iWidth, iHeight, 0, 0 ) )
					{
						Error( "Error converting from %s to %s\n",
							ImageLoader::GetName( srcFormat ), ImageLoader::GetName( dstFormat ) );
						exit( -1 );
					}

					if( dstFormat != IMAGE_FORMAT_RGB323232F )
					{
						if( ImageLoader::IsTransparent( dstFormat ) && ( dstFormat != IMAGE_FORMAT_RGBA8888 ) )
						{
							unsigned char *tmpImage = pDstImage;
							pDstImage = new unsigned char[ImageLoader::GetMemRequired( iWidth, iHeight, 1, IMAGE_FORMAT_RGBA8888, false )];
							if( !ImageLoader::ConvertImageFormat( tmpImage, dstFormat, pDstImage, IMAGE_FORMAT_RGBA8888,
								iWidth, iHeight, 0, 0 ) )
							{
								Error( "Error converting from %s to %s\n",
									ImageLoader::GetName( dstFormat ), ImageLoader::GetName( IMAGE_FORMAT_RGBA8888 ) );
							}
							dstFormat = IMAGE_FORMAT_RGBA8888;
						}
						else if( !ImageLoader::IsTransparent( dstFormat ) && ( dstFormat != IMAGE_FORMAT_RGB888 ) )
						{
							unsigned char *tmpImage = pDstImage;
							pDstImage = new unsigned char[ImageLoader::GetMemRequired( iWidth, iHeight, 1, IMAGE_FORMAT_RGB888, false )];
							if( !ImageLoader::ConvertImageFormat( tmpImage, dstFormat, pDstImage, IMAGE_FORMAT_RGB888,
								iWidth, iHeight, 0, 0 ) )
							{
								Error( "Error converting from %s to %s\n",
									ImageLoader::GetName( dstFormat ), ImageLoader::GetName( IMAGE_FORMAT_RGB888 ) );
							}
							dstFormat = IMAGE_FORMAT_RGB888;
						}

						CUtlBuffer outBuffer;
						TGAWriter::WriteToBuffer( pDstImage, outBuffer, iWidth, iHeight,
							dstFormat, dstFormat );
						if ( !g_pFullFileSystem->WriteFile( pTempNameBuf, NULL, outBuffer ) )
						{
							fprintf( stderr, "unable to write %s\n", pTempNameBuf );
						}
					}
					else
					{
						PFMWrite( ( float * )pDstImage, pTempNameBuf, iWidth, iHeight );
					}
				}
			}
		}
	}

	// leak leak leak leak leak, leak leak, leak leak (Blue Danube)
	return 0;
}
示例#13
0
int main( int argc, char **argv )
{
	if( argc != 4 )
	{
		Usage();
	}

	MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
	InitDefaultFileSystem();

	char pCurrentDirectory[MAX_PATH];
	if ( _getcwd( pCurrentDirectory, sizeof(pCurrentDirectory) ) == NULL )
	{
		fprintf( stderr, "Unable to get the current directory\n" );
		return -1;
	}
	Q_FixSlashes( pCurrentDirectory );
	Q_StripTrailingSlash( pCurrentDirectory );

	char pBuf[3][MAX_PATH];
	const char *pFileName[3];
	for ( int i = 0; i < 3; ++i )
	{
		if ( !Q_IsAbsolutePath( argv[i+1] ) )
		{
			Q_snprintf( pBuf[i], sizeof(pBuf[i]), "%s\\%s", pCurrentDirectory, argv[i+1] );
			pFileName[i] = pBuf[i];
		}
		else
		{
			pFileName[i] = argv[i+1];
		}
	}

	int width1, height1;
	ImageFormat imageFormat1;
	float gamma1;

	CUtlBuffer buf1;
	if ( !g_pFullFileSystem->ReadFile( pFileName[0], NULL, buf1 ) )
	{
		fprintf( stderr, "%s not found\n", pFileName[0] );
		return -1;
	}

	if( !TGALoader::GetInfo( buf1, &width1, &height1, &imageFormat1, &gamma1 ) )
	{
		printf( "error loading %s\n", pFileName[0] );
		exit( -1 );
	}

	int width2, height2;
	ImageFormat imageFormat2;
	float gamma2;

	CUtlBuffer buf2;
	if ( !g_pFullFileSystem->ReadFile( pFileName[1], NULL, buf2 ) )
	{
		fprintf( stderr, "%s not found\n", pFileName[1] );
		return -1;
	}

	if( !TGALoader::GetInfo( buf2, &width2, &height2, &imageFormat2, &gamma2 ) )
	{
		printf( "error loading %s\n", pFileName[1] );
		exit( -1 );
	}

	if( width1 != width2 || height1 != height2 )
	{
		printf( "image dimensions different (%dx%d!=%dx%d): can't do diff for %s\n", 
			width1, height1, width2, height2, pFileName[2] );
		exit( -1 );
	}
#if 0
	// have to allow for different formats for now due to *.txt file screwup.
	if( imageFormat1 != imageFormat2 )
	{
		printf( "image format different (%s!=%s). . can't do diff for %s\n", 
			ImageLoader::GetName( imageFormat1 ), ImageLoader::GetName( imageFormat2 ), pFileName[2] );
		exit( -1 );
	}
#endif
	if( gamma1 != gamma2 )
	{
		printf( "image gamma different (%f!=%f). . can't do diff for %s\n", gamma1, gamma2, pFileName[2] );
		exit( -1 );
	}

	unsigned char *pImage1Tmp = new unsigned char[ImageLoader::GetMemRequired( width1, height1, 1, imageFormat1, false )];
	unsigned char *pImage2Tmp = new unsigned char[ImageLoader::GetMemRequired( width2, height2, 1, imageFormat2, false )];

	buf1.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );
	if( !TGALoader::Load( pImage1Tmp, buf1, width1, height1, imageFormat1, 2.2f, false ) )
	{
		printf( "error loading %s\n", pFileName[0] );
		exit( -1 );
	}
	
	buf2.SeekGet( CUtlBuffer::SEEK_HEAD, 0 );
	if( !TGALoader::Load( pImage2Tmp, buf2, width2, height2, imageFormat2, 2.2f, false ) )
	{
		printf( "error loading %s\n", pFileName[1] );
		exit( -1 );
	}

	unsigned char *pImage1 = new unsigned char[ImageLoader::GetMemRequired( width1, height1, 1, IMAGE_FORMAT_ABGR8888, false )];
	unsigned char *pImage2 = new unsigned char[ImageLoader::GetMemRequired( width2, height2, 1, IMAGE_FORMAT_ABGR8888, false )];
	unsigned char *pDiff = new unsigned char[ImageLoader::GetMemRequired( width2, height2, 1, IMAGE_FORMAT_ABGR8888, false )];
	ImageLoader::ConvertImageFormat( pImage1Tmp, imageFormat1, pImage1, IMAGE_FORMAT_ABGR8888, width1, height1, 0, 0 );
	ImageLoader::ConvertImageFormat( pImage2Tmp, imageFormat2, pImage2, IMAGE_FORMAT_ABGR8888, width2, height2, 0, 0 );

	int sizeInBytes = ImageLoader::SizeInBytes( IMAGE_FORMAT_ABGR8888 );
	bool isDifferent = false;
	for( int i = 0; i < width1 * height1 * sizeInBytes; i++ )
	{
		int d;
		d = pImage2[i] - pImage1[i];
		pDiff[i] = d > 0 ? d : -d;
		if( d != 0 )
		{
			isDifferent = true;
		}
	}

	if( !isDifferent )
	{
		printf( "Files are the same %s %s : not generating %s\n", pFileName[0], pFileName[1], pFileName[2] );
		exit( -1 );
	}
	else
	{
		printf( "Generating diff: %s!\n", pFileName[2] );
	}

	ImageFormat dstImageFormat;
	// get rid of this until we get the formats matching
//	if( sizeInBytes == 3 )
//	{
//		dstImageFormat = IMAGE_FORMAT_RGB888;
//	}
//	else
	{
		dstImageFormat = IMAGE_FORMAT_RGBA8888;
	}
	
	CUtlBuffer outBuffer;
	if ( !TGAWriter::WriteToBuffer( pDiff, outBuffer, width1, height1, dstImageFormat, dstImageFormat ) )
	{
		printf( "error writing %s to buffer\n", pFileName[2] );
		exit( -1 );
	}
	
	if ( !g_pFullFileSystem->WriteFile( pFileName[2], NULL, outBuffer ) )
	{
		fprintf( stderr, "unable to write %s\n", pFileName[2] );
		return -1;
	}

	return 0;	
}
//-----------------------------------------------------------------------------
// Purpose:
// Input  : argc -
//			argv[] -
// Output : int
//-----------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
    SpewOutputFunc( SpewFunc );
    SpewActivate( "vcd_sound_check", 2 );

    int i=1;
    for ( i ; i<argc ; i++)
    {
        if ( argv[ i ][ 0 ] == '-' )
        {
            switch( argv[ i ][ 1 ] )
            {
            case 'l':
                uselogfile = true;
                break;
            case 'v':
                verbose = true;
                break;
            case 'm':
                spewmoveto = true;
                break;
            case 'o':
                vcdonly = true;
                break;
            default:
                printusage();
                break;
            }
        }
    }

    if ( argc < 3 || ( i != argc ) )
    {
        PrintHeader();
        printusage();
    }

    CheckLogFile();

    PrintHeader();

    vprint( 0, "    Looking for .wav files not referenced in .vcd files...\n" );

    char sounddir[ 256 ];
    char vcddir[ 256 ];
    strcpy( sounddir, argv[ i - 2 ] );
    strcpy( vcddir, argv[ i - 1 ] );
    if ( !strstr( sounddir, "sound" ) )
    {
        vprint( 0, "Sound dir %s looks invalid (format:  u:/tf2/hl2/sound/vo)\n", sounddir );
        return 0;
    }
    if ( !strstr( vcddir, "scenes" ) )
    {
        vprint( 0, ".vcd dir %s looks invalid (format:  u:/tf2/hl2/scenes)\n", vcddir );
        return 0;
    }

    char workingdir[ 256 ];
    workingdir[0] = 0;
    Q_getwd( workingdir, sizeof( workingdir ) );

    // If they didn't specify -game on the command line, use VPROJECT.
    CmdLib_InitFileSystem( workingdir );

    CSysModule *pSoundEmitterModule = g_pFullFileSystem->LoadModule( "soundemittersystem.dll" );
    if ( !pSoundEmitterModule )
    {
        vprint( 0, "Sys_LoadModule( soundemittersystem.dll ) failed!\n" );
        return 0;
    }

    CreateInterfaceFn hSoundEmitterFactory = Sys_GetFactory( pSoundEmitterModule );
    if ( !hSoundEmitterFactory )
    {
        vprint( 0, "Sys_GetFactory on soundemittersystem.dll failed!\n" );
        return 0;
    }

    soundemitter = ( ISoundEmitterSystemBase * )hSoundEmitterFactory( SOUNDEMITTERSYSTEM_INTERFACE_VERSION, NULL );
    if ( !soundemitter )
    {
        vprint( 0, "Couldn't get interface %s from soundemittersystem.dll!\n", SOUNDEMITTERSYSTEM_INTERFACE_VERSION );
        return 0;
    }

    filesystem = (IFileSystem *)(CmdLib_GetFileSystemFactory()( FILESYSTEM_INTERFACE_VERSION, NULL ));
    if ( !filesystem )
    {
        AssertMsg( 0, "Failed to create/get IFileSystem" );
        return 1;
    }

    Q_FixSlashes( gamedir );
    Q_strlower( gamedir );

    vprint( 0, "game dir %s\nsounds dir %s\nvcd dir %s\n\n",
            gamedir,
            sounddir,
            vcddir );

    Q_StripTrailingSlash( sounddir );
    Q_StripTrailingSlash( vcddir );


    filesystem->RemoveFile( "moveto.txt", "GAME" );
    //
    //ProcessMaterialsDirectory( vmtdir );

    vprint( 0, "Initializing sound emitter system\n" );
    soundemitter->Connect( FileSystem_GetFactory() );
    soundemitter->Init();

    vprint( 0, "Loaded %i sounds\n", soundemitter->GetSoundCount() );

    vprint( 0, "Building list of .vcd files\n" );
    CUtlVector< CUtlSymbol > vcdfiles;
    BuildFileList( vcdfiles, vcddir, ".vcd" );
    vprint( 0, "found %i .vcd files\n\n", vcdfiles.Count() );

    vprint( 0, "Building list of known .wav files\n" );
    CUtlVector< CUtlSymbol > wavfiles;
    BuildFileList( wavfiles, sounddir, ".wav" );
    vprint( 0, "found %i .wav files\n\n", wavfiles.Count() );

    CorrelateWavsAndVCDs( vcdfiles, wavfiles );

    soundemitter->Shutdown();
    soundemitter = 0;
    g_pFullFileSystem->UnloadModule( pSoundEmitterModule );

    FileSystem_Term();

    return 0;
}