PackageTrackingCatalog.h (3026B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <AppInstallerStrings.h> 5 #include <winget/Manifest.h> 6 7 #include <memory> 8 9 #ifndef AICLI_DISABLE_TEST_HOOKS 10 #include <filesystem> 11 #endif 12 13 namespace AppInstaller::Repository 14 { 15 struct Source; 16 struct SearchRequest; 17 struct SearchResult; 18 enum class PackageVersionMetadata; 19 20 // A catalog for tracking package actions from a given source. 21 struct PackageTrackingCatalog 22 { 23 friend Source; 24 25 PackageTrackingCatalog(); 26 PackageTrackingCatalog(const PackageTrackingCatalog&); 27 PackageTrackingCatalog& operator=(const PackageTrackingCatalog&); 28 PackageTrackingCatalog(PackageTrackingCatalog&&) noexcept; 29 PackageTrackingCatalog& operator=(PackageTrackingCatalog&&) noexcept; 30 ~PackageTrackingCatalog(); 31 32 // Removes the package tracking catalog for a given source identifier. 33 static void RemoveForSource(const std::string& identifier); 34 35 // Determines if the current object holds anything. 36 operator bool() const; 37 38 // Execute a search against the catalog. 39 // Note that the packages in the results have the versions under "available" in order to 40 // expose all versions contained therein (in the event that this is deemed useful at some point). 41 SearchResult Search(const SearchRequest& request) const; 42 43 // Enables more granular control over the metadata in the tracking catalog if necessary. 44 struct Version 45 { 46 friend PackageTrackingCatalog; 47 48 Version(const Version&); 49 Version& operator=(const Version&); 50 Version(Version&&) noexcept; 51 Version& operator=(Version&&) noexcept; 52 ~Version(); 53 54 // Set the given metadata value. 55 void SetMetadata(PackageVersionMetadata metadata, const Utility::NormalizedString& value); 56 57 private: 58 struct implementation; 59 Version(PackageTrackingCatalog& catalog, std::shared_ptr<implementation>&& value); 60 std::shared_ptr<implementation> m_implementation; 61 PackageTrackingCatalog* m_catalog; 62 }; 63 64 // Records an installation of the given package. 65 Version RecordInstall(Manifest::Manifest& manifest, const Manifest::ManifestInstaller& installer, bool isUpgrade); 66 67 // Records an uninstall of the given package. 68 void RecordUninstall(const Utility::LocIndString& packageIdentifier); 69 70 #ifndef AICLI_DISABLE_TEST_HOOKS 71 // Gets the path to the database file. 72 std::filesystem::path GetFilePath() const; 73 #endif 74 75 protected: 76 // Creates or opens the tracking catalog for the given source. 77 static PackageTrackingCatalog CreateForSource(const Source& source); 78 79 private: 80 struct implementation; 81 std::shared_ptr<implementation> m_implementation; 82 }; 83 }