Browse Source

Merge pull request #23 from ionite34/restructuring

moved a1111-specific stuff into the A3WebUI
pull/5/head
JT 2 years ago committed by GitHub
parent
commit
5c0c9cb136
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      StabilityMatrix/InstallPage.xaml
  2. 7
      StabilityMatrix/Models/BasePackage.cs
  3. 2
      StabilityMatrix/Models/InstalledPackage.cs
  4. 48
      StabilityMatrix/Models/Packages/A3WebUI.cs
  5. 6
      StabilityMatrix/Models/Packages/DankDiffusion.cs
  6. 68
      StabilityMatrix/ViewModels/InstallerViewModel.cs
  7. 5
      StabilityMatrix/ViewModels/LaunchViewModel.cs

6
StabilityMatrix/InstallPage.xaml

@ -20,9 +20,11 @@
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Vertical">
<Button Content="Install" Command="{Binding InstallCommand}" Width="100" Height="50" HorizontalAlignment="Center"/>
<Button Content="Install" Command="{Binding InstallCommand}" Width="100" Height="50"
HorizontalAlignment="Center" />
<TextBlock Text="{Binding InstalledText}" HorizontalAlignment="Center" Padding="8" />
<ProgressBar Visibility="{Binding ProgressBarVisibility, FallbackValue=Visible}" Value="{Binding ProgressValue, FallbackValue=10}"
<ProgressBar Visibility="{Binding ProgressBarVisibility, FallbackValue=Visible}"
Value="{Binding ProgressValue, FallbackValue=10}"
IsIndeterminate="{Binding IsIndeterminate, FallbackValue=False}"
Maximum="100" Width="500" />
</StackPanel>

7
StabilityMatrix/Models/BasePackage.cs

@ -9,17 +9,24 @@ public abstract class BasePackage
public abstract string DisplayName { get; }
public abstract string Author { get; }
public abstract string GithubUrl { get; }
public abstract string LaunchCommand { get; }
public abstract Task DownloadPackage();
public abstract Task InstallPackage();
internal virtual string DownloadLocation => $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\StabilityMatrix\\Packages\\{Name}.zip";
internal virtual string InstallLocation => $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\StabilityMatrix\\Packages\\{Name}";
public event EventHandler<int> DownloadProgressChanged;
public event EventHandler<string> DownloadComplete;
public event EventHandler<int> InstallProgressChanged;
public event EventHandler<string> InstallComplete;
public void OnDownloadProgressChanged(int progress) => DownloadProgressChanged?.Invoke(this, progress);
public void OnDownloadComplete(string path) => DownloadComplete?.Invoke(this, path);
public void OnInstallProgressChanged(int progress) => InstallProgressChanged?.Invoke(this, progress);
public void OnInstallComplete(string path) => InstallComplete?.Invoke(this, path);
public string ByAuthor => $"By {Author}";
}

2
StabilityMatrix/Models/InstalledPackage.cs

@ -18,4 +18,6 @@ public class InstalledPackage
// Install path
public string Path { get; set; }
public string LaunchCommand { get; set; }
}

48
StabilityMatrix/Models/Packages/A3WebUI.cs

@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
@ -17,6 +18,7 @@ public class A3WebUI : BasePackage
public override string DisplayName => "Stable Diffusion WebUI";
public override string Author => "AUTOMATIC1111";
public override string GithubUrl => "https://github.com/AUTOMATIC1111/stable-diffusion-webui";
public override string LaunchCommand => "launch.py";
public override async Task DownloadPackage()
{
@ -73,8 +75,54 @@ public class A3WebUI : BasePackage
OnDownloadComplete(DownloadLocation);
}
public override Task InstallPackage()
{
UnzipPackage();
OnInstallComplete("Installation complete");
return Task.CompletedTask;
}
public string CommandLineArgs => $"{GetVramOption()} {GetXformersOption()}";
private void UnzipPackage()
{
OnInstallProgressChanged(0);
Directory.CreateDirectory(InstallLocation);
using var zip = ZipFile.OpenRead(DownloadLocation);
var zipDirName = string.Empty;
var totalEntries = zip.Entries.Count;
var currentEntry = 0;
foreach (var entry in zip.Entries)
{
if (string.IsNullOrWhiteSpace(entry.Name) && entry.FullName.EndsWith("/"))
{
if (string.IsNullOrWhiteSpace(zipDirName))
{
zipDirName = entry.FullName;
continue;
}
var folderPath = Path.Combine(InstallLocation,
entry.FullName.Replace(zipDirName, string.Empty));
Directory.CreateDirectory(folderPath);
continue;
}
var destinationPath = Path.GetFullPath(Path.Combine(InstallLocation,
entry.FullName.Replace(zipDirName, string.Empty)));
entry.ExtractToFile(destinationPath, true);
currentEntry++;
var progressValue = (int)((double)currentEntry / totalEntries * 100);
OnInstallProgressChanged(progressValue);
}
}
private static string GetVramOption()
{
var vramGb = HardwareHelper.GetGpuMemoryBytes() / 1024 / 1024 / 1024;

6
StabilityMatrix/Models/Packages/DankDiffusion.cs

@ -8,9 +8,15 @@ public class DankDiffusion : BasePackage
public override string DisplayName => "Dank Diffusion";
public override string Author => "mohnjiles";
public override string GithubUrl => "https://github.com/mohnjiles/dank-diffusion";
public override string LaunchCommand => "";
public override Task DownloadPackage()
{
throw new System.NotImplementedException();
}
public override Task InstallPackage()
{
throw new System.NotImplementedException();
}
}

68
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -65,7 +65,8 @@ public partial class InstallerViewModel : ObservableObject
public Visibility ProgressBarVisibility => ProgressValue > 0 || IsIndeterminate ? Visibility.Visible : Visibility.Collapsed;
public AsyncRelayCommand InstallCommand => new(async () =>
[RelayCommand]
private async Task Install()
{
var installSuccess = await InstallGitIfNecessary();
if (!installSuccess)
@ -75,8 +76,7 @@ public partial class InstallerViewModel : ObservableObject
}
await DownloadPackage();
UnzipPackage();
await InstallPackage();
InstalledText = "Installing dependencies...";
await PyRunner.Initialize();
@ -106,70 +106,42 @@ public partial class InstallerViewModel : ObservableObject
Path = SelectedPackage.InstallLocation,
Id = Guid.NewGuid(),
PackageName = SelectedPackage.Name,
PackageVersion = "idklol"
PackageVersion = "idklol",
LaunchCommand = SelectedPackage.LaunchCommand
};
settingsManager.AddInstalledPackage(package);
settingsManager.SetActiveInstalledPackage(package);
}
});
}
private async Task DownloadPackage()
{
SelectedPackage.DownloadProgressChanged += (_, progress) =>
{
if (progress == -1)
{
IsIndeterminate = true;
}
else
{
IsIndeterminate = false;
ProgressValue = progress;
}
};
SelectedPackage.DownloadProgressChanged += SelectedPackageOnProgressChanged;
SelectedPackage.DownloadComplete += (_, _) => InstalledText = "Download Complete";
InstalledText = "Downloading package...";
await SelectedPackage.DownloadPackage();
}
private void UnzipPackage()
private async Task InstallPackage()
{
InstalledText = "Unzipping package...";
ProgressValue = 0;
Directory.CreateDirectory(SelectedPackage.InstallLocation);
using var zip = ZipFile.OpenRead(SelectedPackage.DownloadLocation);
var zipDirName = string.Empty;
var totalEntries = zip.Entries.Count;
var currentEntry = 0;
SelectedPackage.InstallProgressChanged += SelectedPackageOnProgressChanged;
SelectedPackage.InstallComplete += (_, _) => InstalledText = "Install Complete";
InstalledText = "Installing package...";
await SelectedPackage.InstallPackage();
}
foreach (var entry in zip.Entries)
private void SelectedPackageOnProgressChanged(object? sender, int progress)
{
if (string.IsNullOrWhiteSpace(entry.Name) && entry.FullName.EndsWith("/"))
{
if (string.IsNullOrWhiteSpace(zipDirName))
if (progress == -1)
{
zipDirName = entry.FullName;
continue;
}
var folderPath = Path.Combine(SelectedPackage.InstallLocation,
entry.FullName.Replace(zipDirName, string.Empty));
Directory.CreateDirectory(folderPath);
continue;
IsIndeterminate = true;
}
var destinationPath = Path.GetFullPath(Path.Combine(SelectedPackage.InstallLocation,
entry.FullName.Replace(zipDirName, string.Empty)));
entry.ExtractToFile(destinationPath, true);
currentEntry++;
ProgressValue = (int)((double)currentEntry / totalEntries * 100);
else
{
IsIndeterminate = false;
ProgressValue = progress;
}
}
private async Task<bool> InstallGitIfNecessary()

5
StabilityMatrix/ViewModels/LaunchViewModel.cs

@ -55,7 +55,8 @@ public partial class LaunchViewModel : ObservableObject
}
}
public ObservableCollection<InstalledPackage> InstalledPackages = new();
[ObservableProperty]
private ObservableCollection<InstalledPackage> installedPackages = new();
public event EventHandler ScrollNeeded;
@ -112,7 +113,7 @@ public partial class LaunchViewModel : ObservableObject
});
}
var args = "\"" + Path.Combine(packagePath, "launch.py") + "\"";
var args = "\"" + Path.Combine(packagePath, SelectedPackage.LaunchCommand) + "\"";
venvRunner.RunDetached(args, OnConsoleOutput, OnExit);
SetProcessRunning(true);

Loading…
Cancel
Save