|
@@ -7,16 +7,22 @@
|
7
|
7
|
|
8
|
8
|
#include <cctype>
|
9
|
9
|
|
10
|
|
-#ifndef WIN32
|
11
|
|
-#include <dirent.h>
|
12
|
|
-#endif
|
13
|
|
-
|
14
|
10
|
#include "global.h"
|
15
|
11
|
#include "Console.h"
|
16
|
12
|
#include "Menu.h"
|
17
|
13
|
#include "OpenRaider.h"
|
18
|
14
|
#include "utils/strings.h"
|
19
|
15
|
|
|
16
|
+#if defined(HAVE_DIRENT_H) && defined(HAVE_OPENDIR) && defined(HAVE_READDIR_R) && defined(HAVE_CLOSEDIR) && defined(HAVE_DT_DIR)
|
|
17
|
+#include <dirent.h>
|
|
18
|
+#define USE_DIRENT
|
|
19
|
+#elif defined(HAVE_WINDOWS_H) && defined(HAVE_FINDFIRSTFILE) && defined(HAVE_FINDNEXTFILE) && defined(HAVE_FINDCLOSE)
|
|
20
|
+#include <windows.h>
|
|
21
|
+#define USE_FINDFILE
|
|
22
|
+#else
|
|
23
|
+#error No support for recursive folder traversal
|
|
24
|
+#endif
|
|
25
|
+
|
20
|
26
|
Menu::Menu() {
|
21
|
27
|
mVisible = false;
|
22
|
28
|
mCursor = 0;
|
|
@@ -55,54 +61,14 @@ bool Menu::isVisible() {
|
55
|
61
|
|
56
|
62
|
#ifdef WIN32
|
57
|
63
|
void Menu::loadPakFolderHelper(std::vector<char *> &list) {
|
58
|
|
- WIN32_FIND_DATA fd;
|
59
|
|
- char *tmp = bufferString("%s\\*", list.at(0));
|
60
|
|
- HANDLE hFind = FindFirstFile(tmp, &fd);
|
61
|
|
- do {
|
62
|
|
- if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
63
|
|
- list.push_back(bufferString("%s\\%s", list.at(0), fd.cFileName));
|
64
|
|
- } else {
|
65
|
|
- char *fullPathMap = bufferString("%s\\%s", list.at(0), fd.cFileName);
|
66
|
|
-
|
67
|
|
- char *lowerPath = bufferString("%s", fullPathMap);
|
68
|
|
- for (char *p = lowerPath; *p; ++p) *p = (char)tolower(*p);
|
69
|
|
-
|
70
|
|
- // Check for valid extension
|
71
|
|
- if (stringEndsWith(lowerPath, ".phd")
|
72
|
|
- || stringEndsWith(lowerPath, ".tr2")
|
73
|
|
- || stringEndsWith(lowerPath, ".tr4")
|
74
|
|
- || stringEndsWith(lowerPath, ".trc")) {
|
75
|
|
- int error = TombRaider::checkMime(fullPathMap);
|
76
|
|
- if (error == 0) {
|
77
|
|
- // Just load relative filename
|
78
|
|
- mMapList.push_back(bufferString("%s", (fullPathMap + strlen(getOpenRaider().mPakDir) + 1)));
|
79
|
|
- } else {
|
80
|
|
- getConsole().print("Error: pak file '%s' %s",
|
81
|
|
- fullPathMap, (error == -1) ? "not found" : "invalid");
|
82
|
|
- }
|
83
|
|
- }
|
84
|
64
|
|
85
|
|
- delete [] lowerPath;
|
86
|
|
- delete [] fullPathMap;
|
87
|
|
- }
|
88
|
|
- } while (FindNextFile(hFind, &fd) != 0);
|
89
|
|
- FindClose(hFind);
|
90
|
|
- delete [] tmp;
|
91
|
|
- delete [] list.at(0);
|
92
|
|
- list.erase(list.begin());
|
93
|
65
|
}
|
94
|
66
|
#endif
|
95
|
67
|
|
96
|
68
|
void Menu::loadPakFolderRecursive(const char *dir) {
|
97
|
69
|
assert(dir != NULL);
|
98
|
70
|
assert(dir[0] != '\0');
|
99
|
|
-#ifdef WIN32
|
100
|
|
- std::vector<char *> list;
|
101
|
|
- list.push_back(bufferString("%s", dir));
|
102
|
|
- do {
|
103
|
|
- loadPakFolderHelper(list);
|
104
|
|
- } while (list.size() > 0);
|
105
|
|
-#else
|
|
71
|
+#ifdef USE_DIRENT
|
106
|
72
|
struct dirent entry;
|
107
|
73
|
struct dirent *ep = NULL;
|
108
|
74
|
DIR *pakDir;
|
|
@@ -150,6 +116,46 @@ void Menu::loadPakFolderRecursive(const char *dir) {
|
150
|
116
|
} else {
|
151
|
117
|
getConsole().print("Could not open PAK dir %s!", dir);
|
152
|
118
|
}
|
|
119
|
+#elif defined(USE_FINDFILE)
|
|
120
|
+ std::vector<char *> list;
|
|
121
|
+ list.push_back(bufferString("%s", dir));
|
|
122
|
+ do {
|
|
123
|
+ WIN32_FIND_DATA fd;
|
|
124
|
+ char *tmp = bufferString("%s\\*", list.at(0));
|
|
125
|
+ HANDLE hFind = FindFirstFile(tmp, &fd);
|
|
126
|
+ do {
|
|
127
|
+ if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
|
128
|
+ list.push_back(bufferString("%s\\%s", list.at(0), fd.cFileName));
|
|
129
|
+ } else {
|
|
130
|
+ char *fullPathMap = bufferString("%s\\%s", list.at(0), fd.cFileName);
|
|
131
|
+
|
|
132
|
+ char *lowerPath = bufferString("%s", fullPathMap);
|
|
133
|
+ for (char *p = lowerPath; *p; ++p) *p = (char)tolower(*p);
|
|
134
|
+
|
|
135
|
+ // Check for valid extension
|
|
136
|
+ if (stringEndsWith(lowerPath, ".phd")
|
|
137
|
+ || stringEndsWith(lowerPath, ".tr2")
|
|
138
|
+ || stringEndsWith(lowerPath, ".tr4")
|
|
139
|
+ || stringEndsWith(lowerPath, ".trc")) {
|
|
140
|
+ int error = TombRaider::checkMime(fullPathMap);
|
|
141
|
+ if (error == 0) {
|
|
142
|
+ // Just load relative filename
|
|
143
|
+ mMapList.push_back(bufferString("%s", (fullPathMap + strlen(getOpenRaider().mPakDir) + 1)));
|
|
144
|
+ } else {
|
|
145
|
+ getConsole().print("Error: pak file '%s' %s",
|
|
146
|
+ fullPathMap, (error == -1) ? "not found" : "invalid");
|
|
147
|
+ }
|
|
148
|
+ }
|
|
149
|
+
|
|
150
|
+ delete [] lowerPath;
|
|
151
|
+ delete [] fullPathMap;
|
|
152
|
+ }
|
|
153
|
+ } while (FindNextFile(hFind, &fd) != 0);
|
|
154
|
+ FindClose(hFind);
|
|
155
|
+ delete [] tmp;
|
|
156
|
+ delete [] list.at(0);
|
|
157
|
+ list.erase(list.begin());
|
|
158
|
+ } while (list.size() > 0);
|
153
|
159
|
#endif
|
154
|
160
|
}
|
155
|
161
|
|