MsiInstallFlow.cpp (2367B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #include "pch.h" 4 #include "MsiInstallFlow.h" 5 #include <winget/MsiExecArguments.h> 6 #include <winget/Runtime.h> 7 8 namespace AppInstaller::CLI::Workflow 9 { 10 namespace 11 { 12 std::optional<UINT> InvokeMsiInstallProduct(const std::filesystem::path& installerPath, const Msi::MsiParsedArguments& msiArgs, IProgressCallback&) 13 { 14 if (msiArgs.LogFile) 15 { 16 THROW_IF_WIN32_ERROR(MsiEnableLogW(msiArgs.LogMode, msiArgs.LogFile->c_str(), msiArgs.LogAttributes)); 17 } 18 else 19 { 20 // Disable logging 21 THROW_IF_WIN32_ERROR(MsiEnableLogW(0, nullptr, 0)); 22 } 23 24 // Returns old UI level. We don't need to reset it so we ignore it. 25 MsiSetInternalUI(msiArgs.UILevel, nullptr); 26 27 // TODO: Use progress callback 28 return MsiInstallProductW(installerPath.c_str(), msiArgs.Properties.c_str()); 29 } 30 } 31 32 void DirectMSIInstallImpl(Execution::Context& context) 33 { 34 context.Reporter.Info() << Resource::String::InstallFlowStartingPackageInstall << std::endl; 35 36 const auto& installer = context.Get<Execution::Data::Installer>(); 37 const std::filesystem::path& installerPath = context.Get<Execution::Data::InstallerPath>(); 38 39 Msi::MsiParsedArguments parsedArgs = Msi::ParseMSIArguments(context.Get<Execution::Data::InstallerArgs>()); 40 41 // Inform of elevation requirements 42 if (!Runtime::IsRunningAsAdmin() && installer->ElevationRequirement == Manifest::ElevationRequirementEnum::ElevatesSelf) 43 { 44 context.Reporter.Warn() << Resource::String::InstallerElevationExpected << std::endl; 45 } 46 47 auto installResult = context.Reporter.ExecuteWithProgress( 48 std::bind(InvokeMsiInstallProduct, 49 installerPath, 50 parsedArgs, 51 std::placeholders::_1)); 52 53 if (!installResult) 54 { 55 context.Reporter.Warn() << Resource::String::InstallAbandoned << std::endl; 56 AICLI_TERMINATE_CONTEXT(E_ABORT); 57 } 58 else 59 { 60 context.Add<Execution::Data::OperationReturnCode>(installResult.value()); 61 } 62 } 63 }