Browse Source

Merge pull request #140 from ionite34/folder-junction-options

pull/14/head v1.1.0
Ionite 1 year ago committed by GitHub
parent
commit
2f36d38a30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      StabilityMatrix/App.xaml.cs
  2. 1
      StabilityMatrix/Helper/ISettingsManager.cs
  3. 7
      StabilityMatrix/Helper/SettingsManager.cs
  4. 1
      StabilityMatrix/Models/ISharedFolders.cs
  5. 3
      StabilityMatrix/Models/Settings/Settings.cs
  6. 30
      StabilityMatrix/Models/SharedFolders.cs
  7. 15
      StabilityMatrix/SettingsPage.xaml
  8. 11
      StabilityMatrix/ViewModels/SettingsViewModel.cs

12
StabilityMatrix/App.xaml.cs

@ -351,10 +351,18 @@ namespace StabilityMatrix
serviceProvider?.GetRequiredService<LaunchViewModel>().OnShutdown();
var settingsManager = serviceProvider?.GetRequiredService<ISettingsManager>();
if (settingsManager?.TryFindLibrary() ?? false)
// Skip remaining steps if no library is set
if (!(settingsManager?.TryFindLibrary() ?? false)) return;
// Unless KeepFolderLinksOnShutdown is set, delete all package junctions
if (!settingsManager.Settings.KeepFolderLinksOnShutdown)
{
serviceProvider?.GetRequiredService<ILiteDbContext>().Dispose();
var sharedFolders = serviceProvider?.GetRequiredService<ISharedFolders>();
sharedFolders?.RemoveLinksForAllPackages();
}
// Dispose of database
serviceProvider?.GetRequiredService<ILiteDbContext>().Dispose();
}
[DoesNotReturn]

1
StabilityMatrix/Helper/ISettingsManager.cs

@ -71,4 +71,5 @@ public interface ISettingsManager
Guid GetOldActivePackageId();
void SetActiveInstalledPackage(Guid guid);
void SetIsImportAsConnected(bool value);
void SetKeepFolderLinksOnShutdown(bool value);
}

7
StabilityMatrix/Helper/SettingsManager.cs

@ -227,6 +227,13 @@ public class SettingsManager : ISettingsManager
public void SetIsImportAsConnected(bool value)
{
Settings.IsImportAsConnected = value;
SaveSettings();
}
public void SetKeepFolderLinksOnShutdown(bool value)
{
Settings.KeepFolderLinksOnShutdown = value;
SaveSettings();
}
public void AddPathExtension(string pathExtension)

1
StabilityMatrix/Models/ISharedFolders.cs

@ -6,4 +6,5 @@ public interface ISharedFolders
{
void SetupLinksForPackage(BasePackage basePackage, string installPath);
void UpdateLinksForPackage(BasePackage basePackage, string installPath);
void RemoveLinksForAllPackages();
}

3
StabilityMatrix/Models/Settings/Settings.cs

@ -24,7 +24,6 @@ public class Settings
public bool ModelBrowserNsfwEnabled { get; set; }
public bool IsNavExpanded { get; set; }
public bool IsImportAsConnected { get; set; }
public SharedFolderType? SharedFolderVisibleCategories { get; set; } =
SharedFolderType.StableDiffusion |
SharedFolderType.Lora |
@ -33,6 +32,8 @@ public class Settings
public string? Placement { get; set; }
public ModelSearchOptions? ModelSearchOptions { get; set; }
public bool KeepFolderLinksOnShutdown { get; set; }
public InstalledPackage? GetActiveInstalledPackage()
{

30
StabilityMatrix/Models/SharedFolders.cs

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using NCode.ReparsePoints;
using NLog;
using StabilityMatrix.Extensions;
@ -11,10 +12,12 @@ public class SharedFolders : ISharedFolders
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly ISettingsManager settingsManager;
private readonly IPackageFactory packageFactory;
public SharedFolders(ISettingsManager settingsManager)
public SharedFolders(ISettingsManager settingsManager, IPackageFactory packageFactory)
{
this.settingsManager = settingsManager;
this.packageFactory = packageFactory;
}
public void SetupLinksForPackage(BasePackage basePackage, string installPath)
@ -108,4 +111,27 @@ public class SharedFolders : ISharedFolders
}
}
}
public void RemoveLinksForAllPackages()
{
var libraryDir = settingsManager.LibraryDir;
var packages = settingsManager.Settings.InstalledPackages;
foreach (var package in packages)
{
if (package.PackageName == null) continue;
var basePackage = packageFactory.FindPackageByName(package.PackageName);
if (basePackage == null) continue;
if (package.LibraryPath == null) continue;
try
{
RemoveLinksForPackage(basePackage, Path.Combine(libraryDir, package.LibraryPath));
}
catch (Exception e)
{
Logger.Warn("Failed to remove junction links for package {Package} " +
"({DisplayName}): {Message}", package.PackageName, package.DisplayName, e.Message);
}
}
}
}

15
StabilityMatrix/SettingsPage.xaml

@ -126,6 +126,21 @@
</StackPanel>
</ui:Card>
<ui:Card Margin="8">
<StackPanel HorizontalAlignment="Left" Orientation="Vertical">
<TextBlock
FontSize="16"
FontWeight="Bold"
Margin="0,8"
Text="Checkpoint Manager Options" />
<CheckBox
IsChecked="{Binding}"
Margin="8"
ToolTip="Normally removed on shutdown to allow the data folder to be moved without potential file explorer issues."
Content="Keep shared checkpoints directory symbolic links on shutdown"/>
</StackPanel>
</ui:Card>
<ui:Card Margin="8">
<StackPanel HorizontalAlignment="Left" Orientation="Vertical">
<TextBlock

11
StabilityMatrix/ViewModels/SettingsViewModel.cs

@ -81,6 +81,16 @@ public partial class SettingsViewModel : ObservableObject
settingsManager.SetWebApiPort(value);
a3WebApiManager.ResetClient();
}
[ObservableProperty] private bool keepFolderLinksOnShutdown;
partial void OnKeepFolderLinksOnShutdownChanged(bool value)
{
if (value != settingsManager.Settings.KeepFolderLinksOnShutdown)
{
settingsManager.SetKeepFolderLinksOnShutdown(value);
}
}
public RefreshBadgeViewModel Text2ImageRefreshBadge { get; } = new()
{
@ -113,6 +123,7 @@ public partial class SettingsViewModel : ObservableObject
this.prerequisiteHelper = prerequisiteHelper;
SelectedTheme = settingsManager.Settings.Theme ?? "Dark";
WindowBackdropType = settingsManager.Settings.WindowBackdropType ?? WindowBackdropType.Mica;
KeepFolderLinksOnShutdown = settingsManager.Settings.KeepFolderLinksOnShutdown;
}
[ObservableProperty]

Loading…
Cancel
Save