Skip to content

Commit

Permalink
IPackageManager and PackageManager will not implement the PackageProv…
Browse files Browse the repository at this point in the history
…iders
  • Loading branch information
marticliment committed Nov 20, 2024
1 parent e9c5fc9 commit 814ad60
Show file tree
Hide file tree
Showing 35 changed files with 230 additions and 335 deletions.
10 changes: 3 additions & 7 deletions src/UniGetUI.PAckageEngine.Interfaces/IPackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace UniGetUI.PackageEngine.Interfaces
{
public interface IPackageManager : ISourceProvider, IPackageDetailsProvider, IOperationProvider
public interface IPackageManager
{
public ManagerProperties Properties { get; }
public ManagerCapabilities Capabilities { get; }
Expand All @@ -15,10 +15,9 @@ public interface IPackageManager : ISourceProvider, IPackageDetailsProvider, IOp
public IManagerSource DefaultSource { get; }
public bool ManagerReady { get; }
public IManagerLogger TaskLogger { get; }

public ISourceProvider? SourceProvider { get; }
public IPackageDetailsProvider? PackageDetailsProvider { get; }
public IOperationProvider? OperationProvider { get; }
public IPackageDetailsProvider PackageDetailsProvider { get; }
public IOperationProvider OperationProvider { get; }

/// <summary>
/// Initializes the Package Manager (asynchronously). Must be run before using any other method of the manager.
Expand Down Expand Up @@ -67,8 +66,5 @@ public interface IPackageManager : ISourceProvider, IPackageDetailsProvider, IOp
/// an example
/// </summary>
public void AttemptFastRepair();

public IManagerSource GetSourceOrDefault(string SourceName);
public IManagerSource? GetSourceIfExists(string SourceName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace UniGetUI.PackageEngine.Interfaces.ManagerProviders
{
public interface ISourceProvider
{
public ISourceFactory SourceFactory { get; }
public ISourceFactory Factory { get; }

/// <summary>
/// Returns the command-line parameters required to add the given source to the manager.
Expand Down Expand Up @@ -43,5 +43,7 @@ public interface ISourceProvider
/// </summary>
/// <returns>An array of ManagerSource objects</returns>
public IEnumerable<IManagerSource> GetSources();


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace UniGetUI.PackageEngine.Managers.CargoManager;

internal sealed class CargoOperationProvider(Cargo cargo) : BaseOperationProvider<Cargo>(cargo)
{
public override IEnumerable<string> GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
protected override IEnumerable<string> _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
{
var version = options.Version == string.Empty ? package.Version : options.Version;
List<string> parameters = operation switch
Expand All @@ -20,7 +20,7 @@ public override IEnumerable<string> GetOperationParameters(IPackage package, IIn
return parameters;
}

public override OperationVeredict GetOperationResult(IPackage package, OperationType operation, IEnumerable<string> processOutput, int returnCode)
protected override OperationVeredict _getOperationResult(IPackage package, OperationType operation, IEnumerable<string> processOutput, int returnCode)
{
return returnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class ChocolateyOperationProvider : BaseOperationProvider<Chocol
{
public ChocolateyOperationProvider(Chocolatey manager) : base(manager) { }

public override IEnumerable<string> GetOperationParameters(
protected override IEnumerable<string> _getOperationParameters(
IPackage package,
IInstallationOptions options,
OperationType operation)
Expand Down Expand Up @@ -47,7 +47,7 @@ public override IEnumerable<string> GetOperationParameters(
return parameters;
}

public override OperationVeredict GetOperationResult(
protected override OperationVeredict _getOperationResult(
IPackage package,
OperationType operation,
IEnumerable<string> processOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class DotNetOperationProvider : BaseOperationProvider<DotNet>
{
public DotNetOperationProvider(DotNet manager) : base(manager) { }

public override IEnumerable<string> GetOperationParameters(
protected override IEnumerable<string> _getOperationParameters(
IPackage package,
IInstallationOptions options,
OperationType operation)
Expand Down Expand Up @@ -46,7 +46,7 @@ public override IEnumerable<string> GetOperationParameters(
return parameters;
}

public override OperationVeredict GetOperationResult(
protected override OperationVeredict _getOperationResult(
IPackage package,
OperationType operation,
IEnumerable<string> processOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected sealed override IEnumerable<Package> FindPackages_UnSafe(string query)
IEnumerable<IManagerSource> sources;
if (Capabilities.SupportsCustomSources)
{
sources = GetSources();
sources = SourceProvider.GetSources();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class NpmOperationProvider : BaseOperationProvider<Npm>
{
public NpmOperationProvider(Npm manager) : base(manager) { }

public override IEnumerable<string> GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
protected override IEnumerable<string> _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
{
List<string> parameters = operation switch {
OperationType.Install => [Manager.Properties.InstallVerb, $"{package.Id}@{(options.Version == string.Empty? package.Version: options.Version)}"],
Expand All @@ -30,7 +30,7 @@ public override IEnumerable<string> GetOperationParameters(IPackage package, IIn
return parameters;
}

public override OperationVeredict GetOperationResult(
protected override OperationVeredict _getOperationResult(
IPackage package,
OperationType operation,
IEnumerable<string> processOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class PipOperationProvider : BaseOperationProvider<Pip>
{
public PipOperationProvider(Pip manager) : base(manager) { }

public override IEnumerable<string> GetOperationParameters(
protected override IEnumerable<string> _getOperationParameters(
IPackage package,
IInstallationOptions options,
OperationType operation)
Expand Down Expand Up @@ -46,7 +46,7 @@ public override IEnumerable<string> GetOperationParameters(
return parameters;
}

public override OperationVeredict GetOperationResult(
protected override OperationVeredict _getOperationResult(
IPackage package,
OperationType operation,
IEnumerable<string> processOutput,
Expand Down
9 changes: 6 additions & 3 deletions src/UniGetUI.PackageEngine.Managers.PowerShell/PowerShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UniGetUI.PackageEngine.Classes.Manager;
using UniGetUI.PackageEngine.Classes.Manager.ManagerHelpers;
using UniGetUI.PackageEngine.Enums;
using UniGetUI.PackageEngine.Interfaces.ManagerProviders;
using UniGetUI.PackageEngine.ManagerClasses.Classes;
using UniGetUI.PackageEngine.ManagerClasses.Manager;
using UniGetUI.PackageEngine.Managers.Chocolatey;
Expand Down Expand Up @@ -130,7 +131,8 @@ function Test-GalleryModuleUpdate {
continue;
}

Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], elements[2], GetSourceOrDefault(elements[3]), this));
Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1],
elements[2], SourceProvider.Factory.GetSourceOrDefault(elements[3]), this));
}

logger.AddToStdErr(p.StandardError.ReadToEnd());
Expand Down Expand Up @@ -186,7 +188,8 @@ protected override IEnumerable<Package> GetInstalledPackages_UnSafe()
elements[i] = elements[i].Trim();
}

Packages.Add(new Package(CoreTools.FormatAsName(elements[1]), elements[1], elements[0], GetSourceOrDefault(elements[2]), this));
Packages.Add(new Package(CoreTools.FormatAsName(elements[1]), elements[1], elements[0],
SourceProvider.Factory.GetSourceOrDefault(elements[2]), this));
}
}

Expand Down Expand Up @@ -220,7 +223,7 @@ protected override ManagerStatus LoadManager()
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
StandardOutputEncoding = System.Text.Encoding.UTF8
StandardOutputEncoding = Encoding.UTF8
}
};
process.Start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class PowerShellOperationProvider : BaseOperationProvider<PowerS
{
public PowerShellOperationProvider(PowerShell manager) : base(manager) { }

public override IEnumerable<string> GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
protected override IEnumerable<string> _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
{
List<string> parameters = [operation switch {
OperationType.Install => Manager.Properties.InstallVerb,
Expand Down Expand Up @@ -48,7 +48,7 @@ public override IEnumerable<string> GetOperationParameters(IPackage package, IIn
return parameters;
}

public override OperationVeredict GetOperationResult(
protected override OperationVeredict _getOperationResult(
IPackage package,
OperationType operation,
IEnumerable<string> processOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ function Test-GalleryModuleUpdate {
continue;
}

Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], elements[2], GetSourceOrDefault(elements[3]), this));
Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1],
elements[2], SourceProvider.Factory.GetSourceOrDefault(elements[3]), this));
}

logger.AddToStdErr(p.StandardError.ReadToEnd());
Expand Down Expand Up @@ -187,7 +188,8 @@ protected override IEnumerable<Package> GetInstalledPackages_UnSafe()
elements[i] = elements[i].Trim();
}

Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1], GetSourceOrDefault(elements[2]), this));
Packages.Add(new Package(CoreTools.FormatAsName(elements[0]), elements[0], elements[1],
SourceProvider.Factory.GetSourceOrDefault(elements[2]), this));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class PowerShell7OperationProvider : BaseOperationProvider<Power
{
public PowerShell7OperationProvider(PowerShell7 manager) : base(manager) { }

public override IEnumerable<string> GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
protected override IEnumerable<string> _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
{
List<string> parameters = [operation switch {
OperationType.Install => Manager.Properties.InstallVerb,
Expand Down Expand Up @@ -44,7 +44,7 @@ public override IEnumerable<string> GetOperationParameters(IPackage package, IIn
return parameters;
}

public override OperationVeredict GetOperationResult(
protected override OperationVeredict _getOperationResult(
IPackage package,
OperationType operation,
IEnumerable<string> processOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class ScoopOperationProvider : BaseOperationProvider<Scoop>
{
public ScoopOperationProvider(Scoop manager) : base(manager) { }

public override IEnumerable<string> GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
protected override IEnumerable<string> _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
{
List<string> parameters = [operation switch {
OperationType.Install => Manager.Properties.InstallVerb,
Expand Down Expand Up @@ -55,7 +55,7 @@ public override IEnumerable<string> GetOperationParameters(IPackage package, IIn
return parameters;
}

public override OperationVeredict GetOperationResult(
protected override OperationVeredict _getOperationResult(
IPackage package,
OperationType operation,
IEnumerable<string> processOutput,
Expand Down
4 changes: 2 additions & 2 deletions src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected override IEnumerable<Package> FindPackages_UnSafe(string query)
if (line.StartsWith("'"))
{
string sourceName = line.Split(" ")[0].Replace("'", "");
source = GetSourceOrDefault(sourceName);
source = SourceProvider.Factory.GetSourceOrDefault(sourceName);
}
else if (line.Trim() != "")
{
Expand Down Expand Up @@ -325,7 +325,7 @@ private IEnumerable<Package> _getInstalledPackages_UnSafe()
CoreTools.FormatAsName(elements[0]),
elements[0],
elements[1],
GetSourceOrDefault(elements[2]),
SourceProvider.Factory.GetSourceOrDefault(elements[2]),
this,
options));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal sealed class VcpkgOperationProvider : BaseOperationProvider<Vcpkg>
{
public VcpkgOperationProvider(Vcpkg manager) : base(manager) { }

public override IEnumerable<string> GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
protected override IEnumerable<string> _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
{
List<string> parameters = operation switch {
OperationType.Install => [Manager.Properties.InstallVerb, package.Id],
Expand All @@ -22,7 +22,7 @@ public override IEnumerable<string> GetOperationParameters(IPackage package, IIn
return parameters;
}

public override OperationVeredict GetOperationResult(
protected override OperationVeredict _getOperationResult(
IPackage package,
OperationType operation,
IEnumerable<string> processOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected override OperationVeredict _getRemoveSourceOperationVeredict(IManagerS
protected override IEnumerable<IManagerSource> GetSources_UnSafe()
{
List<ManagerSource> Sources = [];

foreach (string Triplet in Vcpkg.GetSystemTriplets()) {
Sources.Add(new ManagerSource(Manager, Triplet, Vcpkg.URI_VCPKG_IO));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static string GetIdNamePiece(IPackage package)

public WinGetOperationProvider(WinGet manager) : base(manager) { }

public override IEnumerable<string> GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
protected override IEnumerable<string> _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation)
{
List<string> parameters = [operation switch {
OperationType.Install => Manager.Properties.InstallVerb,
Expand Down Expand Up @@ -108,7 +108,7 @@ public override IEnumerable<string> GetOperationParameters(IPackage package, IIn
return parameters;
}

public override OperationVeredict GetOperationResult(
protected override OperationVeredict _getOperationResult(
IPackage package,
OperationType operation,
IEnumerable<string> processOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public IEnumerable<Package> GetAvailableUpdates_UnSafe()
else
{
string sourceName = line[(SourceIndex - offset)..].Trim().Split(' ')[0];
source = Manager.GetSourceOrDefault(sourceName);
source = Manager.SourceProvider.Factory.GetSourceOrDefault(sourceName);
}

Packages.Add(new Package(name, id, version, newVersion, source, Manager));
Expand Down Expand Up @@ -190,7 +190,7 @@ public IEnumerable<Package> GetInstalledPackages_UnSafe()
else
{
string sourceName = line[(SourceIndex - offset)..].Trim().Split(' ')[0].Trim();
source = Manager.GetSourceOrDefault(sourceName);
source = Manager.SourceProvider.Factory.GetSourceOrDefault(sourceName);
}
Packages.Add(new Package(name, id, version, source, Manager));
}
Expand Down Expand Up @@ -267,7 +267,7 @@ public IEnumerable<Package> FindPackages_UnSafe(string query)
else
{
string sourceName = line[(SourceIndex - offset)..].Trim().Split(' ')[0];
source = Manager.GetSourceOrDefault(sourceName);
source = Manager.SourceProvider.Factory.GetSourceOrDefault(sourceName);
}
Packages.Add(new Package(name, id, version, source, Manager));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public IEnumerable<Package> FindPackages_UnSafe(string query)
try
{
// Get the source for the catalog
IManagerSource source = Manager.GetSourceOrDefault(CatalogTaskPair.Key.Item1.Info.Name);
IManagerSource source = Manager.SourceProvider.Factory.GetSourceOrDefault(CatalogTaskPair.Key.Item1.Info.Name);

FindPackagesResult FoundPackages = CatalogTaskPair.Value.Result;
foreach (MatchResult matchResult in FoundPackages.Matches.ToArray())
Expand All @@ -127,15 +127,6 @@ public IEnumerable<Package> FindPackages_UnSafe(string query)

var overriden_options = new OverridenInstallationOptions();

/*var installOptions = Factory.CreateInstallOptions();
if (catPkg.DefaultInstallVersion.HasApplicableInstaller(installOptions))
{
var options = catPkg.DefaultInstallVersion.GetApplicableInstaller(installOptions);
if (options.ElevationRequirement is ElevationRequirement.ElevationRequired or ElevationRequirement.ElevatesSelf)
overriden_options.RunAsAdministrator = true;
else if (options.ElevationRequirement is ElevationRequirement.ElevationProhibited)
overriden_options.RunAsAdministrator = false;
}*/
var UniGetUIPackage = new Package(
nativePackage.Name,
nativePackage.Id,
Expand Down Expand Up @@ -168,7 +159,7 @@ public IEnumerable<Package> GetAvailableUpdates_UnSafe()
if (nativePackage.IsUpdateAvailable)
{
IManagerSource source;
source = Manager.GetSourceOrDefault(nativePackage.DefaultInstallVersion.PackageCatalog.Info.Name);
source = Manager.SourceProvider.Factory.GetSourceOrDefault(nativePackage.DefaultInstallVersion.PackageCatalog.Info.Name);

var UniGetUIPackage = new Package(
nativePackage.Name,
Expand Down Expand Up @@ -197,7 +188,7 @@ public IEnumerable<Package> GetInstalledPackages_UnSafe()
IManagerSource source;
if (nativePackage.DefaultInstallVersion is not null)
{
source = Manager.GetSourceOrDefault(nativePackage.DefaultInstallVersion.PackageCatalog.Info.Name);
source = Manager.SourceProvider.Factory.GetSourceOrDefault(nativePackage.DefaultInstallVersion.PackageCatalog.Info.Name);
}
else
{
Expand Down
Loading

0 comments on commit 814ad60

Please sign in to comment.