@@ -258,7 +258,7 @@ typedef struct CaseFoldHashBucket
258258
259259#include " pathmatch_casefolding.h"
260260
261- inline static void locate_case_fold_mapping (const uint32_t from, uint32_t *to)
261+ inline __attribute__ ((always_inline)) static void locate_case_fold_mapping(const uint32_t from, uint32_t *to)
262262{
263263 const uint8_t hashed = ((from ^ (from >> 8 )) & 0xFF );
264264 const CaseFoldHashBucket *bucket = &case_fold_hash[hashed];
@@ -282,7 +282,7 @@ inline static void locate_case_fold_mapping(const uint32_t from, uint32_t *to)
282282 to[2 ] = 0 ;
283283}
284284
285- inline static uint32_t *fold_utf8 (const char *str)
285+ inline __attribute__ ((always_inline)) static uint32_t *fold_utf8(const char *str)
286286{
287287 uint32_t *retval = new uint32_t [(Q_strlen (str) * 3 ) + 1 ];
288288 uint32_t *dst = retval;
@@ -313,7 +313,7 @@ inline static uint32_t *fold_utf8(const char *str)
313313 return retval;
314314}
315315
316- inline static int utf8casecmp_loop (const uint32_t *folded1, const uint32_t *folded2)
316+ inline __attribute__ ((always_inline)) static int utf8casecmp_loop(const uint32_t *folded1, const uint32_t *folded2)
317317{
318318 while (true )
319319 {
@@ -356,7 +356,7 @@ class CDirPtr
356356 operator DIR *() { return m_pDir; }
357357 operator bool () { return m_pDir != nullptr ; }
358358
359- private:
359+ private:
360360 void Close () { if (m_pDir) closedir (m_pDir); }
361361
362362 DIR *m_pDir;
@@ -500,22 +500,6 @@ static bool Descend(char *pPath, size_t nStartIdx, bool bAllowBasenameMismatch,
500500 return false ;
501501}
502502
503- char *GetSteamContentPath ()
504- {
505- char szContentLink[4096 ];
506- Q_snprintf (szContentLink, sizeof (szContentLink), " %s/.steam/steam" , getenv (" HOME" ));
507-
508- char *pszContentPath = realpath (szContentLink, nullptr );
509- if (pszContentPath) {
510- Q_strcat (pszContentPath, " /" );
511- }
512- else {
513- pszContentPath = Q_strdup (" /" );
514- }
515-
516- return pszContentPath;
517- }
518-
519503#ifdef DO_PATHMATCH_CACHE
520504typedef std::map<std::string, std::pair<std::string, time_t > > resultCache_t;
521505typedef std::map<std::string, std::pair<std::string, time_t > >::iterator resultCacheItr_t;
@@ -574,33 +558,39 @@ PathMod_t pathmatch(const char *pszIn, char **ppszOut, bool bAllowBasenameMismat
574558
575559 if (pPath)
576560 {
561+ // I believe this code is broken. I'm guessing someone wanted to avoid lowercasing
562+ // the path before the steam directory - but it's actually skipping lowercasing
563+ // whenever steam is found anywhere - including the filename. For example,
564+ // /home/mikesart/valvesrc/console/l4d2/game/left4dead2_dlc1/particles/steam_fx.pcf
565+ // winds up only having the "steam_fx.pcf" portion lowercased.
566+ #ifdef NEVER
577567 // optimization, if the path contained steam somewhere
578568 // assume the path up through the component with 'steam' in
579569 // is valid (because we almost certainly obtained it
580570 // progamatically
581- size_t nStartIdx = 0 ;
582- static char *pszSteamPath = nullptr ;
583- static size_t nSteamPathLen = 0 ;
584- if (!pszSteamPath)
571+ char *p = strcasestr (pPath, " steam" );
572+ if (p)
585573 {
586- pszSteamPath = GetSteamContentPath ();
587- nSteamPathLen = Q_strlen (pszSteamPath);
588- }
574+ while (p > pPath)
575+ {
576+ if (p[-1 ] == ' /' )
577+ break ;
578+ p--;
579+ }
589580
590- // optimization, if the path contained steam somewhere
591- // assume the path up through the component with 'steam' in
592- // is valid (because we almost certainly obtained it
593- // progamatically
594- if (strncasecmp (pPath, pszSteamPath, nSteamPathLen) == 0 )
581+ if ((p == pPath + 1 ) && (*pPath != ' /' ))
582+ p = pPath;
583+ }
584+ else
595585 {
596- nStartIdx = nSteamPathLen - 1 ;
597- Q_memcpy (pPath, pszSteamPath, nStartIdx);
586+ p = pPath;
598587 }
599-
588+ # else
600589 char *p = pPath;
590+ #endif
601591
602592 // Try the lower casing of the remaining path
603- char *pBasename = p + nStartIdx ;
593+ char *pBasename = p;
604594 while (*p)
605595 {
606596 if (*p == ' /' ) {
@@ -620,7 +610,7 @@ PathMod_t pathmatch(const char *pszIn, char **ppszOut, bool bAllowBasenameMismat
620610
621611 // path didn't match lowered successfully, restore the basename
622612 // if bAllowBasenameMismatch was true
623- if (bAllowBasenameMismatch && *pBasename )
613+ if (bAllowBasenameMismatch)
624614 {
625615 const char *pSrc = pszIn + (pBasename - pPath);
626616 while (*pBasename)
@@ -635,7 +625,7 @@ PathMod_t pathmatch(const char *pszIn, char **ppszOut, bool bAllowBasenameMismat
635625 DEBUG_BREAK ();
636626 }
637627
638- bool bSuccess = Descend (pPath, nStartIdx , bAllowBasenameMismatch);
628+ bool bSuccess = Descend (pPath, 0 , bAllowBasenameMismatch);
639629 if (bSuccess)
640630 {
641631 *ppszOut = pPath;
0 commit comments