winget-cli

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

ManifestCommon.h (14461B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <AppInstallerStrings.h>
      5 #include <AppInstallerVersions.h>
      6 #include <functional>
      7 #include <map>
      8 #include <set>
      9 #include <string_view>
     10 
     11 namespace AppInstaller::Manifest
     12 {
     13     // Forward declaration
     14     struct ManifestInstaller;
     15 
     16     using string_t = Utility::NormalizedString;
     17     using namespace std::string_view_literals;
     18     using Utility::RawVersion;
     19 
     20     // The maximum supported major version known about by this code.
     21     constexpr uint64_t s_MaxSupportedMajorVersion = 1;
     22 
     23     // The default manifest version assigned to manifests without a ManifestVersion field.
     24     constexpr std::string_view s_DefaultManifestVersion = "0.1.0"sv;
     25 
     26     // V1 manifest version for GA
     27     constexpr std::string_view s_ManifestVersionV1 = "1.0.0"sv;
     28 
     29     // V1.1 manifest version
     30     constexpr std::string_view s_ManifestVersionV1_1 = "1.1.0"sv;
     31 
     32     // V1.2 manifest version
     33     constexpr std::string_view s_ManifestVersionV1_2 = "1.2.0"sv;
     34 
     35     // V1.4 manifest version
     36     constexpr std::string_view s_ManifestVersionV1_4 = "1.4.0"sv;
     37 
     38     // V1.5 manifest version
     39     constexpr std::string_view s_ManifestVersionV1_5 = "1.5.0"sv;
     40 
     41     // V1.6 manifest version
     42     constexpr std::string_view s_ManifestVersionV1_6 = "1.6.0"sv;
     43 
     44     // V1.7 manifest version
     45     constexpr std::string_view s_ManifestVersionV1_7 = "1.7.0"sv;
     46 
     47     // V1.9 manifest version
     48     constexpr std::string_view s_ManifestVersionV1_9 = "1.9.0"sv;
     49 
     50     // V1.10 manifest version
     51     constexpr std::string_view s_ManifestVersionV1_10 = "1.10.0"sv;
     52 
     53     // V1.12 manifest version
     54     constexpr std::string_view s_ManifestVersionV1_12 = "1.12.0"sv;
     55 
     56     // The manifest extension for the MS Store
     57     constexpr std::string_view s_MSStoreExtension = "msstore"sv;
     58 
     59     struct ManifestValidateOption
     60     {
     61         bool SchemaValidationOnly = false;
     62         bool ErrorOnVerifiedPublisherFields = false;
     63         bool InstallerValidation = false;
     64 
     65         // Options not exposed in winget util
     66         bool FullValidation = false;
     67         bool ThrowOnWarning = false;
     68         bool AllowShadowManifest = false;
     69         bool SchemaHeaderValidationAsWarning = false;
     70     };
     71 
     72     // ManifestVer is inherited from Utility::Version and is a more restricted version.
     73     // ManifestVer is used to specify the version of app manifest itself.
     74     // ManifestVer is a 3 part version in the format of [0-65535].[0-65535].[0-65535]
     75     // and optionally a following tag in the format of -[SomeString] for experimental purpose.
     76     struct ManifestVer : public Utility::Version
     77     {
     78         ManifestVer() = default;
     79 
     80         ManifestVer(std::string_view version);
     81 
     82         uint64_t Major() const { return m_parts.size() > 0 ? m_parts[0].Integer : 0; }
     83         uint64_t Minor() const { return m_parts.size() > 1 ? m_parts[1].Integer : 0; }
     84         uint64_t Patch() const { return m_parts.size() > 2 ? m_parts[2].Integer : 0; }
     85 
     86         bool HasExtension() const;
     87 
     88         bool HasExtension(std::string_view extension) const;
     89 
     90     private:
     91         std::vector<RawVersion> m_extensions;
     92     };
     93 
     94     enum class InstallerTypeEnum
     95     {
     96         Unknown,
     97         Inno,
     98         Wix,
     99         Msi,
    100         Nullsoft,
    101         Zip,
    102         Msix,
    103         Exe,
    104         Burn,
    105         MSStore,
    106         Portable,
    107         Font,
    108     };
    109 
    110     enum class UpdateBehaviorEnum
    111     {
    112         Unknown,
    113         Install,
    114         UninstallPrevious,
    115         Deny,
    116     };
    117 
    118     enum class InstallerSwitchType
    119     {
    120         Custom,
    121         Silent,
    122         SilentWithProgress,
    123         Interactive,
    124         Language,
    125         Log,
    126         InstallLocation,
    127         Update,
    128         Repair,
    129     };
    130 
    131     enum class RepairBehaviorEnum
    132     {
    133         Unknown,
    134         Modify,
    135         Installer,
    136         Uninstaller,
    137     };
    138 
    139     enum class ScopeEnum
    140     {
    141         Unknown,
    142         User,
    143         Machine,
    144     };
    145 
    146     enum class InstallModeEnum
    147     {
    148         Unknown,
    149         Interactive,
    150         Silent,
    151         SilentWithProgress,
    152     };
    153 
    154     enum class ExpectedReturnCodeEnum
    155     {
    156         Unknown,
    157         PackageInUse,
    158         PackageInUseByApplication,
    159         InstallInProgress,
    160         FileInUse,
    161         MissingDependency,
    162         DiskFull,
    163         InsufficientMemory,
    164         InvalidParameter,
    165         NoNetwork,
    166         ContactSupport,
    167         RebootRequiredToFinish,
    168         RebootRequiredForInstall,
    169         RebootInitiated,
    170         CancelledByUser,
    171         AlreadyInstalled,
    172         Downgrade,
    173         BlockedByPolicy,
    174         SystemNotSupported,
    175         Custom,
    176     };
    177 
    178     enum class PlatformEnum
    179     {
    180         Unknown,
    181         Universal,
    182         Desktop,
    183         IoT,
    184         Team,
    185         Holographic,
    186     };
    187 
    188     enum class ElevationRequirementEnum
    189     {
    190         Unknown,
    191         ElevationRequired,
    192         ElevationProhibited,
    193         ElevatesSelf,
    194     };
    195 
    196     enum class UnsupportedArgumentEnum
    197     {
    198         Unknown,
    199         Log,
    200         Location
    201     };
    202 
    203     enum class InstalledFileTypeEnum
    204     {
    205         Unknown,
    206         Launch,
    207         Uninstall,
    208         Other,
    209     };
    210 
    211     enum class ManifestTypeEnum
    212     {
    213         Singleton,
    214         Version,
    215         Installer,
    216         DefaultLocale,
    217         Locale,
    218         Merged,
    219         Preview,
    220         Shadow,
    221     };
    222 
    223     enum class DependencyType
    224     {
    225         WindowsFeature,
    226         WindowsLibrary,
    227         Package,
    228         External
    229     };
    230 
    231     enum class IconFileTypeEnum
    232     {
    233         Unknown,
    234         Jpeg,
    235         Png,
    236         Ico,
    237     };
    238 
    239     enum class IconThemeEnum
    240     {
    241         Unknown,
    242         Default,
    243         Light,
    244         Dark,
    245         HighContrast,
    246     };
    247 
    248     // Icon resolutions from https://learn.microsoft.com/en-us/windows/apps/design/style/iconography/app-icon-construction#app-icon
    249     enum class IconResolutionEnum
    250     {
    251         Unknown,
    252         Custom,
    253         Square16,
    254         Square20,
    255         Square24,
    256         Square30,
    257         Square32,
    258         Square36,
    259         Square40,
    260         Square48,
    261         Square60,
    262         Square64,
    263         Square72,
    264         Square80,
    265         Square96,
    266         Square256,
    267     };
    268 
    269     struct ExpectedReturnCode
    270     {
    271         DWORD InstallerReturnCode = 0;
    272         ExpectedReturnCodeEnum ReturnResponse = ExpectedReturnCodeEnum::Unknown;
    273         string_t ReturnResponseUrl;
    274     };
    275 
    276     struct Dependency
    277     {
    278         DependencyType Type;
    279         const string_t& Id() const { return m_id; };
    280         std::optional<Utility::Version> MinVersion;
    281 
    282         Dependency(DependencyType type, string_t id, string_t minVersion) : Type(type), m_id(std::move(id)), MinVersion(Utility::Version(std::move(minVersion))), m_foldedId(FoldCase(m_id)) {}
    283         Dependency(DependencyType type, string_t id) : Type(type), m_id(std::move(id)), m_foldedId(FoldCase(m_id)){}
    284         Dependency(DependencyType type) : Type(type) {}
    285 
    286         bool operator ==(const Dependency& rhs) const
    287         {
    288             return Type == rhs.Type && m_foldedId == rhs.m_foldedId && MinVersion == rhs.MinVersion;
    289         }
    290 
    291         bool operator <(const Dependency& rhs) const
    292         {
    293             return m_foldedId < rhs.m_foldedId;
    294         }
    295 
    296         bool IsVersionOk(const Utility::Version& version)
    297         {
    298             return MinVersion <= version;
    299         }
    300 
    301         // m_foldedId should be set whenever Id is set
    302         void SetId(string_t id)
    303         {
    304             m_id = std::move(id);
    305             m_foldedId = FoldCase(m_id);
    306         }
    307 
    308     private:
    309         string_t m_id;
    310         std::string m_foldedId;
    311     };
    312 
    313     struct DependencyList
    314     {
    315         void Add(const Dependency& newDependency);
    316         void Add(const DependencyList& otherDependencyList);
    317         bool HasAny() const;
    318         bool HasAnyOf(DependencyType type) const;
    319         Dependency* HasDependency(const Dependency& dependencyToSearch);
    320         void ApplyToType(DependencyType type, std::function<void(const Dependency&)> func) const;
    321         void ApplyToAll(std::function<void(const Dependency&)> func) const;
    322         bool Empty() const;
    323         void Clear();
    324         bool HasExactDependency(DependencyType type, const string_t& id, const string_t& minVersion = "");
    325         size_t Size();
    326 
    327     private:
    328         std::vector<Dependency> m_dependencies;
    329     };
    330 
    331     struct AppsAndFeaturesEntry
    332     {
    333         string_t DisplayName;
    334         string_t Publisher;
    335         string_t DisplayVersion;
    336         string_t ProductCode;
    337         string_t UpgradeCode;
    338         InstallerTypeEnum InstallerType = InstallerTypeEnum::Unknown;
    339     };
    340 
    341     struct MarketsInfo
    342     {
    343         std::vector<string_t> AllowedMarkets;
    344         std::vector<string_t> ExcludedMarkets;
    345     };
    346 
    347     struct NestedInstallerFile
    348     {
    349         string_t RelativeFilePath;
    350         string_t PortableCommandAlias;
    351     };
    352 
    353     struct InstalledFile
    354     {
    355         string_t RelativeFilePath;
    356         std::vector<BYTE> FileSha256;
    357         InstalledFileTypeEnum FileType = InstalledFileTypeEnum::Other;
    358         string_t InvocationParameter;
    359         string_t DisplayName;
    360     };
    361 
    362     struct InstallationMetadataInfo
    363     {
    364         string_t DefaultInstallLocation;
    365         std::vector<InstalledFile> Files;
    366 
    367         // Checks if there are any installation metadata available.
    368         bool HasData() const { return !DefaultInstallLocation.empty() || !Files.empty(); }
    369 
    370         void Clear() { DefaultInstallLocation.clear(); Files.clear(); }
    371     };
    372 
    373     InstallerTypeEnum ConvertToInstallerTypeEnum(const std::string& in);
    374 
    375     UpdateBehaviorEnum ConvertToUpdateBehaviorEnum(const std::string& in);
    376 
    377     ScopeEnum ConvertToScopeEnum(std::string_view in);
    378 
    379     InstallModeEnum ConvertToInstallModeEnum(const std::string& in);
    380 
    381     PlatformEnum ConvertToPlatformEnum(std::string_view in);
    382 
    383     PlatformEnum ConvertToPlatformEnumForMSStoreDownload(std::string_view in);
    384 
    385     ElevationRequirementEnum ConvertToElevationRequirementEnum(const std::string& in);
    386 
    387     UnsupportedArgumentEnum ConvertToUnsupportedArgumentEnum(const std::string& in);
    388 
    389     ManifestTypeEnum ConvertToManifestTypeEnum(const std::string& in);
    390 
    391     ExpectedReturnCodeEnum ConvertToExpectedReturnCodeEnum(const std::string& in);
    392 
    393     InstalledFileTypeEnum ConvertToInstalledFileTypeEnum(const std::string& in);
    394 
    395     IconFileTypeEnum ConvertToIconFileTypeEnum(std::string_view in);
    396 
    397     IconThemeEnum ConvertToIconThemeEnum(std::string_view in);
    398 
    399     IconResolutionEnum ConvertToIconResolutionEnum(std::string_view in);
    400 
    401     RepairBehaviorEnum ConvertToRepairBehaviorEnum(std::string_view in);
    402 
    403     std::string_view InstallerTypeToString(InstallerTypeEnum installerType);
    404 
    405     std::string_view InstallerSwitchTypeToString(InstallerSwitchType installerSwitchType);
    406 
    407     std::string_view ElevationRequirementToString(ElevationRequirementEnum elevationRequirement);
    408 
    409     std::string_view InstallModeToString(InstallModeEnum installMode);
    410 
    411     std::string_view UnsupportedArgumentToString(UnsupportedArgumentEnum unsupportedArgument);
    412 
    413     std::string_view UpdateBehaviorToString(UpdateBehaviorEnum updateBehavior);
    414 
    415     std::string_view RepairBehaviorToString(RepairBehaviorEnum repairBehavior);
    416 
    417     // Short string representation does not contain "Windows."
    418     std::string_view PlatformToString(PlatformEnum platform, bool shortString = false);
    419 
    420     std::string_view ScopeToString(ScopeEnum scope);
    421 
    422     std::string_view InstalledFileTypeToString(InstalledFileTypeEnum installedFileType);
    423 
    424     std::string_view IconFileTypeToString(IconFileTypeEnum iconFileType);
    425 
    426     std::string_view IconThemeToString(IconThemeEnum iconTheme);
    427 
    428     std::string_view IconResolutionToString(IconResolutionEnum iconResolution);
    429 
    430     std::string_view ManifestTypeToString(ManifestTypeEnum manifestType);
    431 
    432     std::string_view ExpectedReturnCodeToString(ExpectedReturnCodeEnum expectedReturnCode);
    433 
    434     // Gets a value indicating whether the given installer uses the PackageFamilyName system reference.
    435     bool DoesInstallerTypeUsePackageFamilyName(InstallerTypeEnum installerType);
    436 
    437     // Gets a value indicating whether the given installer uses the ProductCode system reference.
    438     bool DoesInstallerTypeUseProductCode(InstallerTypeEnum installerType);
    439 
    440     // Gets a value indicating whether the given installer writes ARP entry.
    441     bool DoesInstallerTypeWriteAppsAndFeaturesEntry(InstallerTypeEnum installerType);
    442 
    443     // Gets a value indicating whether the given installer type supports ARP version range.
    444     bool DoesInstallerTypeSupportArpVersionRange(InstallerTypeEnum installer);
    445 
    446     // Gets a value indicating whether the given installer ignores the Scope value from the manifest.
    447     bool DoesInstallerTypeIgnoreScopeFromManifest(InstallerTypeEnum installerType);
    448 
    449     // Gets a value indicating whether the given installer requires admin for install.
    450     bool DoesInstallerTypeRequireAdminForMachineScopeInstall(InstallerTypeEnum installerType);
    451 
    452     // Gets a value indicating whether the given installer requires RepairBehavior for repair.
    453     bool DoesInstallerTypeRequireRepairBehaviorForRepair(InstallerTypeEnum installerType);
    454 
    455     // Gets a value indicating whether the given installer type is an archive.
    456     bool IsArchiveType(InstallerTypeEnum installerType);
    457 
    458     // Gets a value indicating whether the given installer type is a portable.
    459     bool IsPortableType(InstallerTypeEnum installerType);
    460 
    461     // Gets a value indicating whether the given nested installer type is supported.
    462     bool IsNestedInstallerTypeSupported(InstallerTypeEnum nestedInstallerType);
    463 
    464     // Checks whether 2 installer types are compatible. E.g. inno and exe are update compatible
    465     bool IsInstallerTypeCompatible(InstallerTypeEnum type1, InstallerTypeEnum type2);
    466 
    467     // Get a list of default switches for known installer types
    468     std::map<InstallerSwitchType, Utility::NormalizedString> GetDefaultKnownSwitches(InstallerTypeEnum installerType);
    469 
    470     // Get a list of default return codes for known installer types
    471     std::map<DWORD, ExpectedReturnCodeEnum> GetDefaultKnownReturnCodes(InstallerTypeEnum installerType);
    472 }