Browse Source

Merge branch 'main' into connected-models

# Conflicts:
#	StabilityMatrix/Models/ConnectedModelInfo.cs
#	StabilityMatrix/ViewModels/CheckpointBrowserCardViewModel.cs
pull/5/head
Ionite 1 year ago
parent
commit
a7c9b7432e
No known key found for this signature in database
  1. 13
      StabilityMatrix/App.xaml
  2. 6
      StabilityMatrix/CheckpointBrowserPage.xaml
  3. 7
      StabilityMatrix/CheckpointBrowserPage.xaml.cs
  4. 2
      StabilityMatrix/Extensions/EnumAttributes.cs
  5. 54
      StabilityMatrix/Helper/ArchiveHelper.cs
  6. 2
      StabilityMatrix/Helper/IPrerequisiteHelper.cs
  7. 7
      StabilityMatrix/Helper/ISettingsManager.cs
  8. 21
      StabilityMatrix/Helper/PrerequisiteHelper.cs
  9. 8
      StabilityMatrix/Helper/SettingsManager.cs
  10. 2
      StabilityMatrix/MainWindow.xaml.cs
  11. 3
      StabilityMatrix/Models/Api/CivitCommercialUse.cs
  12. 4
      StabilityMatrix/Models/Api/CivitFileHashes.cs
  13. 3
      StabilityMatrix/Models/Api/CivitModelType.cs
  14. 3
      StabilityMatrix/Models/Api/CivitModelsRequest.cs
  15. 3
      StabilityMatrix/Models/Api/CivitSortMode.cs
  16. 2
      StabilityMatrix/Models/Packages/A3WebUI.cs
  17. 13
      StabilityMatrix/Models/ProgressReport.cs
  18. 8
      StabilityMatrix/Models/ProgressType.cs
  19. 1
      StabilityMatrix/Models/Settings.cs
  20. 2
      StabilityMatrix/OneClickInstallDialog.xaml
  21. 1
      StabilityMatrix/Services/DownloadService.cs
  22. 8
      StabilityMatrix/Services/INotificationBarService.cs
  23. 21
      StabilityMatrix/Services/NotificationBarService.cs
  24. 3
      StabilityMatrix/StabilityMatrix.csproj
  25. 12
      StabilityMatrix/Styles/Styles.xaml
  26. 2
      StabilityMatrix/ViewModels/InstallerViewModel.cs
  27. 11
      StabilityMatrix/ViewModels/OneClickInstallViewModel.cs

13
StabilityMatrix/App.xaml

@ -13,19 +13,6 @@
<ui:ControlsDictionary />
<ResourceDictionary Source="Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
<DrawingImage x:Key="PatreonIconColored">
<DrawingImage.Drawing>
<DrawingGroup ClipGeometry="M0,-4.5 V251.5 H256 V0 H-4.5 Z">
<DrawingGroup.Transform>
<TranslateTransform X="0" Y="4.5" />
</DrawingGroup.Transform>
<DrawingGroup Opacity="1">
<GeometryDrawing Brush="#FFFF424D" Geometry="F1 M256,256z M0,0z M45.1355837,0L45.1355837,246.35001 0,246.35001 0,0 45.1355837,0z M163.657111,0C214.65668,0 256,41.3433196 256,92.3428889 256,143.342458 214.65668,184.685778 163.657111,184.685778 112.657542,184.685778 71.3142222,143.342458 71.3142222,92.3428889 71.3142222,41.3433196 112.657542,0 163.657111,0z" />
</DrawingGroup>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</ResourceDictionary>
</Application.Resources>
</Application>

6
StabilityMatrix/CheckpointBrowserPage.xaml

@ -176,7 +176,11 @@
ItemsSource="{Binding ModelCards}"
PreviewMouseWheel="VirtualizingGridView_OnPreviewMouseWheel"/>
</ui:DynamicScrollViewer>
<TextBlock Grid.Row="2" Text="Data provided by CivitAI"
VerticalAlignment="Bottom"
Margin="16, 8"/>
<StackPanel
Grid.Row="2"
HorizontalAlignment="Center"

7
StabilityMatrix/CheckpointBrowserPage.xaml.cs

@ -1,12 +1,7 @@
using System.Diagnostics;
using System.Threading;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
using StabilityMatrix.ViewModels;
using Wpf.Ui.Controls;
namespace StabilityMatrix;

2
StabilityMatrix/Extensions/EnumAttributes.cs

@ -1,6 +1,4 @@
using System;
using System.Linq;
using System.Windows.Ink;
namespace StabilityMatrix.Extensions;

54
StabilityMatrix/Helper/ArchiveHelper.cs

@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
@ -22,7 +23,9 @@ public static class ArchiveHelper
public static string SevenZipPath => Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RelativeSevenZipPath));
private static readonly Regex Regex7ZOutput = new(@"(?<=Size:\s*)\d+|(?<=Compressed:\s*)\d+");
private static readonly Regex Regex7ZProgressDigits = new(@"(?<=\s*)\d+(?=%)");
private static readonly Regex Regex7ZProgressFull = new(@"(\d+)%.*- (.*)");
public static async Task<ArchiveInfo> TestArchive(string archivePath)
{
var process = ProcessRunner.StartProcess(SevenZipPath, new[] {"t", archivePath});
@ -33,6 +36,55 @@ public static class ArchiveHelper
var compressed = ulong.Parse(matches[1].Value);
return new ArchiveInfo(size, compressed);
}
public static async Task<ArchiveInfo> Extract7Z(string archivePath, string extractDirectory)
{
var process = ProcessRunner.StartProcess(SevenZipPath, new[]
{
"x", archivePath, $"-o{ProcessRunner.Quote(extractDirectory)}", "-y"
});
await process.WaitForExitAsync();
var output = await process.StandardOutput.ReadToEndAsync();
var matches = Regex7ZOutput.Matches(output);
var size = ulong.Parse(matches[0].Value);
var compressed = ulong.Parse(matches[1].Value);
return new ArchiveInfo(size, compressed);
}
public static async Task<ArchiveInfo> Extract7Z(string archivePath, string extractDirectory, IProgress<ProgressReport> progress)
{
var outputStore = new StringBuilder();
var onOutput = new Action<string?>(s =>
{
// Parse progress
Logger.Trace($"7z: {s}");
outputStore.AppendLine(s);
var match = Regex7ZProgressFull.Match(s ?? "");
if (match.Success)
{
var percent = int.Parse(match.Groups[1].Value);
var currentFile = match.Groups[2].Value;
progress.Report(new ProgressReport(percent / (float) 100, "Extracting", currentFile, type: ProgressType.Extract));
}
});
progress.Report(new ProgressReport(-1, isIndeterminate: true, type: ProgressType.Extract));
// Need -bsp1 for progress reports
var process = ProcessRunner.StartProcess(SevenZipPath, new[]
{
"x", archivePath, $"-o{ProcessRunner.Quote(extractDirectory)}", "-y", "-bsp1"
}, outputDataReceived: onOutput);
await process.WaitForExitAsync();
progress.Report(new ProgressReport(1, "Finished extracting", type: ProgressType.Extract));
var output = outputStore.ToString();
var matches = Regex7ZOutput.Matches(output);
var size = ulong.Parse(matches[0].Value);
var compressed = ulong.Parse(matches[1].Value);
return new ArchiveInfo(size, compressed);
}
/// <summary>
/// Extract an archive to the output directory.

2
StabilityMatrix/Helper/IPrerequisiteHelper.cs

@ -6,7 +6,5 @@ namespace StabilityMatrix.Helper;
public interface IPrerequisiteHelper
{
event EventHandler<ProgressReport>? InstallProgressChanged;
event EventHandler<ProgressReport>? InstallComplete;
Task InstallGitIfNecessary(IProgress<ProgressReport>? progress = null);
}

7
StabilityMatrix/Helper/ISettingsManager.cs

@ -13,17 +13,18 @@ public interface ISettingsManager
void RemoveInstalledPackage(InstalledPackage p);
void SetActiveInstalledPackage(InstalledPackage? p);
void SetNavExpanded(bool navExpanded);
void UpdatePackageVersionNumber(Guid id, string? newVersion);
void AddPathExtension(string pathExtension);
string GetPathExtensionsAsString();
/// <summary>
/// Insert path extensions to the front of the PATH environment variable
/// </summary>
void InsertPathExtensions();
void UpdatePackageVersionNumber(Guid id, string? newVersion);
void SetLastUpdateCheck(InstalledPackage package);
List<LaunchOption> GetLaunchArgs(Guid packageId);
void SaveLaunchArgs(Guid packageId, List<LaunchOption> launchArgs);
void SetWindowBackdropType(WindowBackdropType backdropType);
void SetHasSeenWelcomeNotification(bool hasSeenWelcomeNotification);
}

21
StabilityMatrix/Helper/PrerequisiteHelper.cs

@ -22,7 +22,7 @@ public class PrerequisiteHelper : IPrerequisiteHelper
private static readonly string PortableGitDownloadPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StabilityMatrix",
"PortableGit.tar.bz2");
"PortableGit.7z.exe");
private static readonly string GitExePath = Path.Combine(PortableGitInstallDir, "bin", "git.exe");
@ -37,9 +37,6 @@ public class PrerequisiteHelper : IPrerequisiteHelper
this.settingsManager = settingsManager;
}
public event EventHandler<ProgressReport>? InstallProgressChanged;
public event EventHandler<ProgressReport>? InstallComplete;
public async Task InstallGitIfNecessary(IProgress<ProgressReport>? progress = null)
{
if (File.Exists(GitExePath))
@ -52,7 +49,7 @@ public class PrerequisiteHelper : IPrerequisiteHelper
var latestRelease = await gitHubClient.Repository.Release.GetLatest("git-for-windows", "git");
var portableGitUrl = latestRelease.Assets
.First(a => a.Name.EndsWith("64-bit.tar.bz2")).BrowserDownloadUrl;
.First(a => a.Name.EndsWith("64-bit.7z.exe")).BrowserDownloadUrl;
if (!File.Exists(PortableGitDownloadPath))
{
@ -65,19 +62,21 @@ public class PrerequisiteHelper : IPrerequisiteHelper
private async Task UnzipGit(IProgress<ProgressReport>? progress = null)
{
progress?.Report(new ProgressReport(-1, isIndeterminate: true, message: ""));
await ArchiveHelper.Extract(PortableGitDownloadPath, PortableGitInstallDir, progress);
if (progress == null)
{
await ArchiveHelper.Extract7Z(PortableGitDownloadPath, PortableGitInstallDir);
}
else
{
await ArchiveHelper.Extract7Z(PortableGitDownloadPath, PortableGitInstallDir, progress);
}
logger.LogInformation("Extracted Git");
OnInstallProgressChanged(this, new ProgressReport(-1, isIndeterminate: true));
File.Delete(PortableGitDownloadPath);
// Also add git to the path
settingsManager.AddPathExtension(GitBinPath);
settingsManager.InsertPathExtensions();
OnInstallComplete(this, new ProgressReport(progress: 1f));
}
private void OnInstallProgressChanged(object? sender, ProgressReport progress) => InstallProgressChanged?.Invoke(sender, progress);
private void OnInstallComplete(object? sender, ProgressReport progress) => InstallComplete?.Invoke(sender, progress);
}

8
StabilityMatrix/Helper/SettingsManager.cs

@ -29,6 +29,8 @@ public class SettingsManager : ISettingsManager
if (!File.Exists(SettingsPath))
{
File.Create(SettingsPath).Close();
Settings.Theme = "Dark";
Settings.WindowBackdropType = WindowBackdropType.Mica;
var defaultSettingsJson = JsonSerializer.Serialize(Settings);
File.WriteAllText(SettingsPath, defaultSettingsJson);
}
@ -141,6 +143,12 @@ public class SettingsManager : ISettingsManager
Settings.WindowBackdropType = backdropType;
SaveSettings();
}
public void SetHasSeenWelcomeNotification(bool hasSeenWelcomeNotification)
{
Settings.HasSeenWelcomeNotification = hasSeenWelcomeNotification;
SaveSettings();
}
private void LoadSettings()
{

2
StabilityMatrix/MainWindow.xaml.cs

@ -1,8 +1,6 @@
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Media;
using Octokit;
using StabilityMatrix.Helper;
using StabilityMatrix.Services;
using StabilityMatrix.ViewModels;

3
StabilityMatrix/Models/Api/CivitCommercialUse.cs

@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;

4
StabilityMatrix/Models/Api/CivitFileHashes.cs

@ -1,6 +1,4 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
namespace StabilityMatrix.Models.Api;
public class CivitFileHashes
{

3
StabilityMatrix/Models/Api/CivitModelType.cs

@ -1,5 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using StabilityMatrix.Extensions;

3
StabilityMatrix/Models/Api/CivitModelsRequest.cs

@ -1,5 +1,4 @@
using System.Text.Json.Serialization;
using Refit;
using Refit;
namespace StabilityMatrix.Models.Api;

3
StabilityMatrix/Models/Api/CivitSortMode.cs

@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;

2
StabilityMatrix/Models/Packages/A3WebUI.cs

@ -134,7 +134,7 @@ public class A3WebUI : BaseGitPackage
await venvRunner.PipInstall("xformers", InstallLocation, HandleConsoleOutput);
}
await venvRunner.PipInstall("-r requirements.txt", InstallLocation, HandleConsoleOutput);
await venvRunner.PipInstall("-r requirements_versions.txt", InstallLocation, HandleConsoleOutput);
Logger.Debug("Finished installing requirements");
progress?.Report(new ProgressReport(1f, "Install complete"));

13
StabilityMatrix/Models/ProgressReport.cs

@ -1,7 +1,4 @@
using System;
using Microsoft.Extensions.Logging;
using NLog;
using LogLevel = NLog.LogLevel;
namespace StabilityMatrix.Models;
@ -23,16 +20,18 @@ public record struct ProgressReport
public string? Message { get; init; }
public bool IsIndeterminate { get; init; } = false;
public float Percentage => (float) Math.Ceiling(Math.Clamp(Progress ?? 0, 0, 1) * 100);
public ProgressType Type { get; init; } = ProgressType.Generic;
public ProgressReport(double progress, string? title = null, string? message = null, bool isIndeterminate = false)
public ProgressReport(double progress, string? title = null, string? message = null, bool isIndeterminate = false, ProgressType type = ProgressType.Generic)
{
Progress = progress;
Title = title;
Message = message;
IsIndeterminate = isIndeterminate;
Type = type;
}
public ProgressReport(ulong current, ulong total, string? title = null, string? message = null, bool isIndeterminate = false)
public ProgressReport(ulong current, ulong total, string? title = null, string? message = null, bool isIndeterminate = false, ProgressType type = ProgressType.Generic)
{
Current = current;
Total = total;
@ -40,13 +39,15 @@ public record struct ProgressReport
Title = title;
Message = message;
IsIndeterminate = isIndeterminate;
Type = type;
}
public ProgressReport(ulong current, string? title = null, string? message = null)
public ProgressReport(ulong current, string? title = null, string? message = null, ProgressType type = ProgressType.Generic)
{
Current = current;
Title = title;
Message = message;
IsIndeterminate = true;
Type = type;
}
}

8
StabilityMatrix/Models/ProgressType.cs

@ -0,0 +1,8 @@
namespace StabilityMatrix.Models;
public enum ProgressType
{
Generic,
Download,
Extract,
}

1
StabilityMatrix/Models/Settings.cs

@ -11,5 +11,6 @@ public class Settings
public List<InstalledPackage> InstalledPackages { get; set; } = new();
public Guid? ActiveInstalledPackage { get; set; }
public bool IsNavExpanded { get; set; }
public bool HasSeenWelcomeNotification { get; set; }
public List<string>? PathExtensions { get; set; }
}

2
StabilityMatrix/OneClickInstallDialog.xaml

@ -61,7 +61,7 @@
Command="{Binding InstallCommand}"
FontSize="32"
HorizontalAlignment="Center"
Appearance="Primary"
Appearance="Success"
Margin="16"
Padding="16, 8, 16, 8" />
</StackPanel>

1
StabilityMatrix/Services/DownloadService.cs

@ -2,7 +2,6 @@
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Polly.Contrib.WaitAndRetry;

8
StabilityMatrix/Services/INotificationBarService.cs

@ -0,0 +1,8 @@
using Wpf.Ui.Contracts;
namespace StabilityMatrix.Services;
public interface INotificationBarService : ISnackbarService
{
public void ShowStartupNotifications();
}

21
StabilityMatrix/Services/NotificationBarService.cs

@ -1,26 +1,33 @@
using AsyncAwaitBestPractices;
using StabilityMatrix.Helper;
using Wpf.Ui.Common;
using Wpf.Ui.Contracts;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;
using Wpf.Ui.Services;
using SnackbarService = Wpf.Ui.Services.SnackbarService;
namespace StabilityMatrix.Services;
public interface INotificationBarService : ISnackbarService
{
public void ShowStartupNotifications();
}
public class NotificationBarService : SnackbarService, INotificationBarService
{
private readonly ISettingsManager settingsManager;
public NotificationBarService(ISettingsManager settingsManager)
{
this.settingsManager = settingsManager;
}
public void ShowStartupNotifications()
{
if (settingsManager.Settings.HasSeenWelcomeNotification)
return;
Timeout = 10000;
var linkIcon = new SymbolIcon(SymbolRegular.Link24);
var snackbar = ShowAsync(
"Welcome to StabilityMatrix!",
"You can join our Discord server for support and feedback.", linkIcon, ControlAppearance.Info);
snackbar.SafeFireAndForget();
settingsManager.SetHasSeenWelcomeNotification(true);
}
}

3
StabilityMatrix/StabilityMatrix.csproj

@ -55,16 +55,13 @@
<None Update="appsettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Remove="Assets\Icon.png" />
<Resource Include="Assets\Icon.png" />
<None Remove="Assets\licenses.json" />
<Content Include="Assets\licenses.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\7za - LICENSE.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Remove="Assets\noimage.png" />
<Resource Include="Assets\noimage.png" />
</ItemGroup>

12
StabilityMatrix/Styles/Styles.xaml

@ -99,4 +99,16 @@
<Setter Property="Background" Value="LightGray"/>
</Style>
<DrawingImage x:Key="PatreonIconColored">
<DrawingImage.Drawing>
<DrawingGroup ClipGeometry="M0,-4.5 V251.5 H256 V0 H-4.5 Z">
<DrawingGroup.Transform>
<TranslateTransform X="0" Y="4.5" />
</DrawingGroup.Transform>
<DrawingGroup Opacity="1">
<GeometryDrawing Brush="#FFFF424D" Geometry="F1 M256,256z M0,0z M45.1355837,0L45.1355837,246.35001 0,246.35001 0,0 45.1355837,0z M163.657111,0C214.65668,0 256,41.3433196 256,92.3428889 256,143.342458 214.65668,184.685778 163.657111,184.685778 112.657542,184.685778 71.3142222,143.342458 71.3142222,92.3428889 71.3142222,41.3433196 112.657542,0 163.657111,0z" />
</DrawingGroup>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</ResourceDictionary>

2
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -397,7 +397,7 @@ public partial class InstallerViewModel : ObservableObject
{
ProgressText = $"Downloading Git... {progress.Percentage:N0}%";
}
else if (string.IsNullOrWhiteSpace(progress.Message))
else if (progress.Type == ProgressType.Extract)
{
ProgressText = $"Installing Git... {progress.Percentage:N0}%";
}

11
StabilityMatrix/ViewModels/OneClickInstallViewModel.cs

@ -73,7 +73,7 @@ public partial class OneClickInstallViewModel : ObservableObject
private async Task DoInstall()
{
var a1111 = packageFactory.FindPackageByName(DefaultPackageName)!;
HeaderText = "Installing Stable Diffusion WebUI...";
HeaderText = "Installing Stable Diffusion WebUI";
var progressHandler = new Progress<ProgressReport>(progress =>
{
@ -81,11 +81,11 @@ public partial class OneClickInstallViewModel : ObservableObject
{
SubHeaderText = $"Downloading Git... {progress.Percentage:N0}%";
}
else if (string.IsNullOrWhiteSpace(progress.Message))
else if (progress.Type == ProgressType.Extract)
{
SubHeaderText = $"Installing Git... {progress.Percentage:N0}%";
}
else
else if (progress.Message != null)
{
SubHeaderText = progress.Message;
}
@ -116,6 +116,9 @@ public partial class OneClickInstallViewModel : ObservableObject
await DownloadPackage(a1111, latestVersion);
await InstallPackage(a1111);
SubHeaderText = "Setting up shared folder links...";
sharedFolders.SetupLinksForPackage(a1111, a1111.InstallLocation);
var package = new InstalledPackage
{
@ -164,7 +167,7 @@ public partial class OneClickInstallViewModel : ObservableObject
private async Task InstallPackage(BasePackage selectedPackage)
{
selectedPackage.ConsoleOutput += (_, output) => SubSubHeaderText = output;
SubHeaderText = "Installing package...";
SubHeaderText = "Downloading and installing package requirements...";
var progress = new Progress<ProgressReport>(progress =>
{

Loading…
Cancel
Save