-
-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2541 from marticliment/improvements-to-package-op…
…erations Migration to OperationProvider
- Loading branch information
Showing
43 changed files
with
863 additions
and
968 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/UniGetUI.PAckageEngine.Interfaces/ManagerProviders/IOperationProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using UniGetUI.PackageEngine.Enums; | ||
|
||
namespace UniGetUI.PackageEngine.Interfaces.ManagerProviders; | ||
public interface IOperationProvider | ||
{ | ||
/// <summary> | ||
/// Returns the list of arguments that need to be passed to the Package Manager executable so | ||
/// that the requested operation is performed over the given package, with its corresponding | ||
/// installation options. | ||
/// </summary> | ||
public abstract IEnumerable<string> GetOperationParameters( | ||
IPackage package, | ||
IInstallationOptions options, | ||
OperationType operation | ||
); | ||
|
||
/// <summary> | ||
/// Returns the veredict of the given package operation, given the package, the operation type, | ||
/// the corresponding output and the return code. | ||
/// </summary> | ||
public abstract OperationVeredict GetOperationResult( | ||
IPackage package, | ||
IInstallationOptions options, | ||
OperationType operation, | ||
IEnumerable<string> processOutput, | ||
int returnCode | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
87 changes: 87 additions & 0 deletions
87
src/UniGetUI.PackageEngine.Managers.Chocolatey/Providers/ChocolateyOperationProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UniGetUI.PackageEngine.Classes.Manager.BaseProviders; | ||
using UniGetUI.PackageEngine.Enums; | ||
using UniGetUI.PackageEngine.Interfaces; | ||
using UniGetUI.PackageEngine.Managers.ChocolateyManager; | ||
using UniGetUI.PackageEngine.PackageClasses; | ||
|
||
namespace UniGetUI.PackageEngine.Managers.ChocolateyManager; | ||
internal sealed class ChocolateyOperationProvider : BaseOperationProvider<Chocolatey> | ||
{ | ||
public ChocolateyOperationProvider(Chocolatey manager) : base(manager) { } | ||
|
||
public override IEnumerable<string> GetOperationParameters( | ||
IPackage package, | ||
IInstallationOptions options, | ||
OperationType operation) | ||
{ | ||
List<string> parameters = [operation switch { | ||
OperationType.Install => Manager.Properties.InstallVerb, | ||
OperationType.Update => Manager.Properties.UpdateVerb, | ||
OperationType.Uninstall => Manager.Properties.UninstallVerb, | ||
_ => throw new InvalidDataException("Invalid package operation") | ||
}]; | ||
parameters.AddRange([package.Id, "-y"]); | ||
|
||
if (options.CustomParameters is not null) | ||
parameters.AddRange(options.CustomParameters); | ||
|
||
if (options.InteractiveInstallation) | ||
parameters.Add("--notsilent"); | ||
|
||
if(operation is OperationType.Install or OperationType.Update) | ||
{ | ||
parameters.Add("--no-progress"); | ||
|
||
if (options.Architecture == Architecture.X86) | ||
parameters.Add("--forcex86"); | ||
|
||
if (options.PreRelease) | ||
parameters.Add("--prerelease"); | ||
|
||
if (options.SkipHashCheck) | ||
parameters.AddRange(["--ignore-checksums", "--force"]); | ||
|
||
if (options.Version != "") | ||
parameters.AddRange([$"--version={options.Version}", "--allow-downgrade"]); | ||
} | ||
|
||
return parameters; | ||
} | ||
|
||
public override OperationVeredict GetOperationResult( | ||
IPackage package, | ||
IInstallationOptions options, | ||
OperationType operation, | ||
IEnumerable<string> processOutput, | ||
int returnCode) | ||
{ | ||
if(returnCode is 3010) | ||
{ | ||
return OperationVeredict.RestartRequired; | ||
} | ||
|
||
if (returnCode is 1641 or 1614 or 1605 or 0) | ||
{ | ||
return OperationVeredict.Succeeded; | ||
} | ||
|
||
|
||
string output_string = string.Join("\n", processOutput); | ||
if (!options.RunAsAdministrator && | ||
(output_string.Contains("Run as administrator") | ||
|| output_string.Contains("The requested operation requires elevation") | ||
|| output_string.Contains("ERROR: Exception calling \"CreateDirectory\" with \"1\" argument(s): \"Access to the path")) ) | ||
{ | ||
options.RunAsAdministrator = true; | ||
return OperationVeredict.AutoRetry; | ||
} | ||
|
||
return OperationVeredict.Failed; | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.