From 99a7067482552a9d3804022487bc4e59853126ff Mon Sep 17 00:00:00 2001 From: JT Date: Sat, 8 Jul 2023 16:49:01 -0700 Subject: [PATCH] moved most everything out of the old project --- .../Controls/UserControlBase.cs | 4 +- .../DesignData/DesignData.cs | 5 -- .../DesignData/MockNotificationService.cs | 1 - .../Services/INotificationService.cs | 1 - .../Services/NotificationService.cs | 6 +- .../ViewModels}/CheckpointFile.cs | 73 +++++++++---------- .../ViewModels}/CheckpointFolder.cs | 7 +- .../ViewModels/LaunchPageViewModel.cs | 4 - .../ViewModels/MainWindowViewModel.cs | 1 - .../ViewModels/PackageManagerViewModel.cs | 2 - .../ViewModels/SettingsViewModel.cs | 6 +- .../Views/LaunchPageView.axaml | 26 +++---- .../Views/SettingsPage.axaml | 2 +- .../Api/A3WebApiManager.cs | 6 +- .../Api/IA3WebApi.cs | 6 +- .../Api/IA3WebApiManager.cs | 2 +- .../Api/ICivitApi.cs | 5 +- .../Database/CivitModelQueryCacheEntry.cs | 6 +- .../Database/ILiteDbContext.cs | 7 +- .../Database/LiteDbContext.cs | 9 +-- .../Helper/ArchiveHelper.cs | 24 +++--- .../Helper}/ISharedFolders.cs | 2 +- .../Helper/ModelFinder.cs | 10 +-- .../Helper/PrerequisiteHelper.cs | 24 +++--- .../Helper}/SharedFolders.cs | 7 +- .../Models/ConnectedModelInfo.cs | 7 +- .../Models/GlobalUserSecrets.cs | 35 +++++---- .../Services/SettingsManager.cs | 7 +- .../StabilityMatrix.Core.csproj | 6 ++ .../Updater/IUpdateHelper.cs | 6 +- .../Updater/SignatureChecker.cs | 5 +- .../Updater/UpdateHelper.cs | 19 ++--- .../Helper/EventManagerTests.cs | 1 - .../Models/SharedFoldersTests.cs | 2 +- .../ReparsePoints/JunctionTests.cs | 3 +- StabilityMatrix/App.xaml.cs | 7 +- StabilityMatrix/CheckpointManagerPage.xaml | 1 - .../DesignData/MockCheckpointFolder.cs | 4 +- StabilityMatrix/StabilityMatrix.csproj | 4 + StabilityMatrix/TextToImagePage.xaml | 1 - .../CheckpointBrowserCardViewModel.cs | 2 +- .../ViewModels/CheckpointBrowserViewModel.cs | 5 +- .../ViewModels/CheckpointManagerViewModel.cs | 2 +- .../DataDirectoryMigrationViewModel.cs | 2 - .../ViewModels/InstallerViewModel.cs | 2 +- StabilityMatrix/ViewModels/LaunchViewModel.cs | 2 +- .../ViewModels/MainWindowViewModel.cs | 5 +- .../ViewModels/OneClickInstallViewModel.cs | 1 - .../ViewModels/SettingsViewModel.cs | 4 +- .../ViewModels/TextToImageViewModel.cs | 3 +- .../ViewModels/UpdateWindowViewModel.cs | 2 +- 51 files changed, 156 insertions(+), 228 deletions(-) rename {StabilityMatrix/Models => StabilityMatrix.Avalonia/ViewModels}/CheckpointFile.cs (79%) rename {StabilityMatrix/Models => StabilityMatrix.Avalonia/ViewModels}/CheckpointFolder.cs (98%) rename {StabilityMatrix => StabilityMatrix.Core}/Api/A3WebApiManager.cs (95%) rename {StabilityMatrix => StabilityMatrix.Core}/Api/IA3WebApi.cs (88%) rename {StabilityMatrix => StabilityMatrix.Core}/Api/IA3WebApiManager.cs (84%) rename {StabilityMatrix => StabilityMatrix.Core}/Api/ICivitApi.cs (83%) rename {StabilityMatrix => StabilityMatrix.Core}/Database/CivitModelQueryCacheEntry.cs (84%) rename {StabilityMatrix => StabilityMatrix.Core}/Database/ILiteDbContext.cs (83%) rename {StabilityMatrix => StabilityMatrix.Core}/Database/LiteDbContext.cs (96%) rename {StabilityMatrix => StabilityMatrix.Core}/Helper/ArchiveHelper.cs (91%) rename {StabilityMatrix/Models => StabilityMatrix.Core/Helper}/ISharedFolders.cs (89%) rename {StabilityMatrix => StabilityMatrix.Core}/Helper/ModelFinder.cs (93%) rename {StabilityMatrix/Models => StabilityMatrix.Core/Helper}/SharedFolders.cs (98%) rename {StabilityMatrix => StabilityMatrix.Core}/Models/ConnectedModelInfo.cs (95%) rename {StabilityMatrix => StabilityMatrix.Core}/Models/GlobalUserSecrets.cs (84%) rename {StabilityMatrix => StabilityMatrix.Core}/Updater/IUpdateHelper.cs (62%) rename {StabilityMatrix => StabilityMatrix.Core}/Updater/SignatureChecker.cs (96%) rename {StabilityMatrix => StabilityMatrix.Core}/Updater/UpdateHelper.cs (91%) diff --git a/StabilityMatrix.Avalonia/Controls/UserControlBase.cs b/StabilityMatrix.Avalonia/Controls/UserControlBase.cs index 9e7c572b..145e9060 100644 --- a/StabilityMatrix.Avalonia/Controls/UserControlBase.cs +++ b/StabilityMatrix.Avalonia/Controls/UserControlBase.cs @@ -1,8 +1,6 @@ -using System; -using AsyncAwaitBestPractices; +using AsyncAwaitBestPractices; using Avalonia.Controls; using Avalonia.Interactivity; -using Avalonia.Markup.Xaml; using StabilityMatrix.Avalonia.ViewModels; namespace StabilityMatrix.Avalonia.Controls; diff --git a/StabilityMatrix.Avalonia/DesignData/DesignData.cs b/StabilityMatrix.Avalonia/DesignData/DesignData.cs index 9d439022..a5e96ffe 100644 --- a/StabilityMatrix.Avalonia/DesignData/DesignData.cs +++ b/StabilityMatrix.Avalonia/DesignData/DesignData.cs @@ -1,11 +1,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; using AvaloniaEdit.Utils; -using Microsoft.Extensions.Logging; -using NLog; -using StabilityMatrix.Avalonia.Services; using StabilityMatrix.Avalonia.ViewModels; using StabilityMatrix.Core.Helper.Factory; using StabilityMatrix.Core.Models; diff --git a/StabilityMatrix.Avalonia/DesignData/MockNotificationService.cs b/StabilityMatrix.Avalonia/DesignData/MockNotificationService.cs index 5c8d233e..ea445be7 100644 --- a/StabilityMatrix.Avalonia/DesignData/MockNotificationService.cs +++ b/StabilityMatrix.Avalonia/DesignData/MockNotificationService.cs @@ -1,7 +1,6 @@ using Avalonia; using Avalonia.Controls.Notifications; using StabilityMatrix.Avalonia.Services; -using StabilityMatrix.Avalonia.ViewModels; namespace StabilityMatrix.Avalonia.DesignData; diff --git a/StabilityMatrix.Avalonia/Services/INotificationService.cs b/StabilityMatrix.Avalonia/Services/INotificationService.cs index 0aeeebce..2d7db8ca 100644 --- a/StabilityMatrix.Avalonia/Services/INotificationService.cs +++ b/StabilityMatrix.Avalonia/Services/INotificationService.cs @@ -1,6 +1,5 @@ using Avalonia; using Avalonia.Controls.Notifications; -using StabilityMatrix.Avalonia.ViewModels; namespace StabilityMatrix.Avalonia.Services; diff --git a/StabilityMatrix.Avalonia/Services/NotificationService.cs b/StabilityMatrix.Avalonia/Services/NotificationService.cs index 7238cfa0..c55f21c9 100644 --- a/StabilityMatrix.Avalonia/Services/NotificationService.cs +++ b/StabilityMatrix.Avalonia/Services/NotificationService.cs @@ -1,10 +1,6 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using Avalonia; +using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Notifications; -using FluentAvalonia.UI.Controls; -using StabilityMatrix.Avalonia.ViewModels; namespace StabilityMatrix.Avalonia.Services; diff --git a/StabilityMatrix/Models/CheckpointFile.cs b/StabilityMatrix.Avalonia/ViewModels/CheckpointFile.cs similarity index 79% rename from StabilityMatrix/Models/CheckpointFile.cs rename to StabilityMatrix.Avalonia/ViewModels/CheckpointFile.cs index c576f0d4..67c371d3 100644 --- a/StabilityMatrix/Models/CheckpointFile.cs +++ b/StabilityMatrix.Avalonia/ViewModels/CheckpointFile.cs @@ -5,24 +5,24 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Threading.Tasks; -using System.Windows; -using System.Windows.Media.Imaging; using AsyncAwaitBestPractices; +using Avalonia.Media.Imaging; +using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using NLog; using StabilityMatrix.Core.Extensions; using StabilityMatrix.Core.Helper; +using StabilityMatrix.Core.Models; +using StabilityMatrix.Core.Models.FileInterfaces; using StabilityMatrix.Core.Models.Progress; using StabilityMatrix.Core.Processes; -using StabilityMatrix.Helper; -namespace StabilityMatrix.Models; +namespace StabilityMatrix.Avalonia.ViewModels; public partial class CheckpointFile : ObservableObject { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private readonly IDialogFactory dialogFactory; // Event for when this file is deleted public event EventHandler? Deleted; @@ -41,7 +41,7 @@ public partial class CheckpointFile : ObservableObject private string title = string.Empty; public string? PreviewImagePath { get; set; } - public BitmapImage? PreviewImage { get; set; } + public Bitmap? PreviewImage { get; set; } public bool IsPreviewImageLoaded => PreviewImage != null; [ObservableProperty] @@ -50,18 +50,13 @@ public partial class CheckpointFile : ObservableObject [ObservableProperty] private bool isLoading; - public string FileName => Path.GetFileName(FilePath); + public string FileName => Path.GetFileName((string?) FilePath); public ObservableCollection Badges { get; set; } = new(); private static readonly string[] SupportedCheckpointExtensions = { ".safetensors", ".pt", ".ckpt", ".pth", "bin" }; private static readonly string[] SupportedImageExtensions = { ".png", ".jpg", ".jpeg" }; private static readonly string[] SupportedMetadataExtensions = { ".json" }; - - public CheckpointFile(IDialogFactory dialogFactory) - { - this.dialogFactory = dialogFactory; - } partial void OnConnectedModelChanged(ConnectedModelInfo? value) { @@ -111,25 +106,27 @@ public partial class CheckpointFile : ObservableObject [RelayCommand] private async Task RenameAsync() { - var responses = await dialogFactory.ShowTextEntryDialog("Rename Model", new [] - { - ("File Name", FileName) - }); - var name = responses?.FirstOrDefault(); - if (name == null) return; + // TODO: Fix with new dialogs - // Rename file in OS - try - { - var newFilePath = Path.Combine(Path.GetDirectoryName(FilePath) ?? "", name); - File.Move(FilePath, newFilePath); - FilePath = newFilePath; - } - catch (Exception e) - { - Console.WriteLine(e); - throw; - } + // var responses = await dialogFactory.ShowTextEntryDialog("Rename Model", new [] + // { + // ("File Name", FileName) + // }); + // var name = responses?.FirstOrDefault(); + // if (name == null) return; + // + // // Rename file in OS + // try + // { + // var newFilePath = Path.Combine(Path.GetDirectoryName((string?) FilePath) ?? "", name); + // File.Move(FilePath, newFilePath); + // FilePath = newFilePath; + // } + // catch (Exception e) + // { + // Console.WriteLine(e); + // throw; + // } } [RelayCommand] @@ -143,14 +140,10 @@ public partial class CheckpointFile : ObservableObject { if (PreviewImagePath == null) return; var bytes = await File.ReadAllBytesAsync(PreviewImagePath); - await Application.Current.Dispatcher.InvokeAsync(() => + await Dispatcher.UIThread.InvokeAsync(() => { - var bitmap = new BitmapImage(); using var ms = new MemoryStream(bytes); - bitmap.BeginInit(); - bitmap.StreamSource = ms; - bitmap.CacheOption = BitmapCacheOption.OnLoad; - bitmap.EndInit(); + var bitmap = new Bitmap(ms); PreviewImage = bitmap; }); } @@ -162,7 +155,7 @@ public partial class CheckpointFile : ObservableObject /// - {filename}.preview.{image-extensions} (preview image) /// - {filename}.cm-info.json (connected model info) /// - public static IEnumerable FromDirectoryIndex(IDialogFactory dialogFactory, string directory, SearchOption searchOption = SearchOption.TopDirectoryOnly) + public static IEnumerable FromDirectoryIndex(string directory, SearchOption searchOption = SearchOption.TopDirectoryOnly) { // Get all files with supported extensions var allExtensions = SupportedCheckpointExtensions @@ -174,7 +167,7 @@ public partial class CheckpointFile : ObservableObject foreach (var file in files.Keys.Where(k => SupportedCheckpointExtensions.Contains(Path.GetExtension(k)))) { - var checkpointFile = new CheckpointFile(dialogFactory) + var checkpointFile = new CheckpointFile() { Title = Path.GetFileNameWithoutExtension(file), FilePath = Path.Combine(directory, file), @@ -211,11 +204,11 @@ public partial class CheckpointFile : ObservableObject /// /// Index with progress reporting. /// - public static IEnumerable FromDirectoryIndex(IDialogFactory dialogFactory, string directory, IProgress progress, + public static IEnumerable FromDirectoryIndex(string directory, IProgress progress, SearchOption searchOption = SearchOption.TopDirectoryOnly) { var current = 0ul; - foreach (var checkpointFile in FromDirectoryIndex(dialogFactory, directory, searchOption)) + foreach (var checkpointFile in FromDirectoryIndex(directory, searchOption)) { current++; progress.Report(new ProgressReport(current, "Indexing", checkpointFile.FileName)); diff --git a/StabilityMatrix/Models/CheckpointFolder.cs b/StabilityMatrix.Avalonia/ViewModels/CheckpointFolder.cs similarity index 98% rename from StabilityMatrix/Models/CheckpointFolder.cs rename to StabilityMatrix.Avalonia/ViewModels/CheckpointFolder.cs index 1a82c338..0f17d582 100644 --- a/StabilityMatrix/Models/CheckpointFolder.cs +++ b/StabilityMatrix.Avalonia/ViewModels/CheckpointFolder.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Threading.Tasks; -using System.Windows; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using StabilityMatrix.Core.Extensions; @@ -15,10 +14,8 @@ using StabilityMatrix.Core.Models; using StabilityMatrix.Core.Models.FileInterfaces; using StabilityMatrix.Core.Models.Progress; using StabilityMatrix.Core.Services; -using StabilityMatrix.Helper; -using StabilityMatrix.ViewModels; -namespace StabilityMatrix.Models; +namespace StabilityMatrix.Avalonia.ViewModels; public partial class CheckpointFolder : ObservableObject { @@ -38,7 +35,7 @@ public partial class CheckpointFolder : ObservableObject /// Custom title for UI. /// [ObservableProperty] - [NotifyPropertyChangedFor(nameof(FolderType))] + [NotifyPropertyChangedFor(nameof(Models.CheckpointFolder.FolderType))] [NotifyPropertyChangedFor(nameof(TitleWithFilesCount))] private string title = string.Empty; diff --git a/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs index 74f1fa75..9d73eba7 100644 --- a/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs @@ -1,12 +1,8 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.ComponentModel; using System.Diagnostics; using System.Linq; -using System.Reflection.Metadata; using System.Threading.Tasks; -using Avalonia.Controls; using Avalonia.Threading; using AvaloniaEdit.Document; using CommunityToolkit.Mvvm.ComponentModel; diff --git a/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs index 3d3b2a64..d2c3e25e 100644 --- a/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs @@ -3,7 +3,6 @@ using System.Linq; using CommunityToolkit.Mvvm.ComponentModel; using StabilityMatrix.Avalonia.Views; using StabilityMatrix.Core.Attributes; -using StabilityMatrix.Core.Models.Settings; namespace StabilityMatrix.Avalonia.ViewModels; diff --git a/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs index cc300cc6..fd5ae498 100644 --- a/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; @@ -10,7 +9,6 @@ using StabilityMatrix.Avalonia.Views; using StabilityMatrix.Core.Attributes; using StabilityMatrix.Core.Helper.Factory; using StabilityMatrix.Core.Models; -using StabilityMatrix.Core.Models.Packages; using StabilityMatrix.Core.Services; namespace StabilityMatrix.Avalonia.ViewModels; diff --git a/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs index 7159828d..2bde610b 100644 --- a/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.ObjectModel; -using System.Threading.Tasks; +using System.Collections.ObjectModel; using Avalonia.Controls.Notifications; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -32,6 +30,8 @@ public partial class SettingsViewModel : PageViewModelBase public SettingsViewModel(INotificationService notificationService) { this.notificationService = notificationService; + + SelectedTheme = AvailableThemes[1]; } [RelayCommand] diff --git a/StabilityMatrix.Avalonia/Views/LaunchPageView.axaml b/StabilityMatrix.Avalonia/Views/LaunchPageView.axaml index 47651f17..0a911745 100644 --- a/StabilityMatrix.Avalonia/Views/LaunchPageView.axaml +++ b/StabilityMatrix.Avalonia/Views/LaunchPageView.axaml @@ -104,11 +104,7 @@ - + - + + + + + + +