コード例 #1
0
//-----------------------------------------------------------------------------
// 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();
}
コード例 #2
0
//-----------------------------------------------------------------------------
// Purpose: Recursively determine directory tree
//-----------------------------------------------------------------------------
static void RecurseFileTree_r( const char *pBasePath, const char *pDirPath, int depth, CUtlVector< CUtlString > &dirList, bool bIsModPath )
{
	if ( depth >= 2 )
	{
		// too much unecessary detail
		return;
	}

	// ignore path roots, only interested in subdirs
	const char *pSubName = pDirPath + strlen( pBasePath );
	if ( pSubName[0] )
	{
		GamePath_t gamePath;
		gamePath.pathName = pSubName;
		gamePath.bIsModPath = bIsModPath;
		
		int iIndex = g_PathTable.Find( gamePath );
		if ( iIndex == g_PathTable.InvalidIndex() )
		{
			g_PathTable.Insert( gamePath );
		}
	}

	// recurse from source directory, get directories only
	CUtlVector< CUtlString > fileList;
	int dirCount = GetFileList( pDirPath, "\\", fileList );
	if ( !dirCount )
	{
		// add directory name to search tree
		int j = dirList.AddToTail();
		dirList[j].Set( pDirPath );
		return;
	}

	for ( int i=0; i<dirCount; i++ )
	{
		// form new path name, recurse into
		RecurseFileTree_r( pBasePath, fileList[i].String(), depth+1, dirList, bIsModPath );
	}

	int j = dirList.AddToTail();
	dirList[j].Set( pDirPath );
}
コード例 #3
0
//-----------------------------------------------------------------------------
// Purpose: Recursively determine directory tree
//-----------------------------------------------------------------------------
void CScriptLib::RecurseFileTree_r( const char* pDirPath, int depth, CUtlVector< CUtlString > &dirList )
{
	// recurse from source directory, get directories only
	CUtlVector< fileList_t > fileList;
	int dirCount = GetFileList( pDirPath, "\\", fileList );
	if ( !dirCount )
	{
		// add directory name to search tree
		int j = dirList.AddToTail();
		dirList[j].Set( pDirPath );
		return;
	}

	for ( int i=0; i<dirCount; i++ )
	{
		// form new path name, recurse into
		RecurseFileTree_r( fileList[i].fileName.String(), depth+1, dirList );
	}

	int j = dirList.AddToTail();
	dirList[j].Set( pDirPath );
}
コード例 #4
0
//-----------------------------------------------------------------------------
//	ExcludePathsDlg_Populate
//
//	Generate a path table.
//-----------------------------------------------------------------------------
void ExcludePathsDlg_Populate( HWND hWnd, bool bRefresh )
{
	struct GamePath_t 
	{
		CUtlString	pathName;
		bool		bIsModPath;
	};

	CUtlVector< GamePath_t > gamePaths;		

	// can skip the time consuming directory scan, unless forced
	if ( bRefresh || !g_PathTable.Count() )
	{
		g_PathTable.Purge();

		for ( int i = 0; i < ARRAYSIZE( g_GameNames ); i++ )
		{
			char szTargetPath[MAX_PATH];
			V_strncpy( szTargetPath, g_localPath, sizeof( szTargetPath ) );
			V_AppendSlash( szTargetPath, sizeof( szTargetPath ) );
			V_strncat( szTargetPath, g_GameNames[i].pName, sizeof( szTargetPath ) );

			GamePath_t gamePath;
			gamePath.pathName = szTargetPath;
			gamePath.bIsModPath = g_GameNames[i].bIsModPath;
			gamePaths.AddToTail( gamePath );
		}

		// iterate all game paths
		for ( int i = 0; i < gamePaths.Count(); i++ )
		{
			CUtlVector< CUtlString > dirList;
			RecurseFileTree_r( g_localPath, gamePaths[i].pathName.String(), 0, dirList, gamePaths[i].bIsModPath );
		}
	}

	// reset the tree
	HWND hWndTree = GetDlgItem( hWnd, IDC_PATHS_TREE );
	TreeView_DeleteAllItems( hWndTree );

	// reset and add root
	// only the root is at depth 0
	AddItemToTree( hWndTree, ROOT_NAME, 0, false );

	// build the tree view
	for ( int iIndex = g_PathTable.FirstInorder(); iIndex != g_PathTable.InvalidIndex(); iIndex = g_PathTable.NextInorder( iIndex ) )
	{
		// due to sorting, number of slashes is depth
		const char *pString = g_PathTable[iIndex].pathName.String();
		int depth = 0;
		for ( int j = 0; j < (int)strlen( pString ); j++ )
		{
			if ( pString[j] == '\\' )
			{
				depth++;
			}
		}
		if ( !depth )
		{
			depth = 1;
		}

		char szPath[MAX_PATH];
		V_FileBase( pString, szPath, sizeof( szPath ) );
		AddItemToTree( hWndTree, szPath, depth, g_PathTable[iIndex].bIsModPath );
	}

	HTREEITEM hTreeRoot = TreeView_GetRoot( hWndTree );
	for ( int i = 0; i < g_ExcludePaths.Count(); i++ )
	{
		HTREEITEM hTree = ExcludePathsDlg_Find_r( hWndTree, hTreeRoot, 0, "", g_ExcludePaths[i].String() );
		if ( hTree )
		{
			ExcludePathsDlg_SetCheckState_r( hWndTree, hTree, 0, true );
		}
	}

	// expand the root node to show state
	ExcludePathsDlg_ExpandToShowState_r( hWndTree, hTreeRoot, 0 );
}