Browse Source

check file extension of level paks

Thomas Buck 10 years ago
parent
commit
3f68f9ed33
4 changed files with 44 additions and 14 deletions
  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 View File

5
 
5
 
6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
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
 	[ 20140304 ]
13
 	[ 20140304 ]
9
 	* Removed memory test
14
 	* Removed memory test
10
 
15
 

+ 8
- 0
include/System.h View File

90
     static char *getFileFromFullPath(char *filename);
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
      * \brief Gets the game tick
101
      * \brief Gets the game tick
94
      * \returns number of milliseconds since start of program
102
      * \returns number of milliseconds since start of program
95
      */
103
      */

+ 18
- 14
src/OpenRaider.cpp View File

3349
                     delete tmp;
3349
                     delete tmp;
3350
                 }
3350
                 }
3351
             } else {
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
                 char *fullPathMap = bufferString("%s%s", dir, ep->d_name);
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
         closedir(pakDir);
3377
         closedir(pakDir);

+ 13
- 0
src/System.cpp View File

73
 // Public Accessors
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
 char *System::bufferString(const char *string, ...)
89
 char *System::bufferString(const char *string, ...)
77
 {
90
 {
78
     int sz = 60;
91
     int sz = 60;

Loading…
Cancel
Save