winget-cli

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

DownloadCommand.cpp (5926B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #include "pch.h"
      4 #include "DownloadCommand.h"
      5 #include "Workflows/CompletionFlow.h"
      6 #include "Workflows/DownloadFlow.h"
      7 #include "Workflows/InstallFlow.h"
      8 #include "Workflows/PromptFlow.h"
      9 #include "Resources.h"
     10 #include <AppInstallerRuntime.h>
     11 #include <winget/ManifestCommon.h>
     12 
     13 namespace AppInstaller::CLI
     14 {
     15     using namespace AppInstaller::CLI::Execution;
     16     using namespace AppInstaller::CLI::Workflow;
     17     using namespace AppInstaller::Utility::literals;
     18 
     19     std::vector<Argument> DownloadCommand::GetArguments() const
     20     {
     21         return {
     22             Argument::ForType(Args::Type::Query),
     23             Argument::ForType(Args::Type::DownloadDirectory),
     24             Argument::ForType(Args::Type::Manifest),
     25             Argument::ForType(Args::Type::Id),
     26             Argument::ForType(Args::Type::Name),
     27             Argument::ForType(Args::Type::Moniker),
     28             Argument::ForType(Args::Type::Version),
     29             Argument::ForType(Args::Type::Channel),
     30             Argument::ForType(Args::Type::Source),
     31             Argument{ Args::Type::InstallScope, Resource::String::InstallScopeDescription, ArgumentType::Standard, Argument::Visibility::Help },
     32             Argument::ForType(Args::Type::InstallerArchitecture),
     33             Argument::ForType(Args::Type::InstallerType),
     34             Argument::ForType(Args::Type::Exact),
     35             Argument::ForType(Args::Type::Locale),
     36             Argument::ForType(Args::Type::HashOverride),
     37             Argument::ForType(Args::Type::SkipDependencies),
     38             Argument::ForType(Args::Type::CustomHeader),
     39             Argument::ForType(Args::Type::AuthenticationMode),
     40             Argument::ForType(Args::Type::AuthenticationAccount),
     41             Argument::ForType(Args::Type::AcceptPackageAgreements),
     42             Argument::ForType(Args::Type::AcceptSourceAgreements),
     43             Argument::ForType(Args::Type::SkipMicrosoftStorePackageLicense),
     44             Argument::ForType(Args::Type::Platform),
     45             Argument{ Args::Type::OSVersion, Resource::String::OSVersionDescription, ArgumentType::Standard, Argument::Visibility::Help },
     46         };
     47     }
     48 
     49     Resource::LocString DownloadCommand::ShortDescription() const
     50     {
     51         return { Resource::String::DownloadCommandShortDescription };
     52     }
     53 
     54     Resource::LocString DownloadCommand::LongDescription() const
     55     {
     56         return { Resource::String::DownloadCommandLongDescription };
     57     }
     58 
     59     void DownloadCommand::Complete(Context& context, Args::Type valueType) const
     60     {
     61         switch (valueType)
     62         {
     63         case Args::Type::Query:
     64         case Args::Type::Manifest:
     65         case Args::Type::Id:
     66         case Args::Type::Name:
     67         case Args::Type::Moniker:
     68         case Args::Type::Version:
     69         case Args::Type::Channel:
     70         case Args::Type::Source:
     71             context <<
     72                 Workflow::CompleteWithSingleSemanticsForValue(valueType);
     73             break;
     74         case Args::Type::InstallerArchitecture:
     75         case Args::Type::Locale:
     76             // May well move to CompleteWithSingleSemanticsForValue,
     77             // but for now output nothing.
     78             context <<
     79                 Workflow::CompleteWithEmptySet;
     80             break;
     81         case Args::Type::Log:
     82         case Args::Type::DownloadDirectory:
     83             // Intentionally output nothing to allow pass through to filesystem.
     84             break;
     85         }
     86     }
     87 
     88     Utility::LocIndView DownloadCommand::HelpLink() const
     89     {
     90         return "https://aka.ms/winget-command-download"_liv;
     91     }
     92 
     93     void DownloadCommand::ValidateArgumentsInternal(Args& execArgs) const
     94     {
     95         Argument::ValidateCommonArguments(execArgs);
     96 
     97         if (execArgs.Contains(Execution::Args::Type::Platform))
     98         {
     99             Manifest::PlatformEnum selectedPlatform = Manifest::ConvertToPlatformEnumForMSStoreDownload(execArgs.GetArg(Execution::Args::Type::Platform));
    100             if (selectedPlatform == Manifest::PlatformEnum::Unknown)
    101             {
    102                 auto validOptions = Utility::Join(", "_liv, std::vector<Utility::LocIndString>{
    103                     "Windows.Universal"_lis, "Windows.Desktop"_lis, "Windows.IoT"_lis, "Windows.Team"_lis, "Windows.Holographic"_lis
    104                 });
    105                 throw CommandException(Resource::String::InvalidArgumentValueError(Argument::ForType(Execution::Args::Type::Platform).Name(), validOptions));
    106             }
    107         }
    108     }
    109 
    110     void DownloadCommand::ExecuteInternal(Context& context) const
    111     {
    112         context.SetFlags(AppInstaller::CLI::Execution::ContextFlag::InstallerDownloadOnly);
    113 
    114         context << Workflow::InitializeInstallerDownloadAuthenticatorsMap;
    115 
    116         if (context.Args.Contains(Execution::Args::Type::Manifest))
    117         {
    118             context <<
    119                 Workflow::ReportExecutionStage(ExecutionStage::Discovery) <<
    120                 Workflow::GetManifestFromArg;
    121         }
    122         else
    123         {
    124             context <<
    125                 Workflow::ReportExecutionStage(ExecutionStage::Discovery) <<
    126                 Workflow::OpenSource() <<
    127                 Workflow::SearchSourceForSingle <<
    128                 Workflow::HandleSearchResultFailures <<
    129                 Workflow::EnsureOneMatchFromSearchResult(OperationType::Download) <<
    130                 Workflow::GetManifestFromPackage(false);
    131         }
    132 
    133         context <<
    134             Workflow::SetDownloadDirectory <<
    135             Workflow::SelectInstaller <<
    136             Workflow::EnsureApplicableInstaller <<
    137             Workflow::ReportIdentityAndInstallationDisclaimer <<
    138             Workflow::ShowPromptsForSinglePackage(/* ensureAcceptance */ true) <<
    139             Workflow::DownloadPackageDependencies <<
    140             Workflow::DownloadInstaller;
    141     }
    142 }