Skip to content

Commit 983e0f1

Browse files
committed
Corrected few bugs. Added find files by extension.
1 parent 815e363 commit 983e0f1

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

cpp/JPAK.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ Json::Value JPAK::FindFileEntry(vector<string> &path, Json::Value &root) {
111111
return Json::Value(JPAK_NOT_FOUND_DATA);
112112
}
113113
}
114+
115+
vector<Json::Value> JPAK::FindFileByExt(string &ext, Json::Value &folder) {
116+
vector<Json::Value> results;
117+
for(auto file : folder["files"]) {
118+
if(file.asString().find(ext) != string::npos)
119+
results.push_back(file);
120+
}
121+
return results;
122+
}
123+
114124
bool JPAK::GetFile(string &path, char **buffer, int *size) {
115125
vector<string> paths = split(path, '/');
116126
// Here is relative to root, so the first will be blank if starts with "/"
@@ -129,3 +139,5 @@ bool JPAK::GetFile(string &path, char **buffer, int *size) {
129139
return false;
130140
}
131141
}
142+
143+

cpp/JPAK.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using namespace std;
2222
class JPAK {
2323
private:
24-
Json::Value root;
2524
Json::Reader reader;
2625
ifstream jpakfile;
2726
bool ready;
@@ -30,6 +29,7 @@ class JPAK {
3029
JPAK();
3130
virtual ~JPAK();
3231

32+
Json::Value root;
3333
bool LoadFromFile(string &);
3434
bool GetFile(string &, char **, int *);
3535
bool GetFile(const char *path, char **buf, int *size) { string t = path; return GetFile(t,buf,size); };
@@ -38,6 +38,7 @@ class JPAK {
3838
void PrintTree();
3939

4040
Json::Value FindFileEntry(vector<string> &, Json::Value &);
41+
vector<Json::Value> FindFileByExt(string &, Json::Value &);
4142
};
4243

4344
#endif /* JPAK_H_ */

0 commit comments

Comments
 (0)