diff --git a/src/AppInstallerCLICore/Argument.cpp b/src/AppInstallerCLICore/Argument.cpp index b2bde9919c..2f47eb1013 100644 --- a/src/AppInstallerCLICore/Argument.cpp +++ b/src/AppInstallerCLICore/Argument.cpp @@ -151,6 +151,10 @@ namespace AppInstaller::CLI return { type, "enable"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::EnableDisable }; case Execution::Args::Type::AdminSettingDisable: return { type, "disable"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::EnableDisable }; + case Execution::Args::Type::SettingName: + return { type, "setting"_liv }; + case Execution::Args::Type::SettingValue: + return { type, "value"_liv }; // Upgrade command case Execution::Args::Type::All: diff --git a/src/AppInstallerCLICore/Commands/SettingsCommand.cpp b/src/AppInstallerCLICore/Commands/SettingsCommand.cpp index 2713f0a18b..a03a2c69d6 100644 --- a/src/AppInstallerCLICore/Commands/SettingsCommand.cpp +++ b/src/AppInstallerCLICore/Commands/SettingsCommand.cpp @@ -20,6 +20,8 @@ namespace AppInstaller::CLI { return InitializeFromMoveOnly>>({ std::make_unique(FullName()), + std::make_unique(FullName()), + std::make_unique(FullName()), }); } @@ -109,4 +111,97 @@ namespace AppInstaller::CLI context << Workflow::ExportSettings; } + + std::vector SettingsSetCommand::GetArguments() const + { + return { + Argument { Execution::Args::Type::SettingName, Resource::String::SettingNameArgumentDescription, ArgumentType::Positional, true }, + Argument { Execution::Args::Type::SettingValue, Resource::String::SettingValueArgumentDescription, ArgumentType::Positional, true }, + }; + } + + Resource::LocString SettingsSetCommand::ShortDescription() const + { + return { Resource::String::SettingsSetCommandShortDescription }; + } + + Resource::LocString SettingsSetCommand::LongDescription() const + { + return { Resource::String::SettingsSetCommandLongDescription }; + } + + Utility::LocIndView SettingsSetCommand::HelpLink() const + { + return s_SettingsCommand_HelpLink; + } + + void SettingsSetCommand::ValidateArgumentsInternal(Execution::Args& execArgs) const + { + // Get admin setting string for all available options except Unknown + std::vector adminSettingList; + for (auto setting : GetAllSequentialEnumValues(StringAdminSetting::Unknown)) + { + adminSettingList.emplace_back(AdminSettingToString(setting)); + } + + Utility::LocIndString validOptions = Join(", "_liv, adminSettingList); + + if (execArgs.Contains(Execution::Args::Type::AdminSettingEnable) && StringAdminSetting::Unknown == StringToStringAdminSetting(execArgs.GetArg(Execution::Args::Type::SettingName))) + { + throw CommandException(Resource::String::InvalidArgumentValueError(ArgumentCommon::ForType(Execution::Args::Type::SettingName).Name, validOptions)); + } + } + + void SettingsSetCommand::ExecuteInternal(Execution::Context& context) const + { + context << + Workflow::EnsureRunningAsAdmin << + Workflow::SetAdminSetting; + } + + std::vector SettingsResetCommand::GetArguments() const + { + return { + Argument { Execution::Args::Type::SettingName, Resource::String::SettingNameArgumentDescription, ArgumentType::Positional, true }, + }; + } + + Resource::LocString SettingsResetCommand::ShortDescription() const + { + return { Resource::String::SettingsResetCommandShortDescription }; + } + + Resource::LocString SettingsResetCommand::LongDescription() const + { + return { Resource::String::SettingsResetCommandLongDescription }; + } + + Utility::LocIndView SettingsResetCommand::HelpLink() const + { + return s_SettingsCommand_HelpLink; + } + + void SettingsResetCommand::ValidateArgumentsInternal(Execution::Args& execArgs) const + { + // Get admin setting string for all available options except Unknown + std::vector adminSettingList; + for (auto setting : GetAllSequentialEnumValues(StringAdminSetting::Unknown)) + { + adminSettingList.emplace_back(AdminSettingToString(setting)); + } + + Utility::LocIndString validOptions = Join(", "_liv, adminSettingList); + + if (execArgs.Contains(Execution::Args::Type::AdminSettingEnable) && StringAdminSetting::Unknown == StringToStringAdminSetting(execArgs.GetArg(Execution::Args::Type::SettingName))) + { + throw CommandException(Resource::String::InvalidArgumentValueError(ArgumentCommon::ForType(Execution::Args::Type::SettingName).Name, validOptions)); + } + } + + void SettingsResetCommand::ExecuteInternal(Execution::Context& context) const + { + context << + Workflow::EnsureRunningAsAdmin << + Workflow::ResetAdminSetting; + } } diff --git a/src/AppInstallerCLICore/Commands/SettingsCommand.h b/src/AppInstallerCLICore/Commands/SettingsCommand.h index aee6cffbfd..78cb164da2 100644 --- a/src/AppInstallerCLICore/Commands/SettingsCommand.h +++ b/src/AppInstallerCLICore/Commands/SettingsCommand.h @@ -34,4 +34,36 @@ namespace AppInstaller::CLI protected: void ExecuteInternal(Execution::Context& context) const override; }; + + struct SettingsSetCommand final : public Command + { + SettingsSetCommand(std::string_view parent) : Command("set", {}, parent, Settings::TogglePolicy::Policy::Settings) {} + + std::vector GetArguments() const override; + + virtual Resource::LocString ShortDescription() const override; + virtual Resource::LocString LongDescription() const override; + + Utility::LocIndView HelpLink() const override; + + protected: + void ValidateArgumentsInternal(Execution::Args& execArgs) const override; + void ExecuteInternal(Execution::Context& context) const override; + }; + + struct SettingsResetCommand final : public Command + { + SettingsResetCommand(std::string_view parent) : Command("reset", {}, parent, Settings::TogglePolicy::Policy::Settings) {} + + std::vector GetArguments() const override; + + virtual Resource::LocString ShortDescription() const override; + virtual Resource::LocString LongDescription() const override; + + Utility::LocIndView HelpLink() const override; + + protected: + void ValidateArgumentsInternal(Execution::Args& execArgs) const override; + void ExecuteInternal(Execution::Context& context) const override; + }; } diff --git a/src/AppInstallerCLICore/ExecutionArgs.h b/src/AppInstallerCLICore/ExecutionArgs.h index 32f5e58535..8ea1e0754d 100644 --- a/src/AppInstallerCLICore/ExecutionArgs.h +++ b/src/AppInstallerCLICore/ExecutionArgs.h @@ -89,6 +89,8 @@ namespace AppInstaller::CLI::Execution // Setting Command AdminSettingEnable, AdminSettingDisable, + SettingName, + SettingValue, // Upgrade command All, // Used in Update command to update all installed packages to latest diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h index b1f48342ce..a05c3c691a 100644 --- a/src/AppInstallerCLICore/Resources.h +++ b/src/AppInstallerCLICore/Resources.h @@ -339,16 +339,16 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(NestedInstallerNotFound); WINGET_DEFINE_RESOURCE_STRINGID(NestedInstallerNotSpecified); WINGET_DEFINE_RESOURCE_STRINGID(NestedInstallerNotSupported); - WINGET_DEFINE_RESOURCE_STRINGID(NoApplicableInstallers); WINGET_DEFINE_RESOURCE_STRINGID(NoAdminRepairForUserScopePackage); + WINGET_DEFINE_RESOURCE_STRINGID(NoApplicableInstallers); WINGET_DEFINE_RESOURCE_STRINGID(NoExperimentalFeaturesMessage); WINGET_DEFINE_RESOURCE_STRINGID(NoInstalledPackageFound); WINGET_DEFINE_RESOURCE_STRINGID(NoPackageFound); WINGET_DEFINE_RESOURCE_STRINGID(NoPackageSelectionArgumentProvided); WINGET_DEFINE_RESOURCE_STRINGID(NoPackagesFoundInImportFile); WINGET_DEFINE_RESOURCE_STRINGID(NoProxyArgumentDescription); - WINGET_DEFINE_RESOURCE_STRINGID(Notes); WINGET_DEFINE_RESOURCE_STRINGID(NoRepairInfoFound); + WINGET_DEFINE_RESOURCE_STRINGID(Notes); WINGET_DEFINE_RESOURCE_STRINGID(NoUninstallInfoFound); WINGET_DEFINE_RESOURCE_STRINGID(NoUpgradeArgumentDescription); WINGET_DEFINE_RESOURCE_STRINGID(NoVTArgumentDescription); @@ -439,6 +439,8 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(ReportIdentityFound); WINGET_DEFINE_RESOURCE_STRINGID(RequiredArgError); WINGET_DEFINE_RESOURCE_STRINGID(ReservedFilenameError); + WINGET_DEFINE_RESOURCE_STRINGID(ResetAdminSettingFailed); + WINGET_DEFINE_RESOURCE_STRINGID(ResetAdminSettingSucceeded); WINGET_DEFINE_RESOURCE_STRINGID(ResumeCommandLongDescription); WINGET_DEFINE_RESOURCE_STRINGID(ResumeCommandShortDescription); WINGET_DEFINE_RESOURCE_STRINGID(ResumeIdArgumentDescription); @@ -459,14 +461,22 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(SearchTruncated); WINGET_DEFINE_RESOURCE_STRINGID(SearchVersion); WINGET_DEFINE_RESOURCE_STRINGID(SeeLineAndColumn); + WINGET_DEFINE_RESOURCE_STRINGID(SetAdminSettingFailed); + WINGET_DEFINE_RESOURCE_STRINGID(SetAdminSettingSucceeded); WINGET_DEFINE_RESOURCE_STRINGID(SettingLoadFailure); + WINGET_DEFINE_RESOURCE_STRINGID(SettingNameArgumentDescription); WINGET_DEFINE_RESOURCE_STRINGID(SettingsCommandLongDescription); WINGET_DEFINE_RESOURCE_STRINGID(SettingsCommandShortDescription); WINGET_DEFINE_RESOURCE_STRINGID(SettingsExportCommandLongDescription); WINGET_DEFINE_RESOURCE_STRINGID(SettingsExportCommandShortDescription); + WINGET_DEFINE_RESOURCE_STRINGID(SettingsResetCommandLongDescription); + WINGET_DEFINE_RESOURCE_STRINGID(SettingsResetCommandShortDescription); + WINGET_DEFINE_RESOURCE_STRINGID(SettingsSetCommandLongDescription); + WINGET_DEFINE_RESOURCE_STRINGID(SettingsSetCommandShortDescription); WINGET_DEFINE_RESOURCE_STRINGID(SettingsWarningField); WINGET_DEFINE_RESOURCE_STRINGID(SettingsWarnings); WINGET_DEFINE_RESOURCE_STRINGID(SettingsWarningValue); + WINGET_DEFINE_RESOURCE_STRINGID(SettingValueArgumentDescription); WINGET_DEFINE_RESOURCE_STRINGID(ShowChannel); WINGET_DEFINE_RESOURCE_STRINGID(ShowCommandLongDescription); WINGET_DEFINE_RESOURCE_STRINGID(ShowCommandShortDescription); @@ -591,8 +601,8 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(UpdateNotApplicableReason); WINGET_DEFINE_RESOURCE_STRINGID(UpgradeArgumentDescription); WINGET_DEFINE_RESOURCE_STRINGID(UpgradeAvailableForPinned); - WINGET_DEFINE_RESOURCE_STRINGID(UpgradeBlockedByPinCount); WINGET_DEFINE_RESOURCE_STRINGID(UpgradeBlockedByManifest); + WINGET_DEFINE_RESOURCE_STRINGID(UpgradeBlockedByPinCount); WINGET_DEFINE_RESOURCE_STRINGID(UpgradeCommandLongDescription); WINGET_DEFINE_RESOURCE_STRINGID(UpgradeCommandShortDescription); WINGET_DEFINE_RESOURCE_STRINGID(UpgradeDifferentInstallTechnology); diff --git a/src/AppInstallerCLICore/Workflows/SettingsFlow.cpp b/src/AppInstallerCLICore/Workflows/SettingsFlow.cpp index 5e5d11f876..99159e72b2 100644 --- a/src/AppInstallerCLICore/Workflows/SettingsFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/SettingsFlow.cpp @@ -79,6 +79,35 @@ namespace AppInstaller::CLI::Workflow } } + void SetAdminSetting(Execution::Context& context) + { + auto adminSettingName = context.Args.GetArg(Execution::Args::Type::SettingName); + auto adminSettingValue = context.Args.GetArg(Execution::Args::Type::SettingValue); + StringAdminSetting adminSetting = Settings::StringToStringAdminSetting(adminSettingName); + if (Settings::SetAdminSetting(adminSetting, adminSettingValue)) + { + context.Reporter.Info() << Resource::String::SetAdminSettingSucceeded(AdminSettingToString(adminSetting), LocIndString{ adminSettingValue }) << std::endl; + } + else + { + context.Reporter.Error() << Resource::String::SetAdminSettingFailed(AdminSettingToString(adminSetting)) << std::endl; + } + } + + void ResetAdminSetting(Execution::Context& context) + { + auto adminSettingName = context.Args.GetArg(Execution::Args::Type::SettingName); + StringAdminSetting adminSetting = Settings::StringToStringAdminSetting(adminSettingName); + if (Settings::ResetAdminSetting(adminSetting)) + { + context.Reporter.Info() << Resource::String::ResetAdminSettingSucceeded(AdminSettingToString(adminSetting)) << std::endl; + } + else + { + context.Reporter.Error() << Resource::String::ResetAdminSettingFailed(AdminSettingToString(adminSetting)) << std::endl; + } + } + void OpenUserSetting(Execution::Context& context) { // Show warnings only when the setting command is executed. diff --git a/src/AppInstallerCLICore/Workflows/SettingsFlow.h b/src/AppInstallerCLICore/Workflows/SettingsFlow.h index e40a0051c9..50998295a5 100644 --- a/src/AppInstallerCLICore/Workflows/SettingsFlow.h +++ b/src/AppInstallerCLICore/Workflows/SettingsFlow.h @@ -17,6 +17,18 @@ namespace AppInstaller::CLI::Workflow // Outputs: None void DisableAdminSetting(Execution::Context& context); + // Sets the value of an admin setting. + // Required Args: SettingName, SettingValue + // Inputs: None + // Outputs: None + void SetAdminSetting(Execution::Context& context); + + // Resets an admin setting to the default. + // Required Args: SettingName + // Inputs: None + // Outputs: None + void ResetAdminSetting(Execution::Context& context); + // Opens the user settings. // Required Args: None // Inputs: None diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw index 8ef4f71a0e..7f5838c20e 100644 --- a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw +++ b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw @@ -2817,7 +2817,7 @@ Please specify one of them using the --source option to proceed. The SQLite connection was terminated to prevent corruption. - + Enable Windows Package Manager proxy command line options Describes a Group Policy that can enable the use of the --proxy option to set a proxy @@ -2827,4 +2827,38 @@ Please specify one of them using the --source option to proceed. Disable the use of proxy for this execution + + Cannot reset {0}. This setting is controlled by policy. For more information contact your system administrator. + {Locked="{0}"} The value will be replaced with the feature name + + + Reset admin setting '{0}'. + {Locked="{0}"} Message displayed after the user resets an admin setting to its default value. Reset is used as verb in past tense. {0} is a placeholder replaced by the setting name. + + + Cannot set {0}. This setting is controlled by policy. For more information contact your system administrator. + {Locked="{0}"} The value will be replaced with the feature name + + + Set admin setting '{0}' to '{1}'. + {Locked="{0}"} Message displayed after the user sets the value of an admin setting. Set is used as a verb in past tense. {0} is a placeholder replaced by the setting name. {1} is a placeholder replaced + + + Name of the setting to modify + + + Value to set for the setting. + + + Resets an admin setting to its default value. + + + Resets an admin setting to its default value. + + + Sets the value of an admin setting. + + + Sets the value of an admin setting. + \ No newline at end of file diff --git a/src/AppInstallerCommonCore/Public/winget/AdminSettings.h b/src/AppInstallerCommonCore/Public/winget/AdminSettings.h index d322da1e3c..09d77fff6f 100644 --- a/src/AppInstallerCommonCore/Public/winget/AdminSettings.h +++ b/src/AppInstallerCommonCore/Public/winget/AdminSettings.h @@ -40,7 +40,7 @@ namespace AppInstaller::Settings bool EnableAdminSetting(BoolAdminSetting setting); bool DisableAdminSetting(BoolAdminSetting setting); bool SetAdminSetting(StringAdminSetting setting, std::string_view value); - bool ResetAdminSetting(StringAdminSetting setting, std::string_view value); + bool ResetAdminSetting(StringAdminSetting setting); bool IsAdminSettingEnabled(BoolAdminSetting setting); std::optional GetAdminSetting(StringAdminSetting setting);