forked from oreo639/LimePlayer3DS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplorer.hpp
63 lines (55 loc) · 1.52 KB
/
explorer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef __FILEBROWSER__
#define __FILEBROWSER__
#include <string>
#include <vector>
#include <filesystem>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
typedef std::vector<std::string> strvec;
typedef std::filesystem::path PathType;
typedef struct
{
strvec files;
int fileNum;
strvec directories;
int dirNum;
std::string currentDir;
int total;
} dirList_t;
typedef struct DirEntry {
DirEntry(const std::string& name, bool directory) : filename(name), directory(directory) {}
std::string filename;
bool directory;
} DirEntry_t;
enum {
EXPATH_NOEXIST = 1, // Directory does not exist
EXPATH_EMPTY = 2, // The given path is an empty string
EXPATH_EXIT = 200 // Attempted to access beyond root dir
};
class Explorer
{
public:
Explorer(const std::string& root);
~Explorer() {}
std::string Item(uint32_t index);
bool IsDir(uint32_t index);
DirEntry GetEntry(uint32_t index);
std::string GetAbsolutePath(uint32_t index);
int ChangeTo(uint32_t index);
int ChangeDir(const PathType path);
int BackDir(void);
void GotoRoot(void) { m_relativePath.clear(); LoadEntries(); }
int Size(void) { return m_entries.size(); }
std::string GetCurrentDir(void) { return m_rootDir / m_relativePath; }
void SetExtFilter(const std::string& extension) {m_filteredExt = extension;}
private:
int LoadEntries(void);
PathType NormalizePath(const PathType& path);
int CheckDir(const PathType& path);
std::vector<DirEntry_t> m_entries;
PathType m_rootDir;
PathType m_relativePath;
std::string m_filteredExt;
};
#endif