diff --git a/StabilityMatrix/App.xaml.cs b/StabilityMatrix/App.xaml.cs index 64039843..154edff6 100644 --- a/StabilityMatrix/App.xaml.cs +++ b/StabilityMatrix/App.xaml.cs @@ -18,7 +18,6 @@ using Microsoft.Extensions.Logging; using NLog; using NLog.Config; using NLog.Extensions.Logging; -using NLog.Layouts; using NLog.Targets; using Octokit; using Polly; @@ -361,9 +360,13 @@ namespace StabilityMatrix }; var exceptionWindow = new ExceptionWindow { - DataContext = vm, - Owner = MainWindow + DataContext = vm }; + + if (MainWindow?.IsActive ?? false) + { + exceptionWindow.Owner = MainWindow; + } exceptionWindow.ShowDialog(); } e.Handled = true; diff --git a/StabilityMatrix/CheckpointBrowserPage.xaml b/StabilityMatrix/CheckpointBrowserPage.xaml index cd6513d2..3a784e6e 100644 --- a/StabilityMatrix/CheckpointBrowserPage.xaml +++ b/StabilityMatrix/CheckpointBrowserPage.xaml @@ -139,7 +139,7 @@ + + : JsonConverter where T : Enum +{ + public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.String) + { + throw new JsonException(); + } + + var enumText = reader.GetString(); + if (Enum.TryParse(typeof(T), enumText, true, out var result)) + { + return (T) result!; + } + + // Unknown value handling + if (Enum.TryParse(typeof(T), "Unknown", true, out var unknownResult)) + { + return (T) unknownResult!; + } + + throw new JsonException($"Unable to parse '{enumText}' to enum '{typeof(T)}'."); + } + + public override void Write(Utf8JsonWriter writer, T? value, JsonSerializerOptions options) + { + if (value == null) + { + writer.WriteNullValue(); + return; + } + writer.WriteStringValue(value.GetStringValue()); + } +} diff --git a/StabilityMatrix/Helper/IPrerequisiteHelper.cs b/StabilityMatrix/Helper/IPrerequisiteHelper.cs index 1bb577ad..6dc948c9 100644 --- a/StabilityMatrix/Helper/IPrerequisiteHelper.cs +++ b/StabilityMatrix/Helper/IPrerequisiteHelper.cs @@ -8,10 +8,13 @@ public interface IPrerequisiteHelper { string GitBinPath { get; } + bool IsPythonInstalled { get; } + Task InstallAllIfNecessary(IProgress? progress = null); Task UnpackResourcesIfNecessary(IProgress? progress = null); Task InstallGitIfNecessary(IProgress? progress = null); Task InstallVcRedistIfNecessary(IProgress? progress = null); + Task InstallPythonIfNecessary(IProgress? progress = null); /// /// Run embedded git with the given arguments. diff --git a/StabilityMatrix/Helper/PrerequisiteHelper.cs b/StabilityMatrix/Helper/PrerequisiteHelper.cs index f4e0a8a2..e317ad65 100644 --- a/StabilityMatrix/Helper/PrerequisiteHelper.cs +++ b/StabilityMatrix/Helper/PrerequisiteHelper.cs @@ -42,6 +42,8 @@ public class PrerequisiteHelper : IPrerequisiteHelper private string PortableGitDownloadPath => Path.Combine(HomeDir, "PortableGit.7z.exe"); private string GitExePath => Path.Combine(PortableGitInstallDir, "bin", "git.exe"); public string GitBinPath => Path.Combine(PortableGitInstallDir, "bin"); + + public bool IsPythonInstalled => File.Exists(PythonDllPath); public PrerequisiteHelper(ILogger logger, IGitHubClient gitHubClient, IDownloadService downloadService, ISettingsManager settingsManager) @@ -215,9 +217,8 @@ public class PrerequisiteHelper : IPrerequisiteHelper logger.LogInformation("Git not found at {GitExePath}, downloading...", GitExePath); - var latestRelease = await gitHubClient.Repository.Release.GetLatest("git-for-windows", "git"); - var portableGitUrl = latestRelease.Assets - .First(a => a.Name.EndsWith("64-bit.7z.exe")).BrowserDownloadUrl; + var portableGitUrl = + "https://github.com/git-for-windows/git/releases/download/v2.41.0.windows.1/PortableGit-2.41.0-64-bit.7z.exe"; if (!File.Exists(PortableGitDownloadPath)) { diff --git a/StabilityMatrix/Models/Api/CivitModelType.cs b/StabilityMatrix/Models/Api/CivitModelType.cs index e397cf23..29c9a169 100644 --- a/StabilityMatrix/Models/Api/CivitModelType.cs +++ b/StabilityMatrix/Models/Api/CivitModelType.cs @@ -1,13 +1,15 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization; +using StabilityMatrix.Converters.Json; using StabilityMatrix.Extensions; namespace StabilityMatrix.Models.Api; -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(DefaultUnknownEnumConverter))] [SuppressMessage("ReSharper", "InconsistentNaming")] public enum CivitModelType { + Unknown, [ConvertTo(SharedFolderType.StableDiffusion)] Checkpoint, [ConvertTo(SharedFolderType.TextualInversion)] diff --git a/StabilityMatrix/SettingsPage.xaml b/StabilityMatrix/SettingsPage.xaml index 005bcd17..a3505e90 100644 --- a/StabilityMatrix/SettingsPage.xaml +++ b/StabilityMatrix/SettingsPage.xaml @@ -133,10 +133,25 @@ FontWeight="Bold" Margin="0,8" Text="Embedded Python" /> -