Skip to content

Commit

Permalink
Add base OverridenInstallationOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
marticliment committed Jul 30, 2024
1 parent bf06452 commit 17e8c40
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 55 deletions.
5 changes: 2 additions & 3 deletions src/UniGetUI.PAckageEngine.Interfaces/IPackage.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -19,8 +19,7 @@ public interface IPackage : INotifyPropertyChanged, IEquatable<IPackage>
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; }

/// <summary>
Expand Down
20 changes: 20 additions & 0 deletions src/UniGetUI.PackageEngine.Enums/OverridenInstallationOptions.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
24 changes: 20 additions & 4 deletions src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -140,7 +141,15 @@ protected override async Task<Package[]> 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());
Expand All @@ -153,14 +162,14 @@ protected override async Task<Package[]> GetAvailableUpdates_UnSafe()
protected override async Task<Package[]> GetInstalledPackages_UnSafe()
{
List<Package> 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,
Expand Down Expand Up @@ -202,7 +211,14 @@ protected override async Task<Package[]> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override IEnumerable<string> 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)
Expand Down
21 changes: 15 additions & 6 deletions src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -101,14 +102,14 @@ protected override async Task<Package[]> FindPackages_UnSafe(string query)
protected override async Task<Package[]> GetAvailableUpdates_UnSafe()
{
List<Package> 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,
Expand Down Expand Up @@ -139,7 +140,15 @@ protected override async Task<Package[]> 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
));
}
}

Expand All @@ -153,14 +162,14 @@ protected override async Task<Package[]> GetAvailableUpdates_UnSafe()
protected override async Task<Package[]> GetInstalledPackages_UnSafe()
{
List<Package> 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,
Expand Down Expand Up @@ -191,7 +200,7 @@ protected override async Task<Package[]> 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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override IEnumerable<string> 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)
Expand Down
7 changes: 4 additions & 3 deletions src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -127,7 +128,7 @@ protected override async Task<Package[]> 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());
Expand Down Expand Up @@ -188,7 +189,7 @@ protected override async Task<Package[]> 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());
Expand Down Expand Up @@ -250,7 +251,7 @@ protected override async Task<Package[]> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override IEnumerable<string> 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");
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public override IEnumerable<string> 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"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public override IEnumerable<string> 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"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public override IEnumerable<string> 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");
}
Expand Down Expand Up @@ -58,9 +58,9 @@ public override IEnumerable<string> GetOperationParameters(IPackage package, IIn
public override OperationVeredict GetOperationResult(IPackage package, IInstallationOptions options, OperationType operation, IEnumerable<string> 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"))
Expand Down
21 changes: 11 additions & 10 deletions src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -232,13 +233,15 @@ protected override async Task<Package[]> 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());
Expand Down Expand Up @@ -297,13 +300,11 @@ protected override async Task<Package[]> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public override IEnumerable<string> 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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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; }
Expand Down
Loading

0 comments on commit 17e8c40

Please sign in to comment.