winget-cli

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

commit 3eca881edb4eb25b58a849a03023b8bfd7eb361a
parent 8a8bfa7a0e6d5b516b393355feffbb1f03c0bef3
Author: yao-msft <50888816+yao-msft@users.noreply.github.com>
Date:   Thu,  8 May 2025 14:30:00 -0700

Use Microsoft.Windows.Settings in configure export all (#5441)


Diffstat:
Mazure-pipelines.yml | 2+-
Msrc/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp | 36+++++++++++++++++++++++++++++++-----
Msrc/AppInstallerCLIE2ETests/ConfigureExportCommand.cs | 3+--
3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/azure-pipelines.yml b/azure-pipelines.yml @@ -373,7 +373,7 @@ jobs: # Install required DSC modules until export all command can handle auto acquisition - pwsh: | - Install-Module -Name Microsoft.Windows.Developer -AllowPrerelease -Force + Install-Module -Name Microsoft.Windows.Settings -AllowPrerelease -Force displayName: Install Required DSC Modules for Tests condition: succeededOrFailed() diff --git a/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp b/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp @@ -66,19 +66,29 @@ namespace AppInstaller::CLI::Workflow constexpr std::wstring_view s_Setting_PowerShellGet_ModuleName = L"name"; + struct PredefinedResourceInfo + { + std::wstring_view UnitType; + bool ElevationRequired = false; + + PredefinedResourceInfo(std::wstring_view unitType) : UnitType(unitType) {} + PredefinedResourceInfo(std::wstring_view unitType, bool elevationRequired) : UnitType(unitType), ElevationRequired(elevationRequired) {} + }; + struct PredefinedResource { // RequiredModule could be empty, meaning no required modules needed. std::wstring_view RequiredModule; - std::vector<std::wstring_view> UnitTypes; + std::vector<PredefinedResourceInfo> ResourceInfos; }; std::vector<PredefinedResource> PredefinedResourcesForExport() { return { - { {}, { s_UnitType_WinGetUserSettingsFile_DSCv3 } }, - { L"Microsoft.Windows.Developer", { L"Microsoft.Windows.Developer/DeveloperMode", L"Microsoft.Windows.Developer/EnableDarkMode", L"Microsoft.Windows.Developer/ShowSecondsInClock", L"Microsoft.Windows.Developer/Taskbar", L"Microsoft.Windows.Developer/WindowsExplorer" } }, + { {}, { { s_UnitType_WinGetUserSettingsFile_DSCv3 } } }, + // TODO: Set ElevationRequired to true after https://github.com/PowerShell/DSC/issues/786 is fixed + { L"Microsoft.Windows.Settings", { { L"Microsoft.Windows.Settings/WindowsSettings", false } } }, }; } @@ -1494,6 +1504,14 @@ namespace AppInstaller::CLI::Workflow } } + void AddElevatedEnvironment(std::vector<ConfigurationUnit>& units) + { + for (auto& unit : units) + { + unit.Environment().Context(SecurityContext::Elevated); + } + } + std::vector<IConfigurationUnitProcessorDetails> GetAllUnitProcessors(Execution::Context& context) { ConfigurationContext& configContext = context.Get<Data::ConfigurationContext>(); @@ -1554,9 +1572,9 @@ namespace AppInstaller::CLI::Workflow } */ - for (const auto& resourceType : resources.UnitTypes) + for (const auto& resourceInfo : resources.ResourceInfos) { - auto resourceUnit = CreateConfigurationUnitFromUnitType(resourceType); + auto resourceUnit = CreateConfigurationUnitFromUnitType(resourceInfo.UnitType); auto exportedUnits = ExportUnit(context, resourceUnit); if (requiredModuleUnit) @@ -1564,6 +1582,14 @@ namespace AppInstaller::CLI::Workflow AddDependentUnit(exportedUnits, requiredModuleUnit.value()); } + // The dynamic processor factory does not support operating elevated units without a set. + // Luckily the Get/Export for all PreDefinedResources do not require elevation. + // Here we add elevation environment to exported results. + if (resourceInfo.ElevationRequired) + { + AddElevatedEnvironment(exportedUnits); + } + for (auto exportedUnit : exportedUnits) { configContext.Set().Units().Append(std::move(exportedUnit)); diff --git a/src/AppInstallerCLIE2ETests/ConfigureExportCommand.cs b/src/AppInstallerCLIE2ETests/ConfigureExportCommand.cs @@ -159,8 +159,7 @@ namespace AppInstallerCLIE2ETests Assert.AreEqual(Constants.ErrorCode.S_OK, showResult.ExitCode); Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/UserSettingsFile")); - Assert.True(showResult.StdOut.Contains("Microsoft.Windows.Developer/DeveloperMode")); - Assert.True(showResult.StdOut.Contains("Microsoft.Windows.Developer/EnableDarkMode")); + Assert.True(showResult.StdOut.Contains("Microsoft.Windows.Settings/WindowsSettings")); Assert.True(showResult.StdOut.Contains("Microsoft.WinGet.Dev/Source")); Assert.True(showResult.StdOut.Contains($"[{Constants.TestSourceName}_{Constants.TestSourceType}]"));