From f20ca2cd812147d226f0167cd3076f47cdffd86b Mon Sep 17 00:00:00 2001 From: Madhusudhan Gumbalapura Sudarshan Date: Wed, 20 Mar 2024 13:12:42 -0700 Subject: [PATCH] Ensure commonality in behavior by managing the context flag setting for COM Commands from a parent-level structure, leveraging inheritance instead of compelling every COMCommand concrete implementation to override the Execute function for flag setting --- .../Commands/COMCommand.cpp | 37 +++++++------------ src/AppInstallerCLICore/Commands/COMCommand.h | 32 +++++++++------- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/AppInstallerCLICore/Commands/COMCommand.cpp b/src/AppInstallerCLICore/Commands/COMCommand.cpp index 1cd11170bf..9afb33e981 100644 --- a/src/AppInstallerCLICore/Commands/COMCommand.cpp +++ b/src/AppInstallerCLICore/Commands/COMCommand.cpp @@ -16,6 +16,15 @@ namespace AppInstaller::CLI using namespace AppInstaller::Manifest; using namespace AppInstaller::Utility::literals; + // IMPORTANT: This serves as a base interface for all COM commands and should not be used directly. + // It allows the COM Command implementations to share and enforce common behavior before invoking the base implementation. + // Currently, it sets the WinGetCOMApiCall flag in the context before invoking the base Execute implementation. + void COMCommand::Execute(Context& context) const + { + context.SetFlags(Execution::ContextFlag::WinGetCOMApiCall); + Command::Execute(context); + } + // IMPORTANT: To use this command, the caller should have already retrieved the package manifest (GetManifest()) and added it to the Context Data void COMDownloadCommand::ExecuteInternal(Context& context) const { @@ -28,12 +37,6 @@ namespace AppInstaller::CLI Workflow::SetDownloadDirectory << Workflow::DownloadPackageDependencies << Workflow::DownloadInstaller; - } - - void COMDownloadCommand::Execute(Context& context) const - { - context.SetFlags(Execution::ContextFlag::WinGetCOMApiCall); - Command::Execute(context); } // IMPORTANT: To use this command, the caller should have already executed the COMDownloadCommand @@ -43,24 +46,12 @@ namespace AppInstaller::CLI Workflow::InstallDependencies << Workflow::ReverifyInstallerHash << Workflow::InstallPackageInstaller; - } - - void COMInstallCommand::Execute(Context& context) const - { - context.SetFlags(Execution::ContextFlag::WinGetCOMApiCall); - Command::Execute(context); } // IMPORTANT: To use this command, the caller should have already retrieved the InstalledPackageVersion and added it to the Context Data - void COMUninstallCommand::ExecuteInternal(Execution::Context& context) const - { - context << - Workflow::UninstallSinglePackage; - } - - void COMUninstallCommand::Execute(Execution::Context& context) const - { - context.SetFlags(Execution::ContextFlag::WinGetCOMApiCall); - Command::Execute(context); - } + void COMUninstallCommand::ExecuteInternal(Execution::Context& context) const + { + context << + Workflow::UninstallSinglePackage; + } } diff --git a/src/AppInstallerCLICore/Commands/COMCommand.h b/src/AppInstallerCLICore/Commands/COMCommand.h index 0aebb23faa..3070a3b17f 100644 --- a/src/AppInstallerCLICore/Commands/COMCommand.h +++ b/src/AppInstallerCLICore/Commands/COMCommand.h @@ -4,39 +4,45 @@ #include "Command.h" namespace AppInstaller::CLI -{ +{ + // IMPORTANT: This acts as a base interface for all COM commands, and should not be used directly + // This will only all the COM Command implementations to share and enforce common behavior before invoking based implementation. + // Right now, it sets the WinGetCOMApiCall flag to the context before invoking the base Execute implementation. + struct COMCommand : public Command + { + protected: + COMCommand(std::string_view name, std::string_view parent) : Command(name, parent) {} + + public: + void Execute(Execution::Context& context) const override; + }; + // IMPORTANT: To use this command, the caller should have already retrieved the package manifest (GetManifest()) and added it to the Context Data - struct COMDownloadCommand final : public Command + struct COMDownloadCommand final : public COMCommand { constexpr static std::string_view CommandName = "download"sv; - COMDownloadCommand(std::string_view parent) : Command(CommandName, parent) {} + COMDownloadCommand(std::string_view parent) : COMCommand(CommandName, parent) {} - void Execute(Execution::Context& context) const override; - protected: void ExecuteInternal(Execution::Context& context) const override; }; // IMPORTANT: To use this command, the caller should have already retrieved the package manifest (GetManifest()) and added it to the Context Data - struct COMInstallCommand final : public Command + struct COMInstallCommand final : public COMCommand { constexpr static std::string_view CommandName = "install"sv; - COMInstallCommand(std::string_view parent) : Command(CommandName, parent) {} + COMInstallCommand(std::string_view parent) : COMCommand(CommandName, parent) {} - void Execute(Execution::Context& context) const override; - protected: void ExecuteInternal(Execution::Context& context) const override; }; // IMPORTANT: To use this command, the caller should have already retrieved the InstalledPackageVersion and added it to the Context Data - struct COMUninstallCommand final : public Command + struct COMUninstallCommand final : public COMCommand { constexpr static std::string_view CommandName = "uninstall"sv; - COMUninstallCommand(std::string_view parent) : Command(CommandName, parent) {} + COMUninstallCommand(std::string_view parent) : COMCommand(CommandName, parent) {} - void Execute(Execution::Context& context) const override; - protected: void ExecuteInternal(Execution::Context& context) const override; };