Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/File/PathBrowser.h
5661 views
1
#pragma once
2
3
#include <condition_variable>
4
#include <mutex>
5
#include <string_view>
6
#include <cstring>
7
#include <thread>
8
#include <vector>
9
#include <cstdlib>
10
11
#include "Common/File/DirListing.h"
12
#include "Common/File/Path.h"
13
14
// Abstraction above path that lets you navigate easily.
15
// "/" is a special path that means the root of the file system. On Windows,
16
// listing this will yield drives.
17
class PathBrowser {
18
public:
19
PathBrowser() {}
20
~PathBrowser();
21
22
void SetPath(const Path &path);
23
void Refresh() {
24
HandlePath();
25
}
26
bool IsListingReady() const {
27
return ready_;
28
}
29
bool GetListing(std::vector<File::FileInfo> &fileInfo, const char *filter = nullptr, bool *cancel = nullptr);
30
31
bool CanNavigateUp();
32
void NavigateUp();
33
34
void Navigate(std::string_view subdir);
35
36
const Path &GetPath() const {
37
return path_;
38
}
39
40
void SetUserAgent(std::string_view s) {
41
userAgent_ = s;
42
}
43
void RestrictToRoot(const Path &root);
44
bool empty() const {
45
return path_.empty();
46
}
47
bool Success() const {
48
return success_;
49
}
50
51
private:
52
void HandlePath();
53
void ResetPending();
54
void ApplyRestriction();
55
56
Path path_;
57
Path pendingPath_;
58
Path restrictedRoot_;
59
std::string userAgent_;
60
std::vector<File::FileInfo> pendingFiles_;
61
std::condition_variable pendingCond_;
62
std::mutex pendingLock_;
63
std::thread pendingThread_;
64
bool pendingActive_ = false;
65
bool pendingCancel_ = false;
66
bool pendingStop_ = false;
67
bool ready_ = false;
68
bool success_ = true;
69
};
70
71
72