Skip to content

Commit

Permalink
(chocolatey#933) Reuse chocolatey for all the instances
Browse files Browse the repository at this point in the history
  • Loading branch information
corbob committed Aug 26, 2022
1 parent 88d5fb0 commit 36f12a8
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions Source/ChocolateyGui.Common.Windows/Services/ChocolateyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,26 +238,9 @@ public async Task<PackageOperationResult> InstallPackage(
config.DownloadChecksumType64 = advancedInstallOptions.DownloadChecksumType64bit;
}
});

Action<LogMessage> 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;
}
}

Expand Down Expand Up @@ -355,8 +338,8 @@ public async Task<PackageOperationResult> 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();
Expand All @@ -369,7 +352,12 @@ public async Task<PackageOperationResult> UninstallPackage(string id, string ver
}
});

return await RunCommand(choco, logger);
var chocoResult = await RunCommand(_choco, logger);
_choco.Set(config =>
{
config = currentConfig;
});
return chocoResult;
}
}

Expand All @@ -378,16 +366,17 @@ public async Task<PackageOperationResult> 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;
}
}

Expand Down

0 comments on commit 36f12a8

Please sign in to comment.