winget-cli

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

PortableIndex.h (2237B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <winget/SQLiteWrapper.h>
      5 #include <winget/SQLiteStorageBase.h>
      6 #include <winget/PortableFileEntry.h>
      7 #include <winget/ManagedFile.h>
      8 
      9 using namespace AppInstaller::Portable;
     10 
     11 namespace AppInstaller::Repository::Microsoft
     12 {
     13     namespace Schema
     14     {
     15         struct IPortableIndex;
     16     }
     17 
     18     struct PortableIndex : SQLite::SQLiteStorageBase
     19     {
     20         // An id that refers to a specific portable file.
     21         using IdType = SQLite::rowid_t;
     22 
     23         PortableIndex(const PortableIndex&) = delete;
     24         PortableIndex& operator=(const PortableIndex&) = delete;
     25 
     26         PortableIndex(PortableIndex&&);
     27         PortableIndex& operator=(PortableIndex&&);
     28 
     29         ~PortableIndex();
     30 
     31         // Creates a new PortableIndex database of the given version.
     32         static PortableIndex CreateNew(const std::string& filePath, SQLite::Version version = SQLite::Version::Latest());
     33 
     34         // Opens an existing PortableIndex database.
     35         static PortableIndex Open(const std::string& filePath, OpenDisposition disposition, Utility::ManagedFile&& indexFile = {});
     36 
     37         IdType AddPortableFile(const Portable::PortableFileEntry& file);
     38 
     39         void RemovePortableFile(const Portable::PortableFileEntry& file);
     40 
     41         bool UpdatePortableFile(const Portable::PortableFileEntry& file);
     42 
     43         void AddOrUpdatePortableFile(const Portable::PortableFileEntry& file);
     44 
     45         std::vector<Portable::PortableFileEntry> GetAllPortableFiles();
     46 
     47         bool Exists(const Portable::PortableFileEntry& file);
     48 
     49         bool IsEmpty();
     50 
     51     private:
     52         // Constructor used to open an existing index.
     53         PortableIndex(const std::string& target, SQLiteStorageBase::OpenDisposition disposition, Utility::ManagedFile&& indexFile);
     54 
     55         // Constructor used to create a new index.
     56         PortableIndex(const std::string& target, SQLite::Version version);
     57 
     58         // Creates the IPortableIndex interface object for this version.
     59         std::unique_ptr<Schema::IPortableIndex> CreateIPortableIndex() const;
     60 
     61         std::unique_ptr<Schema::IPortableIndex> m_interface;
     62     };
     63 }