From 17e8c4096b672987cfc9132c1fceea80fedcd1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Climent?= Date: Tue, 30 Jul 2024 13:07:10 +0200 Subject: [PATCH] Add base OverridenInstallationOptions --- .../IPackage.cs | 5 +-- .../OverridenInstallationOptions.cs | 20 ++++++++++ .../DotNet.cs | 24 ++++++++++-- .../Providers/DotNetOperationProvider.cs | 2 +- .../Npm.cs | 21 +++++++--- .../Providers/NpmOperationProvider.cs | 2 +- .../Pip.cs | 7 ++-- .../Providers/PipOperationProvider.cs | 6 +-- .../Providers/PowerShellOperationProvider.cs | 3 +- .../Providers/PowerShell7OperationProvider.cs | 3 +- .../Providers/ScoopOperationProvider.cs | 8 ++-- .../Scoop.cs | 21 +++++----- .../Providers/WinGetOperationProvider.cs | 1 - .../Packages/InvalidImportedPackage.cs | 4 ++ .../Packages/Package.cs | 39 ++++++++++++++----- .../SoftwarePages/PackageBundlesPage.cs | 2 +- .../Operations/PackageOperations.cs | 11 +++--- 17 files changed, 124 insertions(+), 55 deletions(-) create mode 100644 src/UniGetUI.PackageEngine.Enums/OverridenInstallationOptions.cs diff --git a/src/UniGetUI.PAckageEngine.Interfaces/IPackage.cs b/src/UniGetUI.PAckageEngine.Interfaces/IPackage.cs index a0527018f..fdfb2882b 100644 --- a/src/UniGetUI.PAckageEngine.Interfaces/IPackage.cs +++ b/src/UniGetUI.PAckageEngine.Interfaces/IPackage.cs @@ -1,7 +1,7 @@ using System.ComponentModel; using UniGetUI.Interface.Enums; using UniGetUI.PackageEngine.Classes.Serializable; -using UniGetUI.PackageEngine.Enums; +using UniGetUI.PackageEngine.Structs; namespace UniGetUI.PackageEngine.Interfaces { @@ -19,8 +19,7 @@ public interface IPackage : INotifyPropertyChanged, IEquatable public IPackageManager Manager { get; } public string NewVersion { get; } public bool IsUpgradable { get; } - public PackageScope Scope { get; set; } - public string SourceAsString { get; } + public ref OverridenInstallationOptions OverridenOptions { get; } public string AutomationName { get; } /// diff --git a/src/UniGetUI.PackageEngine.Enums/OverridenInstallationOptions.cs b/src/UniGetUI.PackageEngine.Enums/OverridenInstallationOptions.cs new file mode 100644 index 000000000..0a2ed910c --- /dev/null +++ b/src/UniGetUI.PackageEngine.Enums/OverridenInstallationOptions.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniGetUI.PackageEngine.Enums; +using Windows.Devices.Bluetooth.Advertisement; + +namespace UniGetUI.PackageEngine.Structs; +public struct OverridenInstallationOptions +{ + public PackageScope? Scope; + public bool? RunAsAdministrator; + + public OverridenInstallationOptions(PackageScope? scope = null, bool? runAsAdministrator = null) + { + Scope = scope; + RunAsAdministrator = runAsAdministrator; + } +} diff --git a/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs b/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs index 4dffb8208..bac5b5149 100644 --- a/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs +++ b/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs @@ -12,6 +12,7 @@ using UniGetUI.PackageEngine.Managers.PowerShellManager; using UniGetUI.PackageEngine.PackageClasses; using UniGetUI.PackageEngine.ManagerClasses.Classes; +using UniGetUI.PackageEngine.Structs; namespace UniGetUI.PackageEngine.Managers.DotNetManager { @@ -140,7 +141,15 @@ protected override async Task GetAvailableUpdates_UnSafe() continue; } - Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], elements[2], DefaultSource, this, PackageScope.Global)); + Packages.Add(new Package( + CoreTools.FormatAsName(elements[0]), + elements[0], + elements[1], + elements[2], + DefaultSource, + this, + new(PackageScope.Global) + )); } } logger.AddToStdErr(await p.StandardError.ReadToEndAsync()); @@ -153,14 +162,14 @@ protected override async Task GetAvailableUpdates_UnSafe() protected override async Task GetInstalledPackages_UnSafe() { List Packages = []; - foreach (PackageScope scope in new PackageScope[] { PackageScope.Local, PackageScope.Global }) + foreach (var options in new OverridenInstallationOptions[] { new(PackageScope.Local), new(PackageScope.Global) }) { Process p = new() { StartInfo = new ProcessStartInfo { FileName = Status.ExecutablePath, - Arguments = Properties.ExecutableCallArgs + " list" + (scope == PackageScope.Global ? " --global" : ""), + Arguments = Properties.ExecutableCallArgs + " list" + (options.Scope == PackageScope.Global ? " --global" : ""), RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, @@ -202,7 +211,14 @@ protected override async Task GetInstalledPackages_UnSafe() continue; } - Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], DefaultSource, this, scope)); + Packages.Add(new Package( + CoreTools.FormatAsName(elements[0]), + elements[0], + elements[1], + DefaultSource, + this, + options + )); } } logger.AddToStdErr(await p.StandardError.ReadToEndAsync()); diff --git a/src/UniGetUI.PackageEngine.Managers.Dotnet/Providers/DotNetOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Dotnet/Providers/DotNetOperationProvider.cs index 460a5ceef..020306d60 100644 --- a/src/UniGetUI.PackageEngine.Managers.Dotnet/Providers/DotNetOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Dotnet/Providers/DotNetOperationProvider.cs @@ -35,7 +35,7 @@ public override IEnumerable GetOperationParameters( if (options.CustomInstallLocation != "") parameters.AddRange(["--tool-path", "\"" + options.CustomInstallLocation + "\""]); - if (options.InstallationScope == PackageScope.Global || (options.InstallationScope is null && package.Scope == PackageScope.Global)) + if(package.OverridenOptions.Scope == PackageScope.Global || (package.OverridenOptions.Scope is null && options.InstallationScope == PackageScope.Global)) parameters.Add("--global"); if (operation is OperationType.Install or OperationType.Update) diff --git a/src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs b/src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs index 3eb5ee522..c7434fab9 100644 --- a/src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs +++ b/src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs @@ -8,6 +8,7 @@ using UniGetUI.PackageEngine.ManagerClasses.Manager; using UniGetUI.PackageEngine.PackageClasses; using UniGetUI.PackageEngine.ManagerClasses.Classes; +using UniGetUI.PackageEngine.Structs; namespace UniGetUI.PackageEngine.Managers.NpmManager { @@ -101,14 +102,14 @@ protected override async Task FindPackages_UnSafe(string query) protected override async Task GetAvailableUpdates_UnSafe() { List Packages = []; - foreach (PackageScope scope in new PackageScope[] { PackageScope.Local, PackageScope.Global }) + foreach (var options in new OverridenInstallationOptions[] { new(PackageScope.Local), new(PackageScope.Global) }) { Process p = new() { StartInfo = new ProcessStartInfo { FileName = Status.ExecutablePath, - Arguments = Properties.ExecutableCallArgs + " outdated --parseable" + (scope == PackageScope.Global ? " --global" : ""), + Arguments = Properties.ExecutableCallArgs + " outdated --parseable" + (options.Scope == PackageScope.Global ? " --global" : ""), RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = true, @@ -139,7 +140,15 @@ protected override async Task GetAvailableUpdates_UnSafe() elements[3] = "%" + elements[3][1..]; } - Packages.Add(new Package(CoreTools.FormatAsName(elements[2].Split('@')[0]).Replace('%', '@'), elements[2].Split('@')[0].Replace('%', '@'), elements[3].Split('@')[^1].Replace('%', '@'), elements[2].Split('@')[^1].Replace('%', '@'), DefaultSource, this, scope)); + Packages.Add(new Package( + CoreTools.FormatAsName(elements[2].Split('@')[0]).Replace('%', '@'), + elements[2].Split('@')[0].Replace('%', '@'), + elements[3].Split('@')[^1].Replace('%', '@'), + elements[2].Split('@')[^1].Replace('%', '@'), + DefaultSource, + this, + options + )); } } @@ -153,14 +162,14 @@ protected override async Task GetAvailableUpdates_UnSafe() protected override async Task GetInstalledPackages_UnSafe() { List Packages = []; - foreach (PackageScope scope in new PackageScope[] { PackageScope.Local, PackageScope.Global }) + foreach (var options in new OverridenInstallationOptions[] { new(PackageScope.Local), new(PackageScope.Global) }) { Process p = new() { StartInfo = new ProcessStartInfo { FileName = Status.ExecutablePath, - Arguments = Properties.ExecutableCallArgs + " list" + (scope == PackageScope.Global ? " --global" : ""), + Arguments = Properties.ExecutableCallArgs + " list" + (options.Scope == PackageScope.Global ? " --global" : ""), RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = true, @@ -191,7 +200,7 @@ protected override async Task GetInstalledPackages_UnSafe() elements[1] = elements[2]; } } - Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], DefaultSource, this, scope)); + Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], DefaultSource, this, options)); } } } diff --git a/src/UniGetUI.PackageEngine.Managers.Npm/Providers/NpmOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Npm/Providers/NpmOperationProvider.cs index 60b0370ed..30a21d8bf 100644 --- a/src/UniGetUI.PackageEngine.Managers.Npm/Providers/NpmOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Npm/Providers/NpmOperationProvider.cs @@ -28,7 +28,7 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn if (options.CustomParameters != null) parameters.AddRange(options.CustomParameters); - if (options.InstallationScope == PackageScope.Global || (options.InstallationScope is null && package.Scope == PackageScope.Global)) + if (package.OverridenOptions.Scope == PackageScope.Global || (package.OverridenOptions.Scope is null && options.InstallationScope == PackageScope.Global)) parameters.Add("--global"); if (options.PreRelease) diff --git a/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs b/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs index 4aa818b22..4d563352d 100644 --- a/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs +++ b/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs @@ -9,6 +9,7 @@ using UniGetUI.PackageEngine.ManagerClasses.Classes; using UniGetUI.PackageEngine.ManagerClasses.Manager; using UniGetUI.PackageEngine.PackageClasses; +using UniGetUI.PackageEngine.Structs; namespace UniGetUI.PackageEngine.Managers.PipManager { @@ -127,7 +128,7 @@ protected override async Task FindPackages_UnSafe(string query) continue; } - Packages.Add(new Package(Core.Tools.CoreTools.FormatAsName(elements[0]), elements[0], elements[1], DefaultSource, this, scope: PackageScope.Global)); + Packages.Add(new Package(Core.Tools.CoreTools.FormatAsName(elements[0]), elements[0], elements[1], DefaultSource, this, new(PackageScope.Global))); } } logger.AddToStdErr(await p.StandardError.ReadToEndAsync()); @@ -188,7 +189,7 @@ protected override async Task GetAvailableUpdates_UnSafe() continue; } - Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], elements[2], DefaultSource, this, scope: PackageScope.Global)); + Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], elements[2], DefaultSource, this, new(PackageScope.Global))); } } logger.AddToStdErr(await p.StandardError.ReadToEndAsync()); @@ -250,7 +251,7 @@ protected override async Task GetInstalledPackages_UnSafe() continue; } - Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], DefaultSource, this, scope: PackageScope.Global)); + Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], DefaultSource, this, new(PackageScope.Global))); } } logger.AddToStdErr(await p.StandardError.ReadToEndAsync()); diff --git a/src/UniGetUI.PackageEngine.Managers.Pip/Providers/PipOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Pip/Providers/PipOperationProvider.cs index 7d842f166..35b8040ac 100644 --- a/src/UniGetUI.PackageEngine.Managers.Pip/Providers/PipOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Pip/Providers/PipOperationProvider.cs @@ -46,7 +46,7 @@ public override IEnumerable GetOperationParameters( if (options.PreRelease) parameters.Add("--pre"); - if (options.InstallationScope == PackageScope.User || (options.InstallationScope is null && package.Scope == PackageScope.User)) + if (package.OverridenOptions.Scope == PackageScope.User || (package.OverridenOptions.Scope is null && options.InstallationScope == PackageScope.User)) parameters.Add("--user"); } @@ -67,9 +67,9 @@ public override OperationVeredict GetOperationResult( string output_string = string.Join("\n", processOutput); - if (output_string.Contains("--user") && package.Scope != PackageScope.User) + if (output_string.Contains("--user") && package.OverridenOptions.Scope != PackageScope.User) { - package.Scope = PackageScope.User; + package.OverridenOptions.Scope = PackageScope.User; return OperationVeredict.AutoRetry; } return OperationVeredict.Failed; diff --git a/src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellOperationProvider.cs index 72f79d62b..874cd502a 100644 --- a/src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellOperationProvider.cs @@ -32,8 +32,7 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn if (options.PreRelease) parameters.Add("-AllowPrerelease"); - if (options.InstallationScope == PackageScope.Global || - (options.InstallationScope is null && package.Scope == PackageScope.Global)) + if (package.OverridenOptions.Scope == PackageScope.Global || (package.OverridenOptions.Scope is null && options.InstallationScope == PackageScope.Global)) parameters.AddRange(["-Scope", "AllUsers"]); else parameters.AddRange(["-Scope", "CurrentUser"]); diff --git a/src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7OperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7OperationProvider.cs index e166c7bd4..c6c4b7ab7 100644 --- a/src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7OperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7OperationProvider.cs @@ -32,8 +32,7 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn if (options.PreRelease) parameters.Add("-AllowPrerelease"); - if (options.InstallationScope == PackageScope.Global || - (options.InstallationScope is null && package.Scope == PackageScope.Global)) + if (package.OverridenOptions.Scope == PackageScope.Global || (package.OverridenOptions.Scope is null && options.InstallationScope == PackageScope.Global)) parameters.AddRange(["-Scope", "AllUsers"]); else parameters.AddRange(["-Scope", "CurrentUser"]); diff --git a/src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopOperationProvider.cs index 0afd8efa3..5901d1359 100644 --- a/src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopOperationProvider.cs @@ -24,8 +24,8 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn }]; parameters.Add($"{package.Source.Name}/{package.Id}"); - if (options.InstallationScope == PackageScope.Global || - (options.InstallationScope is null && package.Scope == PackageScope.Global)) + + if (package.OverridenOptions.Scope == PackageScope.Global || (package.OverridenOptions.Scope is null && options.InstallationScope == PackageScope.Global)) { parameters.Add("--global"); } @@ -58,9 +58,9 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn public override OperationVeredict GetOperationResult(IPackage package, IInstallationOptions options, OperationType operation, IEnumerable processOutput, int returnCode) { string output_string = string.Join("\n", processOutput); - if (output_string.Contains("Try again with the --global (or -g) flag instead") && package.Scope == PackageScope.Local) + if (output_string.Contains("Try again with the --global (or -g) flag instead") && package.OverridenOptions.Scope != PackageScope.Global) { - package.Scope = PackageScope.Global; + package.OverridenOptions.Scope = PackageScope.Global; return OperationVeredict.AutoRetry; } if (output_string.Contains("requires admin rights") || output_string.Contains("requires administrator rights") || output_string.Contains("you need admin rights to install global apps")) diff --git a/src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs b/src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs index c6f711372..8b3be8437 100644 --- a/src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs +++ b/src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs @@ -13,6 +13,7 @@ using UniGetUI.PackageEngine.ManagerClasses.Manager; using UniGetUI.PackageEngine.PackageClasses; using UniGetUI.PackageEngine.ManagerClasses.Classes; +using UniGetUI.PackageEngine.Structs; namespace UniGetUI.PackageEngine.Managers.ScoopManager { @@ -232,13 +233,15 @@ protected override async Task GetAvailableUpdates_UnSafe() continue; } - if (!InstalledPackages.ContainsKey(elements[0] + "." + elements[1])) + if (InstalledPackages.TryGetValue(elements[0] + "." + elements[1], out Package? InstalledPackage) && InstalledPackage is not null) + { + OverridenInstallationOptions options = new(InstalledPackage.OverridenOptions.Scope); + Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], elements[2], InstalledPackage.Source, this, options)); + } + else { Logger.Warn("Upgradable scoop package not listed on installed packages - id=" + elements[0]); - continue; } - - Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], elements[2], InstalledPackages[elements[0] + "." + elements[1]].Source, this, InstalledPackages[elements[0] + "." + elements[1]].Scope)); } } logger.AddToStdErr(await p.StandardError.ReadToEndAsync()); @@ -297,13 +300,11 @@ protected override async Task GetInstalledPackages_UnSafe() continue; } - PackageScope scope = PackageScope.User; - if (line.Contains("Global install")) - { - scope = PackageScope.Global; - } + OverridenInstallationOptions options = new( + line.Contains("Global install") ? PackageScope.Global : PackageScope.User + ); - Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], GetSourceOrDefault(elements[2]), this, scope)); + Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], GetSourceOrDefault(elements[2]), this, options)); } } logger.AddToStdErr(await p.StandardError.ReadToEndAsync()); diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetOperationProvider.cs index 861e85015..a508ae383 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetOperationProvider.cs @@ -46,7 +46,6 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn parameters.Add(options.InteractiveInstallation ? "--interactive" : "--silent"); parameters.AddRange(options.CustomParameters); - if(operation is OperationType.Update) { if (package.Name.Contains("64-bit") || package.Id.ToLower().Contains("x64")) diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/InvalidImportedPackage.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/InvalidImportedPackage.cs index c16e02bac..d3ac5a04f 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/InvalidImportedPackage.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/InvalidImportedPackage.cs @@ -6,6 +6,7 @@ using UniGetUI.PackageEngine.Classes.Serializable; using UniGetUI.PackageEngine.Enums; using UniGetUI.PackageEngine.Interfaces; +using UniGetUI.PackageEngine.Structs; namespace UniGetUI.PackageEngine.PackageClasses { @@ -25,6 +26,9 @@ public bool IsChecked private long __hash; private long __extended_hash; + private static OverridenInstallationOptions __overriden_options; + public ref OverridenInstallationOptions OverridenOptions { get => ref __overriden_options; } + public string Name { get; } public string Id { get; } diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs index c5d9c5061..c5cd16452 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs @@ -10,6 +10,7 @@ using UniGetUI.PackageEngine.Classes.Serializable; using UniGetUI.PackageEngine.Enums; using UniGetUI.PackageEngine.Interfaces; +using UniGetUI.PackageEngine.Structs; namespace UniGetUI.PackageEngine.PackageClasses { @@ -45,6 +46,8 @@ public bool IsChecked set { __is_checked = value; OnPropertyChanged(nameof(IsChecked)); } } + private OverridenInstallationOptions _overriden_options; + public ref OverridenInstallationOptions OverridenOptions { get => ref _overriden_options; } public string Name { get; } public string AutomationName { get; } public string Id { get; } @@ -55,29 +58,40 @@ public bool IsChecked public IManagerSource Source { get; } /// - /// IPackageManager is guaranteed to be IPackageManager, but C# doesn't allow covariant attributes + /// IPackageManager is guaranteed to be PackageManager, but C# doesn't allow covariant attributes /// public IPackageManager Manager { get; } public string NewVersion { get; } public virtual bool IsUpgradable { get; } - public PackageScope Scope { get; set; } - public string SourceAsString { get => Source.AsString; } /// /// Construct a package with a given name, id, version, source and manager, and an optional scope. /// - public Package(string name, string id, string version, IManagerSource source, IPackageManager manager, PackageScope scope = PackageScope.Local) + public Package( + string name, + string id, + string version, + IManagerSource source, + IPackageManager manager, + OverridenInstallationOptions? options = null) { Name = name; Id = id; Version = version; VersionAsFloat = CoreTools.GetVersionStringAsFloat(version); Source = source; - Manager = (IPackageManager)manager; - Scope = scope; + Manager = manager; + + if (options != null) + { + _overriden_options = (OverridenInstallationOptions)options; + } + NewVersion = ""; Tag = PackageTag.Default; - AutomationName = CoreTools.Translate("Package {name} from {manager}", new Dictionary { { "name", Name }, { "manager", Source.AsString_DisplayName } }); + AutomationName = CoreTools.Translate("Package {name} from {manager}", + new Dictionary { { "name", Name }, { "manager", Source.AsString_DisplayName } }); + __hash = CoreTools.HashStringAsLong(Manager.Name + "\\" + Source.Name + "\\" + Id); __versioned_hash = CoreTools.HashStringAsLong(Manager.Name + "\\" + Source.Name + "\\" + Id + "\\" + Version); IsUpgradable = false; @@ -86,8 +100,15 @@ public Package(string name, string id, string version, IManagerSource source, IP /// /// Creates an UpgradablePackage object representing a package that can be upgraded; given its name, id, installed version, new version, source and manager, and an optional scope. /// - public Package(string name, string id, string installed_version, string new_version, IManagerSource source, IPackageManager manager, PackageScope scope = PackageScope.Local) - : this(name, id, installed_version, source, manager, scope) + public Package( + string name, + string id, + string installed_version, + string new_version, + IManagerSource source, + IPackageManager manager, + OverridenInstallationOptions? options = null) + : this(name, id, installed_version, source, manager, options) { IsUpgradable = true; NewVersion = new_version; diff --git a/src/UniGetUI/Interface/SoftwarePages/PackageBundlesPage.cs b/src/UniGetUI/Interface/SoftwarePages/PackageBundlesPage.cs index 8c94f38ad..f2b249b93 100644 --- a/src/UniGetUI/Interface/SoftwarePages/PackageBundlesPage.cs +++ b/src/UniGetUI/Interface/SoftwarePages/PackageBundlesPage.cs @@ -249,7 +249,7 @@ public async Task ImportAndInstallPackage(IEnumerable packages, bool? { if(package is ImportedPackage imported) { - Logger.ImportantInfo($"Registering package {imported.Id} from manager {imported.SourceAsString}"); + Logger.ImportantInfo($"Registering package {imported.Id} from manager {imported.Source.AsString}"); packages_to_install.Add(await imported.RegisterAndGetPackageAsync()); } else diff --git a/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs b/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs index 7e29f5271..41df7a61a 100644 --- a/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs +++ b/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs @@ -49,6 +49,8 @@ public PackageOperation( protected sealed override async Task BuildProcessInstance(ProcessStartInfo startInfo) { + string operation_args = string.Join(" ", Package.Manager.GetOperationParameters(Package, Options, Role)); + if (Options.RunAsAdministrator || Settings.Get("AlwaysElevate" + Package.Manager.Name)) { if (Settings.Get("DoCacheAdminRights") || Settings.Get("DoCacheAdminRightsForBatches")) @@ -56,19 +58,18 @@ protected sealed override async Task BuildProcessInstance(ProcessStartI await CoreTools.CacheUACForCurrentProcess(); } startInfo.FileName = CoreData.GSudoPath; - startInfo.Arguments = $"\"{Package.Manager.Status.ExecutablePath}\" " + Package.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Package.Manager.GetOperationParameters(Package, Options, Role)); + startInfo.Arguments = $"\"{Package.Manager.Status.ExecutablePath}\" {Package.Manager.Properties.ExecutableCallArgs} {operation_args}"; } else { startInfo.FileName = Package.Manager.Status.ExecutablePath; - startInfo.Arguments = Package.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Package.Manager.GetOperationParameters(Package, Options, Role)); + startInfo.Arguments = $"{Package.Manager.Properties.ExecutableCallArgs} {operation_args}"; } - Process process = new() + + return new Process() { StartInfo = startInfo }; - - return process; } #pragma warning disable CS1998