LUA_API void luasrc_dofolder (lua_State *L, const char *path) { FileFindHandle_t fh; char searchPath[ 512 ]; Q_snprintf( searchPath, sizeof( searchPath ), "%s\\*.lua", path ); char const *fn = g_pFullFileSystem->FindFirstEx( searchPath, "MOD", &fh ); while ( fn ) { if ( fn[0] != '.' ) { char ext[ 10 ]; Q_ExtractFileExtension( fn, ext, sizeof( ext ) ); if ( !Q_stricmp( ext, "lua" ) ) { char relative[ 512 ]; char loadname[ 512 ]; Q_snprintf( relative, sizeof( relative ), "%s\\%s", path, fn ); filesystem->RelativePathToFullPath( relative, "MOD", loadname, sizeof( loadname ) ); luasrc_dofile( L, loadname ); } } fn = g_pFullFileSystem->FindNext( fh ); } g_pFullFileSystem->FindClose( fh ); }
void luasrc_dofolder (const char *path) { FileFindHandle_t fh; lua_path = cvar->FindVar( "lua_path" ); char searchPath[ 512 ]; Q_snprintf( searchPath, sizeof( searchPath ), "%s\\%s\\*.lua", lua_path->GetString(), path ); char gamePath[ 256 ]; engine->GetGameDir( gamePath, 256 ); char const *fn = g_pFullFileSystem->FindFirstEx( searchPath, "MOD", &fh ); if ( fn ) { do { if ( fn[0] != '.' ) { char ext[ 10 ]; Q_ExtractFileExtension( fn, ext, sizeof( ext ) ); if ( !Q_stricmp( ext, "lua" ) ) { char loadname[ 512 ]; Q_snprintf( loadname, sizeof( loadname ), "%s\\%s\\%s\\%s", gamePath, lua_path->GetString(), path, fn ); luasrc_dofile( loadname ); } } fn = g_pFullFileSystem->FindNext( fh ); } while ( fn ); g_pFullFileSystem->FindClose( fh ); } }
//----------------------------------------------------------------------------- // Purpose: extracts the generic type of a file being loaded //----------------------------------------------------------------------------- CVCProjConvert::CConfiguration::FileType_e CVCProjConvert::GetFileType( const char *fileName ) { CConfiguration::FileType_e type = CConfiguration::FILE_TYPE_UNKNOWN_E; char ext[10]; Q_ExtractFileExtension( fileName, ext, sizeof(ext) ); if ( !Q_stricmp( ext, "lib" ) ) { type = CConfiguration::FILE_LIBRARY; } else if ( !Q_stricmp( ext, "h" ) ) { type = CConfiguration::FILE_HEADER; } else if ( !Q_stricmp( ext, "hh" ) ) { type = CConfiguration::FILE_HEADER; } else if ( !Q_stricmp( ext, "hpp" ) ) { type = CConfiguration::FILE_HEADER; } else if ( !Q_stricmp( ext, "cpp" ) ) { type = CConfiguration::FILE_SOURCE; } else if ( !Q_stricmp( ext, "c" ) ) { type = CConfiguration::FILE_SOURCE; } else if ( !Q_stricmp( ext, "cc" ) ) { type = CConfiguration::FILE_SOURCE; } return type; }
//----------------------------------------------------------------------------- // Purpose: Searches for GameStartup*.mp3 files in the sound/ui folder and plays one //----------------------------------------------------------------------------- void CGameUI::PlayGameStartupSound() { #if defined( LEFT4DEAD ) // L4D not using this path, L4D UI now handling with background menu movies return; #endif if ( IsX360() ) return; if ( CommandLine()->FindParm( "-nostartupsound" ) ) return; FileFindHandle_t fh; CUtlVector<char *> fileNames; char path[ 512 ]; Q_snprintf( path, sizeof( path ), "sound/ui/gamestartup*.mp3" ); Q_FixSlashes( path ); char const *fn = g_pFullFileSystem->FindFirstEx( path, "MOD", &fh ); if ( fn ) { do { char ext[ 10 ]; Q_ExtractFileExtension( fn, ext, sizeof( ext ) ); if ( !Q_stricmp( ext, "mp3" ) ) { char temp[ 512 ]; Q_snprintf( temp, sizeof( temp ), "ui/%s", fn ); char *found = new char[ strlen( temp ) + 1 ]; Q_strncpy( found, temp, strlen( temp ) + 1 ); Q_FixSlashes( found ); fileNames.AddToTail( found ); } fn = g_pFullFileSystem->FindNext( fh ); } while ( fn ); g_pFullFileSystem->FindClose( fh ); } // did we find any? if ( fileNames.Count() > 0 ) { SYSTEMTIME SystemTime; GetSystemTime( &SystemTime ); int index = SystemTime.wMilliseconds % fileNames.Count(); if ( fileNames.IsValidIndex( index ) && fileNames[index] ) { char found[ 512 ]; // escape chars "*#" make it stream, and be affected by snd_musicvolume Q_snprintf( found, sizeof( found ), "play *#%s", fileNames[index] ); engine->ClientCmd_Unrestricted( found ); } fileNames.PurgeAndDeleteElements(); } }
void Correlate( CUtlRBTree< ReferencedFile, int >& referencedfiles, CUtlVector< FileEntry >& contentfiles, const char *modname ) { int i; int c = contentfiles.Count(); double totalDiskSize = 0; double totalReferencedDiskSize = 0; double totalWhiteListDiskSize = 0; for ( i = 0; i < c; ++i ) { totalDiskSize += contentfiles [ i ].size; } vprint( 0, "Content tree size on disk %s\n", Q_pretifymem( totalDiskSize, 3 ) ); // Analysis is to walk tree and see which files on disk are referenced in the .lst files // Need a fast lookup from file symbol to referenced list CUtlRBTree< ReferencedFile, int > tree( 0, 0, ReferencedFileLessFunc ); c = referencedfiles.Count(); for ( i = 0 ; i < c; ++i ) { tree.Insert( referencedfiles[ i ] ); } // Now walk the on disk file and see check off resources which are in referenced c = contentfiles.Count(); int invalidindex = tree.InvalidIndex(); unsigned int refcounted = 0; unsigned int whitelisted = 0; filesystem->RemoveFile( CFmtStr( "%swhitelist.lst", g_szReslistDir ), "GAME" ); for ( i = 0; i < c; ++i ) { FileEntry & entry = contentfiles[ i ]; ReferencedFile foo; foo.sym = entry.sym; bool gameref = tree.Find( foo ) != invalidindex; char const *fn = g_Analysis.symbols.String( entry.sym ); bool whitelist = g_WhiteList.Find( entry.sym ) != g_WhiteList.InvalidIndex(); if ( gameref || whitelist ) { entry.referenced = gameref ? REFERENCED_GAME : REFERENCED_WHITELIST; totalReferencedDiskSize += entry.size; if ( entry.referenced == REFERENCED_WHITELIST ) { logprint( CFmtStr( "%swhitelist.lst", g_szReslistDir ), "\"%s\\%s\"\n", modname, fn ); totalWhiteListDiskSize += entry.size; ++whitelisted; } ++refcounted; } } vprint( 0, "Found %i referenced (%i whitelist) files in tree, %s\n", refcounted, whitelisted, Q_pretifymem( totalReferencedDiskSize, 2 ) ); vprint( 0, "%s appear unused\n", Q_pretifymem( totalDiskSize - totalReferencedDiskSize, 2 ) ); // Now sort and dump the unreferenced ones.. vprint( 0, "Sorting unreferenced files list...\n" ); CUtlRBTree< FileEntry, int > unreftree( 0, 0, FileEntryLessFunc ); for ( i = 0; i < c; ++i ) { FileEntry & entry = contentfiles[ i ]; if ( entry.referenced != REFERENCED_NO ) continue; unreftree.Insert( entry ); } // Now walk the unref tree in order i = unreftree.FirstInorder(); invalidindex = unreftree.InvalidIndex(); int index = 0; while ( i != invalidindex ) { FileEntry & entry = unreftree[ i ]; if ( showreferencedfiles ) { vprint( 1, "%6i %12s: %s\n", ++index, Q_pretifymem( entry.size, 2 ), g_Analysis.symbols.String( entry.sym ) ); } i = unreftree.NextInorder( i ); } if ( showmapfileusage ) { vprint( 0, "Writing referenced.csv...\n" ); // Now walk the list of referenced files and print out how many and which maps reference them i = tree.FirstInorder(); invalidindex = tree.InvalidIndex(); index = 0; while ( i != invalidindex ) { ReferencedFile & entry = tree[ i ]; char ext[ 32 ]; Q_ExtractFileExtension( g_Analysis.symbols.String( entry.sym ), ext, sizeof( ext ) ); logprint( "referenced.csv", "\"%s\",\"%s\",%d", g_Analysis.symbols.String( entry.sym ), ext, entry.maplist.Count() ); int mapcount = entry.maplist.Count(); for ( int j = 0 ; j < mapcount; ++j ) { char basemap[ 128 ]; Q_FileBase( g_Analysis.symbols.String( entry.maplist[ j ] ), basemap, sizeof( basemap ) ); logprint( "referenced.csv", ",\"%s\"", basemap ); } logprint( "referenced.csv", "\n" ); i = tree.NextInorder( i ); } } vprint( 0, "\nBuilding directory summary list...\n" ); // Now build summaries by root branch off of gamedir (e.g., for sound, materials, models, etc.) CUtlDict< DirEntry, int > directories; invalidindex = directories.InvalidIndex(); for ( i = 0; i < c; ++i ) { FileEntry & entry = contentfiles[ i ]; // Get the dir name char const *dirname = g_Analysis.symbols.String( entry.sym ); const char *backslash = strstr( dirname, "\\" ); char dir[ 256 ]; if ( !backslash ) { dir[0] = 0; } else { Q_strncpy( dir, dirname, backslash - dirname + 1); } int idx = directories.Find( dir ); if ( idx == invalidindex ) { DirEntry foo; idx = directories.Insert( dir, foo ); } DirEntry & de = directories[ idx ]; de.total += entry.size; if ( entry.referenced == REFERENCED_NO ) { de.unreferenced += entry.size; } if ( entry.referenced == REFERENCED_WHITELIST ) { de.whitelist += entry.size; } } if ( spewdeletions ) { // Spew deletion commands to console if ( immediatedelete ) { vprint( 0, "\n\nDeleting files...\n" ); } else { vprint( 0, "\n\nGenerating deletions.bat\n" ); } i = unreftree.FirstInorder(); invalidindex = unreftree.InvalidIndex(); float deletionSize = 0.0f; int deletionCount = 0; while ( i != invalidindex ) { FileEntry & entry = unreftree[ i ]; i = unreftree.NextInorder( i ); // Don't delete stuff that's in the white list if ( g_WhiteList.Find( entry.sym ) != g_WhiteList.InvalidIndex() ) { if ( verbose ) { vprint( 0, "whitelist blocked deletion of %s\n", g_Analysis.symbols.String( entry.sym ) ); } continue; } ++deletionCount; deletionSize += entry.size; if ( immediatedelete ) { if ( _chmod( g_Analysis.symbols.String( entry.sym ), _S_IWRITE ) == -1 ) { vprint( 0, "Could not find file %s\n", g_Analysis.symbols.String( entry.sym ) ); } if ( _unlink( g_Analysis.symbols.String( entry.sym ) ) == -1 ) { vprint( 0, "Could not delete file %s\n", g_Analysis.symbols.String( entry.sym ) ); } if ( deletionCount % 1000 == 0 ) { vprint( 0, "...deleted %i files\n", deletionCount ); } } else { logprint( "deletions.bat", "del \"%s\" /f\n", g_Analysis.symbols.String( entry.sym ) ); } } vprint( 0, "\nFile deletion (%d files, %s)\n\n", deletionCount, Q_pretifymem(deletionSize, 2) ); } double grand_total = 0; double grand_total_unref = 0; double grand_total_white = 0; char totalstring[ 20 ]; char unrefstring[ 20 ]; char refstring[ 20 ]; char whiteliststring[ 20 ]; vprint( 0, "---------------------------------------- Summary ----------------------------------------\n" ); vprint( 0, "% 15s % 15s % 15s % 15s %12s\n", "Referenced", "WhiteListed", "Unreferenced", "Total", "Directory" ); // Now walk the dictionary in order i = directories.First(); while ( i != invalidindex ) { DirEntry & de = directories[ i ]; double remainder = de.total - de.unreferenced; float percent_unref = 0.0f; float percent_white = 0.0f; if ( de.total > 0 ) { percent_unref = 100.0f * (float)de.unreferenced / (float)de.total; percent_white = 100.0f * (float)de.whitelist / (float)de.total; } Q_strncpy( totalstring, Q_pretifymem( de.total, 2 ), sizeof( totalstring ) ); Q_strncpy( unrefstring, Q_pretifymem( de.unreferenced, 2 ), sizeof( unrefstring ) ); Q_strncpy( refstring, Q_pretifymem( remainder, 2 ), sizeof( refstring ) ); Q_strncpy( whiteliststring, Q_pretifymem( de.whitelist, 2 ), sizeof( whiteliststring ) ); vprint( 0, "%15s (%8.3f%%) %15s (%8.3f%%) %15s (%8.3f%%) %15s => dir: %s\n", refstring, 100.0f - percent_unref, whiteliststring, percent_white, unrefstring, percent_unref, totalstring, directories.GetElementName( i ) ); grand_total += de.total; grand_total_unref += de.unreferenced; grand_total_white += de.whitelist; i = directories.Next( i ); } Q_strncpy( totalstring, Q_pretifymem( grand_total, 2 ), sizeof( totalstring ) ); Q_strncpy( unrefstring, Q_pretifymem( grand_total_unref, 2 ), sizeof( unrefstring ) ); Q_strncpy( refstring, Q_pretifymem( grand_total - grand_total_unref, 2 ), sizeof( refstring ) ); Q_strncpy( whiteliststring, Q_pretifymem( grand_total_white, 2 ), sizeof( whiteliststring ) ); double percent_unref = 100.0 * grand_total_unref / grand_total; double percent_white = 100.0 * grand_total_white / grand_total; vprint( 0, "-----------------------------------------------------------------------------------------\n" ); vprint( 0, "%15s (%8.3f%%) %15s (%8.3f%%) %15s (%8.3f%%) %15s\n", refstring, 100.0f - percent_unref, whiteliststring, percent_white, unrefstring, percent_unref, totalstring ); }