Mercurial > minori
comparison src/core/filesystem.cc @ 399:a0bc3ae5164a
anime_list: actually obey "highlight anime if they are available"
| author | Paper <paper@tflc.us> |
|---|---|
| date | Fri, 07 Nov 2025 15:28:22 -0500 |
| parents | 650a9159a0e7 |
| children | 2f89797b6a44 |
comparison
equal
deleted
inserted
replaced
| 398:650a9159a0e7 | 399:a0bc3ae5164a |
|---|---|
| 59 { | 59 { |
| 60 return GetDotPath() / "anime" / "posters"; | 60 return GetDotPath() / "anime" / "posters"; |
| 61 } | 61 } |
| 62 | 62 |
| 63 /* ------------------------------------------------------------------------ */ | 63 /* ------------------------------------------------------------------------ */ |
| 64 /* Ehhhhh */ | 64 /* This is the "base class" for basically every watcher. */ |
| 65 | 65 |
| 66 class Watcher : public IWatcher { | 66 class Watcher : public IWatcher { |
| 67 public: | 67 public: |
| 68 Watcher(void *opaque, const std::filesystem::path &path, EventHandler handler) | 68 Watcher(void *opaque, const std::filesystem::path &path, EventHandler handler) |
| 69 : path_(path), handler_(handler), opaque_(opaque) | 69 : path_(path), handler_(handler), opaque_(opaque) |
| 78 void *opaque_; | 78 void *opaque_; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 /* ------------------------------------------------------------------------ */ | 81 /* ------------------------------------------------------------------------ */ |
| 82 /* Filesystem watcher. | 82 /* Filesystem watcher. |
| 83 * This is the portable version for non-Windows (of which the Windows | 83 * This is the portable version for non-Windows; however, pretty much |
| 84 * specific version hasn't been written yet... TODO) */ | 84 * every implementation should be based on this in some shape or form. */ |
| 85 | 85 |
| 86 /* | 86 /* |
| 87 We can't use std::recursive_directory_iterator! | 87 We can't use std::recursive_directory_iterator! |
| 88 Why? Well, to put it blunt, it sucks. The main reason | 88 Why? Well, to put it blunt, it sucks. The main reason |
| 89 being is that if it finds a single directory it cannot | 89 being is that if it finds a single directory it cannot |
| 175 /* unordered hashmap, path[found] */ | 175 /* unordered hashmap, path[found] */ |
| 176 std::unordered_map<std::filesystem::path, bool> paths_; | 176 std::unordered_map<std::filesystem::path, bool> paths_; |
| 177 bool recursive_; | 177 bool recursive_; |
| 178 }; | 178 }; |
| 179 | 179 |
| 180 /* There does actually exist an API in Qt to do file system watching. | |
| 181 * However, it is of little use for us, since it | |
| 182 * a) isn't recursive | |
| 183 * b) requires constant conversion to and from QString, which takes | |
| 184 * up valuable system resources | |
| 185 * c) uses signals etc. that are a pain in the ass to use in an | |
| 186 * event-processing logic like we do here. */ | |
| 187 | |
| 180 #ifdef WIN32 | 188 #ifdef WIN32 |
| 181 /* On Windows, we can ask the OS whether the folder has changed or not. | 189 /* On Windows, we can ask the OS whether the directory tree has changed or not. |
| 182 * This is great for us! */ | 190 * This is great for us! */ |
| 183 class Win32Watcher : public StdFilesystemWatcher { | 191 class Win32Watcher : public StdFilesystemWatcher { |
| 184 public: | 192 public: |
| 185 Win32Watcher(void *opaque, const std::filesystem::path &path, IWatcher::EventHandler handler, bool recursive) | 193 Win32Watcher(void *opaque, const std::filesystem::path &path, IWatcher::EventHandler handler, bool recursive) |
| 186 : StdFilesystemWatcher(opaque, path, handler, recursive), dirwatcher_(INVALID_HANDLE_VALUE), first_(true) | 194 : StdFilesystemWatcher(opaque, path, handler, recursive), dirwatcher_(INVALID_HANDLE_VALUE), first_(true) |
| 226 /* variables */ | 234 /* variables */ |
| 227 HANDLE dirwatcher_; | 235 HANDLE dirwatcher_; |
| 228 bool first_; | 236 bool first_; |
| 229 }; | 237 }; |
| 230 | 238 |
| 239 /* I think "Vista" is actually a misnomer, MSDN says that ReadDirectoryChangesW | |
| 240 * has existed since Windows XP. | |
| 241 * | |
| 242 * Anyway, this is a version that doesn't need to keep the whole directory | |
| 243 * tree in-memory if it is available. */ | |
| 231 class Win32WatcherVista : public Win32Watcher { | 244 class Win32WatcherVista : public Win32Watcher { |
| 232 public: | 245 public: |
| 233 Win32WatcherVista(void *opaque, const std::filesystem::path &path, IWatcher::EventHandler handler, bool recursive) | 246 Win32WatcherVista(void *opaque, const std::filesystem::path &path, IWatcher::EventHandler handler, bool recursive) |
| 234 : Win32Watcher(opaque, path, handler, recursive), dirhandle_(INVALID_HANDLE_VALUE) | 247 : Win32Watcher(opaque, path, handler, recursive), dirhandle_(INVALID_HANDLE_VALUE) |
| 235 { | 248 { |
