OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
Folder.h
Go to the documentation of this file.
1 
8 #ifndef _UTILS_FOLDER_H_
9 #define _UTILS_FOLDER_H_
10 
11 #include <functional>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 class File {
17  public:
18  File(std::string file);
19 
20  std::string& getName() { return name; }
21  std::string& getPath() { return path; }
22 
23  private:
24  std::string name;
25  std::string path;
26 };
27 
28 class Folder {
29  public:
30  Folder(std::string folder, bool listDotFiles = false);
31 
32  std::string& getName() { return name; }
33  std::string& getPath() { return path; }
34 
35  unsigned long fileCount();
36  File& getFile(unsigned long i);
37 
38  unsigned long folderCount();
39  Folder& getFolder(unsigned long i);
40 
41  Folder getParent();
42 
43  void executeRemoveFiles(std::function<bool (File& f)> func);
44  void findFilesEndingWith(std::vector<File>& found, std::string end, bool casesensitive = false);
45 
46  // Accessing a folder recursively
47  // This treats all files in all subfolders as if they were in this folder
48  unsigned long countRecursiveFiles();
49  void executeRemoveRecursiveFiles(std::function<bool (File& f)> func);
50  std::string getRecursiveFileName(unsigned long i);
51  File& getRecursiveFile(unsigned long i);
52  void findRecursiveFilesEndingWith(std::vector<File>& found, std::string end,
53  bool casesensitive = false);
54 
55  private:
56  void createFolderItems();
57  int readFolderItems(std::vector<std::string>& foundFiles, std::vector<std::string>& foundFolders);
58 
59  std::string name;
60  std::string path;
61 
62  bool hasListed;
63  bool listDot;
64 
65  std::vector<File> files;
66  std::vector<Folder> folders;
67 };
68 
69 #endif
70 
std::string name
Only last part of path.
Definition: Folder.h:59
std::string getRecursiveFileName(unsigned long i)
Folder & getFolder(unsigned long i)
Definition: Folder.cpp:96
unsigned long countRecursiveFiles()
std::string path
Definition: Folder.h:25
Definition: Folder.h:16
std::string & getPath()
Definition: Folder.h:33
unsigned long folderCount()
Definition: Folder.cpp:91
bool listDot
Definition: Folder.h:63
Folder getParent()
Definition: Folder.cpp:102
Folder(std::string folder, bool listDotFiles=false)
Definition: Folder.cpp:35
std::vector< File > files
Definition: Folder.h:65
File & getRecursiveFile(unsigned long i)
unsigned long fileCount()
Definition: Folder.cpp:80
std::vector< Folder > folders
Definition: Folder.h:66
bool hasListed
Definition: Folder.h:62
std::string path
Full path, with name and '/' at end.
Definition: Folder.h:60
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
File(std::string file)
Definition: Folder.cpp:17
void createFolderItems()
Definition: Folder.cpp:119
Definition: Folder.h:28
void findFilesEndingWith(std::vector< File > &found, std::string end, bool casesensitive=false)
Definition: Folder.cpp:223
std::string name
Definition: Folder.h:24
std::string & getName()
Definition: Folder.h:20
std::string & getName()
Definition: Folder.h:32
std::string & getPath()
Definition: Folder.h:21
void executeRemoveRecursiveFiles(std::function< bool(File &f)> func)
int readFolderItems(std::vector< std::string > &foundFiles, std::vector< std::string > &foundFolders)