Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish the modularization of package managers. #3000

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions src/UniGetUI.Core.Classes.Tests/SingletonBaseTest.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/UniGetUI.Core.Classes/SingletonBase.cs

This file was deleted.

3 changes: 1 addition & 2 deletions src/UniGetUI.Core.IconStore/IconCacheEngine.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.ObjectModel;
using System.Drawing;
using System.Security.Cryptography;
using Windows.ApplicationModel;
using Windows.Graphics.Imaging;
Expand Down Expand Up @@ -243,7 +242,7 @@ private static void DownsizeImage(string cachedIconFile, string extension)
int width, height;

using (var fileStream = new FileStream(cachedIconFile, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var image = Image.FromStream(fileStream, false, false))
using (var image = System.Drawing.Image.FromStream(fileStream, false, false))
{
height = image.Height;
width = image.Width;
Expand Down
14 changes: 6 additions & 8 deletions src/UniGetUI.PAckageEngine.Interfaces/IPackageManager.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using UniGetUI.PackageEngine.Classes.Manager.Classes;
using UniGetUI.PackageEngine.Classes.Manager.ManagerHelpers;
using UniGetUI.PackageEngine.Interfaces.ManagerProviders;
using UniGetUI.PackageEngine.ManagerClasses.Classes;
using UniGetUI.PackageEngine.ManagerClasses.Manager;

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 +16,10 @@ 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 IMultiSourceHelper SourcesHelper { get; }
public IPackageDetailsHelper DetailsHelper { get; }
public IPackageOperationHelper OperationHelper { get; }
public IEnumerable<ManagerDependency> Dependencies { get; }

/// <summary>
/// Initializes the Package Manager (asynchronously). Must be run before using any other method of the manager.
Expand Down Expand Up @@ -67,8 +68,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 @@ -2,9 +2,12 @@

namespace UniGetUI.PackageEngine.Interfaces.ManagerProviders
{
public interface ISourceProvider
/// <summary>
/// Has the required methods to handle a package manager that can handle multiple source
/// </summary>
public interface IMultiSourceHelper
{
public ISourceFactory SourceFactory { get; }
public ISourceFactory Factory { get; }

/// <summary>
/// Returns the command-line parameters required to add the given source to the manager.
Expand All @@ -27,7 +30,7 @@ public interface ISourceProvider
/// <param name="ReturnCode">The return code of the operation</param>
/// <param name="Output">the command-line output of the operation</param>
/// <returns>An OperationVeredict value</returns>
public OperationVeredict GetAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output);
public OperationVeredict GetAddOperationVeredict(IManagerSource source, int ReturnCode, string[] Output);

/// <summary>
/// Checks the result of attempting to remove a source
Expand All @@ -36,12 +39,14 @@ public interface ISourceProvider
/// <param name="ReturnCode">The return code of the operation</param>
/// <param name="Output">the command-line output of the operation</param>
/// <returns>An OperationVeredict value</returns>
public OperationVeredict GetRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output);
public OperationVeredict GetRemoveOperationVeredict(IManagerSource source, int ReturnCode, string[] Output);

/// <summary>
/// Returns the available sources
/// </summary>
/// <returns>An array of ManagerSource objects</returns>
public IEnumerable<IManagerSource> GetSources();


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace UniGetUI.PackageEngine.Interfaces.ManagerProviders
{
public interface IPackageDetailsProvider
/// <summary>
/// Provides useful information about the packages
/// </summary>
public interface IPackageDetailsHelper
{
/// <summary>
/// Returns a PackageDetails object that represents the details for the given Package object.
Expand All @@ -11,7 +14,7 @@ public interface IPackageDetailsProvider
/// </summary>
/// <param name="details">The PackageDetails instance to load</param>
/// <returns>A PackageDetails object</returns>
public void GetPackageDetails(IPackageDetails details);
public void GetDetails(IPackageDetails details);

/// <summary>
/// Returns the available versions to install for the given package.
Expand All @@ -20,28 +23,28 @@ public interface IPackageDetailsProvider
/// </summary>
/// <param name="package">The package from which to load its versions</param>
/// <returns>An array of stings containing the found versions, an empty array if none.</returns>
public IEnumerable<string> GetPackageVersions(IPackage package);
public IEnumerable<string> GetVersions(IPackage package);

/// <summary>
/// Returns an Uri pointing to the icon of this package.
/// The uri may be either a ms-appx:/// url or a http(s):// protocol url
/// </summary>
/// <param name="package">The package from which to load the icon</param>
/// <returns>A full path to a valid icon file</returns>
public CacheableIcon? GetPackageIconUrl(IPackage package);
public CacheableIcon? GetIcon(IPackage package);

/// <summary>
/// Returns the URLs to the screenshots (if any) of this package.
/// </summary>
/// <param name="package">The package from which to load the screenshots</param>
/// <returns>An array with valid URIs to the screenshots</returns>
public IEnumerable<Uri> GetPackageScreenshotsUrl(IPackage package);
public IEnumerable<Uri> GetScreenshots(IPackage package);

/// <summary>
/// Returns the location where the package is installed, or null if the location cannot be loaded.
/// </summary>
/// <param name="package">The package for which to get the location</param>
/// <returns>A valid path in the form of a string or a null object</returns>
public string? GetPackageInstallLocation(IPackage package);
public string? GetInstallLocation(IPackage package);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using UniGetUI.PackageEngine.Enums;

namespace UniGetUI.PackageEngine.Interfaces.ManagerProviders
{
/// <summary>
/// Handled the process of installing and uninstalling packages
/// </summary>
public interface IPackageOperationHelper
{
/// <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 IEnumerable<string> GetParameters(
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 OperationVeredict GetResult(
IPackage package,
OperationType operation,
IEnumerable<string> processOutput,
int returnCode
);
}
}

This file was deleted.

4 changes: 2 additions & 2 deletions src/UniGetUI.PackageEngine.Managers.Cargo/Cargo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public Cargo()
KnownSources = [cratesIo]
};

PackageDetailsProvider = new CargoPackageDetailsProvider(this);
OperationProvider = new CargoOperationProvider(this);
DetailsHelper = new CargoPkgDetailsHelper(this);
OperationHelper = new CargoPkgOperationHelper(this);
}

protected override IEnumerable<Package> FindPackages_UnSafe(string query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using UniGetUI.PackageEngine.ManagerClasses.Manager;

namespace UniGetUI.PackageEngine.Managers.CargoManager;
internal sealed class CargoPackageDetailsProvider(Cargo manager) : BasePackageDetailsProvider<PackageManager>(manager)
internal sealed class CargoPkgDetailsHelper(Cargo manager) : BasePkgDetailsHelper(manager)
{
protected override void GetDetails_UnSafe(IPackageDetails details)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace UniGetUI.PackageEngine.Managers.CargoManager;

internal sealed class CargoOperationProvider(Cargo cargo) : BaseOperationProvider<Cargo>(cargo)
internal sealed class CargoPkgOperationHelper(Cargo cargo) : PackagePkgOperationHelper(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
6 changes: 3 additions & 3 deletions src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public Chocolatey()

};

SourceProvider = new ChocolateySourceProvider(this);
PackageDetailsProvider = new ChocolateyDetailsProvider(this);
OperationProvider = new ChocolateyOperationProvider(this);
SourcesHelper = new ChocolateySourceHelper(this);
DetailsHelper = new ChocolateyDetailsHelper(this);
OperationHelper = new ChocolateyPkgOperationHelper(this);
}

protected override IEnumerable<Package> GetAvailableUpdates_UnSafe()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace UniGetUI.PackageEngine.Managers.Chocolatey
{
public class ChocolateyDetailsProvider : BaseNuGetDetailsProvider
public class ChocolateyDetailsHelper : BaseNuGetDetailsHelper
{
public ChocolateyDetailsProvider(BaseNuGet manager) : base(manager)
public ChocolateyDetailsHelper(BaseNuGet manager) : base(manager)
{ }

protected override IEnumerable<string> GetInstallableVersions_UnSafe(IPackage package)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using UniGetUI.PackageEngine.Interfaces;

namespace UniGetUI.PackageEngine.Managers.ChocolateyManager;
internal sealed class ChocolateyOperationProvider : BaseOperationProvider<Chocolatey>
internal sealed class ChocolateyPkgOperationHelper : PackagePkgOperationHelper
{
public ChocolateyOperationProvider(Chocolatey manager) : base(manager) { }
public ChocolateyPkgOperationHelper(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,9 +8,9 @@

namespace UniGetUI.PackageEngine.Managers.ChocolateyManager
{
internal sealed class ChocolateySourceProvider : BaseSourceProvider<PackageManager>
internal sealed class ChocolateySourceHelper : BaseSourceHelper
{
public ChocolateySourceProvider(Chocolatey manager) : base(manager) { }
public ChocolateySourceHelper(Chocolatey manager) : base(manager) { }

public override string[] GetAddSourceParameters(IManagerSource source)
{
Expand Down
4 changes: 2 additions & 2 deletions src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public DotNet()
KnownSources = [new ManagerSource(this, "nuget.org", new Uri("https://www.nuget.org/api/v2"))],
};

PackageDetailsProvider = new DotNetDetailsProvider(this);
OperationProvider = new DotNetOperationProvider(this);
DetailsHelper = new DotNetDetailsHelper(this);
OperationHelper = new DotNetPkgOperationHelper(this);
}

protected override IEnumerable<Package> GetAvailableUpdates_UnSafe()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace UniGetUI.PackageEngine.Managers.Chocolatey
{
public class DotNetDetailsProvider : BaseNuGetDetailsProvider
public class DotNetDetailsHelper : BaseNuGetDetailsHelper
{
public DotNetDetailsProvider(BaseNuGet manager) : base(manager)
public DotNetDetailsHelper(BaseNuGet manager) : base(manager)
{ }

protected override string? GetInstallLocation_UnSafe(IPackage package)
Expand Down
Loading
Loading