From 8ae6d1f4834dff239586d4f2577494fe1d8f7ddf Mon Sep 17 00:00:00 2001 From: JT Date: Sat, 27 May 2023 22:10:05 -0700 Subject: [PATCH] implemented package updater - Packages are now injected & so is IPackageFactory - Updater checks on load, so probably only once per launch? but should be fine - Moved install button - Multi-purpose install button - probably more idk --- StabilityMatrix/App.xaml.cs | 6 + StabilityMatrix/Helper/EventManager.cs | 2 + StabilityMatrix/Helper/IPackageFactory.cs | 10 ++ StabilityMatrix/Helper/ISettingsManager.cs | 1 + StabilityMatrix/Helper/PackageFactory.cs | 22 ++-- StabilityMatrix/Helper/SettingsManager.cs | 13 +++ StabilityMatrix/InstallPage.xaml | 23 ++-- StabilityMatrix/MainWindow.xaml.cs | 9 ++ StabilityMatrix/Models/BasePackage.cs | 15 ++- StabilityMatrix/Models/InstalledPackage.cs | 1 - StabilityMatrix/Models/Packages/A3WebUI.cs | 92 +++++++++++++-- .../Models/Packages/DankDiffusion.cs | 14 ++- .../ViewModels/InstallerViewModel.cs | 106 ++++++++++++++---- StabilityMatrix/ViewModels/LaunchViewModel.cs | 6 +- .../ViewModels/MainWindowViewModel.cs | 7 +- 15 files changed, 266 insertions(+), 61 deletions(-) create mode 100644 StabilityMatrix/Helper/IPackageFactory.cs diff --git a/StabilityMatrix/App.xaml.cs b/StabilityMatrix/App.xaml.cs index 6d108a3a..82e6640d 100644 --- a/StabilityMatrix/App.xaml.cs +++ b/StabilityMatrix/App.xaml.cs @@ -5,12 +5,15 @@ using System.IO; using System.Text.Json; using System.Text.Json.Serialization; using System.Windows; +using Windows.ApplicationModel; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using Refit; using StabilityMatrix.Api; using StabilityMatrix.Helper; +using StabilityMatrix.Models; +using StabilityMatrix.Models.Packages; using StabilityMatrix.Services; using StabilityMatrix.ViewModels; using Wpf.Ui.Contracts; @@ -46,6 +49,9 @@ namespace StabilityMatrix serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); diff --git a/StabilityMatrix/Helper/EventManager.cs b/StabilityMatrix/Helper/EventManager.cs index 455edc1b..06ebed05 100644 --- a/StabilityMatrix/Helper/EventManager.cs +++ b/StabilityMatrix/Helper/EventManager.cs @@ -12,5 +12,7 @@ public class EventManager } public event EventHandler? GlobalProgressChanged; + public event EventHandler? PageChangeRequested; public void OnGlobalProgressChanged(int progress) => GlobalProgressChanged?.Invoke(this, progress); + public void RequestPageChange(Type pageType) => PageChangeRequested?.Invoke(this, pageType); } diff --git a/StabilityMatrix/Helper/IPackageFactory.cs b/StabilityMatrix/Helper/IPackageFactory.cs new file mode 100644 index 00000000..af441435 --- /dev/null +++ b/StabilityMatrix/Helper/IPackageFactory.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using StabilityMatrix.Models; + +namespace StabilityMatrix.Helper; + +public interface IPackageFactory +{ + IEnumerable GetAllAvailablePackages(); + BasePackage? FindPackageByName(string packageName); +} \ No newline at end of file diff --git a/StabilityMatrix/Helper/ISettingsManager.cs b/StabilityMatrix/Helper/ISettingsManager.cs index 15f5ad86..c342c0c6 100644 --- a/StabilityMatrix/Helper/ISettingsManager.cs +++ b/StabilityMatrix/Helper/ISettingsManager.cs @@ -11,4 +11,5 @@ public interface ISettingsManager void SetHasInstalledPip(bool hasInstalledPip); void SetHasInstalledVenv(bool hasInstalledVenv); void SetNavExpanded(bool navExpanded); + void UpdatePackageVersionNumber(string packageName, string newVersion); } diff --git a/StabilityMatrix/Helper/PackageFactory.cs b/StabilityMatrix/Helper/PackageFactory.cs index ae3abf94..f5535ffc 100644 --- a/StabilityMatrix/Helper/PackageFactory.cs +++ b/StabilityMatrix/Helper/PackageFactory.cs @@ -2,25 +2,25 @@ using System.Collections.Generic; using System.Linq; using StabilityMatrix.Models; -using StabilityMatrix.Models.Packages; namespace StabilityMatrix.Helper; -public static class PackageFactory +public class PackageFactory : IPackageFactory { - private static readonly List AllPackages = new() - { - new A3WebUI(), - new DankDiffusion() - }; + private readonly IEnumerable basePackages; - public static IEnumerable GetAllAvailablePackages() + public PackageFactory(IEnumerable basePackages) + { + this.basePackages = basePackages; + } + + public IEnumerable GetAllAvailablePackages() { - return AllPackages; + return basePackages; } - public static BasePackage? FindPackageByName(string packageName) + public BasePackage? FindPackageByName(string packageName) { - return AllPackages.FirstOrDefault(x => x.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase)); + return basePackages.FirstOrDefault(x => x.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase)); } } diff --git a/StabilityMatrix/Helper/SettingsManager.cs b/StabilityMatrix/Helper/SettingsManager.cs index 21d31c55..7d4dcf2c 100644 --- a/StabilityMatrix/Helper/SettingsManager.cs +++ b/StabilityMatrix/Helper/SettingsManager.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Text.Json; using StabilityMatrix.Models; @@ -74,6 +75,18 @@ public class SettingsManager : ISettingsManager SaveSettings(); } + public void UpdatePackageVersionNumber(string packageName, string? newVersion) + { + var package = Settings.InstalledPackages.FirstOrDefault(x => x.PackageName == packageName); + if (package == null || newVersion == null) + { + return; + } + + package.PackageVersion = newVersion; + SaveSettings(); + } + private void LoadSettings() { var settingsContent = File.ReadAllText(SettingsPath); diff --git a/StabilityMatrix/InstallPage.xaml b/StabilityMatrix/InstallPage.xaml index 3b3cdd65..c474ad5e 100644 --- a/StabilityMatrix/InstallPage.xaml +++ b/StabilityMatrix/InstallPage.xaml @@ -19,17 +19,18 @@ - -