Explorar el Código

check file extension of level paks

Thomas Buck hace 10 años
padre
commit
3f68f9ed33
Se han modificado 4 ficheros con 44 adiciones y 14 borrados
  1. 5
    0
      ChangeLog
  2. 8
    0
      include/System.h
  3. 18
    14
      src/OpenRaider.cpp
  4. 13
    0
      src/System.cpp

+ 5
- 0
ChangeLog Ver fichero

@@ -5,6 +5,11 @@
5 5
 
6 6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
7 7
 
8
+	[ 20140305 ]
9
+	* Now using cmake build system
10
+	* Pak file extensions are checked to see if they could be valid
11
+	* Bugfix: String was used after being deleted in OpenRaider.cpp
12
+
8 13
 	[ 20140304 ]
9 14
 	* Removed memory test
10 15
 

+ 8
- 0
include/System.h Ver fichero

@@ -90,6 +90,14 @@ public:
90 90
     static char *getFileFromFullPath(char *filename);
91 91
 
92 92
     /*!
93
+     * \brief Check if a string ends with another string.
94
+     * \param str string to check
95
+     * \param suffix suffix for which to check
96
+     * \returns true if str ends with suffix
97
+     */
98
+    static bool stringEndsWith(const char *str, const char *suffix);
99
+
100
+    /*!
93 101
      * \brief Gets the game tick
94 102
      * \returns number of milliseconds since start of program
95 103
      */

+ 18
- 14
src/OpenRaider.cpp Ver fichero

@@ -3349,25 +3349,29 @@ void OpenRaider::loadPakFolderRecursive(const char *dir) {
3349 3349
                     delete tmp;
3350 3350
                 }
3351 3351
             } else {
3352
-                /*!
3353
-                 * \fixme Currently just tries to validate every file
3354
-                 * in the pak folders. Should check the exstension to
3355
-                 * see if it could be a level pak...
3356
-                 */
3357
-
3358 3352
                 char *fullPathMap = bufferString("%s%s", dir, ep->d_name);
3359 3353
 
3360
-                if (m_tombraider.checkMime(fullPathMap) == 0) {
3361
-                    // printf("Validated pak: '%s'\n", fullPathMap);
3362
-                    delete [] fullPathMap;
3354
+                char *lowerPath = bufferString("%s", fullPathMap);
3355
+                for (char *p = lowerPath; *p; ++p) *p = (char)tolower(*p);
3356
+
3357
+                // Check for valid extension
3358
+                if (stringEndsWith(lowerPath, ".phd")
3359
+                     || stringEndsWith(lowerPath, ".tr2")
3360
+                     || stringEndsWith(lowerPath, ".tr4")
3361
+                     || stringEndsWith(lowerPath, ".trc")) {
3362
+                    if (m_tombraider.checkMime(fullPathMap) == 0) {
3363
+                        // printf("Validated pak: '%s'\n", fullPathMap);
3363 3364
 
3364
-                    // Just load relative filename
3365
-                    mMapList.pushBack(bufferString("%s", (fullPathMap + strlen(m_pakDir))));
3366
-                } else {
3367
-                    printf("ERROR: pak file '%s' not found or invalid\n", fullPathMap);
3365
+                        // Just load relative filename
3366
+                        mMapList.pushBack(bufferString("%s", (fullPathMap + strlen(m_pakDir))));
3367
+                    } else {
3368
+                        printf("ERROR: pak file '%s' not found or invalid\n", fullPathMap);
3368 3369
 
3369
-                    delete [] fullPathMap;
3370
+                        delete [] fullPathMap;
3371
+                    }
3370 3372
                 }
3373
+
3374
+                delete [] lowerPath;
3371 3375
             }
3372 3376
         }
3373 3377
         closedir(pakDir);

+ 13
- 0
src/System.cpp Ver fichero

@@ -73,6 +73,19 @@ System::~System()
73 73
 // Public Accessors
74 74
 ////////////////////////////////////////////////////////////
75 75
 
76
+bool System::stringEndsWith(const char *str, const char *suffix) {
77
+    if (!str || !suffix)
78
+        return false;
79
+
80
+    size_t lenstr = strlen(str);
81
+    size_t lensuffix = strlen(suffix);
82
+
83
+    if (lensuffix > lenstr)
84
+        return false;
85
+
86
+    return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
87
+}
88
+
76 89
 char *System::bufferString(const char *string, ...)
77 90
 {
78 91
     int sz = 60;

Loading…
Cancelar
Guardar