2013-11-18 14:02:56 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-10-06 11:49:35 -07:00
|
|
|
#include <condition_variable>
|
|
|
|
|
#include <mutex>
|
2013-11-18 14:02:56 +01:00
|
|
|
#include <string>
|
2020-10-04 00:25:21 +02:00
|
|
|
#include <cstring>
|
2019-10-06 11:49:35 -07:00
|
|
|
#include <thread>
|
2013-11-18 14:02:56 +01:00
|
|
|
#include <vector>
|
2020-10-04 20:48:47 +02:00
|
|
|
#include <cstdlib>
|
2013-11-18 14:02:56 +01:00
|
|
|
|
2020-10-04 20:48:47 +02:00
|
|
|
#include "Common/File/DirListing.h"
|
2021-05-09 19:06:02 +02:00
|
|
|
#include "Common/File/Path.h"
|
2013-11-18 14:02:56 +01:00
|
|
|
|
|
|
|
|
// Abstraction above path that lets you navigate easily.
|
|
|
|
|
// "/" is a special path that means the root of the file system. On Windows,
|
|
|
|
|
// listing this will yield drives.
|
|
|
|
|
class PathBrowser {
|
|
|
|
|
public:
|
|
|
|
|
PathBrowser() {}
|
2019-10-06 11:49:35 -07:00
|
|
|
~PathBrowser();
|
2013-11-18 14:02:56 +01:00
|
|
|
|
2021-05-09 19:06:02 +02:00
|
|
|
void SetPath(const Path &path);
|
2023-12-29 00:17:35 +01:00
|
|
|
void Refresh() {
|
|
|
|
|
HandlePath();
|
|
|
|
|
}
|
2024-09-17 15:13:13 +02:00
|
|
|
bool IsListingReady() const {
|
|
|
|
|
return ready_;
|
|
|
|
|
}
|
2021-04-25 20:38:22 +02:00
|
|
|
bool GetListing(std::vector<File::FileInfo> &fileInfo, const char *filter = nullptr, bool *cancel = nullptr);
|
2020-12-20 00:41:28 +01:00
|
|
|
|
2020-12-20 01:38:45 +01:00
|
|
|
bool CanNavigateUp();
|
2020-12-20 00:41:28 +01:00
|
|
|
void NavigateUp();
|
2021-07-18 22:28:59 +02:00
|
|
|
|
2021-05-09 19:06:02 +02:00
|
|
|
void Navigate(const std::string &subdir);
|
2013-11-18 14:02:56 +01:00
|
|
|
|
2021-07-18 22:28:59 +02:00
|
|
|
const Path &GetPath() const {
|
2021-05-09 19:06:02 +02:00
|
|
|
return path_;
|
2013-11-18 14:02:56 +01:00
|
|
|
}
|
2020-12-20 01:00:07 +01:00
|
|
|
std::string GetFriendlyPath() const;
|
2013-11-18 14:02:56 +01:00
|
|
|
|
2022-12-27 15:08:57 -08:00
|
|
|
void SetUserAgent(const std::string &s) {
|
|
|
|
|
userAgent_ = s;
|
|
|
|
|
}
|
2024-05-03 17:54:57 +02:00
|
|
|
void SetRootAlias(const std::string &alias, const Path &rootPath) {
|
2022-12-27 15:08:57 -08:00
|
|
|
aliasDisplay_ = alias;
|
2024-05-03 17:54:57 +02:00
|
|
|
aliasMatch_ = rootPath;
|
2022-12-27 15:08:57 -08:00
|
|
|
}
|
2024-05-03 17:54:57 +02:00
|
|
|
void RestrictToRoot(const Path &root);
|
2021-07-25 00:16:30 +02:00
|
|
|
bool empty() const {
|
|
|
|
|
return path_.empty();
|
|
|
|
|
}
|
2024-05-10 10:39:58 +02:00
|
|
|
bool Success() const {
|
|
|
|
|
return success_;
|
|
|
|
|
}
|
2021-07-25 00:16:30 +02:00
|
|
|
|
2019-10-06 11:49:35 -07:00
|
|
|
private:
|
|
|
|
|
void HandlePath();
|
2021-02-17 00:29:39 -08:00
|
|
|
void ResetPending();
|
2024-05-03 17:54:57 +02:00
|
|
|
void ApplyRestriction();
|
2019-10-06 11:49:35 -07:00
|
|
|
|
2021-05-09 19:06:02 +02:00
|
|
|
Path path_;
|
|
|
|
|
Path pendingPath_;
|
2024-05-03 17:54:57 +02:00
|
|
|
Path restrictedRoot_;
|
2022-12-27 15:08:57 -08:00
|
|
|
std::string userAgent_;
|
|
|
|
|
std::string aliasDisplay_;
|
2024-05-03 17:54:57 +02:00
|
|
|
Path aliasMatch_;
|
2021-04-25 20:38:22 +02:00
|
|
|
std::vector<File::FileInfo> pendingFiles_;
|
2019-10-06 11:49:35 -07:00
|
|
|
std::condition_variable pendingCond_;
|
|
|
|
|
std::mutex pendingLock_;
|
|
|
|
|
std::thread pendingThread_;
|
2021-02-17 00:29:39 -08:00
|
|
|
bool pendingActive_ = false;
|
2019-10-06 11:49:35 -07:00
|
|
|
bool pendingCancel_ = false;
|
|
|
|
|
bool pendingStop_ = false;
|
|
|
|
|
bool ready_ = false;
|
2024-05-10 10:39:58 +02:00
|
|
|
bool success_ = true;
|
2013-11-18 14:02:56 +01:00
|
|
|
};
|
|
|
|
|
|