PackageCollection.h (2843B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "AppInstallerDateTime.h" 5 #include "winget/RepositorySource.h" 6 #include <winget/Manifest.h> 7 8 #include <json/json.h> 9 10 #include <vector> 11 12 namespace AppInstaller::CLI 13 { 14 // Container for data to identify multiple packages to be installed from multiple sources. 15 struct PackageCollection 16 { 17 // Description of a package. 18 // Does not represent the actual package, just enough to find and install it. 19 struct Package 20 { 21 Package() = default; 22 Package(Utility::LocIndString&& id) : 23 Id(std::move(id)) {} 24 Package(Utility::LocIndString&& id, Utility::Version&& version, Utility::Channel&& channel) : 25 Id(std::move(id)), VersionAndChannel(std::move(version), std::move(channel)) {} 26 Package(Utility::LocIndString&& id, Utility::VersionAndChannel&& versionAndChannel) : 27 Id(std::move(id)), VersionAndChannel(std::move(versionAndChannel)) {} 28 29 Utility::LocIndString Id; 30 Utility::VersionAndChannel VersionAndChannel; 31 Manifest::ScopeEnum Scope = Manifest::ScopeEnum::Unknown; 32 std::filesystem::path InstalledLocation; 33 }; 34 35 // A source along with a set of packages available from it. 36 struct Source 37 { 38 Source() = default; 39 Source(const Repository::SourceDetails& sourceDetails) : Details(sourceDetails) {} 40 Source(Repository::SourceDetails&& sourceDetails) : Details(std::move(sourceDetails)) {} 41 42 Repository::SourceDetails Details; 43 std::vector<Package> Packages; 44 }; 45 46 // Version of the WinGet client that produced this collection. 47 std::string ClientVersion; 48 49 // Requests from each individual source. 50 std::vector<Source> Sources; 51 }; 52 53 namespace PackagesJson 54 { 55 struct ParseResult 56 { 57 enum class Type 58 { 59 MissingSchema, 60 UnrecognizedSchema, 61 SchemaValidationFailed, 62 Success, 63 }; 64 65 ParseResult(Type result) : Result(result) {} 66 ParseResult(Type result, std::string_view errors) : Result(result), Errors(errors) {} 67 ParseResult(PackageCollection&& packages) : Result(Type::Success), Packages(std::move(packages)) {} 68 69 Type Result; 70 PackageCollection Packages; 71 std::string Errors; 72 }; 73 74 // Converts a collection of packages to its JSON representation for exporting. 75 Json::Value CreateJson(const PackageCollection& packages); 76 77 // Tries to parse a JSON into a collection of packages. 78 ParseResult TryParseJson(const Json::Value& root); 79 } 80 }