|
4 | 4 | #include "DscPackageResource.h" |
5 | 5 | #include "DscComposableObject.h" |
6 | 6 | #include "Resources.h" |
| 7 | +#include "Workflows/WorkflowBase.h" |
7 | 8 |
|
8 | 9 | using namespace AppInstaller::Utility::literals; |
9 | 10 |
|
10 | 11 | namespace AppInstaller::CLI |
11 | 12 | { |
12 | 13 | namespace |
13 | 14 | { |
14 | | - WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_FLAGS(IdProperty, std::string, Identifier, "id", DscComposablePropertyFlag::Required | DscComposablePropertyFlag::CopyToOutput, "The identifier of the package."); |
15 | | - WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_FLAGS(SourceProperty, std::string, Source, "source", DscComposablePropertyFlag::CopyToOutput, "The source of the package."); |
16 | | - WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY(VersionProperty, std::string, Version, "version", "The version of the package."); |
17 | | - WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(MatchOptionProperty, std::string, MatchOption, "matchOption", "The method for matching the identifier with a package.", ({ "equals", "equalsCaseInsensitive", "startsWithCaseInsensitive", "containsCaseInsensitive" }), "equalsCaseInsensitive"); |
18 | | - WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_DEFAULT(UseLatestProperty, bool, UseLatest, "useLatest", "Indicate that the latest available version of the package should be installed.", "false"); |
19 | | - WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(InstallModeProperty, std::string, InstallMode, "installMode", "The install mode to use if needed.", ({ "default", "silent", "interactive" }), "silent"); |
| 15 | + WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_FLAGS(IdProperty, std::string, Identifier, "id", DscComposablePropertyFlag::Required | DscComposablePropertyFlag::CopyToOutput, Resource::String::DscResourcePropertyDescriptionPackageId); |
| 16 | + WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_FLAGS(SourceProperty, std::string, Source, "source", DscComposablePropertyFlag::CopyToOutput, Resource::String::DscResourcePropertyDescriptionPackageSource); |
| 17 | + WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY(VersionProperty, std::string, Version, "version", Resource::String::DscResourcePropertyDescriptionPackageVersion); |
| 18 | + WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(MatchOptionProperty, std::string, MatchOption, "matchOption", Resource::String::DscResourcePropertyDescriptionPackageMatchOption, ({ "equals", "equalsCaseInsensitive", "startsWithCaseInsensitive", "containsCaseInsensitive" }), "equalsCaseInsensitive"); |
| 19 | + WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_DEFAULT(UseLatestProperty, bool, UseLatest, "useLatest", Resource::String::DscResourcePropertyDescriptionPackageUseLatest, "false"); |
| 20 | + WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY_ENUM(InstallModeProperty, std::string, InstallMode, "installMode", Resource::String::DscResourcePropertyDescriptionPackageInstallMode, ({ "default", "silent", "interactive" }), "silent"); |
20 | 21 |
|
21 | 22 | using PackageResourceObject = DscComposableObject<StandardExistProperty, StandardInDesiredStateProperty, IdProperty, SourceProperty, VersionProperty, MatchOptionProperty, UseLatestProperty, InstallModeProperty>; |
22 | 23 |
|
23 | 24 | struct PackageFunctionData |
24 | 25 | { |
25 | | - PackageFunctionData(const std::optional<Json::Value>& json) : Input(json), Output(Input.CopyForOutput()) |
| 26 | + PackageFunctionData(Execution::Context& context, const std::optional<Json::Value>& json) : |
| 27 | + Input(json), |
| 28 | + Output(Input.CopyForOutput()), |
| 29 | + ParentContext(context), |
| 30 | + SubContext(context.CreateSubContext()) |
26 | 31 | { |
| 32 | + SubContext->SetFlags(Execution::ContextFlag::DisableInteractivity); |
27 | 33 | } |
28 | 34 |
|
29 | 35 | PackageResourceObject Input; |
30 | 36 | PackageResourceObject Output; |
| 37 | + Execution::Context& ParentContext; |
| 38 | + std::unique_ptr<Execution::Context> SubContext; |
31 | 39 |
|
32 | 40 | // Fills the Output object with the current state |
33 | 41 | void Get() |
34 | 42 | { |
35 | | - THROW_HR(E_NOTIMPL); |
| 43 | + if (Input.Source()) |
| 44 | + { |
| 45 | + SubContext->Args.AddArg(Execution::Args::Type::Source, Input.Source().value()); |
| 46 | + } |
| 47 | + |
| 48 | + *SubContext << |
| 49 | + Workflow::OpenSource() << |
| 50 | + Workflow::OpenCompositeSource(Workflow::DetermineInstalledSource(*SubContext)); |
| 51 | + |
| 52 | + if (SubContext->IsTerminated()) |
| 53 | + { |
| 54 | + ParentContext.Terminate(SubContext->GetTerminationHR()); |
| 55 | + } |
36 | 56 | } |
37 | 57 |
|
38 | 58 | // Determines if the current Output values match the Input values state. |
|
0 commit comments