OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
FolderRecursive.cpp
Go to the documentation of this file.
1 
8 #include "global.h"
9 #include "utils/strings.h"
10 #include "utils/Folder.h"
11 
12 unsigned long Folder::countRecursiveFiles() {
14  unsigned long count = fileCount();
15  for (unsigned long i = 0; i < folderCount(); i++)
16  count += getFolder(i).countRecursiveFiles();
17  return count;
18 }
19 
20 void Folder::executeRemoveRecursiveFiles(std::function<bool (File& f)> func) {
21  executeRemoveFiles(func);
22  for (unsigned long i = 0; i < folderCount(); i++) {
24  }
25 }
26 
27 std::string Folder::getRecursiveFileName(unsigned long i) {
30  if (i < fileCount()) {
31  return getFile(i).getName();
32  } else {
33  unsigned long count = fileCount();
34  for (unsigned long n = 0; n < folderCount(); n++) {
35  if ((i - count) < getFolder(n).countRecursiveFiles()) {
36  return getFolder(n).getName() + '/'
37  + getFolder(n).getRecursiveFileName(i - count);
38  }
39  count += getFolder(n).countRecursiveFiles();
40  }
41  }
42 
43  assert(false);
44  return "";
45 }
46 
47 File& Folder::getRecursiveFile(unsigned long i) {
50  if (i < fileCount()) {
51  return getFile(i);
52  } else {
53  unsigned long count = fileCount();
54  for (unsigned long n = 0; n < folderCount(); n++) {
55  if ((i - count) < getFolder(n).countRecursiveFiles()) {
56  return getFolder(n).getRecursiveFile(i - count);
57  }
58  count += getFolder(n).countRecursiveFiles();
59  }
60  }
61 
62  assert(false);
63  return files.at(0);
64 }
65 
66 void Folder::findRecursiveFilesEndingWith(std::vector<File>& found, std::string end,
67  bool casesensitive) {
69  for (unsigned long i = 0; i < countRecursiveFiles(); i++) {
70  if (stringEndsWith(getRecursiveFile(i).getName(), end, casesensitive)) {
71  found.push_back(getRecursiveFile(i));
72  }
73  }
74 }
75 
std::string getRecursiveFileName(unsigned long i)
Folder & getFolder(unsigned long i)
Definition: Folder.cpp:96
unsigned long countRecursiveFiles()
String handling utilities.
Definition: Folder.h:16
unsigned long folderCount()
Definition: Folder.cpp:91
Included everywhere.
std::vector< File > files
Definition: Folder.h:65
File & getRecursiveFile(unsigned long i)
unsigned long fileCount()
Definition: Folder.cpp:80
bool stringEndsWith(std::string s, std::string suffix, bool casesensitive=false)
Definition: strings.cpp:32
#define assert(x)
Definition: global.h:124
Recursive file-system walking utilities.
void findRecursiveFilesEndingWith(std::vector< File > &found, std::string end, bool casesensitive=false)
void executeRemoveFiles(std::function< bool(File &f)> func)
Definition: Folder.cpp:110
File & getFile(unsigned long i)
Definition: Folder.cpp:85
void createFolderItems()
Definition: Folder.cpp:119
std::string & getName()
Definition: Folder.h:20
std::string & getName()
Definition: Folder.h:32
void executeRemoveRecursiveFiles(std::function< bool(File &f)> func)