瀏覽代碼

* Adjustment: Cleanups to the case insensitivity code for POSIX systems and add case insensitivty to directory dumping code.

Robert MacGregor 3 年之前
父節點
當前提交
497a94f884

+ 16 - 79
Engine/source/platformPOSIX/posixVolume.cpp

@@ -42,7 +42,7 @@
 
 
 
 
 //#define DEBUG_SPEW
 //#define DEBUG_SPEW
-
+extern void ResolvePathCaseInsensitive(char* pathName, S32 pathNameSize);
 
 
 namespace Torque
 namespace Torque
 {
 {
@@ -149,95 +149,32 @@ PosixFileSystem::~PosixFileSystem()
 {
 {
 }
 }
 
 
-static void MungeCase(char* pathName, S32 pathNameSize)
-{
-    const int MaxPath = PATH_MAX;
-
-    char tempBuf[MaxPath];
-    dStrncpy(tempBuf, pathName, pathNameSize);
-
-    AssertFatal(pathName[0] == '/', "PATH must be absolute");
-
-    struct stat filestat;
-    const int MaxPathEl = 200;
-    char *currChar = pathName;
-    char testPath[MaxPath];
-    char pathEl[MaxPathEl];
-    bool done = false;
-
-    dStrncpy(tempBuf, "/", MaxPath);
-    currChar++;
-
-    while (!done)
-    {
-        char* termChar = dStrchr(currChar, '/');
-        if (termChar == NULL)
-            termChar = dStrchr(currChar, '\0');
-        AssertFatal(termChar, "Can't find / or NULL terminator");
-
-        S32 pathElLen = (termChar - currChar);
-        dStrncpy(pathEl, currChar, pathElLen);
-        pathEl[pathElLen] = '\0';
-        dStrncpy(testPath, tempBuf, MaxPath);
-        dStrcat(testPath, pathEl, MaxPath);
-        if (stat(testPath, &filestat) != -1)
-        {
-            dStrncpy(tempBuf, testPath, MaxPath);
-        }
-        else
-        {
-            DIR *dir = opendir(tempBuf);
-            struct dirent* ent;
-            bool foundMatch = false;
-            while (dir != NULL && (ent = readdir(dir)) != NULL)
-            {
-                if (dStricmp(pathEl, ent->d_name) == 0)
-                {
-                    foundMatch = true;
-                    dStrcat(tempBuf, ent->d_name, MaxPath);
-                    break;
-                }
-            }
-
-            if (!foundMatch)
-                dStrncpy(tempBuf, testPath, MaxPath);
-            if (dir)
-                closedir(dir);
-        }
-        if (*termChar == '/')
-        {
-            dStrcat(tempBuf, "/", MaxPath);
-            termChar++;
-            currChar = termChar;
-        }
-        else
-            done = true;
-    }
-
-    dStrncpy(pathName, tempBuf, pathNameSize);
-}
-
-//  static void MungeCase(char* pathName, S32 pathNameSize)
 FileNodeRef PosixFileSystem::resolve(const Path& path)
 FileNodeRef PosixFileSystem::resolve(const Path& path)
 {
 {
    String file = buildFileName(_volume,path);
    String file = buildFileName(_volume,path);
    struct stat info;
    struct stat info;
 
 
-   UTF8 testPath[1024];
-   dMemcpy(testPath, file.c_str(), file.length());
-   testPath[file.length()] = 0x00;
-   MungeCase(testPath, file.length());
-
-   String realFile(testPath);
+#ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE
+   // Resolve the case sensitive filepath
+   String::SizeType fileLength = file.length();
+   UTF8 caseSensitivePath[fileLength + 1];
+   dMemcpy(caseSensitivePath, file.c_str(), fileLength);
+   caseSensitivePath[fileLength] = 0x00;
+   ResolvePathCaseInsensitive(caseSensitivePath, fileLength);
+
+   String caseSensitiveFile(caseSensitivePath);
+#else
+   String caseSensitiveFile = file;
+#endif
 
 
-   if (stat(realFile.c_str(),&info) == 0)
+   if (stat(caseSensitiveFile.c_str(),&info) == 0)
    {
    {
       // Construct the appropriate object
       // Construct the appropriate object
       if (S_ISREG(info.st_mode))
       if (S_ISREG(info.st_mode))
-         return new PosixFile(path,realFile);
+         return new PosixFile(path,caseSensitiveFile);
          
          
       if (S_ISDIR(info.st_mode))
       if (S_ISDIR(info.st_mode))
-         return new PosixDirectory(path,realFile);
+         return new PosixDirectory(path,caseSensitiveFile);
    }
    }
    
    
    return 0;
    return 0;

+ 16 - 4
Engine/source/platformX86UNIX/x86UNIXFileio.cpp

@@ -33,7 +33,7 @@
     directory.  Files are never created or modified in the game directory.
     directory.  Files are never created or modified in the game directory.
 
 
     For case-sensitivity, the MungePath code will test whether a given path
     For case-sensitivity, the MungePath code will test whether a given path
-    specified by the engine exists.  If not, it will use the MungeCase function
+    specified by the engine exists.  If not, it will use the ResolvePathCaseInsensitive function
     which will try to determine if an actual filesystem path matches the
     which will try to determine if an actual filesystem path matches the
     specified path case insensitive.  If one is found, the actual path
     specified path case insensitive.  If one is found, the actual path
     transparently (we hope) replaces the one requested by the engine.
     transparently (we hope) replaces the one requested by the engine.
@@ -183,7 +183,7 @@ bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite)
  // munge the case of the specified pathName.  This means try to find the actual
  // munge the case of the specified pathName.  This means try to find the actual
  // filename in with case-insensitive matching on the specified pathName, and
  // filename in with case-insensitive matching on the specified pathName, and
  // store the actual found name.
  // store the actual found name.
- static void MungeCase(char* pathName, S32 pathNameSize)
+ void ResolvePathCaseInsensitive(char* pathName, S32 pathNameSize)
  {
  {
     char tempBuf[MaxPath];
     char tempBuf[MaxPath];
     dStrncpy(tempBuf, pathName, pathNameSize);
     dStrncpy(tempBuf, pathName, pathNameSize);
@@ -296,7 +296,7 @@ bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite)
        return;
        return;
 
 
     // otherwise munge the case of the path
     // otherwise munge the case of the path
-    MungeCase(dest, destSize);
+     ResolvePathCaseInsensitive(dest, destSize);
  }
  }
 
 
  //-----------------------------------------------------------------------------
  //-----------------------------------------------------------------------------
@@ -1284,7 +1284,19 @@ bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite)
 
 
  bool Platform::dumpDirectories(const char *path, Vector<StringTableEntry> &directoryVector, S32 depth, bool noBasePath)
  bool Platform::dumpDirectories(const char *path, Vector<StringTableEntry> &directoryVector, S32 depth, bool noBasePath)
  {
  {
-   bool retVal = recurseDumpDirectories(path, "", directoryVector, -1, depth, noBasePath);
+#ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE
+   dsize_t pathLength = dStrlen(path);
+   char caseSensitivePath[pathLength + 1];
+
+   // Load path into temporary buffer
+   dMemcpy(caseSensitivePath, path, pathLength);
+   caseSensitivePath[pathLength] = 0x00;
+   ResolvePathCaseInsensitive(caseSensitivePath, pathLength);
+#else
+   const char* caseSensitivePath = path;
+#endif
+
+   bool retVal = recurseDumpDirectories(caseSensitivePath, "", directoryVector, -1, depth, noBasePath);
    clearExcludedDirectories();
    clearExcludedDirectories();
    return retVal;
    return retVal;
  }
  }

+ 3 - 0
Tools/CMake/torque3d.cmake

@@ -163,6 +163,9 @@ endif()
 option(TORQUE_MULTITHREAD "Multi Threading" ON)
 option(TORQUE_MULTITHREAD "Multi Threading" ON)
 mark_as_advanced(TORQUE_MULTITHREAD)
 mark_as_advanced(TORQUE_MULTITHREAD)
 
 
+option(TORQUE_POSIX_PATH_CASE_INSENSITIVE ON)
+mark_as_advanced(TORQUE_POSIX_PATH_CASE_INSENSITIVE)
+
 option(TORQUE_DISABLE_MEMORY_MANAGER "Disable memory manager" ON)
 option(TORQUE_DISABLE_MEMORY_MANAGER "Disable memory manager" ON)
 mark_as_advanced(TORQUE_DISABLE_MEMORY_MANAGER)
 mark_as_advanced(TORQUE_DISABLE_MEMORY_MANAGER)
 
 

+ 3 - 0
Tools/CMake/torqueConfig.h.in

@@ -44,6 +44,9 @@
 /// Define me if you want to enable Arcane FX support.
 /// Define me if you want to enable Arcane FX support.
 #cmakedefine TORQUE_AFX_ENABLED
 #cmakedefine TORQUE_AFX_ENABLED
 
 
+/// Define me if you want path case insensitivity support on POSIX systems. Does nothing on Windows.
+#cmakedefine TORQUE_POSIX_PATH_CASE_INSENSITIVE
+
 /// Define me if you want to enable multithreading support.
 /// Define me if you want to enable multithreading support.
 #cmakedefine TORQUE_MULTITHREAD
 #cmakedefine TORQUE_MULTITHREAD