Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Enabled Admin Settings in --info #2901

Merged
merged 6 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/AppInstallerCLICore/Commands/RootCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ namespace AppInstaller::CLI
auto info = context.Reporter.Info();
info << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I guess this could be removed too with the latest change


Execution::TableOutput<2> policiesTable{ context.Reporter, { Resource::String::PoliciesPolicy, Resource::String::PoliciesState } };
Execution::TableOutput<2> policiesTable{ context.Reporter, { Resource::String::PoliciesPolicy, Resource::String::StateHeader } };

// Output the toggle policies.
for (const auto& activePolicy : activePolicies)
{
auto policy = Settings::TogglePolicy::GetPolicy(activePolicy.first);
policiesTable.OutputLine({
Resource::LocString{ policy.PolicyName() }.get(),
Resource::LocString{ activePolicy.second == Settings::PolicyState::Enabled ? Resource::String::PoliciesEnabled : Resource::String::PoliciesDisabled }.get() });
Resource::LocString{ activePolicy.second == Settings::PolicyState::Enabled ? Resource::String::StateEnabled : Resource::String::StateDisabled }.get() });
}

// Output the update interval in the same table if needed.
Expand Down Expand Up @@ -108,7 +108,23 @@ namespace AppInstaller::CLI
OutputGroupPolicySourceList(context, sources->get(), Resource::String::SourceListAllowedSource);
}
}
info << std::endl;
}
}

void OutputAdminSettings(Execution::Context& context)
{
Execution::TableOutput<2> adminSettingsTable{ context.Reporter, { Resource::String::AdminSettingHeader, Resource::String::StateHeader } };

// Output the admin settings.
for (const auto& setting : Settings::GetAllAdminSettings())
{
adminSettingsTable.OutputLine({
std::string{ AdminSettingToString(setting)},
Resource::LocString{ IsAdminSettingEnabled(setting) ? Resource::String::StateEnabled : Resource::String::StateDisabled }
});
}
adminSettingsTable.Complete();
}
}

Expand Down Expand Up @@ -208,8 +224,10 @@ namespace AppInstaller::CLI
links.OutputLine({ Resource::LocString(Resource::String::WindowsStoreTerms).get(), "https://www.microsoft.com/en-us/storedocs/terms-of-sale" });

links.Complete();
info << std::endl;

OutputGroupPolicies(context);
OutputAdminSettings(context);
}
else if (context.Args.Contains(Execution::Args::Type::ToolVersion))
{
Expand Down
7 changes: 4 additions & 3 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(AdminSettingDisableDescription);
WINGET_DEFINE_RESOURCE_STRINGID(AdminSettingEnabled);
WINGET_DEFINE_RESOURCE_STRINGID(AdminSettingEnableDescription);
WINGET_DEFINE_RESOURCE_STRINGID(AdminSettingHeader);
WINGET_DEFINE_RESOURCE_STRINGID(ArchiveFailedMalwareScan);
WINGET_DEFINE_RESOURCE_STRINGID(ArchiveFailedMalwareScanOverridden);
WINGET_DEFINE_RESOURCE_STRINGID(ArgumentForSinglePackageProvidedWithMultipleQueries);
Expand Down Expand Up @@ -264,10 +265,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(PinResettingAll);
WINGET_DEFINE_RESOURCE_STRINGID(PinResetUseForceArg);
WINGET_DEFINE_RESOURCE_STRINGID(PinType);
WINGET_DEFINE_RESOURCE_STRINGID(PoliciesDisabled);
WINGET_DEFINE_RESOURCE_STRINGID(PoliciesEnabled);
WINGET_DEFINE_RESOURCE_STRINGID(PoliciesPolicy);
WINGET_DEFINE_RESOURCE_STRINGID(PoliciesState);
WINGET_DEFINE_RESOURCE_STRINGID(PortableHashMismatchOverridden);
WINGET_DEFINE_RESOURCE_STRINGID(PortableHashMismatchOverrideRequired);
WINGET_DEFINE_RESOURCE_STRINGID(PortableAliasAdded);
Expand Down Expand Up @@ -405,6 +403,9 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(SourceUpdateCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SourceUpdateCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(SourceUpdateOne);
WINGET_DEFINE_RESOURCE_STRINGID(StateDisabled);
WINGET_DEFINE_RESOURCE_STRINGID(StateEnabled);
WINGET_DEFINE_RESOURCE_STRINGID(StateHeader);
WINGET_DEFINE_RESOURCE_STRINGID(SystemArchitecture);
WINGET_DEFINE_RESOURCE_STRINGID(TagArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(ThankYou);
Expand Down
6 changes: 2 additions & 4 deletions src/AppInstallerCLICore/Workflows/SettingsFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,10 @@ namespace AppInstaller::CLI::Workflow
void ExportSettings(Execution::Context& context)
{
ExportSettingsJson exportSettingsJson;
using AdminSetting_t = std::underlying_type_t<AdminSetting>;

// Skip Unknown.
for (AdminSetting_t i = 1 + static_cast<AdminSetting_t>(AdminSetting::Unknown); i < static_cast<AdminSetting_t>(AdminSetting::Max); ++i)
for (const auto& setting : GetAllAdminSettings())
{
exportSettingsJson.AddAdminSetting(static_cast<AdminSetting>(i));
exportSettingsJson.AddAdminSetting(setting);
}

context.Reporter.Info() << exportSettingsJson.ToJsonString() << std::endl;
Expand Down
29 changes: 16 additions & 13 deletions src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -909,22 +909,10 @@ They can be configured through the settings file 'winget settings'.</value>
<data name="PolicySourceAutoUpdateInterval" xml:space="preserve">
<value>Set Windows Package Manager Source Auto Update Interval In Minutes</value>
</data>
<data name="PoliciesDisabled" xml:space="preserve">
<value>Disabled</value>
<comment>As in enabled/disabled</comment>
</data>
<data name="PoliciesEnabled" xml:space="preserve">
<value>Enabled</value>
<comment>As in enabled/disabled</comment>
</data>
<data name="PoliciesPolicy" xml:space="preserve">
<value>Group Policy</value>
<comment>Header for a table listing active Group Policies</comment>
</data>
<data name="PoliciesState" xml:space="preserve">
<value>State</value>
<comment>Header for a table listing the state (enabled/disabled) of Group Policies</comment>
</data>
<data name="PolicyEnableLocalManifests" xml:space="preserve">
<value>Enable Windows App Installer Local Manifest Files</value>
</data>
Expand Down Expand Up @@ -1232,6 +1220,10 @@ Do you agree to the terms?</value>
<value>Disabled admin setting '{0}'.</value>
<comment>{Locked="{0}"} Message displayed when the user disables an admin setting. {0} is a placeholder replaced by the setting name.</comment>
</data>
<data name="AdminSettingHeader" xml:space="preserve">
<value>Admin Setting</value>
<comment>Header for a table displaying admin settings.</comment>
</data>
<data name="InstallFlowReturnCodePackageInUse" xml:space="preserve">
<value>Application is currently running. Exit the application then try again.</value>
</data>
Expand Down Expand Up @@ -1643,10 +1635,21 @@ Please specify one of them using the --source option to proceed.</value>
</data>
<data name="ArgumentForSinglePackageProvidedWithMultipleQueries" xml:space="preserve">
<value>An argument was provided that can only be used for single package</value>

</data>
<data name="MultipleExclusiveArgumentsProvided" xml:space="preserve">
<value>Multiple mutually exclusive arguments provided: {0}</value>
<comment>{Locked="{0}"} Error message shown when mutually incompatible command line arguments are used. {0} is a placeholder replaced by the arguments that cannot be specified together</comment>
</data>
<data name="StateDisabled" xml:space="preserve">
<value>Disabled</value>
<comment>As in enabled/disabled</comment>
</data>
<data name="StateEnabled" xml:space="preserve">
<value>Enabled</value>
<comment>As in enabled/disabled</comment>
</data>
<data name="StateHeader" xml:space="preserve">
<value>State</value>
<comment>Header for a table listing the state (enabled/disabled) of Group Policies and Settings</comment>
</data>
</root>
14 changes: 14 additions & 0 deletions src/AppInstallerCommonCore/AdminSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,18 @@ namespace AppInstaller::Settings
AdminSettingsInternal adminSettingsInternal;
return adminSettingsInternal.GetAdminSettingBoolValue(setting);
}

std::vector<AdminSetting> GetAllAdminSettings()
{
std::vector<AdminSetting> result;
using AdminSetting_t = std::underlying_type_t<AdminSetting>;

// Skip Unknown.
for (AdminSetting_t i = 1 + static_cast<AdminSetting_t>(AdminSetting::Unknown); i < static_cast<AdminSetting_t>(AdminSetting::Max); ++i)
{
result.emplace_back(static_cast<AdminSetting>(i));;
}

return result;
}
}
2 changes: 2 additions & 0 deletions src/AppInstallerCommonCore/Public/winget/AdminSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ namespace AppInstaller::Settings
bool DisableAdminSetting(AdminSetting setting);

bool IsAdminSettingEnabled(AdminSetting setting);

std::vector<AdminSetting> GetAllAdminSettings();
}