winget-cli

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

SQLiteIndexSourceV2.h (2740B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include "Microsoft/SQLiteIndexSource.h"
      5 #include <winget/PackageVersionDataManifest.h>
      6 
      7 
      8 namespace AppInstaller::Repository::Microsoft::details::V2
      9 {
     10     // The IPackage implementation for V2 index.
     11     struct SQLitePackage : public std::enable_shared_from_this<SQLitePackage>, public SourceReference, public IPackage, public ICompositePackage
     12     {
     13         static constexpr IPackageType PackageType = IPackageType::SQLitePackage2;
     14 
     15         SQLitePackage(
     16             const std::shared_ptr<SQLiteIndexSource>& source,
     17             SQLiteIndex::IdType packageRowId,
     18             const std::shared_ptr<Caching::FileCache>& manifestCache,
     19             const std::shared_ptr<Caching::FileCache>& packageVersionDataCache,
     20             bool isInstalled);
     21 
     22         // Inherited via IPackage
     23         Utility::LocIndString GetProperty(PackageProperty property) const;
     24 
     25         std::vector<Utility::LocIndString> GetMultiProperty(PackageMultiProperty property) const override;
     26 
     27         std::vector<PackageVersionKey> GetVersionKeys() const override;
     28 
     29         std::shared_ptr<IPackageVersion> GetLatestVersion() const override;
     30 
     31         std::shared_ptr<IPackageVersion> GetVersion(const PackageVersionKey& versionKey) const override;
     32 
     33         Source GetSource() const override;
     34 
     35         bool IsSame(const IPackage* other) const override;
     36 
     37         const void* CastTo(IPackageType type) const override;
     38 
     39         // Inherited via ICompositePackage
     40         std::shared_ptr<IPackage> GetInstalled() override;
     41 
     42         std::vector<std::shared_ptr<IPackage>> GetAvailable() override;
     43 
     44     private:
     45         // Contains the information needed to map a version key to it's rows.
     46         struct MapKey
     47         {
     48             Utility::Version Version;
     49             Utility::NormalizedString Channel;
     50 
     51             bool operator<(const MapKey& other) const;
     52         };
     53 
     54         // Ensures that we have the package version data present.
     55         void EnsurePackageVersionData(const std::shared_ptr<SQLiteIndexSource>& source) const;
     56 
     57         SQLiteIndex::IdType m_packageRowId;
     58         std::shared_ptr<Caching::FileCache> m_manifestCache;
     59         std::shared_ptr<Caching::FileCache> m_packageVersionDataCache;
     60         bool m_isInstalled;
     61 
     62         // To avoid removing const from the interface
     63         mutable wil::srwlock m_versionKeysLock;
     64         mutable std::vector<PackageVersionKey> m_versionKeys;
     65         mutable std::map<MapKey, Manifest::PackageVersionDataManifest::VersionData> m_versionKeysMap;
     66         mutable std::optional<Manifest::PackageVersionDataManifest::VersionData> m_latestVersionData;
     67     };
     68 }