void CScriptParser::SearchForFiles( const char *szWildcardPath ) { char filePath[FILE_PATH_MAX_LENGTH]; char basePath[FILE_PATH_MAX_LENGTH]; Q_strncpy( basePath, szWildcardPath, FILE_PATH_MAX_LENGTH ); V_StripFilename( basePath ); FileFindHandle_t findHandle; const char *fileName = filesystem->FindFirstEx( szWildcardPath, GetFSSearchPath(), &findHandle ); while ( fileName != NULL ) { Q_ComposeFileName( basePath, fileName, filePath, FILE_PATH_MAX_LENGTH ); if( !ParseFile( filePath ) ) { if ( m_bAlert ) DevWarning( "[script_parser] Unable to parse '%s'!\n", filePath ); } fileName = filesystem->FindNext( findHandle ); } filesystem->FindClose( findHandle ); }
int luascript (lua_State *L, char *script) { int status; struct Smain s; if(L == NULL) return 0; s.script = script; strncpy(lastscriptpath, script, sizeof(lastscriptpath)); V_StripFilename(lastscriptpath); status = lua_cpcall(L, &pmain, &s); report(L, status); return (status || s.status) ? 0 : 1; }
//----------------------------------------------------------------------------- // Purpose: Generate a list of file matching mask //----------------------------------------------------------------------------- int CScriptLib::FindFiles( char* pFileMask, bool bRecurse, CUtlVector<fileList_t> &fileList ) { char dirPath[MAX_PATH]; char pattern[MAX_PATH]; char extension[MAX_PATH]; // get path only strcpy( dirPath, pFileMask ); V_StripFilename( dirPath ); // get pattern only V_FileBase( pFileMask, pattern, sizeof( pattern ) ); V_ExtractFileExtension( pFileMask, extension, sizeof( extension ) ); if ( extension[0] ) { strcat( pattern, "." ); strcat( pattern, extension ); } if ( !bRecurse ) { GetFileList( dirPath, pattern, fileList ); } else { // recurse and get the tree CUtlVector< fileList_t > tempList; CUtlVector< CUtlString > dirList; RecurseFileTree_r( dirPath, 0, dirList ); for ( int i=0; i<dirList.Count(); i++ ) { // iterate each directory found tempList.Purge(); tempList.EnsureCapacity( dirList.Count() ); GetFileList( dirList[i].String(), pattern, tempList ); int start = fileList.AddMultipleToTail( tempList.Count() ); for ( int j=0; j<tempList.Count(); j++ ) { fileList[start+j] = tempList[j]; } } } return fileList.Count(); }
//----------------------------------------------------------------------------- // Purpose: Given an absolute path, do a find first find next on it and build // a list of files. Physical file system only //----------------------------------------------------------------------------- static void FindFileAbsoluteList( CUtlVector< CUtlString > &outAbsolutePathNames, const char *pszFindName ) { char szPath[MAX_PATH]; V_strncpy( szPath, pszFindName, sizeof( szPath ) ); V_StripFilename( szPath ); char szResult[MAX_PATH]; FileFindHandle_t hFile = FILESYSTEM_INVALID_FIND_HANDLE; for ( const char *pszFoundFile = g_pFullFileSystem->FindFirst( pszFindName, &hFile ); pszFoundFile && hFile != FILESYSTEM_INVALID_FIND_HANDLE; pszFoundFile = g_pFullFileSystem->FindNext( hFile ) ) { V_ComposeFileName( szPath, pszFoundFile, szResult, sizeof( szResult ) ); outAbsolutePathNames.AddToTail( szResult ); } g_pFullFileSystem->FindClose( hFile ); }
//----------------------------------------------------------------------------- // Models require specialized group handling to generate intermediate lod culled // versions that are then used as the the source for target conversion. //----------------------------------------------------------------------------- bool PreprocessModelFiles( CUtlVector<fileList_t> &fileList ) { if ( !InitStudioByteSwap() ) { return false; } CUtlVector< CUtlString > updateList; CUtlRBTree< CUtlString, int > visitedModels( 0, 0, ModelNamesLessFunc ); char szSourcePath[MAX_PATH]; strcpy( szSourcePath, g_szSourcePath ); V_StripFilename( szSourcePath ); if ( !szSourcePath[0] ) strcpy( szSourcePath, "." ); V_AppendSlash( szSourcePath, sizeof( szSourcePath ) ); char szModelName[MAX_PATH]; for ( int i=0; i<fileList.Count(); i++ ) { V_strncpy( szModelName, fileList[i].fileName.String(), sizeof( szModelName ) ); if ( V_stristr( szModelName, ".360." ) ) { // must ignore any target files continue; } // want only model related files char *pExtension = V_stristr( szModelName, ".mdl" ); if ( !pExtension ) { pExtension = V_stristr( szModelName, ".dx90.vtx" ); if ( !pExtension ) { pExtension = V_stristr( szModelName, ".vvd" ); if ( !pExtension ) { pExtension = V_stristr( szModelName, ".ani" ); if ( !pExtension ) { pExtension = V_stristr( szModelName, ".phy" ); if ( !pExtension ) { pExtension = V_stristr( szModelName, ".vsi" ); if ( !pExtension ) { continue; } } } } } } *pExtension = '\0'; V_strncat( szModelName, ".mdl", sizeof( szModelName ) ); if ( visitedModels.Find( szModelName ) != visitedModels.InvalidIndex() ) { // already processed continue; } visitedModels.Insert( szModelName ); // resolve to full source path const char *ptr = szModelName; if ( !strnicmp( ptr, ".\\", 2 ) ) ptr += 2; else if ( !strnicmp( ptr, szSourcePath, strlen( szSourcePath ) ) ) ptr += strlen( szSourcePath ); char szCleanName[MAX_PATH]; strcpy( szCleanName, szSourcePath ); strcat( szCleanName, ptr ); char szFullSourcePath[MAX_PATH]; _fullpath( szFullSourcePath, szCleanName, sizeof( szFullSourcePath ) ); // any one dirty component generates the set of all expected files if ( ModelNeedsUpdate( szFullSourcePath ) ) { int index = updateList.AddToTail(); updateList[index].Set( szFullSourcePath ); } } Msg( "\n" ); Msg( "Model Pre Pass: Updating %d Models.\n", updateList.Count() ); for ( int i = 0; i < updateList.Count(); i++ ) { if ( !GenerateModelFiles( updateList[i].String() ) ) { int error = g_errorList.AddToTail(); g_errorList[error].result = false; g_errorList[error].fileName.Set( updateList[i].String() ); } } // iterate error list if ( g_errorList.Count() ) { Msg( "\n" ); for ( int i = 0; i < g_errorList.Count(); i++ ) { Msg( "ERROR: could not pre-process model: %s\n", g_errorList[i].fileName.String() ); } } return true; }