From 98a524839fcd0bfee0936df95569bc2eaa55c85f Mon Sep 17 00:00:00 2001 From: Ionite Date: Mon, 28 Aug 2023 02:25:01 -0400 Subject: [PATCH] Add ModelIndexService --- StabilityMatrix.Avalonia/App.axaml.cs | 1 + .../DesignData/DesignData.cs | 1 + .../DesignData/MockLiteDbContext.cs | 2 + .../DesignData/MockModelIndexService.cs | 27 ++++ .../ViewModels/SettingsViewModel.cs | 13 +- .../Views/SettingsPage.axaml | 12 ++ .../Database/ILiteDbContext.cs | 1 + .../Database/LiteDbContext.cs | 1 + .../Models/Database/LocalModelFile.cs | 47 ++++++ .../Models/FileInterfaces/FilePath.cs | 5 + .../Services/IModelIndexService.cs | 22 +++ .../Services/ModelIndexService.cs | 135 ++++++++++++++++++ 12 files changed, 265 insertions(+), 2 deletions(-) create mode 100644 StabilityMatrix.Avalonia/DesignData/MockModelIndexService.cs create mode 100644 StabilityMatrix.Core/Models/Database/LocalModelFile.cs create mode 100644 StabilityMatrix.Core/Services/IModelIndexService.cs create mode 100644 StabilityMatrix.Core/Services/ModelIndexService.cs diff --git a/StabilityMatrix.Avalonia/App.axaml.cs b/StabilityMatrix.Avalonia/App.axaml.cs index 78baebba..ca3af39d 100644 --- a/StabilityMatrix.Avalonia/App.axaml.cs +++ b/StabilityMatrix.Avalonia/App.axaml.cs @@ -346,6 +346,7 @@ public sealed class App : Application services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(provider => diff --git a/StabilityMatrix.Avalonia/DesignData/DesignData.cs b/StabilityMatrix.Avalonia/DesignData/DesignData.cs index b3b3379e..225a03a5 100644 --- a/StabilityMatrix.Avalonia/DesignData/DesignData.cs +++ b/StabilityMatrix.Avalonia/DesignData/DesignData.cs @@ -89,6 +89,7 @@ public static class DesignData .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton(); // Placeholder services that nobody should need during design time diff --git a/StabilityMatrix.Avalonia/DesignData/MockLiteDbContext.cs b/StabilityMatrix.Avalonia/DesignData/MockLiteDbContext.cs index c102805c..3b56d19a 100644 --- a/StabilityMatrix.Avalonia/DesignData/MockLiteDbContext.cs +++ b/StabilityMatrix.Avalonia/DesignData/MockLiteDbContext.cs @@ -14,6 +14,8 @@ public class MockLiteDbContext : ILiteDbContext public ILiteCollectionAsync CivitModels => throw new NotImplementedException(); public ILiteCollectionAsync CivitModelVersions => throw new NotImplementedException(); public ILiteCollectionAsync CivitModelQueryCache => throw new NotImplementedException(); + public ILiteCollectionAsync LocalModelFiles => throw new NotImplementedException(); + public Task<(CivitModel?, CivitModelVersion?)> FindCivitModelFromFileHashAsync(string hashBlake3) { return Task.FromResult<(CivitModel?, CivitModelVersion?)>((null, null)); diff --git a/StabilityMatrix.Avalonia/DesignData/MockModelIndexService.cs b/StabilityMatrix.Avalonia/DesignData/MockModelIndexService.cs new file mode 100644 index 00000000..ab52abf8 --- /dev/null +++ b/StabilityMatrix.Avalonia/DesignData/MockModelIndexService.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using StabilityMatrix.Core.Models; +using StabilityMatrix.Core.Models.Database; +using StabilityMatrix.Core.Services; + +namespace StabilityMatrix.Avalonia.DesignData; + +public class MockModelIndexService : IModelIndexService +{ + /// + public Task RefreshIndex() + { + return Task.CompletedTask; + } + + /// + public Task> GetModelsOfType(SharedFolderType type) + { + return Task.FromResult>(new List()); + } + + /// + public void BackgroundRefreshIndex() + { + } +} diff --git a/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs index ba33442d..6def5d69 100644 --- a/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/SettingsViewModel.cs @@ -50,6 +50,7 @@ public partial class SettingsViewModel : PageViewModelBase private readonly IPyRunner pyRunner; private readonly ServiceManager dialogFactory; private readonly ITrackedDownloadService trackedDownloadService; + private readonly IModelIndexService modelIndexService; public SharedState SharedState { get; } @@ -114,7 +115,8 @@ public partial class SettingsViewModel : PageViewModelBase IPyRunner pyRunner, ServiceManager dialogFactory, SharedState sharedState, - ITrackedDownloadService trackedDownloadService) + ITrackedDownloadService trackedDownloadService, + IModelIndexService modelIndexService) { this.notificationService = notificationService; this.settingsManager = settingsManager; @@ -122,7 +124,8 @@ public partial class SettingsViewModel : PageViewModelBase this.pyRunner = pyRunner; this.dialogFactory = dialogFactory; this.trackedDownloadService = trackedDownloadService; - + this.modelIndexService = modelIndexService; + SharedState = sharedState; SelectedTheme = settingsManager.Settings.Theme ?? AvailableThemes[1]; @@ -501,6 +504,12 @@ public partial class SettingsViewModel : PageViewModelBase throw new OperationCanceledException("Example Message"); } + [RelayCommand] + private async Task DebugRefreshModelsIndex() + { + await modelIndexService.RefreshIndex(); + } + [RelayCommand] private async Task DebugTrackedDownload() { diff --git a/StabilityMatrix.Avalonia/Views/SettingsPage.axaml b/StabilityMatrix.Avalonia/Views/SettingsPage.axaml index cb745ba9..100d64a9 100644 --- a/StabilityMatrix.Avalonia/Views/SettingsPage.axaml +++ b/StabilityMatrix.Avalonia/Views/SettingsPage.axaml @@ -307,6 +307,18 @@ Content="Add Tracked Download" /> + + + +