winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

FolderFileWatcher.h (1260B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <unordered_set>
      5 #pragma warning( push )
      6 #pragma warning ( disable : 6387 28196 )
      7 #include <wil/filesystem.h>
      8 #pragma warning( pop )
      9 
     10 namespace AppInstaller::Utility
     11 {
     12     // Watch for new/renamed files recursively in a given directory with an optional extension.
     13     struct FolderFileWatcher
     14     {
     15         FolderFileWatcher(const std::filesystem::path& path, const std::optional<std::string>& ext = std::nullopt);
     16         ~FolderFileWatcher() {};
     17 
     18         FolderFileWatcher(const FolderFileWatcher&) = delete;
     19         FolderFileWatcher& operator=(const FolderFileWatcher&) = delete;
     20 
     21         FolderFileWatcher(FolderFileWatcher&&) = default;
     22         FolderFileWatcher& operator=(FolderFileWatcher&&) = default;
     23 
     24         void Start();
     25         void Stop();
     26 
     27         const std::unordered_set<std::filesystem::path>& Files() { return m_files; }
     28         const std::filesystem::path& FolderPath() { return m_path; }
     29 
     30     private:
     31         std::filesystem::path m_path;
     32         std::optional<std::string> m_ext;
     33         std::unordered_set<std::filesystem::path> m_files;
     34         wil::unique_folder_change_reader m_changeReader;
     35     };
     36 }