FSReturnCode_t GetSteamCfgPath( char *steamCfgPath, int steamCfgPathLen ) { steamCfgPath[0] = 0; char executablePath[MAX_PATH]; if ( !FileSystem_GetExecutableDir( executablePath, sizeof( executablePath ) ) ) { return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); } Q_strncpy( steamCfgPath, executablePath, steamCfgPathLen ); while ( 1 ) { if ( DoesFileExistIn( steamCfgPath, "steam.cfg" ) ) break; if ( !Q_StripLastDir( steamCfgPath, steamCfgPathLen) ) { // the file isnt found, thats ok, its not mandatory return FS_OK; } } Q_AppendSlash( steamCfgPath, steamCfgPathLen ); Q_strncat( steamCfgPath, "steam.cfg", steamCfgPathLen, COPY_ALL_CHARACTERS ); return FS_OK; }
void SetSteamAppUser( KeyValues *pSteamInfo, const char *steamInstallPath, CSteamEnvVars &steamEnvVars ) { // Always inherit the Steam user if it's already set, since it probably means we (or the // the app that launched us) were launched from Steam. char appUser[MAX_PATH]; if ( steamEnvVars.m_SteamAppUser.GetValue( appUser, sizeof( appUser ) ) ) return; const char *pTempAppUser = NULL; if ( pSteamInfo && (pTempAppUser = pSteamInfo->GetString( "SteamAppUser", NULL )) != NULL ) { Q_strncpy( appUser, pTempAppUser, sizeof( appUser ) ); } else { // They don't have SteamInfo.txt, or it's missing SteamAppUser. Try to figure out the user // by looking in <steam install path>\config\SteamAppData.vdf. char fullFilename[MAX_PATH]; Q_strncpy( fullFilename, steamInstallPath, sizeof( fullFilename ) ); Q_AppendSlash( fullFilename, sizeof( fullFilename ) ); Q_strncat( fullFilename, "config\\SteamAppData.vdf", sizeof( fullFilename ), COPY_ALL_CHARACTERS ); KeyValues *pSteamAppData = ReadKeyValuesFile( fullFilename ); if ( !pSteamAppData || (pTempAppUser = pSteamAppData->GetString( "AutoLoginUser", NULL )) == NULL ) { Error( "Can't find steam app user info." ); } Q_strncpy( appUser, pTempAppUser, sizeof( appUser ) ); pSteamAppData->deleteThis(); } Q_strlower( appUser ); steamEnvVars.m_SteamAppUser.SetValue( "%s", appUser ); }
void CRoomTemplate::SetFullName( const char *pFullName ) { Q_strncpy( m_FullName, pFullName, MAX_PATH ); Q_StripExtension( m_FullName, m_FullName, MAX_PATH ); Q_FixSlashes( m_FullName ); Q_ExtractFilePath( m_FullName, m_SubFolder, MAX_PATH ); Q_AppendSlash( m_SubFolder, MAX_PATH ); Q_strncpy( m_TemplateName, m_FullName + Q_strlen( m_SubFolder ), MAX_PATH ); }
FSReturnCode_t LoadGameInfoFile( const char *pDirectoryName, KeyValues *&pMainFile, KeyValues *&pFileSystemInfo, KeyValues *&pSearchPaths ) { // If GameInfo.txt exists under pBaseDir, then this is their game directory. // All the filesystem mappings will be in this file. char gameinfoFilename[MAX_PATH]; Q_strncpy( gameinfoFilename, pDirectoryName, sizeof( gameinfoFilename ) ); Q_AppendSlash( gameinfoFilename, sizeof( gameinfoFilename ) ); Q_strncat( gameinfoFilename, GAMEINFO_FILENAME, sizeof( gameinfoFilename ), COPY_ALL_CHARACTERS ); Q_FixSlashes( gameinfoFilename ); pMainFile = ReadKeyValuesFile( gameinfoFilename ); if ( IsX360() && !pMainFile ) { // try again Q_strncpy( gameinfoFilename, pDirectoryName, sizeof( gameinfoFilename ) ); Q_AppendSlash( gameinfoFilename, sizeof( gameinfoFilename ) ); Q_strncat( gameinfoFilename, GAMEINFO_FILENAME_ALTERNATE, sizeof( gameinfoFilename ), COPY_ALL_CHARACTERS ); Q_FixSlashes( gameinfoFilename ); pMainFile = ReadKeyValuesFile( gameinfoFilename ); } if ( !pMainFile ) { return SetupFileSystemError( true, FS_MISSING_GAMEINFO_FILE, "%s is missing.", gameinfoFilename ); } pFileSystemInfo = pMainFile->FindKey( "FileSystem" ); if ( !pFileSystemInfo ) { pMainFile->deleteThis(); return SetupFileSystemError( true, FS_INVALID_GAMEINFO_FILE, "%s is not a valid format.", gameinfoFilename ); } // Now read in all the search paths. pSearchPaths = pFileSystemInfo->FindKey( "SearchPaths" ); if ( !pSearchPaths ) { pMainFile->deleteThis(); return SetupFileSystemError( true, FS_INVALID_GAMEINFO_FILE, "%s is not a valid format.", gameinfoFilename ); } return FS_OK; }
void FileSystem_SetupStandardDirectories( const char *pFilename, const char *pGameInfoPath ) { // Set qdir. if ( !pFilename ) { pFilename = "."; } Q_MakeAbsolutePath( qdir, sizeof( qdir ), pFilename, NULL ); Q_StripFilename( qdir ); Q_strlower( qdir ); if ( qdir[0] != 0 ) { Q_AppendSlash( qdir, sizeof( qdir ) ); } // Set gamedir. Q_MakeAbsolutePath( gamedir, sizeof( gamedir ), pGameInfoPath ); Q_AppendSlash( gamedir, sizeof( gamedir ) ); }
bool DoesFileExistIn( const char *pDirectoryName, const char *pFilename ) { char filename[MAX_PATH]; Q_strncpy( filename, pDirectoryName, sizeof( filename ) ); Q_AppendSlash( filename, sizeof( filename ) ); Q_strncat( filename, pFilename, sizeof( filename ), COPY_ALL_CHARACTERS ); Q_FixSlashes( filename ); bool bExist = ( _access( filename, 0 ) == 0 ); return ( bExist ); }
//----------------------------------------------------------------------------- // Pre-init //----------------------------------------------------------------------------- bool CVConfigApp::PreInit() { if ( !BaseClass::PreInit() ) return false; // Create a window to capture messages CreateMessageWindow(); // Make sure we're using the proper environment variable ConvertObsoleteVConfigRegistrySetting( GAMEDIR_TOKEN ); FileSystem_SetErrorMode( FS_ERRORMODE_AUTO ); // We only want to use the gameinfo.txt that is in the bin\vconfig directory. char dirName[MAX_PATH]; Q_strncpy( dirName, GetBaseDirectory(), sizeof( dirName ) ); Q_AppendSlash( dirName, sizeof( dirName ) ); Q_strncat( dirName, "vconfig", sizeof( dirName ), COPY_ALL_CHARACTERS ); if ( !SetupSearchPaths( dirName, true, true ) ) { ::MessageBox( NULL, "Error", "Unable to initialize file system\n", MB_OK ); return false; } // Load our configs if ( g_ConfigManager.LoadConfigs() == false ) { ::MessageBox( NULL, "Error", "Unable to load configuration file\n", MB_OK ); return false; } // Parse them for internal use if ( ParseConfigs() == false ) { ::MessageBox( NULL, "Error", "Unable to parse configuration file\n", MB_OK ); return false; } // Start looking for file updates UpdateConfigsStatus_Init(); // the "base dir" so we can scan mod name g_pFullFileSystem->AddSearchPath( GetBaseDirectory(), VCONFIG_MAIN_PATH_ID ); // the main platform dir g_pFullFileSystem->AddSearchPath( "platform","PLATFORM", PATH_ADD_TO_HEAD ); return true; }
void LaunchVConfig() { #if defined( _WIN32 ) && !defined( _X360 ) char vconfigExe[MAX_PATH]; FileSystem_GetExecutableDir( vconfigExe, sizeof( vconfigExe ) ); Q_AppendSlash( vconfigExe, sizeof( vconfigExe ) ); Q_strncat( vconfigExe, "vconfig.exe", sizeof( vconfigExe ), COPY_ALL_CHARACTERS ); char *argv[] = { vconfigExe, "-allowdebug", NULL }; _spawnv( _P_NOWAIT, vconfigExe, argv ); #elif defined( _X360 ) Msg( "Launching vconfig.exe not supported\n" ); #endif }
FSReturnCode_t SetupSteamStartupEnvironment( KeyValues *pFileSystemInfo, const char *pGameInfoDirectory, CSteamEnvVars &steamEnvVars ) { // Ok, we're going to run Steam. See if they have SteamInfo.txt. If not, we'll try to deduce what we can. char steamInfoFile[MAX_PATH]; Q_strncpy( steamInfoFile, pGameInfoDirectory, sizeof( steamInfoFile ) ); Q_AppendSlash( steamInfoFile, sizeof( steamInfoFile ) ); Q_strncat( steamInfoFile, "steaminfo.txt", sizeof( steamInfoFile ), COPY_ALL_CHARACTERS ); KeyValues *pSteamInfo = ReadKeyValuesFile( steamInfoFile ); char steamInstallPath[MAX_PATH]; FSReturnCode_t ret = SetSteamInstallPath( steamInstallPath, sizeof( steamInstallPath ), steamEnvVars, false ); if ( ret != FS_OK ) return ret; SetSteamAppUser( pSteamInfo, steamInstallPath, steamEnvVars ); SetSteamUserPassphrase( pSteamInfo, steamEnvVars ); SetSteamAppId( pFileSystemInfo, pGameInfoDirectory, steamEnvVars ); if ( pSteamInfo ) pSteamInfo->deleteThis(); return FS_OK; }
void MakeFilename( char *pDest, int destSize, const char *pPathname, const char *pFilenameExt ) { Q_strncpy(pDest, pPathname, destSize); Q_AppendSlash(pDest, destSize); Q_strncat(pDest, pFilenameExt, destSize); }
FSReturnCode_t LocateGameInfoFile( const CFSSteamSetupInfo &fsInfo, char *pOutDir, int outDirLen ) { // Engine and Hammer don't want to search around for it. if ( fsInfo.m_bOnlyUseDirectoryName ) { if ( !fsInfo.m_pDirectoryName ) return SetupFileSystemError( false, FS_MISSING_GAMEINFO_FILE, "bOnlyUseDirectoryName=1 and pDirectoryName=NULL." ); bool bExists = DoesFileExistIn( fsInfo.m_pDirectoryName, GAMEINFO_FILENAME ); if ( IsX360() && !bExists ) { bExists = DoesFileExistIn( fsInfo.m_pDirectoryName, GAMEINFO_FILENAME_ALTERNATE ); } if ( !bExists ) { if ( IsX360() && CommandLine()->FindParm( "-basedir" ) ) { char basePath[MAX_PATH]; strcpy( basePath, CommandLine()->ParmValue( "-basedir", "" ) ); Q_AppendSlash( basePath, sizeof( basePath ) ); Q_strncat( basePath, fsInfo.m_pDirectoryName, sizeof( basePath ), COPY_ALL_CHARACTERS ); if ( DoesFileExistIn( basePath, GAMEINFO_FILENAME ) ) { Q_strncpy( pOutDir, basePath, outDirLen ); return FS_OK; } if ( IsX360() && DoesFileExistIn( basePath, GAMEINFO_FILENAME_ALTERNATE ) ) { Q_strncpy( pOutDir, basePath, outDirLen ); return FS_OK; } } return SetupFileSystemError( true, FS_MISSING_GAMEINFO_FILE, "Setup file '%s' doesn't exist in subdirectory '%s'.\nCheck your -game parameter or VCONFIG setting.", GAMEINFO_FILENAME, fsInfo.m_pDirectoryName ); } Q_strncpy( pOutDir, fsInfo.m_pDirectoryName, outDirLen ); return FS_OK; } // First, check for overrides on the command line or environment variables. const char *pProject = GetVProjectCmdLineValue(); if ( pProject ) { if ( DoesFileExistIn( pProject, GAMEINFO_FILENAME ) ) { Q_MakeAbsolutePath( pOutDir, outDirLen, pProject ); return FS_OK; } if ( IsX360() && DoesFileExistIn( pProject, GAMEINFO_FILENAME_ALTERNATE ) ) { Q_MakeAbsolutePath( pOutDir, outDirLen, pProject ); return FS_OK; } if ( IsX360() && CommandLine()->FindParm( "-basedir" ) ) { char basePath[MAX_PATH]; strcpy( basePath, CommandLine()->ParmValue( "-basedir", "" ) ); Q_AppendSlash( basePath, sizeof( basePath ) ); Q_strncat( basePath, pProject, sizeof( basePath ), COPY_ALL_CHARACTERS ); if ( DoesFileExistIn( basePath, GAMEINFO_FILENAME ) ) { Q_strncpy( pOutDir, basePath, outDirLen ); return FS_OK; } if ( DoesFileExistIn( basePath, GAMEINFO_FILENAME_ALTERNATE ) ) { Q_strncpy( pOutDir, basePath, outDirLen ); return FS_OK; } } if ( fsInfo.m_bNoGameInfo ) { // fsInfo.m_bNoGameInfo is set by the Steam dedicated server, before it knows which mod to use. // Steam dedicated server doesn't need a gameinfo.txt, because we'll ask which mod to use, even if // -game is supplied on the command line. Q_strncpy( pOutDir, "", outDirLen ); return FS_OK; } else { // They either specified vproject on the command line or it's in their registry. Either way, // we don't want to continue if they've specified it but it's not valid. goto ShowError; } } if ( fsInfo.m_bNoGameInfo ) { Q_strncpy( pOutDir, "", outDirLen ); return FS_OK; } // Ask the application if it can provide us with a game info directory { bool bBubbleDir = true; SuggestGameInfoDirFn_t pfnSuggestGameInfoDirFn = GetSuggestGameInfoDirFn(); if ( pfnSuggestGameInfoDirFn && ( * pfnSuggestGameInfoDirFn )( &fsInfo, pOutDir, outDirLen, &bBubbleDir ) && FS_OK == TryLocateGameInfoFile( pOutDir, outDirLen, bBubbleDir ) ) return FS_OK; } // Try to use the environment variable / registry if ( ( pProject = getenv( GAMEDIR_TOKEN ) ) != NULL && ( Q_MakeAbsolutePath( pOutDir, outDirLen, pProject ), 1 ) && FS_OK == TryLocateGameInfoFile( pOutDir, outDirLen, false ) ) return FS_OK; if ( IsPC() ) { Warning( "Warning: falling back to auto detection of vproject directory.\n" ); // Now look for it in the directory they passed in. if ( fsInfo.m_pDirectoryName ) Q_MakeAbsolutePath( pOutDir, outDirLen, fsInfo.m_pDirectoryName ); else Q_MakeAbsolutePath( pOutDir, outDirLen, "." ); if ( FS_OK == TryLocateGameInfoFile( pOutDir, outDirLen, true ) ) return FS_OK; // Use the CWD Q_getwd( pOutDir, outDirLen ); if ( FS_OK == TryLocateGameInfoFile( pOutDir, outDirLen, true ) ) return FS_OK; } ShowError: return SetupFileSystemError( true, FS_MISSING_GAMEINFO_FILE, "Unable to find %s. Solutions:\n\n" "1. Read http://www.valve-erc.com/srcsdk/faq.html#NoGameDir\n" "2. Run vconfig to specify which game you're working on.\n" "3. Add -game <path> on the command line where <path> is the directory that %s is in.\n", GAMEINFO_FILENAME, GAMEINFO_FILENAME ); }
bool FileSystem_Init_Normal( const char *pFilename, FSInitType_t initType, bool bOnlyUseDirectoryName ) { if ( initType == FS_INIT_FULL ) { // First, get the name of the module char fileSystemDLLName[MAX_PATH]; bool bSteam; if ( FileSystem_GetFileSystemDLLName( fileSystemDLLName, MAX_PATH, bSteam ) != FS_OK ) return false; // If we're under Steam we need extra setup to let us find the proper modules FileSystem_SetupSteamInstallPath(); // Next, load the module, call Connect/Init. CFSLoadModuleInfo loadModuleInfo; loadModuleInfo.m_pFileSystemDLLName = fileSystemDLLName; loadModuleInfo.m_pDirectoryName = pFilename; loadModuleInfo.m_bOnlyUseDirectoryName = bOnlyUseDirectoryName; loadModuleInfo.m_ConnectFactory = Sys_GetFactoryThis(); loadModuleInfo.m_bSteam = bSteam; loadModuleInfo.m_bToolsMode = true; if ( FileSystem_LoadFileSystemModule( loadModuleInfo ) != FS_OK ) return false; // Next, mount the content CFSMountContentInfo mountContentInfo; mountContentInfo.m_pDirectoryName= loadModuleInfo.m_GameInfoPath; mountContentInfo.m_pFileSystem = loadModuleInfo.m_pFileSystem; mountContentInfo.m_bToolsMode = true; if ( FileSystem_MountContent( mountContentInfo ) != FS_OK ) return false; // Finally, load the search paths. CFSSearchPathsInit searchPathsInit; searchPathsInit.m_pDirectoryName = loadModuleInfo.m_GameInfoPath; searchPathsInit.m_pFileSystem = loadModuleInfo.m_pFileSystem; if ( FileSystem_LoadSearchPaths( searchPathsInit ) != FS_OK ) return false; // Store the data we got from filesystem_init. g_pFileSystem = g_pFullFileSystem = loadModuleInfo.m_pFileSystem; g_pFullFileSystemModule = loadModuleInfo.m_pModule; FileSystem_AddSearchPath_Platform( g_pFullFileSystem, loadModuleInfo.m_GameInfoPath ); // Set qdir. if ( !pFilename ) pFilename = "."; Q_MakeAbsolutePath( qdir, sizeof( qdir ), pFilename, NULL ); Q_StripFilename( qdir ); strlwr( qdir ); if ( qdir[0] != 0 ) Q_AppendSlash( qdir, sizeof( qdir ) ); // Set gamedir. Q_MakeAbsolutePath( gamedir, sizeof( gamedir ), loadModuleInfo.m_GameInfoPath ); Q_AppendSlash( gamedir, sizeof( gamedir ) ); } else { if ( !Sys_LoadInterface( "filesystem_stdio", FILESYSTEM_INTERFACE_VERSION, &g_pFullFileSystemModule, (void**)&g_pFullFileSystem ) ) { return false; } if ( g_pFullFileSystem->Init() != INIT_OK ) return false; g_pFullFileSystem->RemoveAllSearchPaths(); g_pFullFileSystem->AddSearchPath( "../platform", "PLATFORM" ); g_pFullFileSystem->AddSearchPath( ".", "GAME" ); g_pFileSystem = g_pFullFileSystem; } return true; }
//----------------------------------------------------------------------------- // Purpose: // Input : argc - // argv[] - // Output : int //----------------------------------------------------------------------------- int main( int argc, char* argv[] ) { SpewOutputFunc( SpewFunc ); SpewActivate( "unusedcontent", 2 ); CommandLine()->CreateCmdLine( argc, argv ); 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 'r': showreferencedfiles = true; break; case 'd': spewdeletions = true; break; case 'i': immediatedelete = true; break; case 'w': printwhitelist = true; break; case 'm': showmapfileusage = true; break; case 'g': // Just skip -game Assert( !Q_stricmp( argv[ i ], "-game" ) ); ++i; break; case 'f': // grab reslists folder { ++i; Q_strncpy( g_szReslistDir, argv[ i ], sizeof( g_szReslistDir ) ); Q_strlower( g_szReslistDir ); Q_FixSlashes( g_szReslistDir ); Q_AppendSlash( g_szReslistDir, sizeof( g_szReslistDir ) ); } break; default: printusage(); break; } } } if ( argc < 3 || ( i != argc ) ) { PrintHeader(); printusage(); return 0; } CheckLogFile(); PrintHeader(); vprint( 0, " Using reslist dir '%s'\n", g_szReslistDir ); vprint( 0, " Looking for extraneous content...\n" ); char resfile[ 256 ]; strcpy( resfile, argv[ i - 1 ] ); vprint( 0, " Comparing results of resfile (%s) with files under current directory...\n", resfile ); 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 ); filesystem = (IFileSystem *)(CmdLib_GetFileSystemFactory()( FILESYSTEM_INTERFACE_VERSION, NULL )); if ( !filesystem ) { AssertMsg( 0, "Failed to create/get IFileSystem" ); return 1; } g_pFullFileSystem->RemoveAllSearchPaths(); g_pFullFileSystem->AddSearchPath(gamedir, "GAME"); Q_strlower( gamedir ); Q_FixSlashes( gamedir ); // //ProcessMaterialsDirectory( vmtdir ); // find out the mod dir name Q_strncpy( modname, gamedir, sizeof(modname) ); modname[ strlen(modname) - 1] = 0; if ( strrchr( modname, '\\' ) ) { Q_strncpy( modname, strrchr( modname, '\\' ) + 1, sizeof(modname) ); } else { Q_strncpy( modname, "", sizeof(modname) ); } vprint( 1, "Mod Name:%s\n", modname); BuildCheckdirList(); BuildWhiteList(); vprint( 0, "Building aggregate file list from resfile output\n" ); CUtlRBTree< ReferencedFile, int > referencedfiles( 0, 0, RefFileLessFunc ); CUtlVector< UnusedContent::CUtlSymbol > resfiles; BuildReferencedFileList( resfiles, referencedfiles, resfile ); vprint( 0, "found %i files\n\n", referencedfiles.Count() ); vprint( 0, "Building list of all game content files\n" ); CUtlVector< FileEntry > contentfiles; CUtlVector< FileEntry > otherfiles; BuildFileList( 0, contentfiles, &otherfiles, "", 0 ); vprint( 0, "found %i files in content tree\n\n", contentfiles.Count() ); Correlate( referencedfiles, contentfiles, modname ); // now output the files not referenced in the whitelist or general reslists filesystem->RemoveFile( CFmtStr( "%sunreferenced_files.lst", g_szReslistDir ), "GAME" ); int c = otherfiles.Count(); for ( i = 0; i < c; ++i ) { FileEntry & entry = otherfiles[ i ]; char const *name = g_Analysis.symbols.String( entry.sym ); logprint( CFmtStr( "%sunreferenced_files.lst", g_szReslistDir ), "\"%s\\%s\"\n", modname, name ); } // also include the files from deletions.bat, as we don't actually run that now c = contentfiles.Count(); for ( i = 0; i < c; ++i ) { FileEntry & entry = contentfiles[ i ]; if ( entry.referenced != REFERENCED_NO ) continue; char const *fn = g_Analysis.symbols.String( entry.sym ); logprint( CFmtStr( "%sunreferenced_files.lst", g_szReslistDir ), "\"%s\\%s\"\n", modname, fn ); } FileSystem_Term(); return 0; }