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 12 #include "Common/File/DirListing.h" 13 #include "Common/File/Path.h" 14 15 // Abstraction above path that lets you navigate easily. 16 // "/" is a special path that means the root of the file system. On Windows, 17 // listing this will yield drives. 18 class PathBrowser { 19 public: 20 PathBrowser() {} 21 PathBrowser(const Path &path) { SetPath(path); } 22 ~PathBrowser(); 23 24 void SetPath(const Path &path); 25 bool IsListingReady(); 26 bool GetListing(std::vector<File::FileInfo> &fileInfo, const char *filter = nullptr, bool *cancel = nullptr); 27 28 bool CanNavigateUp(); 29 void NavigateUp(); 30 31 void Navigate(const std::string &subdir); 32 33 const Path &GetPath() const { 34 return path_; 35 } 36 std::string GetFriendlyPath() const; 37 38 bool empty() const { 39 return path_.empty(); 40 } 41 42 private: 43 void HandlePath(); 44 void ResetPending(); 45 46 Path path_; 47 Path pendingPath_; 48 std::vector<File::FileInfo> pendingFiles_; 49 std::condition_variable pendingCond_; 50 std::mutex pendingLock_; 51 std::thread pendingThread_; 52 bool pendingActive_ = false; 53 bool pendingCancel_ = false; 54 bool pendingStop_ = false; 55 bool ready_ = false; 56 }; 57 58