From e7508090994f85655dfd2fa5197e0eddc1069b5c Mon Sep 17 00:00:00 2001 From: RaphaelIT7 Date: Fri, 22 Nov 2024 08:59:40 +0100 Subject: [PATCH] [filesystem] Greatly improve CBaseFileSystem::FixUpPath Origin: https://github.com/RaphaelIT7/obsolete-source-engine/commit/72f37977e51f4ad5f5b108b2ad3a5104aa735dbf --- filesystem/basefilesystem.cpp | 18 ++++++------------ filesystem/basefilesystem.h | 3 +++ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/filesystem/basefilesystem.cpp b/filesystem/basefilesystem.cpp index fa69b0ff9..3c22d6559 100644 --- a/filesystem/basefilesystem.cpp +++ b/filesystem/basefilesystem.cpp @@ -4181,23 +4181,17 @@ bool CBaseFileSystem::FixUpPath( const char *pFileName, char *pFixedUpFileName, } else { - // Get the BASE_PATH, skip past - if necessary, and lowercase the rest - // Not just yet... - - - int iBaseLength = 0; - char pBaseDir[MAX_PATH]; - // Need to get "BASE_PATH" from the filesystem paths, and then check this name against it. - // - iBaseLength = GetSearchPath( "BASE_PATH", true, pBaseDir, sizeof( pBaseDir ) ); - if ( iBaseLength ) + if ( m_iBaseLength < 3 ) // If It's below 3 it's most likely empty. So we try again. (GetSearchPath never returns 0?) + m_iBaseLength = GetSearchPath( "BASE_PATH", true, m_pBaseDir, sizeof( m_pBaseDir ) ); + + if ( m_iBaseLength > 3 ) { // If the first part of the pFixedUpFilename is pBaseDir // then lowercase the part after that. - if ( *pBaseDir && (iBaseLength+1 < V_strlen( pFixedUpFileName ) ) && (0 != V_strncmp( pBaseDir, pFixedUpFileName, iBaseLength ) ) ) + if ( *m_pBaseDir && (m_iBaseLength+1 < V_strlen( pFixedUpFileName ) ) && (0 != V_strncmp( m_pBaseDir, pFixedUpFileName, m_iBaseLength ) ) ) { - V_strlower( &pFixedUpFileName[iBaseLength-1] ); + V_strlower( &pFixedUpFileName[m_iBaseLength-1] ); } } diff --git a/filesystem/basefilesystem.h b/filesystem/basefilesystem.h index 97a2a7f94..aa033fa1d 100644 --- a/filesystem/basefilesystem.h +++ b/filesystem/basefilesystem.h @@ -850,6 +850,9 @@ abstract_class CBaseFileSystem : public CTier1AppSystem< IFileSystem > /// Remove a custom fetch job from the list (and release our reference) friend class CFileAsyncReadJob; void RemoveAsyncCustomFetchJob( CFileAsyncReadJob *pJob ); + + char m_pBaseDir[MAX_PATH]; + int m_iBaseLength; }; inline const CUtlSymbol& CBaseFileSystem::CPathIDInfo::GetPathID() const