From ea8e2d6038acd1a1a26db01f3687f370f024805a Mon Sep 17 00:00:00 2001 From: John McPherson Date: Mon, 26 Aug 2024 16:06:42 -0700 Subject: [PATCH 1/2] Allow for smaller configuration outputs --- src/AppInstallerCLICore/Argument.cpp | 2 + .../Commands/ConfigureCommand.cpp | 1 + src/AppInstallerCLICore/ExecutionArgs.h | 1 + src/AppInstallerCLICore/Resources.h | 1 + .../Workflows/ConfigurationFlow.cpp | 47 +++++++++++-------- .../Shared/Strings/en-us/winget.resw | 3 ++ src/ConfigurationRemotingServer/Program.cs | 7 +++ 7 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/AppInstallerCLICore/Argument.cpp b/src/AppInstallerCLICore/Argument.cpp index e9867b1bb3..e9fcb3c02f 100644 --- a/src/AppInstallerCLICore/Argument.cpp +++ b/src/AppInstallerCLICore/Argument.cpp @@ -203,6 +203,8 @@ namespace AppInstaller::CLI return { type, "file"_liv, 'f', ArgTypeCategory::ConfigurationSetChoice, ArgTypeExclusiveSet::ConfigurationSetChoice }; case Execution::Args::Type::ConfigurationAcceptWarning: return { type, "accept-configuration-agreements"_liv }; + case Execution::Args::Type::ConfigurationSuppressPrologue: + return { type, "suppress-prologue"_liv }; case Execution::Args::Type::ConfigurationEnable: return { type, "enable"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::StubType }; case Execution::Args::Type::ConfigurationDisable: diff --git a/src/AppInstallerCLICore/Commands/ConfigureCommand.cpp b/src/AppInstallerCLICore/Commands/ConfigureCommand.cpp index 6388aefa32..bdc0ba56a3 100644 --- a/src/AppInstallerCLICore/Commands/ConfigureCommand.cpp +++ b/src/AppInstallerCLICore/Commands/ConfigureCommand.cpp @@ -39,6 +39,7 @@ namespace AppInstaller::CLI Argument{ Execution::Args::Type::ConfigurationModulePath, Resource::String::ConfigurationModulePath, ArgumentType::Positional }, Argument{ Execution::Args::Type::ConfigurationHistoryItem, Resource::String::ConfigurationHistoryItemArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help }, Argument{ Execution::Args::Type::ConfigurationAcceptWarning, Resource::String::ConfigurationAcceptWarningArgumentDescription, ArgumentType::Flag }, + Argument{ Execution::Args::Type::ConfigurationSuppressPrologue, Resource::String::ConfigurationSuppressPrologueArgumentDescription, ArgumentType::Flag, Argument::Visibility::Help }, Argument{ Execution::Args::Type::ConfigurationEnable, Resource::String::ConfigurationEnableMessage, ArgumentType::Flag, Argument::Visibility::Help }, Argument{ Execution::Args::Type::ConfigurationDisable, Resource::String::ConfigurationDisableMessage, ArgumentType::Flag, Argument::Visibility::Help }, }; diff --git a/src/AppInstallerCLICore/ExecutionArgs.h b/src/AppInstallerCLICore/ExecutionArgs.h index 19448d96fa..41739b36f4 100644 --- a/src/AppInstallerCLICore/ExecutionArgs.h +++ b/src/AppInstallerCLICore/ExecutionArgs.h @@ -124,6 +124,7 @@ namespace AppInstaller::CLI::Execution // Configuration ConfigurationFile, ConfigurationAcceptWarning, + ConfigurationSuppressPrologue, ConfigurationEnable, ConfigurationDisable, ConfigurationModulePath, diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h index e51f038b3f..284c012577 100644 --- a/src/AppInstallerCLICore/Resources.h +++ b/src/AppInstallerCLICore/Resources.h @@ -106,6 +106,7 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationSettings); WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationStatusWatchArgumentDescription); WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationSuccessfullyApplied); + WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationSuppressPrologueArgumentDescription); WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnexpectedTestResult); WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitAssertHadNegativeResult); WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailed); diff --git a/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp b/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp index 259443e0da..c30cb561cb 100644 --- a/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp @@ -1369,27 +1369,31 @@ namespace AppInstaller::CLI::Workflow auto getDetailsOperation = configContext.Processor().GetSetDetailsAsync(configContext.Set(), ConfigurationUnitDetailFlags::ReadOnly); auto unification = anon::CreateProgressCancellationUnification(std::move(progressScope), getDetailsOperation); + bool suppressDetailsOutput = context.Args.Contains(Args::Type::ConfigurationAcceptWarning) && context.Args.Contains(Args::Type::ConfigurationSuppressPrologue); anon::OutputHelper outputHelper{ context }; uint32_t unitsShown = 0; - getDetailsOperation.Progress([&](const IAsyncOperationWithProgress& operation, const GetConfigurationUnitDetailsResult&) - { - auto threadContext = context.SetForCurrentThread(); + if (!suppressDetailsOutput) + { + getDetailsOperation.Progress([&](const IAsyncOperationWithProgress& operation, const GetConfigurationUnitDetailsResult&) + { + auto threadContext = context.SetForCurrentThread(); - unification.Reset(); + unification.Reset(); - auto unitResults = operation.GetResults().UnitResults(); - for (unitsShown; unitsShown < unitResults.Size(); ++unitsShown) - { - GetConfigurationUnitDetailsResult unitResult = unitResults.GetAt(unitsShown); - anon::LogFailedGetConfigurationUnitDetails(unitResult.Unit(), unitResult.ResultInformation()); - outputHelper.OutputConfigurationUnitInformation(unitResult.Unit()); - } + auto unitResults = operation.GetResults().UnitResults(); + for (unitsShown; unitsShown < unitResults.Size(); ++unitsShown) + { + GetConfigurationUnitDetailsResult unitResult = unitResults.GetAt(unitsShown); + anon::LogFailedGetConfigurationUnitDetails(unitResult.Unit(), unitResult.ResultInformation()); + outputHelper.OutputConfigurationUnitInformation(unitResult.Unit()); + } - progressScope = context.Reporter.BeginAsyncProgress(true); - progressScope->Callback().SetProgressMessage(gettingDetailString); - unification.Progress(std::move(progressScope)); - }); + progressScope = context.Reporter.BeginAsyncProgress(true); + progressScope->Callback().SetProgressMessage(gettingDetailString); + unification.Progress(std::move(progressScope)); + }); + } HRESULT hr = S_OK; GetConfigurationSetDetailsResult result = nullptr; @@ -1419,7 +1423,7 @@ namespace AppInstaller::CLI::Workflow } // Handle any missing progress callbacks that are in the results - if (result) + if (result && !suppressDetailsOutput) { auto unitResults = result.UnitResults(); if (unitResults) @@ -1434,11 +1438,14 @@ namespace AppInstaller::CLI::Workflow } // Handle any units that are NOT in the results (due to an exception part of the way through) - auto allUnits = configContext.Set().Units(); - for (unitsShown; unitsShown < allUnits.Size(); ++unitsShown) + if (!suppressDetailsOutput) { - ConfigurationUnit unit = allUnits.GetAt(unitsShown); - outputHelper.OutputConfigurationUnitInformation(unit); + auto allUnits = configContext.Set().Units(); + for (unitsShown; unitsShown < allUnits.Size(); ++unitsShown) + { + ConfigurationUnit unit = allUnits.GetAt(unitsShown); + outputHelper.OutputConfigurationUnitInformation(unit); + } } if (outputHelper.ValuesTruncated) diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw index 1f6edbde4a..325a3b3aa6 100644 --- a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw +++ b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw @@ -3109,4 +3109,7 @@ Please specify one of them using the --source option to proceed. The package is not compatible with the current Windows version or platform. + + Suppress the configuration prologue when possible + \ No newline at end of file diff --git a/src/ConfigurationRemotingServer/Program.cs b/src/ConfigurationRemotingServer/Program.cs index 6a79a64bd6..1185e4037a 100644 --- a/src/ConfigurationRemotingServer/Program.cs +++ b/src/ConfigurationRemotingServer/Program.cs @@ -70,6 +70,9 @@ internal class Program static int Main(string[] args) { + // Remove any attached console to prevent modules (or their actions) from writing to our console. + FreeConsole(); + // Help find WindowsPackageManager.dll AssemblyLoadContext.Default.ResolvingUnmanagedDll += NativeAssemblyLoadContext.ResolvingUnmanagedHandler; @@ -196,5 +199,9 @@ private static extern int WindowsPackageManagerConfigurationCompleteOutOfProcess [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] private static extern IntPtr GetCommandLineW(); + + [DllImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool FreeConsole(); } } From fda11105f08a615a96a56af7eb966318c85e1beb Mon Sep 17 00:00:00 2001 From: John McPherson Date: Thu, 29 Aug 2024 15:56:16 -0700 Subject: [PATCH 2/2] Change from prologue to initial details --- src/AppInstallerCLICore/Argument.cpp | 2 +- src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AppInstallerCLICore/Argument.cpp b/src/AppInstallerCLICore/Argument.cpp index e9fcb3c02f..a5334a2ceb 100644 --- a/src/AppInstallerCLICore/Argument.cpp +++ b/src/AppInstallerCLICore/Argument.cpp @@ -204,7 +204,7 @@ namespace AppInstaller::CLI case Execution::Args::Type::ConfigurationAcceptWarning: return { type, "accept-configuration-agreements"_liv }; case Execution::Args::Type::ConfigurationSuppressPrologue: - return { type, "suppress-prologue"_liv }; + return { type, "suppress-initial-details"_liv }; case Execution::Args::Type::ConfigurationEnable: return { type, "enable"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::StubType }; case Execution::Args::Type::ConfigurationDisable: diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw index 325a3b3aa6..d4af72d952 100644 --- a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw +++ b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw @@ -3110,6 +3110,6 @@ Please specify one of them using the --source option to proceed. The package is not compatible with the current Windows version or platform. - Suppress the configuration prologue when possible + Suppress showing initial configuration details when possible \ No newline at end of file