winget-cli

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

InstalledFilesCorrelation.h (2332B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <winget/Manifest.h>
      5 #include <winget/FolderFileWatcher.h>
      6 #include <optional>
      7 
      8 namespace AppInstaller::Repository::Correlation
      9 {
     10     // TODO: This definition could be moved to Manifest when winget supports launch scenarios.
     11     struct InstalledStartupLinkFile
     12     {
     13         // Relative file path to the startup menu folder.
     14         // Same installers write the links to user startup folder or machine startup folder depending on the scope
     15         // the installers were running for. So only relative file paths were collected. And seems enough.
     16         AppInstaller::Manifest::string_t RelativeFilePath;
     17         // Heuristic startup link type.
     18         AppInstaller::Manifest::InstalledFileTypeEnum FileType = AppInstaller::Manifest::InstalledFileTypeEnum::Unknown;
     19     };
     20 
     21     struct InstallationMetadata
     22     {
     23         // Installed files metadata. Currently only capturing files pointed by a startup link.
     24         AppInstaller::Manifest::InstallationMetadataInfo InstalledFiles;
     25         // Startup links metadata.
     26         std::vector<InstalledStartupLinkFile> StartupLinkFiles;
     27     };
     28 
     29     struct InstalledFilesCorrelation
     30     {
     31         // Constructor initializes the file watchers.
     32         InstalledFilesCorrelation();
     33         virtual ~InstalledFilesCorrelation() = default;
     34 
     35         // Start the file watcher before the package installation.
     36         virtual void StartFileWatcher();
     37 
     38         // Stop the file watcher after the package installation.
     39         virtual void StopFileWatcher();
     40 
     41         // Correlates the given manifest against the data previously collected with capture calls.
     42         virtual InstallationMetadata CorrelateForNewlyInstalled(
     43             const Manifest::Manifest& manifest,
     44             const std::string& arpInstallLocation);
     45 
     46     private:
     47         struct FileWatcherFiles
     48         {
     49             // FileWatcher folder base.
     50             std::filesystem::path Folder;
     51             // List of files represented as relative file path to the base folder.
     52             std::vector<std::filesystem::path> Files;
     53         };
     54 
     55         std::vector<AppInstaller::Utility::FolderFileWatcher> m_fileWatchers;
     56         std::vector<FileWatcherFiles> m_files;
     57     };
     58 }