commit b96dbdbe718b6a307ff9655c5e414083aa04d6d1
parent e781da4da6ddf80d670d5a73f2f601e46a7e5507
Author: JohnMcPMS <johnmcp@microsoft.com>
Date: Thu, 19 Oct 2023 11:38:33 -0700
Fix non-test hook code (#3789)
Diffstat:
1 file changed, 55 insertions(+), 53 deletions(-)
diff --git a/src/AppInstallerCLICore/Workflows/ShellExecuteInstallerHandler.cpp b/src/AppInstallerCLICore/Workflows/ShellExecuteInstallerHandler.cpp
@@ -202,45 +202,6 @@ namespace AppInstaller::CLI::Workflow
return args;
}
-
- std::filesystem::path GetDismExecutablePath()
- {
- return AppInstaller::Filesystem::GetExpandedPath("%windir%\\system32\\dism.exe");
- }
-
- std::optional<DWORD> DoesWindowsFeatureExist(Execution::Context& context, std::string_view featureName)
- {
- std::string args = "/Online /Get-FeatureInfo /FeatureName:" + std::string{ featureName };
- auto dismExecPath = GetDismExecutablePath();
-
- auto getFeatureInfoResult = context.Reporter.ExecuteWithProgress(
- std::bind(InvokeShellExecuteEx,
- dismExecPath,
- args,
- false,
- SW_HIDE,
- std::placeholders::_1));
-
- return getFeatureInfoResult;
- }
-
- std::optional<DWORD> EnableWindowsFeature(Execution::Context& context, std::string_view featureName)
- {
- std::string args = "/Online /Enable-Feature /NoRestart /FeatureName:" + std::string{ featureName };
- auto dismExecPath = GetDismExecutablePath();
-
- AICLI_LOG(Core, Info, << "Enabling Windows Feature [" << featureName << "]");
-
- auto enableFeatureResult = context.Reporter.ExecuteWithProgress(
- std::bind(InvokeShellExecuteEx,
- dismExecPath,
- args,
- false,
- SW_HIDE,
- std::placeholders::_1));
-
- return enableFeatureResult;
- }
}
void ShellExecuteInstallImpl(Execution::Context& context)
@@ -370,18 +331,65 @@ namespace AppInstaller::CLI::Workflow
}
#endif
- void ShellExecuteEnableWindowsFeature::operator()(Execution::Context& context) const
+ std::filesystem::path GetDismExecutablePath()
{
- Utility::LocIndView locIndFeatureName{ m_featureName };
+ return AppInstaller::Filesystem::GetExpandedPath("%windir%\\system32\\dism.exe");
+ }
+ std::optional<DWORD> DoesWindowsFeatureExist(Execution::Context& context, std::string_view featureName)
+ {
#ifndef AICLI_DISABLE_TEST_HOOKS
- auto doesFeatureExistResult = s_DoesWindowsFeatureExistResult_Override.has_value() ?
- s_DoesWindowsFeatureExistResult_Override.value() :
- DoesWindowsFeatureExist(context, m_featureName);
-#else
- auto doesFeatureExistResult = DoesWindowsFeatureExist(context, featureName);
+ if (s_DoesWindowsFeatureExistResult_Override)
+ {
+ return s_DoesWindowsFeatureExistResult_Override;
+ }
#endif
+ std::string args = "/Online /Get-FeatureInfo /FeatureName:" + std::string{ featureName };
+ auto dismExecPath = GetDismExecutablePath();
+
+ auto getFeatureInfoResult = context.Reporter.ExecuteWithProgress(
+ std::bind(InvokeShellExecuteEx,
+ dismExecPath,
+ args,
+ false,
+ SW_HIDE,
+ std::placeholders::_1));
+
+ return getFeatureInfoResult;
+ }
+
+ std::optional<DWORD> EnableWindowsFeature(Execution::Context& context, std::string_view featureName)
+ {
+#ifndef AICLI_DISABLE_TEST_HOOKS
+ if (s_EnableWindowsFeatureResult_Override)
+ {
+ return s_EnableWindowsFeatureResult_Override;
+ }
+#endif
+
+ std::string args = "/Online /Enable-Feature /NoRestart /FeatureName:" + std::string{ featureName };
+ auto dismExecPath = GetDismExecutablePath();
+
+ AICLI_LOG(Core, Info, << "Enabling Windows Feature [" << featureName << "]");
+
+ auto enableFeatureResult = context.Reporter.ExecuteWithProgress(
+ std::bind(InvokeShellExecuteEx,
+ dismExecPath,
+ args,
+ false,
+ SW_HIDE,
+ std::placeholders::_1));
+
+ return enableFeatureResult;
+ }
+
+ void ShellExecuteEnableWindowsFeature::operator()(Execution::Context& context) const
+ {
+ Utility::LocIndView locIndFeatureName{ m_featureName };
+
+ std::optional<DWORD> doesFeatureExistResult = DoesWindowsFeatureExist(context, m_featureName);
+
if (!doesFeatureExistResult)
{
AICLI_TERMINATE_CONTEXT(E_ABORT);
@@ -394,13 +402,7 @@ namespace AppInstaller::CLI::Workflow
context.Reporter.Info() << Resource::String::EnablingWindowsFeature(locIndFeatureName) << std::endl;
-#ifndef AICLI_DISABLE_TEST_HOOKS
- auto enableFeatureResult = s_EnableWindowsFeatureResult_Override.has_value() ?
- s_EnableWindowsFeatureResult_Override.value() :
- EnableWindowsFeature(context, m_featureName);
-#else
- auto enableFeatureResult = EnableWindowsFeature(context, featureName);
-#endif
+ std::optional<DWORD> enableFeatureResult = EnableWindowsFeature(context, m_featureName);
if (!enableFeatureResult)
{