From 36f12a860a455c98c02fd1419b6df248958bfa52 Mon Sep 17 00:00:00 2001 From: Cory Knox Date: Fri, 26 Aug 2022 12:08:03 -0700 Subject: [PATCH] (#933) Reuse chocolatey for all the instances --- .../Services/ChocolateyService.cs | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs b/Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs index cef18b377..bb9bb2de7 100644 --- a/Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs +++ b/Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs @@ -238,26 +238,9 @@ public async Task InstallPackage( config.DownloadChecksumType64 = advancedInstallOptions.DownloadChecksumType64bit; } }); - - Action grabErrors; - var errors = GetErrors(out grabErrors); - - using (logger.Intercept(grabErrors)) - { - await _choco.RunAsync(); - - if (Environment.ExitCode != 0) - { - Environment.ExitCode = 0; - return new PackageOperationResult { Successful = false, Messages = errors.ToArray() }; - } - - _choco.Set(config => - { - config = currentConfig; - }); - return PackageOperationResult.SuccessfulCached; - } + var chocoResult = await RunCommand(_choco, logger); + _choco.Set(config => { config = currentConfig; }); + return chocoResult; } } @@ -355,8 +338,8 @@ public async Task UninstallPackage(string id, string ver using (await Lock.WriteLockAsync()) { var logger = new SerilogLogger(Logger, _progressService); - var choco = Lets.GetChocolatey(initializeLogging: false).SetCustomLogging(logger, logExistingMessages: false, addToExistingLoggers: true); - choco.Set( + var currentConfig = _choco.GetConfiguration(); + _choco.Set( config => { config.CommandName = CommandNameType.uninstall.ToString(); @@ -369,7 +352,12 @@ public async Task UninstallPackage(string id, string ver } }); - return await RunCommand(choco, logger); + var chocoResult = await RunCommand(_choco, logger); + _choco.Set(config => + { + config = currentConfig; + }); + return chocoResult; } } @@ -378,16 +366,17 @@ public async Task UpdatePackage(string id, Uri source = using (await Lock.WriteLockAsync()) { var logger = new SerilogLogger(Logger, _progressService); - var choco = Lets.GetChocolatey(initializeLogging: false).SetCustomLogging(logger, logExistingMessages: false, addToExistingLoggers: true); - choco.Set( + var currentConfig = _choco.GetConfiguration(); + _choco.Set( config => { config.CommandName = CommandNameType.upgrade.ToString(); config.PackageNames = id; config.Features.UsePackageExitCodes = false; }); - - return await RunCommand(choco, logger); + var chocoReturn = await RunCommand(_choco, logger); + _choco.Set(config => { config = currentConfig; }); + return chocoReturn; } }