master
h 108 lines 3.17 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 Distribution.cpp
8
9 Abstract:
10
11 This file contains definitions for distribution app download, install and launch.
12
13 --*/
14
15 #pragma once
16
17 #include <optional>
18 #include <vector>
19 #include <functional>
20 #include <nlohmann/json.hpp>
21 #include "JsonUtils.h"
22
23 namespace wsl::windows::common::distribution {
24
25 struct DistributionArchive
26 {
27 std::wstring Url;
28 std::wstring Sha256;
29
30 NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(DistributionArchive, Url, Sha256);
31 };
32
33 struct ModernDistributionVersion
34 {
35 std::wstring Name;
36 std::wstring FriendlyName;
37 std::optional<bool> Default;
38 std::optional<DistributionArchive> Amd64Url;
39 std::optional<DistributionArchive> Arm64Url;
40
41 NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(ModernDistributionVersion, Name, FriendlyName, Default, Amd64Url, Arm64Url);
42 };
43
44 struct Distribution
45 {
46 std::wstring Name;
47 std::wstring FriendlyName;
48 std::wstring StoreAppId;
49 bool Amd64;
50 bool Arm64;
51 std::optional<std::wstring> Amd64PackageUrl;
52 std::optional<std::wstring> Arm64PackageUrl;
53 std::optional<std::wstring> PackageFamilyName;
54
55 NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Distribution, Name, FriendlyName, StoreAppId, Amd64, Arm64, Amd64PackageUrl, Arm64PackageUrl, PackageFamilyName);
56 };
57
58 struct DistributionList
59 {
60 std::optional<std::vector<Distribution>> Distributions;
61 std::optional<nlohmann::ordered_map<std::string, std::vector<ModernDistributionVersion>>> ModernDistributions;
62 std::optional<std::wstring> Default;
63
64 friend void from_json(const nlohmann::ordered_json& nlohmann_json_j, DistributionList& nlohmann_json_t)
65 {
66 const DistributionList nlohmann_json_default_obj{};
67 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, Distributions, Default));
68
69 auto modernDistributions = nlohmann_json_j.find("ModernDistributions");
70 if (modernDistributions != nlohmann_json_j.end())
71 {
72 nlohmann_json_t.ModernDistributions.emplace();
73
74 for (const auto& e : modernDistributions->items())
75 {
76 std::vector<ModernDistributionVersion> distros;
77 from_json(e.value(), distros);
78
79 nlohmann_json_t.ModernDistributions->emplace_back(e.key(), std::move(distros));
80 }
81 }
82 }
83 };
84
85 constexpr inline auto c_distroUrlRegistryValue = L"DistributionListUrl";
86 constexpr inline auto c_distroUrlAppendRegistryValue = L"DistributionListUrlAppend";
87 constexpr inline auto fileUrlPrefix = L"file://";
88
89 using TDistribution = std::variant<Distribution, ModernDistributionVersion>;
90
91 struct AvailableDistributions
92 {
93 DistributionList Manifest;
94 std::optional<DistributionList> OverrideManifest;
95 };
96
97 AvailableDistributions GetAvailable();
98 TDistribution LookupByName(const AvailableDistributions& distributions, LPCWSTR name, bool legacy);
99
100 bool IsInstalled(const Distribution& distro, bool directDownload);
101
102 void LegacyInstallViaStore(const Distribution& distro);
103
104 void LegacyInstallViaGithub(const Distribution& distro);
105
106 void Launch(const Distribution& distro, bool directDownload, bool throwOnError);
107
108 } // namespace wsl::windows::common::distribution