CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/File/PathBrowser.h
Views: 1401
1
#pragma once
2
3
#include <condition_variable>
4
#include <mutex>
5
#include <string>
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(const std::string &subdir);
35
36
const Path &GetPath() const {
37
return path_;
38
}
39
std::string GetFriendlyPath() const;
40
41
void SetUserAgent(const std::string &s) {
42
userAgent_ = s;
43
}
44
void SetRootAlias(const std::string &alias, const Path &rootPath) {
45
aliasDisplay_ = alias;
46
aliasMatch_ = rootPath;
47
}
48
void RestrictToRoot(const Path &root);
49
bool empty() const {
50
return path_.empty();
51
}
52
bool Success() const {
53
return success_;
54
}
55
56
private:
57
void HandlePath();
58
void ResetPending();
59
void ApplyRestriction();
60
61
Path path_;
62
Path pendingPath_;
63
Path restrictedRoot_;
64
std::string userAgent_;
65
std::string aliasDisplay_;
66
Path aliasMatch_;
67
std::vector<File::FileInfo> pendingFiles_;
68
std::condition_variable pendingCond_;
69
std::mutex pendingLock_;
70
std::thread pendingThread_;
71
bool pendingActive_ = false;
72
bool pendingCancel_ = false;
73
bool pendingStop_ = false;
74
bool ready_ = false;
75
bool success_ = true;
76
};
77
78
79