diff --git a/src/UniGetUI.Core.Classes.Tests/SingletonBaseTest.cs b/src/UniGetUI.Core.Classes.Tests/SingletonBaseTest.cs deleted file mode 100644 index bb806b5fa..000000000 --- a/src/UniGetUI.Core.Classes.Tests/SingletonBaseTest.cs +++ /dev/null @@ -1,37 +0,0 @@ -#pragma warning disable CA1852 -namespace UniGetUI.Core.Classes.Tests -{ - public class SingletonBaseTest - { - - private class InheritedClass1 : SingletonBase - { - public int Attribute1 { get; set; } - } - - private class InheritedClass2 : SingletonBase - { - public int Attribute1 { get; set; } - } - - [Fact] - public void TestSingletonClass() - { - InheritedClass1 Type1Instance1 = InheritedClass1.Instance; - Type1Instance1.Attribute1 = 1; - - InheritedClass1 Type1Instance2 = InheritedClass1.Instance; - Type1Instance2.Attribute1 = 3; - - Assert.Equal(Type1Instance1.Attribute1, Type1Instance2.Attribute1); - Assert.Equal(Type1Instance1, Type1Instance2); - - InheritedClass2 Type2Instance1 = new() - { - Attribute1 = 2 - }; - - Assert.NotEqual(Type1Instance1.Attribute1, Type2Instance1.Attribute1); - } - } -} diff --git a/src/UniGetUI.Core.Classes/SingletonBase.cs b/src/UniGetUI.Core.Classes/SingletonBase.cs deleted file mode 100644 index e9a4ec699..000000000 --- a/src/UniGetUI.Core.Classes/SingletonBase.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace UniGetUI.Core.Classes -{ - public abstract class SingletonBase where T : SingletonBase - { - private static readonly Lazy Lazy = - new(() => (Activator.CreateInstance(typeof(T), true) as T)!); - - public static T Instance => Lazy.Value; - } -} diff --git a/src/UniGetUI.Core.IconStore/IconCacheEngine.cs b/src/UniGetUI.Core.IconStore/IconCacheEngine.cs index 1b50b97ce..cea19e121 100644 --- a/src/UniGetUI.Core.IconStore/IconCacheEngine.cs +++ b/src/UniGetUI.Core.IconStore/IconCacheEngine.cs @@ -1,5 +1,4 @@ using System.Collections.ObjectModel; -using System.Drawing; using System.Security.Cryptography; using Windows.ApplicationModel; using Windows.Graphics.Imaging; @@ -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; diff --git a/src/UniGetUI.PAckageEngine.Interfaces/IPackageManager.cs b/src/UniGetUI.PAckageEngine.Interfaces/IPackageManager.cs index 28bee7aad..dc979dad6 100644 --- a/src/UniGetUI.PAckageEngine.Interfaces/IPackageManager.cs +++ b/src/UniGetUI.PAckageEngine.Interfaces/IPackageManager.cs @@ -1,3 +1,4 @@ +using UniGetUI.PackageEngine.Classes.Manager.Classes; using UniGetUI.PackageEngine.Classes.Manager.ManagerHelpers; using UniGetUI.PackageEngine.Interfaces.ManagerProviders; using UniGetUI.PackageEngine.ManagerClasses.Classes; @@ -5,7 +6,7 @@ namespace UniGetUI.PackageEngine.Interfaces { - public interface IPackageManager : ISourceProvider, IPackageDetailsProvider, IOperationProvider + public interface IPackageManager { public ManagerProperties Properties { get; } public ManagerCapabilities Capabilities { get; } @@ -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 Dependencies { get; } /// /// Initializes the Package Manager (asynchronously). Must be run before using any other method of the manager. @@ -67,8 +68,5 @@ public interface IPackageManager : ISourceProvider, IPackageDetailsProvider, IOp /// an example /// public void AttemptFastRepair(); - - public IManagerSource GetSourceOrDefault(string SourceName); - public IManagerSource? GetSourceIfExists(string SourceName); } } diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerDependency.cs b/src/UniGetUI.PAckageEngine.Interfaces/ManagerDependency.cs similarity index 100% rename from src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerDependency.cs rename to src/UniGetUI.PAckageEngine.Interfaces/ManagerDependency.cs diff --git a/src/UniGetUI.PAckageEngine.Interfaces/ManagerProviders/ISourceProvider.cs b/src/UniGetUI.PAckageEngine.Interfaces/ManagerHelpers/IMultiSourceHelper.cs similarity index 80% rename from src/UniGetUI.PAckageEngine.Interfaces/ManagerProviders/ISourceProvider.cs rename to src/UniGetUI.PAckageEngine.Interfaces/ManagerHelpers/IMultiSourceHelper.cs index e2da4960e..4a4747612 100644 --- a/src/UniGetUI.PAckageEngine.Interfaces/ManagerProviders/ISourceProvider.cs +++ b/src/UniGetUI.PAckageEngine.Interfaces/ManagerHelpers/IMultiSourceHelper.cs @@ -2,9 +2,12 @@ namespace UniGetUI.PackageEngine.Interfaces.ManagerProviders { - public interface ISourceProvider + /// + /// Has the required methods to handle a package manager that can handle multiple source + /// + public interface IMultiSourceHelper { - public ISourceFactory SourceFactory { get; } + public ISourceFactory Factory { get; } /// /// Returns the command-line parameters required to add the given source to the manager. @@ -27,7 +30,7 @@ public interface ISourceProvider /// The return code of the operation /// the command-line output of the operation /// An OperationVeredict value - public OperationVeredict GetAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output); + public OperationVeredict GetAddOperationVeredict(IManagerSource source, int ReturnCode, string[] Output); /// /// Checks the result of attempting to remove a source @@ -36,12 +39,14 @@ public interface ISourceProvider /// The return code of the operation /// the command-line output of the operation /// An OperationVeredict value - public OperationVeredict GetRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output); + public OperationVeredict GetRemoveOperationVeredict(IManagerSource source, int ReturnCode, string[] Output); /// /// Returns the available sources /// /// An array of ManagerSource objects public IEnumerable GetSources(); + + } } diff --git a/src/UniGetUI.PAckageEngine.Interfaces/ManagerProviders/IPackageDetailsProvider.cs b/src/UniGetUI.PAckageEngine.Interfaces/ManagerHelpers/IPackageDetailsHelper.cs similarity index 81% rename from src/UniGetUI.PAckageEngine.Interfaces/ManagerProviders/IPackageDetailsProvider.cs rename to src/UniGetUI.PAckageEngine.Interfaces/ManagerHelpers/IPackageDetailsHelper.cs index 6a58c664a..68a62c601 100644 --- a/src/UniGetUI.PAckageEngine.Interfaces/ManagerProviders/IPackageDetailsProvider.cs +++ b/src/UniGetUI.PAckageEngine.Interfaces/ManagerHelpers/IPackageDetailsHelper.cs @@ -2,7 +2,10 @@ namespace UniGetUI.PackageEngine.Interfaces.ManagerProviders { - public interface IPackageDetailsProvider + /// + /// Provides useful information about the packages + /// + public interface IPackageDetailsHelper { /// /// Returns a PackageDetails object that represents the details for the given Package object. @@ -11,7 +14,7 @@ public interface IPackageDetailsProvider /// /// The PackageDetails instance to load /// A PackageDetails object - public void GetPackageDetails(IPackageDetails details); + public void GetDetails(IPackageDetails details); /// /// Returns the available versions to install for the given package. @@ -20,7 +23,7 @@ public interface IPackageDetailsProvider /// /// The package from which to load its versions /// An array of stings containing the found versions, an empty array if none. - public IEnumerable GetPackageVersions(IPackage package); + public IEnumerable GetVersions(IPackage package); /// /// Returns an Uri pointing to the icon of this package. @@ -28,20 +31,20 @@ public interface IPackageDetailsProvider /// /// The package from which to load the icon /// A full path to a valid icon file - public CacheableIcon? GetPackageIconUrl(IPackage package); + public CacheableIcon? GetIcon(IPackage package); /// /// Returns the URLs to the screenshots (if any) of this package. /// /// The package from which to load the screenshots /// An array with valid URIs to the screenshots - public IEnumerable GetPackageScreenshotsUrl(IPackage package); + public IEnumerable GetScreenshots(IPackage package); /// /// Returns the location where the package is installed, or null if the location cannot be loaded. /// /// The package for which to get the location /// A valid path in the form of a string or a null object - public string? GetPackageInstallLocation(IPackage package); + public string? GetInstallLocation(IPackage package); } } diff --git a/src/UniGetUI.PAckageEngine.Interfaces/ManagerHelpers/IPackageOperationHelper.cs b/src/UniGetUI.PAckageEngine.Interfaces/ManagerHelpers/IPackageOperationHelper.cs new file mode 100644 index 000000000..a5f0f3e97 --- /dev/null +++ b/src/UniGetUI.PAckageEngine.Interfaces/ManagerHelpers/IPackageOperationHelper.cs @@ -0,0 +1,32 @@ +using UniGetUI.PackageEngine.Enums; + +namespace UniGetUI.PackageEngine.Interfaces.ManagerProviders +{ + /// + /// Handled the process of installing and uninstalling packages + /// + public interface IPackageOperationHelper + { + /// + /// 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. + /// + public IEnumerable GetParameters( + IPackage package, + IInstallationOptions options, + OperationType operation + ); + + /// + /// Returns the veredict of the given package operation, given the package, the operation type, + /// the corresponding output and the return code. + /// + public OperationVeredict GetResult( + IPackage package, + OperationType operation, + IEnumerable processOutput, + int returnCode + ); + } +} diff --git a/src/UniGetUI.PAckageEngine.Interfaces/ManagerProviders/IOperationProvider.cs b/src/UniGetUI.PAckageEngine.Interfaces/ManagerProviders/IOperationProvider.cs deleted file mode 100644 index 94d92317b..000000000 --- a/src/UniGetUI.PAckageEngine.Interfaces/ManagerProviders/IOperationProvider.cs +++ /dev/null @@ -1,27 +0,0 @@ -using UniGetUI.PackageEngine.Enums; - -namespace UniGetUI.PackageEngine.Interfaces.ManagerProviders; -public interface IOperationProvider -{ - /// - /// 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. - /// - public IEnumerable GetOperationParameters( - IPackage package, - IInstallationOptions options, - OperationType operation - ); - - /// - /// Returns the veredict of the given package operation, given the package, the operation type, - /// the corresponding output and the return code. - /// - public OperationVeredict GetOperationResult( - IPackage package, - OperationType operation, - IEnumerable processOutput, - int returnCode - ); -} diff --git a/src/UniGetUI.PackageEngine.Managers.Cargo/Cargo.cs b/src/UniGetUI.PackageEngine.Managers.Cargo/Cargo.cs index f1eab62c8..49200e3f6 100644 --- a/src/UniGetUI.PackageEngine.Managers.Cargo/Cargo.cs +++ b/src/UniGetUI.PackageEngine.Managers.Cargo/Cargo.cs @@ -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 FindPackages_UnSafe(string query) diff --git a/src/UniGetUI.PackageEngine.Managers.Cargo/Providers/CargoPackageDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.Cargo/Helpers/CargoPkgDetailsHelper.cs similarity index 96% rename from src/UniGetUI.PackageEngine.Managers.Cargo/Providers/CargoPackageDetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Cargo/Helpers/CargoPkgDetailsHelper.cs index a52561bd2..561beae40 100644 --- a/src/UniGetUI.PackageEngine.Managers.Cargo/Providers/CargoPackageDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Cargo/Helpers/CargoPkgDetailsHelper.cs @@ -5,7 +5,7 @@ using UniGetUI.PackageEngine.ManagerClasses.Manager; namespace UniGetUI.PackageEngine.Managers.CargoManager; -internal sealed class CargoPackageDetailsProvider(Cargo manager) : BasePackageDetailsProvider(manager) +internal sealed class CargoPkgDetailsHelper(Cargo manager) : BasePkgDetailsHelper(manager) { protected override void GetDetails_UnSafe(IPackageDetails details) { diff --git a/src/UniGetUI.PackageEngine.Managers.Cargo/Providers/CargoOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Cargo/Helpers/CargoPkgOperationHelper.cs similarity index 68% rename from src/UniGetUI.PackageEngine.Managers.Cargo/Providers/CargoOperationProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Cargo/Helpers/CargoPkgOperationHelper.cs index 363db0430..ca31f9836 100644 --- a/src/UniGetUI.PackageEngine.Managers.Cargo/Providers/CargoOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Cargo/Helpers/CargoPkgOperationHelper.cs @@ -4,9 +4,9 @@ namespace UniGetUI.PackageEngine.Managers.CargoManager; -internal sealed class CargoOperationProvider(Cargo cargo) : BaseOperationProvider(cargo) +internal sealed class CargoPkgOperationHelper(Cargo cargo) : PackagePkgOperationHelper(cargo) { - public override IEnumerable GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) + protected override IEnumerable _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) { var version = options.Version == string.Empty ? package.Version : options.Version; List parameters = operation switch @@ -20,7 +20,7 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn return parameters; } - public override OperationVeredict GetOperationResult(IPackage package, OperationType operation, IEnumerable processOutput, int returnCode) + protected override OperationVeredict _getOperationResult(IPackage package, OperationType operation, IEnumerable processOutput, int returnCode) { return returnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed; } diff --git a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs index 8ed004d93..c2dd07488 100644 --- a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs +++ b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs @@ -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 GetAvailableUpdates_UnSafe() diff --git a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Providers/ChocolateyDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateyDetailsHelper.cs similarity index 95% rename from src/UniGetUI.PackageEngine.Managers.Chocolatey/Providers/ChocolateyDetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateyDetailsHelper.cs index b27022bd5..bba926192 100644 --- a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Providers/ChocolateyDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateyDetailsHelper.cs @@ -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 GetInstallableVersions_UnSafe(IPackage package) diff --git a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Providers/ChocolateyOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateyPkgOperationHelper.cs similarity index 90% rename from src/UniGetUI.PackageEngine.Managers.Chocolatey/Providers/ChocolateyOperationProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateyPkgOperationHelper.cs index 721e3eea6..bc4e9ebba 100644 --- a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Providers/ChocolateyOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateyPkgOperationHelper.cs @@ -4,11 +4,11 @@ using UniGetUI.PackageEngine.Interfaces; namespace UniGetUI.PackageEngine.Managers.ChocolateyManager; -internal sealed class ChocolateyOperationProvider : BaseOperationProvider +internal sealed class ChocolateyPkgOperationHelper : PackagePkgOperationHelper { - public ChocolateyOperationProvider(Chocolatey manager) : base(manager) { } + public ChocolateyPkgOperationHelper(Chocolatey manager) : base(manager) { } - public override IEnumerable GetOperationParameters( + protected override IEnumerable _getOperationParameters( IPackage package, IInstallationOptions options, OperationType operation) @@ -47,7 +47,7 @@ public override IEnumerable GetOperationParameters( return parameters; } - public override OperationVeredict GetOperationResult( + protected override OperationVeredict _getOperationResult( IPackage package, OperationType operation, IEnumerable processOutput, diff --git a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Providers/ChocolateySourceProvider.cs b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateySourceHelper.cs similarity index 95% rename from src/UniGetUI.PackageEngine.Managers.Chocolatey/Providers/ChocolateySourceProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateySourceHelper.cs index ed9446af6..dd6807f6d 100644 --- a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Providers/ChocolateySourceProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateySourceHelper.cs @@ -8,9 +8,9 @@ namespace UniGetUI.PackageEngine.Managers.ChocolateyManager { - internal sealed class ChocolateySourceProvider : BaseSourceProvider + internal sealed class ChocolateySourceHelper : BaseSourceHelper { - public ChocolateySourceProvider(Chocolatey manager) : base(manager) { } + public ChocolateySourceHelper(Chocolatey manager) : base(manager) { } public override string[] GetAddSourceParameters(IManagerSource source) { diff --git a/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs b/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs index a911ea5d9..1400d9aaf 100644 --- a/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs +++ b/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs @@ -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 GetAvailableUpdates_UnSafe() diff --git a/src/UniGetUI.PackageEngine.Managers.Dotnet/Providers/DotNetDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.Dotnet/Helpers/DotNetDetailsHelper.cs similarity index 74% rename from src/UniGetUI.PackageEngine.Managers.Dotnet/Providers/DotNetDetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Dotnet/Helpers/DotNetDetailsHelper.cs index b36e9ded0..79dd73f35 100644 --- a/src/UniGetUI.PackageEngine.Managers.Dotnet/Providers/DotNetDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Dotnet/Helpers/DotNetDetailsHelper.cs @@ -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) diff --git a/src/UniGetUI.PackageEngine.Managers.Dotnet/Providers/DotNetOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Dotnet/Helpers/DotNetPkgOperationHelper.cs similarity index 87% rename from src/UniGetUI.PackageEngine.Managers.Dotnet/Providers/DotNetOperationProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Dotnet/Helpers/DotNetPkgOperationHelper.cs index 9d17519b4..ac489b80c 100644 --- a/src/UniGetUI.PackageEngine.Managers.Dotnet/Providers/DotNetOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Dotnet/Helpers/DotNetPkgOperationHelper.cs @@ -4,11 +4,11 @@ using UniGetUI.PackageEngine.Interfaces; namespace UniGetUI.PackageEngine.Managers.DotNetManager; -internal sealed class DotNetOperationProvider : BaseOperationProvider +internal sealed class DotNetPkgOperationHelper : PackagePkgOperationHelper { - public DotNetOperationProvider(DotNet manager) : base(manager) { } + public DotNetPkgOperationHelper(DotNet manager) : base(manager) { } - public override IEnumerable GetOperationParameters( + protected override IEnumerable _getOperationParameters( IPackage package, IInstallationOptions options, OperationType operation) @@ -46,7 +46,7 @@ public override IEnumerable GetOperationParameters( return parameters; } - public override OperationVeredict GetOperationResult( + protected override OperationVeredict _getOperationResult( IPackage package, OperationType operation, IEnumerable processOutput, diff --git a/src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGet.cs b/src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGet.cs index b1028cdca..5050edf09 100644 --- a/src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGet.cs +++ b/src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGet.cs @@ -13,7 +13,7 @@ public abstract class BaseNuGet : PackageManager { public sealed override void Initialize() { - if (PackageDetailsProvider is not BaseNuGetDetailsProvider) + if (DetailsHelper is not BaseNuGetDetailsHelper) { throw new InvalidOperationException("NuGet-based package managers must not reassign the PackageDetailsProvider property"); } @@ -46,7 +46,7 @@ protected sealed override IEnumerable FindPackages_UnSafe(string query) IEnumerable sources; if (Capabilities.SupportsCustomSources) { - sources = GetSources(); + sources = SourcesHelper.GetSources(); } else { diff --git a/src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGetDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGetDetailsHelper.cs similarity index 97% rename from src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGetDetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGetDetailsHelper.cs index 778e5826b..208a8a8a4 100644 --- a/src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGetDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGetDetailsHelper.cs @@ -11,9 +11,9 @@ namespace UniGetUI.PackageEngine.Managers.PowerShellManager { - public abstract class BaseNuGetDetailsProvider : BasePackageDetailsProvider + public abstract class BaseNuGetDetailsHelper : BasePkgDetailsHelper { - public BaseNuGetDetailsProvider(BaseNuGet manager) : base(manager) { } + public BaseNuGetDetailsHelper(BaseNuGet manager) : base(manager) { } protected override void GetDetails_UnSafe(IPackageDetails details) { diff --git a/src/UniGetUI.PackageEngine.Managers.Npm/Providers/NpmPackageDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.Npm/Helpers/NpmPkgDetailsHelper.cs similarity index 97% rename from src/UniGetUI.PackageEngine.Managers.Npm/Providers/NpmPackageDetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Npm/Helpers/NpmPkgDetailsHelper.cs index 1cea566e2..2665698a3 100644 --- a/src/UniGetUI.PackageEngine.Managers.Npm/Providers/NpmPackageDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Npm/Helpers/NpmPkgDetailsHelper.cs @@ -13,9 +13,9 @@ namespace UniGetUI.PackageEngine.Managers.NpmManager { - internal sealed class NpmPackageDetailsProvider : BasePackageDetailsProvider + internal sealed class NpmPkgDetailsHelper : BasePkgDetailsHelper { - public NpmPackageDetailsProvider(Npm manager) : base(manager) { } + public NpmPkgDetailsHelper(Npm manager) : base(manager) { } protected override void GetDetails_UnSafe(IPackageDetails details) { diff --git a/src/UniGetUI.PackageEngine.Managers.Npm/Providers/NpmOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Npm/Helpers/NpmPkgOperationHelper.cs similarity index 80% rename from src/UniGetUI.PackageEngine.Managers.Npm/Providers/NpmOperationProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Npm/Helpers/NpmPkgOperationHelper.cs index a57b0f324..d0b2d767c 100644 --- a/src/UniGetUI.PackageEngine.Managers.Npm/Providers/NpmOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Npm/Helpers/NpmPkgOperationHelper.cs @@ -3,11 +3,11 @@ using UniGetUI.PackageEngine.Interfaces; namespace UniGetUI.PackageEngine.Managers.NpmManager; -internal sealed class NpmOperationProvider : BaseOperationProvider +internal sealed class NpmPkgOperationHelper : PackagePkgOperationHelper { - public NpmOperationProvider(Npm manager) : base(manager) { } + public NpmPkgOperationHelper(Npm manager) : base(manager) { } - public override IEnumerable GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) + protected override IEnumerable _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) { List parameters = operation switch { OperationType.Install => [Manager.Properties.InstallVerb, $"{package.Id}@{(options.Version == string.Empty? package.Version: options.Version)}"], @@ -30,7 +30,7 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn return parameters; } - public override OperationVeredict GetOperationResult( + protected override OperationVeredict _getOperationResult( IPackage package, OperationType operation, IEnumerable processOutput, diff --git a/src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs b/src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs index cbb973d29..8cce1b667 100644 --- a/src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs +++ b/src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs @@ -41,8 +41,8 @@ public Npm() }; - PackageDetailsProvider = new NpmPackageDetailsProvider(this); - OperationProvider = new NpmOperationProvider(this); + DetailsHelper = new NpmPkgDetailsHelper(this); + OperationHelper = new NpmPkgOperationHelper(this); } protected override IEnumerable FindPackages_UnSafe(string query) diff --git a/src/UniGetUI.PackageEngine.Managers.Pip/Providers/PipPackageDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.Pip/Helpers/PipPkgDetailsHelper.cs similarity index 96% rename from src/UniGetUI.PackageEngine.Managers.Pip/Providers/PipPackageDetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Pip/Helpers/PipPkgDetailsHelper.cs index 1bd0b9f88..28613c57f 100644 --- a/src/UniGetUI.PackageEngine.Managers.Pip/Providers/PipPackageDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Pip/Helpers/PipPkgDetailsHelper.cs @@ -11,9 +11,9 @@ namespace UniGetUI.PackageEngine.Managers.PipManager { - internal sealed class PipPackageDetailsProvider : BasePackageDetailsProvider + internal sealed class PipPkgDetailsHelper : BasePkgDetailsHelper { - public PipPackageDetailsProvider(Pip manager) : base(manager) { } + public PipPkgDetailsHelper(Pip manager) : base(manager) { } protected override void GetDetails_UnSafe(IPackageDetails details) { diff --git a/src/UniGetUI.PackageEngine.Managers.Pip/Providers/PipOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Pip/Helpers/PipPkgOperationHelper.cs similarity index 88% rename from src/UniGetUI.PackageEngine.Managers.Pip/Providers/PipOperationProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Pip/Helpers/PipPkgOperationHelper.cs index 8af0ebef1..9c07687f4 100644 --- a/src/UniGetUI.PackageEngine.Managers.Pip/Providers/PipOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Pip/Helpers/PipPkgOperationHelper.cs @@ -3,11 +3,11 @@ using UniGetUI.PackageEngine.Interfaces; namespace UniGetUI.PackageEngine.Managers.PipManager; -internal sealed class PipOperationProvider : BaseOperationProvider +internal sealed class PipPkgOperationHelper : PackagePkgOperationHelper { - public PipOperationProvider(Pip manager) : base(manager) { } + public PipPkgOperationHelper(Pip manager) : base(manager) { } - public override IEnumerable GetOperationParameters( + protected override IEnumerable _getOperationParameters( IPackage package, IInstallationOptions options, OperationType operation) @@ -46,7 +46,7 @@ public override IEnumerable GetOperationParameters( return parameters; } - public override OperationVeredict GetOperationResult( + protected override OperationVeredict _getOperationResult( IPackage package, OperationType operation, IEnumerable processOutput, diff --git a/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs b/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs index 605f2cd8d..78ddd52bf 100644 --- a/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs +++ b/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs @@ -54,8 +54,8 @@ public Pip() }; - PackageDetailsProvider = new PipPackageDetailsProvider(this); - OperationProvider = new PipOperationProvider(this); + DetailsHelper = new PipPkgDetailsHelper(this); + OperationHelper = new PipPkgOperationHelper(this); } protected override IEnumerable FindPackages_UnSafe(string query) diff --git a/src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.PowerShell/Helpers/PowerShellDetailsHelper.cs similarity index 84% rename from src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellDetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.PowerShell/Helpers/PowerShellDetailsHelper.cs index bb7555e1e..2543d96d6 100644 --- a/src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.PowerShell/Helpers/PowerShellDetailsHelper.cs @@ -3,9 +3,9 @@ namespace UniGetUI.PackageEngine.Managers.Chocolatey { - public class PowerShellDetailsProvider : BaseNuGetDetailsProvider + public class PowerShellDetailsHelper : BaseNuGetDetailsHelper { - public PowerShellDetailsProvider(BaseNuGet manager) : base(manager) + public PowerShellDetailsHelper(BaseNuGet manager) : base(manager) { } protected override string? GetInstallLocation_UnSafe(IPackage package) diff --git a/src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.PowerShell/Helpers/PowerShellPkgOperationHelper.cs similarity index 87% rename from src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellOperationProvider.cs rename to src/UniGetUI.PackageEngine.Managers.PowerShell/Helpers/PowerShellPkgOperationHelper.cs index 4bcf1c369..009bf6083 100644 --- a/src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.PowerShell/Helpers/PowerShellPkgOperationHelper.cs @@ -3,11 +3,11 @@ using UniGetUI.PackageEngine.Interfaces; namespace UniGetUI.PackageEngine.Managers.PowerShellManager; -internal sealed class PowerShellOperationProvider : BaseOperationProvider +internal sealed class PowerShellPkgOperationHelper : PackagePkgOperationHelper { - public PowerShellOperationProvider(PowerShell manager) : base(manager) { } + public PowerShellPkgOperationHelper(PowerShell manager) : base(manager) { } - public override IEnumerable GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) + protected override IEnumerable _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) { List parameters = [operation switch { OperationType.Install => Manager.Properties.InstallVerb, @@ -48,7 +48,7 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn return parameters; } - public override OperationVeredict GetOperationResult( + protected override OperationVeredict _getOperationResult( IPackage package, OperationType operation, IEnumerable processOutput, diff --git a/src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellSourceProvider.cs b/src/UniGetUI.PackageEngine.Managers.PowerShell/Helpers/PowerShellSourceHelper.cs similarity index 95% rename from src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellSourceProvider.cs rename to src/UniGetUI.PackageEngine.Managers.PowerShell/Helpers/PowerShellSourceHelper.cs index a0fff1b2d..caf4f9c7c 100644 --- a/src/UniGetUI.PackageEngine.Managers.PowerShell/Providers/PowerShellSourceProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.PowerShell/Helpers/PowerShellSourceHelper.cs @@ -10,9 +10,9 @@ namespace UniGetUI.PackageEngine.Managers.PowerShellManager { - internal sealed class PowerShellSourceProvider : BaseSourceProvider + internal sealed class PowerShellSourceHelper : BaseSourceHelper { - public PowerShellSourceProvider(PowerShell manager) : base(manager) { } + public PowerShellSourceHelper(PowerShell manager) : base(manager) { } public override string[] GetAddSourceParameters(IManagerSource source) { diff --git a/src/UniGetUI.PackageEngine.Managers.PowerShell/PowerShell.cs b/src/UniGetUI.PackageEngine.Managers.PowerShell/PowerShell.cs index 7b9e7720c..14d377621 100644 --- a/src/UniGetUI.PackageEngine.Managers.PowerShell/PowerShell.cs +++ b/src/UniGetUI.PackageEngine.Managers.PowerShell/PowerShell.cs @@ -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; @@ -50,9 +51,9 @@ public PowerShell() DefaultSource = new ManagerSource(this, "PSGallery", new Uri("https://www.powershellgallery.com/api/v2")), }; - PackageDetailsProvider = new PowerShellDetailsProvider(this); - SourceProvider = new PowerShellSourceProvider(this); - OperationProvider = new PowerShellOperationProvider(this); + DetailsHelper = new PowerShellDetailsHelper(this); + SourcesHelper = new PowerShellSourceHelper(this); + OperationHelper = new PowerShellPkgOperationHelper(this); } protected override IEnumerable GetAvailableUpdates_UnSafe() { @@ -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], SourcesHelper.Factory.GetSourceOrDefault(elements[3]), this)); } logger.AddToStdErr(p.StandardError.ReadToEnd()); @@ -186,7 +188,8 @@ protected override IEnumerable 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], + SourcesHelper.Factory.GetSourceOrDefault(elements[2]), this)); } } @@ -220,7 +223,7 @@ protected override ManagerStatus LoadManager() RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, - StandardOutputEncoding = System.Text.Encoding.UTF8 + StandardOutputEncoding = Encoding.UTF8 } }; process.Start(); diff --git a/src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7DetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.PowerShell7/Helpers/PowerShell7DetailsHelper.cs similarity index 83% rename from src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7DetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.PowerShell7/Helpers/PowerShell7DetailsHelper.cs index ad42c8629..6178683a0 100644 --- a/src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7DetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.PowerShell7/Helpers/PowerShell7DetailsHelper.cs @@ -3,9 +3,9 @@ namespace UniGetUI.PackageEngine.Managers.Chocolatey { - public class PowerShell7DetailsProvider : BaseNuGetDetailsProvider + public class PowerShell7DetailsHelper : BaseNuGetDetailsHelper { - public PowerShell7DetailsProvider(BaseNuGet manager) : base(manager) + public PowerShell7DetailsHelper(BaseNuGet manager) : base(manager) { } diff --git a/src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7OperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.PowerShell7/Helpers/PowerShell7PkgOperationHelper.cs similarity index 85% rename from src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7OperationProvider.cs rename to src/UniGetUI.PackageEngine.Managers.PowerShell7/Helpers/PowerShell7PkgOperationHelper.cs index fb7fb8d89..8a326f1a0 100644 --- a/src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7OperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.PowerShell7/Helpers/PowerShell7PkgOperationHelper.cs @@ -3,11 +3,11 @@ using UniGetUI.PackageEngine.Interfaces; namespace UniGetUI.PackageEngine.Managers.PowerShell7Manager; -internal sealed class PowerShell7OperationProvider : BaseOperationProvider +internal sealed class PowerShell7PkgOperationHelper : PackagePkgOperationHelper { - public PowerShell7OperationProvider(PowerShell7 manager) : base(manager) { } + public PowerShell7PkgOperationHelper(PowerShell7 manager) : base(manager) { } - public override IEnumerable GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) + protected override IEnumerable _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) { List parameters = [operation switch { OperationType.Install => Manager.Properties.InstallVerb, @@ -44,7 +44,7 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn return parameters; } - public override OperationVeredict GetOperationResult( + protected override OperationVeredict _getOperationResult( IPackage package, OperationType operation, IEnumerable processOutput, diff --git a/src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7SourceProvider.cs b/src/UniGetUI.PackageEngine.Managers.PowerShell7/Helpers/PowerShell7SourceHelper.cs similarity index 95% rename from src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7SourceProvider.cs rename to src/UniGetUI.PackageEngine.Managers.PowerShell7/Helpers/PowerShell7SourceHelper.cs index 21b34bcea..f833b796d 100644 --- a/src/UniGetUI.PackageEngine.Managers.PowerShell7/Providers/PowerShell7SourceProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.PowerShell7/Helpers/PowerShell7SourceHelper.cs @@ -10,9 +10,9 @@ namespace UniGetUI.PackageEngine.Managers.PowerShell7Manager { - internal sealed class PowerShell7SourceProvider : BaseSourceProvider + internal sealed class PowerShell7SourceHelper : BaseSourceHelper { - public PowerShell7SourceProvider(PowerShell7 manager) : base(manager) { } + public PowerShell7SourceHelper(PowerShell7 manager) : base(manager) { } public override string[] GetAddSourceParameters(IManagerSource source) { diff --git a/src/UniGetUI.PackageEngine.Managers.PowerShell7/PowerShell7.cs b/src/UniGetUI.PackageEngine.Managers.PowerShell7/PowerShell7.cs index 1b8a0d266..e355c74fe 100644 --- a/src/UniGetUI.PackageEngine.Managers.PowerShell7/PowerShell7.cs +++ b/src/UniGetUI.PackageEngine.Managers.PowerShell7/PowerShell7.cs @@ -51,9 +51,9 @@ public PowerShell7() DefaultSource = new ManagerSource(this, "PSGallery", new Uri("https://www.powershellgallery.com/api/v2")), }; - PackageDetailsProvider = new PowerShell7DetailsProvider(this); - SourceProvider = new PowerShell7SourceProvider(this); - OperationProvider = new PowerShell7OperationProvider(this); + DetailsHelper = new PowerShell7DetailsHelper(this); + SourcesHelper = new PowerShell7SourceHelper(this); + OperationHelper = new PowerShell7PkgOperationHelper(this); } protected override IEnumerable GetAvailableUpdates_UnSafe() { @@ -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], SourcesHelper.Factory.GetSourceOrDefault(elements[3]), this)); } logger.AddToStdErr(p.StandardError.ReadToEnd()); @@ -187,7 +188,8 @@ protected override IEnumerable 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], + SourcesHelper.Factory.GetSourceOrDefault(elements[2]), this)); } } diff --git a/src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopPackageDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.Scoop/Helpers/ScoopPkgDetailsHelper.cs similarity index 97% rename from src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopPackageDetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Scoop/Helpers/ScoopPkgDetailsHelper.cs index 7dcaf10ba..07f850703 100644 --- a/src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopPackageDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Scoop/Helpers/ScoopPkgDetailsHelper.cs @@ -12,9 +12,9 @@ namespace UniGetUI.PackageEngine.Managers.ScoopManager { - internal sealed class ScoopPackageDetailsProvider : BasePackageDetailsProvider + internal sealed class ScoopPkgDetailsHelper : BasePkgDetailsHelper { - public ScoopPackageDetailsProvider(Scoop manager) : base(manager) { } + public ScoopPkgDetailsHelper(Scoop manager) : base(manager) { } protected override void GetDetails_UnSafe(IPackageDetails details) { diff --git a/src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Scoop/Helpers/ScoopPkgOperationHelper.cs similarity index 90% rename from src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopOperationProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Scoop/Helpers/ScoopPkgOperationHelper.cs index f7bd906a1..d510de5a7 100644 --- a/src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Scoop/Helpers/ScoopPkgOperationHelper.cs @@ -4,11 +4,11 @@ using UniGetUI.PackageEngine.Interfaces; namespace UniGetUI.PackageEngine.Managers.ScoopManager; -internal sealed class ScoopOperationProvider : BaseOperationProvider +internal sealed class ScoopPkgOperationHelper : PackagePkgOperationHelper { - public ScoopOperationProvider(Scoop manager) : base(manager) { } + public ScoopPkgOperationHelper(Scoop manager) : base(manager) { } - public override IEnumerable GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) + protected override IEnumerable _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) { List parameters = [operation switch { OperationType.Install => Manager.Properties.InstallVerb, @@ -55,7 +55,7 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn return parameters; } - public override OperationVeredict GetOperationResult( + protected override OperationVeredict _getOperationResult( IPackage package, OperationType operation, IEnumerable processOutput, diff --git a/src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopSourceProvider.cs b/src/UniGetUI.PackageEngine.Managers.Scoop/Helpers/ScoopSourceHelper.cs similarity index 96% rename from src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopSourceProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Scoop/Helpers/ScoopSourceHelper.cs index 58a2b8aa1..3b58dfb7d 100644 --- a/src/UniGetUI.PackageEngine.Managers.Scoop/Providers/ScoopSourceProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Scoop/Helpers/ScoopSourceHelper.cs @@ -10,9 +10,9 @@ namespace UniGetUI.PackageEngine.Managers.ScoopManager { - internal sealed class ScoopSourceProvider : BaseSourceProvider + internal sealed class ScoopSourceHelper : BaseSourceHelper { - public ScoopSourceProvider(Scoop manager) : base(manager) { } + public ScoopSourceHelper(Scoop manager) : base(manager) { } protected override OperationVeredict _getAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) { diff --git a/src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs b/src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs index 4e176b617..4cf942b7a 100644 --- a/src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs +++ b/src/UniGetUI.PackageEngine.Managers.Scoop/Scoop.cs @@ -85,9 +85,9 @@ public Scoop() DefaultSource = new ManagerSource(this, "main", new Uri("https://github.com/ScoopInstaller/Main")), }; - SourceProvider = new ScoopSourceProvider(this); - PackageDetailsProvider = new ScoopPackageDetailsProvider(this); - OperationProvider = new ScoopOperationProvider(this); + SourcesHelper = new ScoopSourceHelper(this); + DetailsHelper = new ScoopPkgDetailsHelper(this); + OperationHelper = new ScoopPkgOperationHelper(this); } protected override IEnumerable FindPackages_UnSafe(string query) @@ -144,7 +144,7 @@ protected override IEnumerable FindPackages_UnSafe(string query) if (line.StartsWith("'")) { string sourceName = line.Split(" ")[0].Replace("'", ""); - source = GetSourceOrDefault(sourceName); + source = SourcesHelper.Factory.GetSourceOrDefault(sourceName); } else if (line.Trim() != "") { @@ -325,7 +325,7 @@ private IEnumerable _getInstalledPackages_UnSafe() CoreTools.FormatAsName(elements[0]), elements[0], elements[1], - GetSourceOrDefault(elements[2]), + SourcesHelper.Factory.GetSourceOrDefault(elements[2]), this, options)); } diff --git a/src/UniGetUI.PackageEngine.Managers.Vcpkg/Providers/VcpkgPackageDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.Vcpkg/Helpers/VcpkgPkgDetailsHelper.cs similarity index 96% rename from src/UniGetUI.PackageEngine.Managers.Vcpkg/Providers/VcpkgPackageDetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Vcpkg/Helpers/VcpkgPkgDetailsHelper.cs index 7e1378e6e..92c869671 100644 --- a/src/UniGetUI.PackageEngine.Managers.Vcpkg/Providers/VcpkgPackageDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Vcpkg/Helpers/VcpkgPkgDetailsHelper.cs @@ -14,9 +14,9 @@ namespace UniGetUI.PackageEngine.Managers.VcpkgManager { - internal sealed class VcpkgPackageDetailsProvider : BasePackageDetailsProvider + internal sealed class VcpkgPkgDetailsHelper : BasePkgDetailsHelper { - public VcpkgPackageDetailsProvider(Vcpkg manager) : base(manager) { } + public VcpkgPkgDetailsHelper(Vcpkg manager) : base(manager) { } protected override void GetDetails_UnSafe(IPackageDetails details) { diff --git a/src/UniGetUI.PackageEngine.Managers.Vcpkg/Providers/VcpkgOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.Vcpkg/Helpers/VcpkgPkgOperationHelper.cs similarity index 74% rename from src/UniGetUI.PackageEngine.Managers.Vcpkg/Providers/VcpkgOperationProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Vcpkg/Helpers/VcpkgPkgOperationHelper.cs index f4b44ffa3..53c5ba685 100644 --- a/src/UniGetUI.PackageEngine.Managers.Vcpkg/Providers/VcpkgOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Vcpkg/Helpers/VcpkgPkgOperationHelper.cs @@ -5,11 +5,11 @@ using UniGetUI.PackageEngine.Interfaces; namespace UniGetUI.PackageEngine.Managers.VcpkgManager; -internal sealed class VcpkgOperationProvider : BaseOperationProvider +internal sealed class VcpkgPkgOperationHelper : PackagePkgOperationHelper { - public VcpkgOperationProvider(Vcpkg manager) : base(manager) { } + public VcpkgPkgOperationHelper(Vcpkg manager) : base(manager) { } - public override IEnumerable GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) + protected override IEnumerable _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) { List parameters = operation switch { OperationType.Install => [Manager.Properties.InstallVerb, package.Id], @@ -22,7 +22,7 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn return parameters; } - public override OperationVeredict GetOperationResult( + protected override OperationVeredict _getOperationResult( IPackage package, OperationType operation, IEnumerable processOutput, diff --git a/src/UniGetUI.PackageEngine.Managers.Vcpkg/Providers/VcpkgSourceProvider.cs b/src/UniGetUI.PackageEngine.Managers.Vcpkg/Helpers/VcpkgSourceHelper.cs similarity index 88% rename from src/UniGetUI.PackageEngine.Managers.Vcpkg/Providers/VcpkgSourceProvider.cs rename to src/UniGetUI.PackageEngine.Managers.Vcpkg/Helpers/VcpkgSourceHelper.cs index 4c26632d6..d74b3a5c0 100644 --- a/src/UniGetUI.PackageEngine.Managers.Vcpkg/Providers/VcpkgSourceProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.Vcpkg/Helpers/VcpkgSourceHelper.cs @@ -8,9 +8,9 @@ namespace UniGetUI.PackageEngine.Managers.VcpkgManager { - internal sealed class VcpkgSourceProvider : BaseSourceProvider + internal sealed class VcpkgSourceHelper : BaseSourceHelper { - public VcpkgSourceProvider(Vcpkg manager) : base(manager) { } + public VcpkgSourceHelper(Vcpkg manager) : base(manager) { } public override string[] GetAddSourceParameters(IManagerSource source) => throw new NotImplementedException(); @@ -27,7 +27,7 @@ protected override OperationVeredict _getRemoveSourceOperationVeredict(IManagerS protected override IEnumerable GetSources_UnSafe() { List Sources = []; - + foreach (string Triplet in Vcpkg.GetSystemTriplets()) { Sources.Add(new ManagerSource(Manager, Triplet, Vcpkg.URI_VCPKG_IO)); } diff --git a/src/UniGetUI.PackageEngine.Managers.Vcpkg/Vcpkg.cs b/src/UniGetUI.PackageEngine.Managers.Vcpkg/Vcpkg.cs index ddf2c1b0a..7bd794866 100644 --- a/src/UniGetUI.PackageEngine.Managers.Vcpkg/Vcpkg.cs +++ b/src/UniGetUI.PackageEngine.Managers.Vcpkg/Vcpkg.cs @@ -75,9 +75,9 @@ public Vcpkg() KnownSources = [.. TripletSourceMap.Values], }; - SourceProvider = new VcpkgSourceProvider(this); - PackageDetailsProvider = new VcpkgPackageDetailsProvider(this); - OperationProvider = new VcpkgOperationProvider(this); + SourcesHelper = new VcpkgSourceHelper(this); + DetailsHelper = new VcpkgPkgDetailsHelper(this); + OperationHelper = new VcpkgPkgOperationHelper(this); } protected override IEnumerable FindPackages_UnSafe(string query) diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/BundledWinGetHelper.cs similarity index 97% rename from src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs rename to src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/BundledWinGetHelper.cs index 83ccd6521..bf55777f4 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/BundledWinGetHelper.cs @@ -103,7 +103,7 @@ public IEnumerable GetAvailableUpdates_UnSafe() else { string sourceName = line[(SourceIndex - offset)..].Trim().Split(' ')[0]; - source = Manager.GetSourceOrDefault(sourceName); + source = Manager.SourcesHelper.Factory.GetSourceOrDefault(sourceName); } Packages.Add(new Package(name, id, version, newVersion, source, Manager)); @@ -190,7 +190,7 @@ public IEnumerable GetInstalledPackages_UnSafe() else { string sourceName = line[(SourceIndex - offset)..].Trim().Split(' ')[0].Trim(); - source = Manager.GetSourceOrDefault(sourceName); + source = Manager.SourcesHelper.Factory.GetSourceOrDefault(sourceName); } Packages.Add(new Package(name, id, version, source, Manager)); } @@ -267,7 +267,7 @@ public IEnumerable FindPackages_UnSafe(string query) else { string sourceName = line[(SourceIndex - offset)..].Trim().Split(' ')[0]; - source = Manager.GetSourceOrDefault(sourceName); + source = Manager.SourcesHelper.Factory.GetSourceOrDefault(sourceName); } Packages.Add(new Package(name, id, version, source, Manager)); } @@ -308,7 +308,7 @@ public void GetPackageDetails_UnSafe(IPackageDetails details) ProcessStartInfo startInfo = new() { FileName = Manager.WinGetBundledPath, - Arguments = Manager.Properties.ExecutableCallArgs + " show " + WinGetOperationProvider.GetIdNamePiece(details.Package) + + Arguments = Manager.Properties.ExecutableCallArgs + " show " + WinGetPkgOperationHelper.GetIdNamePiece(details.Package) + " --disable-interactivity --accept-source-agreements --locale " + System.Globalization.CultureInfo.CurrentCulture, RedirectStandardOutput = true, @@ -347,7 +347,7 @@ public void GetPackageDetails_UnSafe(IPackageDetails details) startInfo = new() { FileName = Manager.WinGetBundledPath, - Arguments = Manager.Properties.ExecutableCallArgs + " show " + WinGetOperationProvider.GetIdNamePiece(details.Package) + + Arguments = Manager.Properties.ExecutableCallArgs + " show " + WinGetPkgOperationHelper.GetIdNamePiece(details.Package) + " --disable-interactivity --accept-source-agreements --locale en-US", RedirectStandardOutput = true, RedirectStandardError = true, @@ -384,7 +384,7 @@ public void GetPackageDetails_UnSafe(IPackageDetails details) startInfo = new() { FileName = Manager.WinGetBundledPath, - Arguments = Manager.Properties.ExecutableCallArgs + " show " + WinGetOperationProvider.GetIdNamePiece(details.Package) + + Arguments = Manager.Properties.ExecutableCallArgs + " show " + WinGetPkgOperationHelper.GetIdNamePiece(details.Package) + " --disable-interactivity --accept-source-agreements", RedirectStandardOutput = true, RedirectStandardError = true, @@ -522,7 +522,7 @@ public IEnumerable GetInstallableVersions_Unsafe(IPackage package) StartInfo = new ProcessStartInfo { FileName = Manager.WinGetBundledPath, - Arguments = Manager.Properties.ExecutableCallArgs + " show " + WinGetOperationProvider.GetIdNamePiece(package) + + Arguments = Manager.Properties.ExecutableCallArgs + " show " + WinGetPkgOperationHelper.GetIdNamePiece(package) + $" --versions --accept-source-agreements", UseShellExecute = false, RedirectStandardOutput = true, diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/IWinGetManagerHelpers.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/IWinGetManagerHelpers.cs similarity index 100% rename from src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/IWinGetManagerHelpers.cs rename to src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/IWinGetManagerHelpers.cs diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativePackageHandler.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/NativePackageHandler.cs similarity index 100% rename from src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativePackageHandler.cs rename to src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/NativePackageHandler.cs diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/NativeWinGetHelper.cs similarity index 93% rename from src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs rename to src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/NativeWinGetHelper.cs index 7df27597d..a5b79673b 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/NativeWinGetHelper.cs @@ -115,7 +115,7 @@ public IEnumerable FindPackages_UnSafe(string query) try { // Get the source for the catalog - IManagerSource source = Manager.GetSourceOrDefault(CatalogTaskPair.Key.Item1.Info.Name); + IManagerSource source = Manager.SourcesHelper.Factory.GetSourceOrDefault(CatalogTaskPair.Key.Item1.Info.Name); FindPackagesResult FoundPackages = CatalogTaskPair.Value.Result; foreach (MatchResult matchResult in FoundPackages.Matches.ToArray()) @@ -127,15 +127,6 @@ public IEnumerable 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, @@ -168,7 +159,7 @@ public IEnumerable GetAvailableUpdates_UnSafe() if (nativePackage.IsUpdateAvailable) { IManagerSource source; - source = Manager.GetSourceOrDefault(nativePackage.DefaultInstallVersion.PackageCatalog.Info.Name); + source = Manager.SourcesHelper.Factory.GetSourceOrDefault(nativePackage.DefaultInstallVersion.PackageCatalog.Info.Name); var UniGetUIPackage = new Package( nativePackage.Name, @@ -197,7 +188,7 @@ public IEnumerable GetInstalledPackages_UnSafe() IManagerSource source; if (nativePackage.DefaultInstallVersion is not null) { - source = Manager.GetSourceOrDefault(nativePackage.DefaultInstallVersion.PackageCatalog.Info.Name); + source = Manager.SourcesHelper.Factory.GetSourceOrDefault(nativePackage.DefaultInstallVersion.PackageCatalog.Info.Name); } else { @@ -358,7 +349,7 @@ public void GetPackageDetails_UnSafe(IPackageDetails details) ProcessStartInfo startInfo = new() { FileName = Manager.WinGetBundledPath, - Arguments = Manager.Properties.ExecutableCallArgs + " show " + WinGetOperationProvider.GetIdNamePiece(details.Package) + + Arguments = Manager.Properties.ExecutableCallArgs + " show " + WinGetPkgOperationHelper.GetIdNamePiece(details.Package) + " --disable-interactivity --accept-source-agreements --source " + details.Package.Source.Name, RedirectStandardOutput = true, diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetPackageDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgDetailsHelper.cs similarity index 97% rename from src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetPackageDetailsProvider.cs rename to src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgDetailsHelper.cs index 242c9bc49..7351877d2 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetPackageDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgDetailsHelper.cs @@ -11,11 +11,11 @@ namespace UniGetUI.PackageEngine.Managers.WingetManager { - internal sealed class WinGetPackageDetailsProvider : BasePackageDetailsProvider + internal sealed class WinGetPkgDetailsHelper : BasePkgDetailsHelper { private static readonly Dictionary __msstore_package_manifests = []; - public WinGetPackageDetailsProvider(WinGet manager) : base(manager) { } + public WinGetPkgDetailsHelper(WinGet manager) : base(manager) { } protected override IEnumerable GetInstallableVersions_UnSafe(IPackage package) { diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetOperationProvider.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgOperationHelper.cs similarity index 94% rename from src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetOperationProvider.cs rename to src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgOperationHelper.cs index 65a872216..121b510f6 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetOperationProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgOperationHelper.cs @@ -6,7 +6,7 @@ using UniGetUI.PackageEngine.Interfaces; namespace UniGetUI.PackageEngine.Managers.WingetManager; -internal sealed class WinGetOperationProvider : BaseOperationProvider +internal sealed class WinGetPkgOperationHelper : PackagePkgOperationHelper { public static string GetIdNamePiece(IPackage package) { @@ -19,9 +19,9 @@ public static string GetIdNamePiece(IPackage package) return $"--id \"{package.Id.TrimEnd('…')}\""; } - public WinGetOperationProvider(WinGet manager) : base(manager) { } + public WinGetPkgOperationHelper(WinGet manager) : base(manager) { } - public override IEnumerable GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) + protected override IEnumerable _getOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) { List parameters = [operation switch { OperationType.Install => Manager.Properties.InstallVerb, @@ -108,7 +108,7 @@ public override IEnumerable GetOperationParameters(IPackage package, IIn return parameters; } - public override OperationVeredict GetOperationResult( + protected override OperationVeredict _getOperationResult( IPackage package, OperationType operation, IEnumerable processOutput, diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetSourceProvider.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetSourceHelper.cs similarity index 90% rename from src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetSourceProvider.cs rename to src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetSourceHelper.cs index e5f9971d9..3744cf35b 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/Providers/WinGetSourceProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetSourceHelper.cs @@ -5,9 +5,9 @@ namespace UniGetUI.PackageEngine.Managers.WingetManager { - internal sealed class WinGetSourceProvider : BaseSourceProvider + internal sealed class WinGetSourceHelper : BaseSourceHelper { - public WinGetSourceProvider(WinGet manager) : base(manager) { } + public WinGetSourceHelper(WinGet manager) : base(manager) { } public override string[] GetAddSourceParameters(IManagerSource source) { diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs index 9ba3741cb..e148d3e28 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs @@ -74,9 +74,9 @@ public WinGet() DefaultSource = new ManagerSource(this, "winget", new Uri("https://cdn.winget.microsoft.com/cache")) }; - SourceProvider = new WinGetSourceProvider(this); - PackageDetailsProvider = new WinGetPackageDetailsProvider(this); - OperationProvider = new WinGetOperationProvider(this); + SourcesHelper = new WinGetSourceHelper(this); + DetailsHelper = new WinGetPkgDetailsHelper(this); + OperationHelper = new WinGetPkgOperationHelper(this); LocalPcSource = new LocalWinGetSource(this, CoreTools.Translate("Local PC"), IconType.LocalPc); AndroidSubsystemSource = new(this, CoreTools.Translate("Android Subsystem"), IconType.Android); diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BaseOperationProvider.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BaseOperationProvider.cs deleted file mode 100644 index 0ae9ede13..000000000 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BaseOperationProvider.cs +++ /dev/null @@ -1,24 +0,0 @@ -using UniGetUI.PackageEngine.Enums; -using UniGetUI.PackageEngine.Interfaces; -using UniGetUI.PackageEngine.Interfaces.ManagerProviders; - -namespace UniGetUI.PackageEngine.Classes.Manager.BaseProviders; -public abstract class BaseOperationProvider : IOperationProvider where ManagerT : IPackageManager -{ - protected ManagerT Manager; - public BaseOperationProvider(ManagerT manager) - { - Manager = manager; - } - - public abstract IEnumerable GetOperationParameters( - IPackage package, - IInstallationOptions options, - OperationType operation); - - public abstract OperationVeredict GetOperationResult( - IPackage package, - OperationType operation, - IEnumerable processOutput, - int returnCode); -} diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BasePackageDetailsProvider.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BasePackageDetailsProvider.cs deleted file mode 100644 index 3e5585b30..000000000 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BasePackageDetailsProvider.cs +++ /dev/null @@ -1,115 +0,0 @@ -using UniGetUI.Core.IconEngine; -using UniGetUI.Core.Logging; -using UniGetUI.PackageEngine.Interfaces; -using UniGetUI.PackageEngine.Interfaces.ManagerProviders; - -namespace UniGetUI.PackageEngine.Classes.Manager.BaseProviders -{ - public abstract class BasePackageDetailsProvider : IPackageDetailsProvider where ManagerT : IPackageManager - { - protected ManagerT Manager; - - public BasePackageDetailsProvider(ManagerT manager) - { - Manager = manager; - } - - public void GetPackageDetails(IPackageDetails details) - { - GetDetails_UnSafe(details); - } - - public IEnumerable GetPackageVersions(IPackage package) - { - if (Manager.Capabilities.SupportsCustomVersions) - { - var result = GetInstallableVersions_UnSafe(package); - Logger.Debug($"Found {result.Count()} versions for package Id={package.Id} on manager {Manager.Name}"); - return result; - } - - Logger.Warn($"Manager {Manager.Name} does not support version retrieving, this method should have not been called"); - return []; - } - - public CacheableIcon? GetPackageIconUrl(IPackage package) - { - if (Manager.Capabilities.SupportsCustomPackageIcons) - { - var nativeIcon = GetIcon_UnSafe(package); - if (nativeIcon is not null) - { - return nativeIcon; - } - } - - string? iconUrl = IconDatabase.Instance.GetIconUrlForId(package.GetIconId()); - if (iconUrl is not null) - { - return new CacheableIcon(new Uri(iconUrl), package.Version); - } - - return null; - } - - public IEnumerable GetPackageScreenshotsUrl(IPackage package) - { - IEnumerable URIs = []; - - if (Manager.Capabilities.SupportsCustomPackageScreenshots) - { - URIs = GetScreenshots_UnSafe(package); - } - else - { - Logger.Debug($"Manager {Manager.Name} does not support native screenshots"); - } - - if (!URIs.Any()) - { - string[] UrlArray = IconDatabase.Instance.GetScreenshotsUrlForId(package.GetIconId()); - List UriList = []; - foreach (string url in UrlArray) - { - if (url != "") - { - UriList.Add(new Uri(url)); - } - } - - URIs = UriList; - } - Logger.Info($"Found {URIs.Count()} screenshots for package Id={package.Id}"); - return URIs; - } - - protected abstract void GetDetails_UnSafe(IPackageDetails details); - protected abstract IEnumerable GetInstallableVersions_UnSafe(IPackage package); - protected abstract CacheableIcon? GetIcon_UnSafe(IPackage package); - protected abstract IEnumerable GetScreenshots_UnSafe(IPackage package); - protected abstract string? GetInstallLocation_UnSafe(IPackage package); - - public string? GetPackageInstallLocation(IPackage package) - { - try - { - string? path = GetInstallLocation_UnSafe(package); - if (path is not null && !Directory.Exists(path)) - { - Logger.Warn($"Path returned by the package manager \"{path}\" did not exist while loading package install location for package Id={package.Id} with Manager={package.Manager.Name}"); - return null; - } - - return path; - } - catch (Exception ex) - { - Logger.Error($"An error occurred while loading package install location for package Id={package.Id} with Manager={package.Manager.Name}"); - Logger.Error(ex); - return null; - } - } - - - } -} diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BaseSourceProvider.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BaseSourceProvider.cs deleted file mode 100644 index 2f7611b88..000000000 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BaseSourceProvider.cs +++ /dev/null @@ -1,57 +0,0 @@ -using UniGetUI.Core.Classes; -using UniGetUI.PackageEngine.Enums; -using UniGetUI.PackageEngine.Interfaces; -using UniGetUI.PackageEngine.Interfaces.ManagerProviders; - -namespace UniGetUI.PackageEngine.Classes.Manager.Providers -{ - public abstract class BaseSourceProvider : ISourceProvider where ManagerT : IPackageManager - { - public ISourceFactory SourceFactory { get; } - protected ManagerT Manager; - - public BaseSourceProvider(ManagerT manager) - { - Manager = manager; - SourceFactory = new SourceFactory(manager); - } - - public abstract string[] GetAddSourceParameters(IManagerSource source); - public abstract string[] GetRemoveSourceParameters(IManagerSource source); - protected abstract OperationVeredict _getAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output); - protected abstract OperationVeredict _getRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output); - - public OperationVeredict GetAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) - { - TaskRecycler>.RemoveFromCache(_getSources); - return _getAddSourceOperationVeredict(source, ReturnCode, Output); - } - - public OperationVeredict GetRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) - { - TaskRecycler>.RemoveFromCache(_getSources); - return _getRemoveSourceOperationVeredict(source, ReturnCode, Output); - } - - - - /// - /// Loads the sources for the manager. This method SHOULD NOT handle exceptions - /// - protected abstract IEnumerable GetSources_UnSafe(); - - public virtual IEnumerable GetSources() - => TaskRecycler>.RunOrAttach(_getSources, 15); - - public virtual IEnumerable _getSources() - { - IEnumerable sources = GetSources_UnSafe(); - SourceFactory.Reset(); - - foreach (IManagerSource source in sources) - SourceFactory.AddSource(source); - - return sources; - } - } -} diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/NullPackageManager.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/NullPackageManager.cs index 7cf842501..990083df2 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/NullPackageManager.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/NullPackageManager.cs @@ -3,6 +3,7 @@ using UniGetUI.Core.Tools; using UniGetUI.Interface.Enums; using UniGetUI.PackageEngine.Classes.Manager.BaseProviders; +using UniGetUI.PackageEngine.Classes.Manager.Classes; using UniGetUI.PackageEngine.Classes.Manager.ManagerHelpers; using UniGetUI.PackageEngine.Classes.Manager.Providers; using UniGetUI.PackageEngine.Enums; @@ -17,32 +18,26 @@ namespace UniGetUI.PackageEngine.Classes.Manager public class NullPackageManager : IPackageManager { public static NullPackageManager Instance = new(); - public ManagerProperties Properties { get; set; } - public ManagerCapabilities Capabilities { get; set; } - public ManagerStatus Status { get; set; } - public string Name { get => Properties.Name; set { } } - public string DisplayName { get => Properties.DisplayName ?? Properties.Name; set { } } - public IManagerSource DefaultSource { get => Properties.DefaultSource; set { } } - public bool ManagerReady { get => true; set { } } - - public IManagerLogger TaskLogger { get; set; } - - public ISourceProvider? SourceProvider { get; set; } - - public IPackageDetailsProvider? PackageDetailsProvider { get; set; } - - public ISourceFactory SourceFactory { get; set; } - - public IOperationProvider? OperationProvider { get; set; } + public ManagerProperties Properties { get; } + public ManagerCapabilities Capabilities { get; } + public ManagerStatus Status { get; } + public string Name { get => Properties.Name; } + public string DisplayName { get => Properties.DisplayName ?? Properties.Name; } + public IManagerSource DefaultSource { get => Properties.DefaultSource; } + public bool ManagerReady { get => true; } + public IManagerLogger TaskLogger { get; } + public IMultiSourceHelper SourcesHelper { get; } + public IPackageDetailsHelper DetailsHelper { get; } + public IPackageOperationHelper OperationHelper { get; } + public IEnumerable Dependencies { get; } public NullPackageManager() { TaskLogger = new ManagerLogger(this); var nullsource = NullSource.Instance; - SourceProvider = new NullSourceProvider(this); - PackageDetailsProvider = new NullPackageDetailsProvider(this); - OperationProvider = new NullOperationProvider(this); - SourceFactory = new SourceFactory(this); + SourcesHelper = new NullSourceHelper(); + DetailsHelper = new NullPkgDetailsHelper(); + OperationHelper = new NullPkgOperationHelper(); Properties = new ManagerProperties { IsDummy = true, @@ -58,240 +53,67 @@ public NullPackageManager() KnownSources = [nullsource], DefaultSource = nullsource, }; - Capabilities = new ManagerCapabilities(); - Status = new ManagerStatus { ExecutablePath = "C:/file.exe", Found = false, Version = "0" }; + Dependencies = []; } - public IEnumerable FindPackages(string query) - { - throw new NotImplementedException(); - } - - public OperationVeredict GetAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) - { - throw new NotImplementedException(); - } - - public string[] GetAddSourceParameters(IManagerSource source) - { - throw new NotImplementedException(); - } - - public IEnumerable GetAvailableUpdates() - { - throw new NotImplementedException(); - } - - public IEnumerable GetInstalledPackages() - { - throw new NotImplementedException(); - } - - public OperationVeredict GetInstallOperationVeredict(IPackage package, IInstallationOptions options, int ReturnCode, string[] Output) - { - throw new NotImplementedException(); - } - - public string[] GetInstallParameters(IPackage package, IInstallationOptions options) - { - throw new NotImplementedException(); - } - - public void GetPackageDetails(IPackageDetails details) - { - throw new NotImplementedException(); - } - - public CacheableIcon? GetPackageIconUrl(IPackage package) - { - throw new NotImplementedException(); - } - - public IEnumerable GetPackageScreenshotsUrl(IPackage package) - { - throw new NotImplementedException(); - } - - public string? GetPackageInstallLocation(IPackage package) - { - throw new NotImplementedException(); - } - - public IEnumerable GetPackageVersions(IPackage package) - { - throw new NotImplementedException(); - } - - public OperationVeredict GetRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) - { - throw new NotImplementedException(); - } - - public string[] GetRemoveSourceParameters(IManagerSource source) - { - throw new NotImplementedException(); - } + public IEnumerable FindPackages(string query) => throw new NotImplementedException(); - public IManagerSource? GetSourceIfExists(string SourceName) - { - throw new NotImplementedException(); - } + public IEnumerable GetAvailableUpdates() => throw new NotImplementedException(); - public IManagerSource GetSourceOrDefault(string SourceName) - { - throw new NotImplementedException(); - } + public IEnumerable GetInstalledPackages() => throw new NotImplementedException(); - public IEnumerable GetSources() - { - throw new NotImplementedException(); - } + public void Initialize() => throw new NotImplementedException(); - public OperationVeredict GetUninstallOperationVeredict(IPackage package, IInstallationOptions options, int ReturnCode, string[] Output) - { - throw new NotImplementedException(); - } + public bool IsEnabled() => throw new NotImplementedException(); - public string[] GetUninstallParameters(IPackage package, IInstallationOptions options) - { - throw new NotImplementedException(); - } + public bool IsReady() => throw new NotImplementedException(); - public OperationVeredict GetUpdateOperationVeredict(IPackage package, IInstallationOptions options, int ReturnCode, string[] Output) - { - throw new NotImplementedException(); - } + public void RefreshPackageIndexes() => throw new NotImplementedException(); - public string[] GetUpdateParameters(IPackage package, IInstallationOptions options) - { - throw new NotImplementedException(); - } - - public void Initialize() - { - throw new NotImplementedException(); - } - - public bool IsEnabled() - { - throw new NotImplementedException(); - } - - public bool IsReady() - { - throw new NotImplementedException(); - } - - public void LogOperation(Process process, string output) - { - throw new NotImplementedException(); - } - - public void RefreshPackageIndexes() - { - throw new NotImplementedException(); - } - - public IEnumerable GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) - { - throw new NotImplementedException(); - } - - public OperationVeredict GetOperationResult(IPackage package, OperationType operation, IEnumerable processOutput, int returnCode) - { - throw new NotImplementedException(); - } - - public void AttemptFastRepair() - { - throw new NotImplementedException(); - } + public void AttemptFastRepair() => throw new NotImplementedException(); } - internal sealed class NullSourceProvider : BaseSourceProvider + internal class NullSourceHelper : IMultiSourceHelper { - public NullSourceProvider(IPackageManager manager) : base(manager) - { - } + public ISourceFactory Factory => throw new NotImplementedException(); - public override string[] GetAddSourceParameters(IManagerSource source) - { - throw new InvalidOperationException("Package manager does not support adding sources"); - } - public override string[] GetRemoveSourceParameters(IManagerSource source) - { - throw new InvalidOperationException("Package manager does not support removing sources"); - } + public string[] GetAddSourceParameters(IManagerSource source) => throw new NotImplementedException(); - protected override OperationVeredict _getAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) - { - return OperationVeredict.Failed; - } + public string[] GetRemoveSourceParameters(IManagerSource source) => throw new NotImplementedException(); - protected override OperationVeredict _getRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) - { - return OperationVeredict.Failed; - } + public OperationVeredict GetAddOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) => throw new NotImplementedException(); - protected override IEnumerable GetSources_UnSafe() - { - return Array.Empty(); - } + public OperationVeredict GetRemoveOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) => throw new NotImplementedException(); + + public IEnumerable GetSources() => throw new NotImplementedException(); } - internal sealed class NullPackageDetailsProvider : BasePackageDetailsProvider + internal sealed class NullPkgDetailsHelper : IPackageDetailsHelper { - public NullPackageDetailsProvider(IPackageManager manager) : base(manager) - { - } + public void GetDetails(IPackageDetails details) => throw new NotImplementedException(); - protected override void GetDetails_UnSafe(IPackageDetails details) - { - return; - } + public IEnumerable GetVersions(IPackage package) => throw new NotImplementedException(); - protected override CacheableIcon? GetIcon_UnSafe(IPackage package) - { - return null; - } + public CacheableIcon? GetIcon(IPackage package) => throw new NotImplementedException(); - protected override IEnumerable GetScreenshots_UnSafe(IPackage package) - { - return []; - } + public IEnumerable GetScreenshots(IPackage package) => throw new NotImplementedException(); - protected override string? GetInstallLocation_UnSafe(IPackage package) - { - return null; - } - - protected override IEnumerable GetInstallableVersions_UnSafe(IPackage package) - { - return []; - } + public string? GetInstallLocation(IPackage package) => throw new NotImplementedException(); } - internal sealed class NullOperationProvider : BaseOperationProvider + internal sealed class NullPkgOperationHelper : IPackageOperationHelper { - public NullOperationProvider(IPackageManager manager) : base(manager) - { - } + public IEnumerable GetParameters(IPackage package, IInstallationOptions options, OperationType operation) + => throw new NotImplementedException(); - public override IEnumerable GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) - { - return Array.Empty(); - } - - public override OperationVeredict GetOperationResult(IPackage package, OperationType operation, IEnumerable processOutput, int returnCode) - { - return OperationVeredict.Failed; - } + public OperationVeredict GetResult(IPackage package, OperationType operation, IEnumerable processOutput, int returnCode) + => throw new NotImplementedException(); } } diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Helpers/BasePkgDetailsHelper.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Helpers/BasePkgDetailsHelper.cs new file mode 100644 index 000000000..746ea2634 --- /dev/null +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Helpers/BasePkgDetailsHelper.cs @@ -0,0 +1,151 @@ +using UniGetUI.Core.IconEngine; +using UniGetUI.Core.Logging; +using UniGetUI.PackageEngine.Interfaces; +using UniGetUI.PackageEngine.Interfaces.ManagerProviders; + +namespace UniGetUI.PackageEngine.Classes.Manager.BaseProviders +{ + public abstract class BasePkgDetailsHelper : IPackageDetailsHelper + { + protected IPackageManager Manager; + + public BasePkgDetailsHelper(IPackageManager manager) + { + Manager = manager; + } + + public void GetDetails(IPackageDetails details) + { + if (!Manager.IsReady()) { Logger.Warn($"Manager {Manager.Name} is disabled but yet GetPackageDetails was called"); return; } + try + { + GetDetails_UnSafe(details); + Logger.Info($"Loaded details for package {details.Package.Id} on manager {Manager.Name}"); + } + catch (Exception e) + { + Logger.Error("Error finding installed packages on manager " + Manager.Name); + Logger.Error(e); + } + } + + public IEnumerable GetVersions(IPackage package) + { + if (!Manager.IsReady()) + { + Logger.Warn($"Manager {Manager.Name} is disabled but yet GetPackageVersions was called"); + return []; + } + try + { + if (Manager.Capabilities.SupportsCustomVersions) + { + var result = GetInstallableVersions_UnSafe(package); + Logger.Debug($"Found {result.Count()} versions for package Id={package.Id} on manager {Manager.Name}"); + return result; + } + + Logger.Warn($"Manager {Manager.Name} does not support version retrieving, this method should have not been called"); + return []; + } + catch (Exception e) + { + Logger.Error($"Error finding available package versions for package {package.Id} on manager " + Manager.Name); + Logger.Error(e); + return []; + } + } + + public CacheableIcon? GetIcon(IPackage package) + { + try + { + if (Manager.Capabilities.SupportsCustomPackageIcons) + { + var nativeIcon = GetIcon_UnSafe(package); + if (nativeIcon is not null) + { + return nativeIcon; + } + } + + string? iconUrl = IconDatabase.Instance.GetIconUrlForId(package.GetIconId()); + if (iconUrl is not null) + { + return new CacheableIcon(new Uri(iconUrl), package.Version); + } + + return null; + } catch (Exception e) + { + Logger.Error($"Error when loading the package icon for the package {package.Id} on manager " + Manager.Name); + Logger.Error(e); + return null; + } + } + + public IEnumerable GetScreenshots(IPackage package) + { + try + { + IEnumerable URIs = []; + + if (Manager.Capabilities.SupportsCustomPackageScreenshots) + { + URIs = GetScreenshots_UnSafe(package); + } + else + { + Logger.Debug($"Manager {Manager.Name} does not support native screenshots"); + } + + if (!URIs.Any()) + { + string[] UrlArray = IconDatabase.Instance.GetScreenshotsUrlForId(package.GetIconId()); + List UriList = []; + foreach (string url in UrlArray) + { + if (url != "") UriList.Add(new Uri(url)); + } + URIs = UriList; + } + + Logger.Info($"Found {URIs.Count()} screenshots for package Id={package.Id}"); + return URIs; + } + catch (Exception e) + { + Logger.Error($"Error when loading the package icon for the package {package.Id} on manager " + Manager.Name); + Logger.Error(e); + return []; + } + } + + protected abstract void GetDetails_UnSafe(IPackageDetails details); + protected abstract IEnumerable GetInstallableVersions_UnSafe(IPackage package); + protected abstract CacheableIcon? GetIcon_UnSafe(IPackage package); + protected abstract IEnumerable GetScreenshots_UnSafe(IPackage package); + protected abstract string? GetInstallLocation_UnSafe(IPackage package); + + public string? GetInstallLocation(IPackage package) + { + try + { + string? path = GetInstallLocation_UnSafe(package); + if (path is not null && !Directory.Exists(path)) + { + Logger.Warn($"Path returned by the package manager \"{path}\" did not exist while loading package install location for package Id={package.Id} with Manager={package.Manager.Name}"); + return null; + } + + return path; + } + catch (Exception ex) + { + Logger.Error($"An error occurred while loading package install location for package Id={package.Id} with Manager={package.Manager.Name}"); + Logger.Error(ex); + return null; + } + } + } +} diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Helpers/BaseSourceHelper.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Helpers/BaseSourceHelper.cs new file mode 100644 index 000000000..568d0edec --- /dev/null +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Helpers/BaseSourceHelper.cs @@ -0,0 +1,80 @@ +using UniGetUI.Core.Classes; +using UniGetUI.Core.Logging; +using UniGetUI.PackageEngine.Enums; +using UniGetUI.PackageEngine.Interfaces; +using UniGetUI.PackageEngine.Interfaces.ManagerProviders; + +namespace UniGetUI.PackageEngine.Classes.Manager.Providers +{ + public abstract class BaseSourceHelper : IMultiSourceHelper + { + public ISourceFactory Factory { get; } + protected IPackageManager Manager; + + public BaseSourceHelper(IPackageManager manager) + { + Manager = manager; + Factory = new SourceFactory(manager); + } + + public abstract string[] GetAddSourceParameters(IManagerSource source); + public abstract string[] GetRemoveSourceParameters(IManagerSource source); + protected abstract OperationVeredict _getAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output); + protected abstract OperationVeredict _getRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output); + + public OperationVeredict GetAddOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) + { + TaskRecycler>.RemoveFromCache(_getSources); + if (ReturnCode is 999 && Output.Last() == "Error: The operation was canceled by the user.") + { + Logger.Warn("Elevator [or GSudo] UAC prompt was canceled, not showing error message..."); + return OperationVeredict.Canceled; + } + return _getAddSourceOperationVeredict(source, ReturnCode, Output); + } + + public OperationVeredict GetRemoveOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) + { + TaskRecycler>.RemoveFromCache(_getSources); + if (ReturnCode is 999 && Output.Last() == "Error: The operation was canceled by the user.") + { + Logger.Warn("Elevator [or GSudo] UAC prompt was canceled, not showing error message..."); + return OperationVeredict.Canceled; + } + return _getRemoveSourceOperationVeredict(source, ReturnCode, Output); + } + + /// + /// Loads the sources for the manager. This method SHOULD NOT handle exceptions + /// + protected abstract IEnumerable GetSources_UnSafe(); + + public virtual IEnumerable GetSources() + => TaskRecycler>.RunOrAttach(_getSources, 15); + + public virtual IEnumerable _getSources() + { + if (!Manager.IsReady()) { Logger.Warn($"Manager {Manager.Name} is disabled but yet GetSources was called"); return []; } + + try + { + IEnumerable sources = GetSources_UnSafe().ToArray(); + Factory.Reset(); + + foreach (IManagerSource source in sources) + Factory.AddSource(source); + + Logger.Debug($"Loaded {sources.Count()} sources for manager {Manager.Name}"); + return sources; + } + catch (Exception e) + { + Logger.Error("Error finding sources for manager " + Manager.Name); + Logger.Error(e); + return []; + } + + + } + } +} diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Helpers/PackagePkgOperationHelper.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Helpers/PackagePkgOperationHelper.cs new file mode 100644 index 000000000..289b2c8c1 --- /dev/null +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Helpers/PackagePkgOperationHelper.cs @@ -0,0 +1,75 @@ +using UniGetUI.Core.Logging; +using UniGetUI.PackageEngine.Enums; +using UniGetUI.PackageEngine.Interfaces; +using UniGetUI.PackageEngine.Interfaces.ManagerProviders; + +namespace UniGetUI.PackageEngine.Classes.Manager.BaseProviders; + +public abstract class PackagePkgOperationHelper : IPackageOperationHelper +{ + protected IPackageManager Manager; + + public PackagePkgOperationHelper(IPackageManager manager) + { + Manager = manager; + } + + protected abstract IEnumerable _getOperationParameters( + IPackage package, + IInstallationOptions options, + OperationType operation); + + protected abstract OperationVeredict _getOperationResult( + IPackage package, + OperationType operation, + IEnumerable processOutput, + int returnCode); + + + public IEnumerable GetParameters( + IPackage package, + IInstallationOptions options, + OperationType operation) + { + try + { + var parameters = _getOperationParameters(package, options, operation); + Logger.Info( + $"Loaded operation parameters for package id={package.Id} on manager {Manager.Name} and operation {operation}: " + + string.Join(' ', parameters)); + return parameters; + } + catch (Exception ex) + { + Logger.Error( + $"A fatal error ocurred while loading operation parameters for package id={package.Id} on manager {Manager.Name} and operation {operation}"); + Logger.Error(ex); + return []; + } + } + + public OperationVeredict GetResult( + IPackage package, + OperationType operation, + IEnumerable processOutput, + int returnCode) + { + try + { + if (returnCode is 999 && processOutput.Last() == "Error: The operation was canceled by the user.") + { + Logger.Warn("Elevator [or GSudo] UAC prompt was canceled, not showing error message..."); + return OperationVeredict.Canceled; + } + + return _getOperationResult(package, operation, processOutput, returnCode); + } + catch (Exception ex) + { + Logger.Error( + $"A fatal error ocurred while loading operation parameters for package id={package.Id} on manager {Manager.Name} and operation {operation}"); + Logger.Error(ex); + return OperationVeredict.Failed; + } + } +} diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/PackageManager.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/PackageManager.cs index e973932eb..c459d76ef 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/PackageManager.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/PackageManager.cs @@ -14,37 +14,32 @@ namespace UniGetUI.PackageEngine.ManagerClasses.Manager { - public abstract class PackageManager : SingletonBase, IPackageManager + public abstract class PackageManager : IPackageManager { public ManagerProperties Properties { get; set; } = new(IsDummy: true); public ManagerCapabilities Capabilities { get; set; } = new(IsDummy: true); public ManagerStatus Status { get; set; } = new() { Found = false }; - public string Name { get => Properties.Name ?? "Unset"; } + public string Name { get => Properties.Name; } public string DisplayName { get => Properties.DisplayName ?? Name; } public IManagerSource DefaultSource { get => Properties.DefaultSource; } - - public static string[] FALSE_PACKAGE_NAMES = [""]; - public static string[] FALSE_PACKAGE_IDS = [""]; - public static string[] FALSE_PACKAGE_VERSIONS = [""]; public bool ManagerReady { get; set; } public IManagerLogger TaskLogger { get; } - - public ISourceProvider SourceProvider { get; set; } - public ISourceFactory SourceFactory { get => SourceProvider.SourceFactory; } public IEnumerable Dependencies { get; protected set; } = []; + public IMultiSourceHelper SourcesHelper { get; protected set; } = new NullSourceHelper(); + public IPackageDetailsHelper DetailsHelper { get; protected set; } = null!; + public IPackageOperationHelper OperationHelper { get; protected set; } = null!; - public IPackageDetailsProvider? PackageDetailsProvider { get; set; } - public IOperationProvider OperationProvider { get; set; } - - private readonly bool __base_constructor_called; + private readonly bool _baseConstructorCalled; public PackageManager() { - __base_constructor_called = true; + _baseConstructorCalled = true; TaskLogger = new ManagerLogger(this); - SourceProvider = new NullSourceProvider(this); - PackageDetailsProvider = new NullPackageDetailsProvider(this); - OperationProvider = new NullOperationProvider(this); + } + + private static void Throw(string message) + { + throw new InvalidDataException(message); } /// @@ -53,30 +48,15 @@ public PackageManager() public virtual void Initialize() { // BEGIN integrity check - if (!__base_constructor_called) - { - throw new InvalidOperationException($"The Manager {Properties.Name} has not called the base constructor."); - } + if (!_baseConstructorCalled) Throw($"The Manager {Properties.Name} has not called the base constructor."); + if (Capabilities.IsDummy) Throw($"The current instance of PackageManager with name ${Properties.Name} does not have a valid Capabilities object"); + if (Properties.IsDummy) Throw($"The current instance of PackageManager with name ${Properties.Name} does not have a valid Properties object"); - if (Capabilities.IsDummy) - { - throw new InvalidOperationException($"The current instance of PackageManager with name ${Properties.Name} does not have a valid Capabilities object"); - } - - if (Properties.IsDummy) - { - throw new InvalidOperationException($"The current instance of PackageManager with name ${Properties.Name} does not have a valid Properties object"); - } + if (OperationHelper is NullPkgOperationHelper) Throw($"Manager {Name} does not have an OperationProvider"); + if (DetailsHelper is NullPkgDetailsHelper) Throw($"Manager {Name} does not have a valid DetailsHelper"); - if (Capabilities.SupportsCustomSources && SourceProvider is NullSourceProvider) - { - throw new InvalidOperationException($"Manager {Name} has been declared as SupportsCustomSources but has no helper associated with it"); - } - - if (OperationProvider is NullOperationProvider) - { - throw new InvalidOperationException($"Manager {Name} does not have an OperationProvider"); - } + if (Capabilities.SupportsCustomSources && SourcesHelper is NullSourceHelper) + Throw($"Manager {Name} has been declared as SupportsCustomSources but has no helper associated with it"); // END integrity check Properties.DefaultSource.RefreshSourceNames(); @@ -88,12 +68,12 @@ public virtual void Initialize() if (IsReady() && Capabilities.SupportsCustomSources) { - Task> sourcesTask = Task.Run(() => GetSources()); + Task> sourcesTask = Task.Run(() => SourcesHelper.GetSources()); if (sourcesTask.Wait(TimeSpan.FromSeconds(15))) { foreach (var source in sourcesTask.Result) - SourceFactory.AddSource(source); + SourcesHelper?.Factory.AddSource(source); } else { @@ -325,213 +305,5 @@ public virtual void AttemptFastRepair() { // Implementing this method is optional } - - - // BEGIN SOURCE-RELATED METHODS - - /// - /// Will check if the Manager supports custom sources, and throw an exception if not - /// - /// - private void AssertSourceCompatibility(string MethodName) - { - if (!Capabilities.SupportsCustomSources) - { - throw new InvalidOperationException($"Manager {Name} does not support custom sources but yet {MethodName} method was called.\n {Environment.StackTrace}"); - } - - if (SourceProvider is null) - { - throw new InvalidOperationException($"Manager {Name} does support custom sources but yet the source helper is null"); - } - } - public IManagerSource GetSourceOrDefault(string SourceName) - { - AssertSourceCompatibility("GetSourceFromName"); - return SourceProvider.SourceFactory.GetSourceOrDefault(SourceName); - } - public IManagerSource? GetSourceIfExists(string SourceName) - { - AssertSourceCompatibility("GetSourceIfExists"); - return SourceProvider.SourceFactory.GetSourceIfExists(SourceName); - } - public string[] GetAddSourceParameters(IManagerSource source) - { - AssertSourceCompatibility("GetAddSourceParameters"); - return SourceProvider.GetAddSourceParameters(source); - } - public string[] GetRemoveSourceParameters(IManagerSource source) - { - AssertSourceCompatibility("GetRemoveSourceParameters"); - return SourceProvider.GetRemoveSourceParameters(source); - } - public OperationVeredict GetAddSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) - { - AssertSourceCompatibility("GetAddSourceOperationVeredict"); - - if (ReturnCode is 999 && Output.Last() == "Error: The operation was canceled by the user.") - { - Logger.Warn("Elevator [or GSudo] UAC prompt was canceled, not showing error message..."); - return OperationVeredict.Canceled; - } - return SourceProvider.GetAddSourceOperationVeredict(source, ReturnCode, Output); - } - - public OperationVeredict GetRemoveSourceOperationVeredict(IManagerSource source, int ReturnCode, string[] Output) - { - AssertSourceCompatibility("GetRemoveSourceOperationVeredict"); - - if (ReturnCode is 999 && Output.Last() == "Error: The operation was canceled by the user.") - { - Logger.Warn("Elevator [or GSudo] UAC prompt was canceled, not showing error message..."); - return OperationVeredict.Canceled; - } - return SourceProvider.GetRemoveSourceOperationVeredict(source, ReturnCode, Output); - } - - public virtual IEnumerable GetSources() - { - if (!IsReady()) { Logger.Warn($"Manager {Name} is disabled but yet GetSources was called"); return []; } - try - { - AssertSourceCompatibility("GetSources"); - var result = SourceProvider.GetSources(); - Logger.Debug($"Loaded {result.Count()} sources for manager {Name}"); - return result; - } - catch (Exception e) - { - Logger.Error("Error finding sources for manager " + Name); - Logger.Error(e); - return []; - } - } - // END SOURCE-RELATED METHODS - - // BEGIN PACKAGEDEAILS-RELATED METHODS - private void AssertPackageDetailsCompatibility(string methodName) - { - if (PackageDetailsProvider is null) - { - throw new InvalidOperationException($"Manager {Name} does not have a valid PackageDetailsProvider helper, when attemtping to call {methodName}"); - } - } - - public void GetPackageDetails(IPackageDetails details) - { - if (!IsReady()) { Logger.Warn($"Manager {Name} is disabled but yet GetPackageDetails was called"); return; } - try - { - AssertPackageDetailsCompatibility("GetPackageDetails"); - PackageDetailsProvider?.GetPackageDetails(details); - Logger.Info($"Loaded details for package {details.Package.Id} on manager {Name}"); - } - catch (Exception e) - { - Logger.Error("Error finding installed packages on manager " + Name); - Logger.Error(e); - } - } - - public IEnumerable GetPackageVersions(IPackage package) - { - if (!IsReady()) - { - Logger.Warn($"Manager {Name} is disabled but yet GetPackageVersions was called"); - return []; - } - try - { - AssertPackageDetailsCompatibility("GetPackageVersions"); - if (package.Manager.Capabilities.SupportsCustomVersions) - { - return PackageDetailsProvider?.GetPackageVersions(package) ?? []; - } - - return []; - } - catch (Exception e) - { - Logger.Error($"Error finding available package versions for package {package.Id} on manager " + Name); - Logger.Error(e); - return []; - } - } - - public CacheableIcon? GetPackageIconUrl(IPackage package) - { - try - { - AssertPackageDetailsCompatibility("GetPackageIcon"); - return PackageDetailsProvider?.GetPackageIconUrl(package); - } - catch (Exception e) - { - Logger.Error($"Error when loading the package icon for the package {package.Id} on manager " + Name); - Logger.Error(e); - return null; - } - } - - public IEnumerable GetPackageScreenshotsUrl(IPackage package) - { - try - { - AssertPackageDetailsCompatibility("GetPackageScreenshots"); - return PackageDetailsProvider?.GetPackageScreenshotsUrl(package) ?? []; - } - catch (Exception e) - { - Logger.Error($"Error when loading the package icon for the package {package.Id} on manager " + Name); - Logger.Error(e); - return []; - } - } - - public string? GetPackageInstallLocation(IPackage package) - { - return PackageDetailsProvider?.GetPackageInstallLocation(package); - } - // END PACKAGEDETAILS-RELATED METHODS - - - // BEGIN OPERATION-RELATED METHODS - public IEnumerable GetOperationParameters(IPackage package, IInstallationOptions options, OperationType operation) - { - try - { - var parameters = OperationProvider.GetOperationParameters(package, options, operation); - Logger.Info($"Loaded operation parameters for package id={package.Id} on manager {Name} and operation {operation}: " + string.Join(' ', parameters)); - return parameters; - } - catch (Exception ex) - { - Logger.Error($"A fatal error ocurred while loading operation parameters for package id={package.Id} on manager {Name} and operation {operation}"); - Logger.Error(ex); - return []; - } - } - - public OperationVeredict GetOperationResult(IPackage package, OperationType operation, IEnumerable processOutput, int returnCode) - { - try - { - if (returnCode is 999 && processOutput.Last() == "Error: The operation was canceled by the user.") - { - Logger.Warn("Elevator [or GSudo] UAC prompt was canceled, not showing error message..."); - return OperationVeredict.Canceled; - } - - return OperationProvider.GetOperationResult(package, operation, processOutput, returnCode); - } - catch (Exception ex) - { - Logger.Error($"A fatal error ocurred while loading operation parameters for package id={package.Id} on manager {Name} and operation {operation}"); - Logger.Error(ex); - return OperationVeredict.Failed; - } - } - // END OPERATION-RELATED METHODS -#pragma warning restore CS8602 } } diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/PackageDetails.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/PackageDetails.cs index 9962a86ea..2ad067831 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/PackageDetails.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/PackageDetails.cs @@ -103,7 +103,7 @@ public async Task Load() { try { - await Task.Run(() => Package.Manager.GetPackageDetails(this)); + await Task.Run(() => Package.Manager.DetailsHelper.GetDetails(this)); IsPopulated = true; } catch (Exception ex) diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs index b94540798..18e80908d 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs @@ -173,7 +173,7 @@ public virtual Uri GetIconUrl() { try { - CacheableIcon? icon = TaskRecycler.RunOrAttach(Manager.GetPackageIconUrl, this); + CacheableIcon? icon = TaskRecycler.RunOrAttach(Manager.DetailsHelper.GetIcon, this); string? path = IconCacheEngine.GetCacheOrDownloadIcon(icon, Manager.Name, Id); return path is null? null: new Uri("file:///" + path); } @@ -187,7 +187,7 @@ public virtual Uri GetIconUrl() public virtual IEnumerable GetScreenshots() { - return Manager.GetPackageScreenshotsUrl(this); + return Manager.DetailsHelper.GetScreenshots(this); } public virtual async Task AddToIgnoredUpdatesAsync(string version = "*") diff --git a/src/UniGetUI/App.xaml.cs b/src/UniGetUI/App.xaml.cs index 5021f1274..b4919f878 100644 --- a/src/UniGetUI/App.xaml.cs +++ b/src/UniGetUI/App.xaml.cs @@ -295,10 +295,8 @@ private async Task CheckForMissingDependencies() { // Check for missing dependencies on package managers List missing_deps = []; - foreach (IPackageManager imanager in PEInterface.Managers) + foreach (IPackageManager manager in PEInterface.Managers) { - if (imanager is not PackageManager manager) continue; - if (!manager.IsReady()) { continue; diff --git a/src/UniGetUI/Controls/OperationWidgets/PackageOperations.cs b/src/UniGetUI/Controls/OperationWidgets/PackageOperations.cs index 386d3a46e..b3e87642d 100644 --- a/src/UniGetUI/Controls/OperationWidgets/PackageOperations.cs +++ b/src/UniGetUI/Controls/OperationWidgets/PackageOperations.cs @@ -58,7 +58,7 @@ public PackageOperation( protected sealed override async Task BuildProcessInstance(ProcessStartInfo startInfo) { - string operation_args = string.Join(" ", Package.Manager.GetOperationParameters(Package, Options, Role)); + string operation_args = string.Join(" ", Package.Manager.OperationHelper.GetParameters(Package, Options, Role)); if (Package.OverridenOptions.RunAsAdministrator == true || Options.RunAsAdministrator @@ -92,7 +92,7 @@ protected override Task HandleCancelation() protected sealed override Task GetProcessVeredict(int ReturnCode, string[] Output) { - return Task.FromResult(Package.Manager.GetOperationResult(Package, Role, Output, ReturnCode)); + return Task.FromResult(Package.Manager.OperationHelper.GetResult(Package, Role, Output, ReturnCode)); } protected override async Task WaitForAvailability() diff --git a/src/UniGetUI/Controls/OperationWidgets/SourceOperations.cs b/src/UniGetUI/Controls/OperationWidgets/SourceOperations.cs index d97ee41df..5aea58d79 100644 --- a/src/UniGetUI/Controls/OperationWidgets/SourceOperations.cs +++ b/src/UniGetUI/Controls/OperationWidgets/SourceOperations.cs @@ -133,12 +133,12 @@ protected override async Task BuildProcessInstance(ProcessStar await CoreTools.CacheUACForCurrentProcess(); } startInfo.FileName = CoreData.GSudoPath; - startInfo.Arguments = $"\"{Source.Manager.Status.ExecutablePath}\" " + Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.GetAddSourceParameters(Source)); + startInfo.Arguments = $"\"{Source.Manager.Status.ExecutablePath}\" " + Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.SourcesHelper.GetAddSourceParameters(Source)); } else { startInfo.FileName = Source.Manager.Status.ExecutablePath; - startInfo.Arguments = Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.GetAddSourceParameters(Source)); + startInfo.Arguments = Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.SourcesHelper.GetAddSourceParameters(Source)); } return startInfo; @@ -154,7 +154,7 @@ protected override string[] GenerateProcessLogHeader() protected override Task GetProcessVeredict(int ReturnCode, string[] Output) { - return Task.Run(() => Source.Manager.GetAddSourceOperationVeredict(Source, ReturnCode, Output)); + return Task.Run(() => Source.Manager.SourcesHelper.GetAddOperationVeredict(Source, ReturnCode, Output)); } protected override async Task HandleFailure() @@ -214,13 +214,13 @@ protected override async Task BuildProcessInstance(ProcessStar await CoreTools.CacheUACForCurrentProcess(); } startInfo.FileName = CoreData.GSudoPath; - startInfo.Arguments = $"\"{Source.Manager.Status.ExecutablePath}\" " + Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.GetRemoveSourceParameters(Source)); + startInfo.Arguments = $"\"{Source.Manager.Status.ExecutablePath}\" " + Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.SourcesHelper.GetRemoveSourceParameters(Source)); } else { startInfo.FileName = Source.Manager.Status.ExecutablePath; - startInfo.Arguments = Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.GetRemoveSourceParameters(Source)); + startInfo.Arguments = Source.Manager.Properties.ExecutableCallArgs + " " + string.Join(" ", Source.Manager.SourcesHelper.GetRemoveSourceParameters(Source)); } return startInfo; @@ -236,7 +236,7 @@ protected override string[] GenerateProcessLogHeader() protected override Task GetProcessVeredict(int ReturnCode, string[] Output) { - return Task.Run(() => Source.Manager.GetRemoveSourceOperationVeredict(Source, ReturnCode, Output)); + return Task.Run(() => Source.Manager.SourcesHelper.GetRemoveOperationVeredict(Source, ReturnCode, Output)); } protected override async Task HandleFailure() diff --git a/src/UniGetUI/Controls/SourceManager.xaml.cs b/src/UniGetUI/Controls/SourceManager.xaml.cs index 05d4bc7ac..dabca5f8b 100644 --- a/src/UniGetUI/Controls/SourceManager.xaml.cs +++ b/src/UniGetUI/Controls/SourceManager.xaml.cs @@ -166,7 +166,7 @@ public async void LoadSources() LoadingBar.Visibility = Visibility.Visible; Sources.Clear(); - foreach (IManagerSource source in await Task.Run(Manager.GetSources)) + foreach (IManagerSource source in await Task.Run(Manager.SourcesHelper.GetSources)) { Sources.Add(new SourceItem(this, source)); } diff --git a/src/UniGetUI/Pages/DialogPages/DialogHelper_Generic.cs b/src/UniGetUI/Pages/DialogPages/DialogHelper_Generic.cs index ec4157a0b..64e417f1e 100644 --- a/src/UniGetUI/Pages/DialogPages/DialogHelper_Generic.cs +++ b/src/UniGetUI/Pages/DialogPages/DialogHelper_Generic.cs @@ -324,11 +324,11 @@ public static async void HandleBrokenWinGet() "cmd.exe /C \"rmdir /Q /S `\"%temp%\\WinGet`\"\"; " + "cmd.exe /C \"`\"%localappdata%\\Microsoft\\WindowsApps\\winget.exe`\" source reset --force\"; " + "taskkill /im winget.exe /f; " + - "taskkill /im WindowsPackageManagerServer.exe /f; " + + "taskkill /im WindowsIPackageManagerServer.exe /f; " + "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force; " + "Install-Module Microsoft.WinGet.Client -Force -Scope AllUsers -AllowClobber; " + "Import-Module Microsoft.WinGet.Client; " + - "Repair-WinGetPackageManager -Force -Latest; " + + "Repair-WinGetIPackageManager -Force -Latest; " + "Get-AppxPackage -Name 'Microsoft.DesktopAppInstaller' | Reset-AppxPackage" + "}\"", UseShellExecute = true, diff --git a/src/UniGetUI/Pages/DialogPages/InstallOptions.xaml.cs b/src/UniGetUI/Pages/DialogPages/InstallOptions.xaml.cs index d0463d4d5..8d24dfe41 100644 --- a/src/UniGetUI/Pages/DialogPages/InstallOptions.xaml.cs +++ b/src/UniGetUI/Pages/DialogPages/InstallOptions.xaml.cs @@ -132,7 +132,7 @@ private async Task LoadVersions() IgnoreUpdatesCheckbox.IsChecked = await Package.HasUpdatesIgnoredAsync(); VersionComboBox.IsEnabled = false; - IEnumerable versions = await Task.Run(() => Package.Manager.GetPackageVersions(Package)); + IEnumerable versions = await Task.Run(() => Package.Manager.DetailsHelper.GetVersions(Package)); foreach (string ver in versions) { VersionComboBox.Items.Add(ver); diff --git a/src/UniGetUI/Pages/DialogPages/PackageDetailsPage.xaml.cs b/src/UniGetUI/Pages/DialogPages/PackageDetailsPage.xaml.cs index 1cbadbadc..a35ccbf59 100644 --- a/src/UniGetUI/Pages/DialogPages/PackageDetailsPage.xaml.cs +++ b/src/UniGetUI/Pages/DialogPages/PackageDetailsPage.xaml.cs @@ -306,7 +306,7 @@ public async Task LoadInformation() } CommandTextBlock.Text = Package.Manager.Properties.ExecutableFriendlyName + " " + - string.Join(' ', Package.Manager.GetOperationParameters(Package, await InstallationOptions.FromPackageAsync(Package), OperationRole)); + string.Join(' ', Package.Manager.OperationHelper.GetParameters(Package, await InstallationOptions.FromPackageAsync(Package), OperationRole)); LoadingIndicator.Visibility = Visibility.Collapsed; diff --git a/src/UniGetUI/Pages/LogPages/ManagerLogsPage.cs b/src/UniGetUI/Pages/LogPages/ManagerLogsPage.cs index 89d3386a4..eed0d4da8 100644 --- a/src/UniGetUI/Pages/LogPages/ManagerLogsPage.cs +++ b/src/UniGetUI/Pages/LogPages/ManagerLogsPage.cs @@ -2,6 +2,7 @@ using Microsoft.UI.Xaml.Media; using UniGetUI.Core.Tools; using UniGetUI.PackageEngine; +using UniGetUI.PackageEngine.Interfaces; using UniGetUI.PackageEngine.ManagerClasses.Classes; using UniGetUI.PackageEngine.ManagerClasses.Manager; @@ -15,7 +16,7 @@ public ManagerLogsPage() : base(true) } - public void LoadForManager(PackageManager manager) + public void LoadForManager(IPackageManager manager) { bool IS_DARK = ActualTheme == Microsoft.UI.Xaml.ElementTheme.Dark; bool verbose = LogLevelCombo.SelectedValue?.ToString()?.Contains(CoreTools.Translate("Verbose")) ?? false; @@ -54,7 +55,7 @@ public void LoadForManager(PackageManager manager) public override void LoadLog(bool isReload = false) { - foreach (PackageManager manager in PEInterface.Managers) + foreach (IPackageManager manager in PEInterface.Managers) { if (LogLevelCombo.SelectedValue?.ToString()?.Contains(manager.DisplayName) ?? false) { @@ -69,7 +70,7 @@ public override void LoadLog(bool isReload = false) protected override void LoadLogLevels() { LogLevelCombo.Items.Clear(); - foreach (PackageManager manager in PEInterface.Managers) + foreach (IPackageManager manager in PEInterface.Managers) { LogLevelCombo.Items.Add(manager.DisplayName); LogLevelCombo.Items.Add($"{manager.DisplayName} ({CoreTools.Translate("Verbose")})"); diff --git a/src/UniGetUI/Pages/MainView.xaml.cs b/src/UniGetUI/Pages/MainView.xaml.cs index b1a86e860..56b746d4e 100644 --- a/src/UniGetUI/Pages/MainView.xaml.cs +++ b/src/UniGetUI/Pages/MainView.xaml.cs @@ -12,6 +12,7 @@ using UniGetUI.Interface.SoftwarePages; using UniGetUI.Interface.Widgets; using Windows.UI.Core; +using UniGetUI.PackageEngine.Interfaces; using UniGetUI.PackageEngine.ManagerClasses.Manager; using UniGetUI.Pages.DialogPages; @@ -263,9 +264,9 @@ private void OperationHistoryMenu_Click(object sender, RoutedEventArgs e) => NavigateTo(PageType.OperationHistory); private void ManagerLogsMenu_Click(object sender, RoutedEventArgs e) - => OpenPackageManagerLogs(); + => OpenManagerLogs(); - public void OpenPackageManagerLogs(PackageManager? manager = null) + public void OpenManagerLogs(IPackageManager? manager = null) { NavigateTo(PageType.ManagerLog); if(manager is not null) ManagerLogPage?.LoadForManager(manager); diff --git a/src/UniGetUI/Pages/SettingsPage.xaml.cs b/src/UniGetUI/Pages/SettingsPage.xaml.cs index fa5d9c069..b9bdf95a3 100644 --- a/src/UniGetUI/Pages/SettingsPage.xaml.cs +++ b/src/UniGetUI/Pages/SettingsPage.xaml.cs @@ -114,7 +114,7 @@ public SettingsPage() ExperimentalSettingsExpander.HideRestartRequiredBanner(); // Package Manager banners; - Dictionary PackageManagerExpanders = []; + Dictionary IPackageManagerExpanders = []; Dictionary> ExtraSettingsCards = []; foreach (IPackageManager Manager in PEInterface.Managers) @@ -126,12 +126,12 @@ public SettingsPage() // ---------------------------------------------------------------------------------------- - ButtonCard WinGet_ResetWindowsPackageManager = new() { + ButtonCard WinGet_ResetWindowsIPackageManager = new() { Text = CoreTools.AutoTranslated("Reset WinGet") + $" ({CoreTools.Translate("This may help if no packages are listed")})", ButtonText = CoreTools.AutoTranslated("Reset") }; - WinGet_ResetWindowsPackageManager.Click += (_, _) => + WinGet_ResetWindowsIPackageManager.Click += (_, _) => { DialogHelper.HandleBrokenWinGet(); // CoreTools.LaunchBatchFile(Path.Join(CoreData.UniGetUIExecutableDirectory, "Assets", "Utilities", "reset_winget_sources.cmd"), CoreTools.Translate("Resetting Winget sources - WingetUI"), RunAsAdmin: true); @@ -144,7 +144,7 @@ public SettingsPage() }; WinGet_UseBundled.StateChanged += (_, _) => { - PackageManagerExpanders[PEInterface.WinGet].ShowRestartRequiredBanner(); + IPackageManagerExpanders[PEInterface.WinGet].ShowRestartRequiredBanner(); }; CheckboxCard WinGet_EnableTroubleshooter = new() @@ -159,7 +159,7 @@ public SettingsPage() }; ExtraSettingsCards[PEInterface.WinGet].Add(WinGet_EnableTroubleshooter); - ExtraSettingsCards[PEInterface.WinGet].Add(WinGet_ResetWindowsPackageManager); + ExtraSettingsCards[PEInterface.WinGet].Add(WinGet_ResetWindowsIPackageManager); ExtraSettingsCards[PEInterface.WinGet].Add(WinGet_UseBundled); @@ -170,13 +170,13 @@ public SettingsPage() Scoop_Install.Click += (_, _) => { CoreTools.LaunchBatchFile(Path.Join(CoreData.UniGetUIExecutableDirectory, "Assets", "Utilities", "install_scoop.cmd"), CoreTools.Translate("Scoop Installer - WingetUI")); - PackageManagerExpanders[PEInterface.Scoop].ShowRestartRequiredBanner(); + IPackageManagerExpanders[PEInterface.Scoop].ShowRestartRequiredBanner(); }; ButtonCard Scoop_Uninstall = new() { Text = CoreTools.AutoTranslated("Uninstall Scoop (and its packages)"), ButtonText = CoreTools.AutoTranslated("Uninstall") }; Scoop_Uninstall.Click += (_, _) => { CoreTools.LaunchBatchFile(Path.Join(CoreData.UniGetUIExecutableDirectory, "Assets", "Utilities", "uninstall_scoop.cmd"), CoreTools.Translate("Scoop Uninstaller - WingetUI")); - PackageManagerExpanders[PEInterface.Scoop].ShowRestartRequiredBanner(); + IPackageManagerExpanders[PEInterface.Scoop].ShowRestartRequiredBanner(); }; ButtonCard Scoop_ResetAppCache = new() { Text = CoreTools.AutoTranslated("Run cleanup and clear cache"), ButtonText = CoreTools.AutoTranslated("Run") }; Scoop_ResetAppCache.Click += (_, _) => @@ -195,7 +195,7 @@ public SettingsPage() CheckboxCard Chocolatey_SystemChoco = new() { Text = CoreTools.AutoTranslated("Use system Chocolatey"), SettingName = "UseSystemChocolatey" }; Chocolatey_SystemChoco.StateChanged += (_, _) => { - PackageManagerExpanders[PEInterface.Chocolatey].ShowRestartRequiredBanner(); + IPackageManagerExpanders[PEInterface.Chocolatey].ShowRestartRequiredBanner(); }; ExtraSettingsCards[PEInterface.Chocolatey].Add(Chocolatey_SystemChoco); @@ -276,7 +276,7 @@ public SettingsPage() Vcpkg_CustomVcpkgRoot.Click += (_, _) => { - PackageManagerExpanders[PEInterface.Vcpkg].ShowRestartRequiredBanner(); + IPackageManagerExpanders[PEInterface.Vcpkg].ShowRestartRequiredBanner(); }; @@ -296,7 +296,7 @@ public SettingsPage() Text = Manager.DisplayName, Description = Manager.Properties.Description.Replace("
", "\n").Replace("", "").Replace("", "") }; - PackageManagerExpanders.Add(Manager, ManagerExpander); + IPackageManagerExpanders.Add(Manager, ManagerExpander); ManagerExpander.HeaderIcon = new LocalIcon(Manager.Properties.IconId); // Creation of the status footer @@ -335,7 +335,7 @@ public SettingsPage() }; managerLogs.Click += (_, _) => { - MainApp.Instance.MainWindow.NavigationPage.OpenPackageManagerLogs(Manager as PackageManager); + MainApp.Instance.MainWindow.NavigationPage.OpenManagerLogs(Manager as IPackageManager); }; Grid g = new() diff --git a/src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml.cs b/src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml.cs index 9b5e3a82c..28a344f01 100644 --- a/src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml.cs +++ b/src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml.cs @@ -508,7 +508,7 @@ public void FilterPackages() VisibleManagers.Add(manager); if (manager.Capabilities.SupportsCustomSources) { - foreach (IManagerSource source in manager.SourceFactory.GetAvailableSources()) + foreach (IManagerSource source in manager.SourcesHelper.Factory.GetAvailableSources()) if (!VisibleSources.Contains(source)) VisibleSources.Add(source); } } @@ -704,7 +704,7 @@ protected void ShowDetailsForPackage(IPackage? package) protected void OpenPackageInstallLocation(IPackage? package) { - string? path = package?.Manager.GetPackageInstallLocation(package); + string? path = package?.Manager.DetailsHelper.GetInstallLocation(package); if(path is not null) Process.Start(new ProcessStartInfo diff --git a/src/UniGetUI/Pages/SoftwarePages/InstalledPackagesPage.cs b/src/UniGetUI/Pages/SoftwarePages/InstalledPackagesPage.cs index 85b7d4525..9fc4be77c 100644 --- a/src/UniGetUI/Pages/SoftwarePages/InstalledPackagesPage.cs +++ b/src/UniGetUI/Pages/SoftwarePages/InstalledPackagesPage.cs @@ -321,7 +321,7 @@ protected override async void WhenShowingContextMenu(IPackage package) MenuSharePackage.IsEnabled = !IS_LOCAL; MenuPackageDetails.IsEnabled = !IS_LOCAL; - MenuOpenInstallLocation.IsEnabled = package.Manager.GetPackageInstallLocation(package) is not null; + MenuOpenInstallLocation.IsEnabled = package.Manager.DetailsHelper.GetInstallLocation(package) is not null; if (!IS_LOCAL) { if (await package.HasUpdatesIgnoredAsync()) diff --git a/src/UniGetUI/Pages/SoftwarePages/PackageBundlesPage.cs b/src/UniGetUI/Pages/SoftwarePages/PackageBundlesPage.cs index 594e1f4d5..68561ccbb 100644 --- a/src/UniGetUI/Pages/SoftwarePages/PackageBundlesPage.cs +++ b/src/UniGetUI/Pages/SoftwarePages/PackageBundlesPage.cs @@ -650,7 +650,7 @@ public static IPackage PackageFromSerializable(SerializablePackage_v1 raw_packag if (manager?.Capabilities.SupportsCustomSources == true) { - source = manager?.SourceProvider?.SourceFactory.GetSourceIfExists(raw_package.Source); + source = manager?.SourcesHelper?.Factory.GetSourceIfExists(raw_package.Source); } else source = manager?.DefaultSource; diff --git a/src/UniGetUI/Pages/SoftwarePages/SoftwareUpdatesPage.cs b/src/UniGetUI/Pages/SoftwarePages/SoftwareUpdatesPage.cs index 90b39b2da..9a149b1f5 100644 --- a/src/UniGetUI/Pages/SoftwarePages/SoftwareUpdatesPage.cs +++ b/src/UniGetUI/Pages/SoftwarePages/SoftwareUpdatesPage.cs @@ -179,7 +179,7 @@ protected override void WhenShowingContextMenu(IPackage package) MenuInteractive.IsEnabled = package.Manager.Capabilities.CanRunInteractively; MenuskipHash.IsEnabled = package.Manager.Capabilities.CanSkipIntegrityChecks; - MenuOpenInstallLocation.IsEnabled = package.Manager.GetPackageInstallLocation(package) is not null; + MenuOpenInstallLocation.IsEnabled = package.Manager.DetailsHelper.GetInstallLocation(package) is not null; } public override void GenerateToolBar()