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. 44
      StabilityMatrix/InstallPage.xaml
  2. 7
      StabilityMatrix/Models/BasePackage.cs
  3. 4
      StabilityMatrix/Models/InstalledPackage.cs
  4. 48
      StabilityMatrix/Models/Packages/A3WebUI.cs
  5. 6
      StabilityMatrix/Models/Packages/DankDiffusion.cs
  6. 74
      StabilityMatrix/ViewModels/InstallerViewModel.cs
  7. 5
      StabilityMatrix/ViewModels/LaunchViewModel.cs

44
StabilityMatrix/InstallPage.xaml

@ -12,37 +12,39 @@
Background="{DynamicResource ApplicationBackgroundBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
mc:Ignorable="d">
<Grid Margin="16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Vertical">
<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}"
<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}"
IsIndeterminate="{Binding IsIndeterminate, FallbackValue=False}"
Maximum="100" Width="500"/>
Maximum="100" Width="500" />
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="16" HorizontalAlignment="Left" Height="400">
<ListView ItemsSource="{Binding Packages}"
SelectedItem="{Binding SelectedPackage, Mode=TwoWay}">
<ListView.Style>
<Style TargetType="ListView">
<Setter Property="Background" Value="#191919"/>
<Setter Property="Background" Value="#191919" />
</Style>
</ListView.Style>
<ListView.ItemTemplate>
<DataTemplate DataType="{x:Type models:BasePackage}">
<StackPanel VerticalAlignment="Top" Margin="8">
<TextBlock Text="{Binding DisplayName}" Margin="0,5,0,5" />
<TextBlock Text="{Binding ByAuthor}" Margin="0,0,0,5" />
</StackPanel>
<StackPanel VerticalAlignment="Top" Margin="8">
<TextBlock Text="{Binding DisplayName}" Margin="0,5,0,5" />
<TextBlock Text="{Binding ByAuthor}" Margin="0,0,0,5" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
@ -51,18 +53,18 @@
<TextBlock Text="{Binding SelectedPackage.DisplayName, FallbackValue=Stable Diffusion Web UI}"
FontSize="24" FontWeight="Bold" />
<Grid Visibility="{Binding PackageInstalledVisibility}">
<Ellipse Width="24" Height="24" Fill="Green" Margin="8,0,0,0"/>
<ui:SymbolIcon Symbol="Checkmark24" Foreground="White" Margin="8,0,0,0"/>
<Ellipse Width="24" Height="24" Fill="Green" Margin="8,0,0,0" />
<ui:SymbolIcon Symbol="Checkmark24" Foreground="White" Margin="8,0,0,0" />
</Grid>
<TextBlock Text="Installed" VerticalAlignment="Center" Margin="8,0,0,0"
Visibility="{Binding PackageInstalledVisibility}"/>
Visibility="{Binding PackageInstalledVisibility}" />
</StackPanel>
<TextBlock Text="{Binding SelectedPackage.ByAuthor, FallbackValue=by Automatic111}"
FontSize="12" Margin="0,5, 0, 5" />
<ui:Hyperlink NavigateUri="{Binding SelectedPackage.GithubUrl}">
<TextBlock>
<Run Text="GitHub Page:"/>
<Run Text="{Binding SelectedPackage.GithubUrl, Mode=OneWay}" TextDecorations="Underline"/>
<Run Text="GitHub Page:" />
<Run Text="{Binding SelectedPackage.GithubUrl, Mode=OneWay}" TextDecorations="Underline" />
</TextBlock>
</ui:Hyperlink>
</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}";
}

4
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,7 +75,53 @@ 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()
{

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();
}
}

74
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;
foreach (var entry in zip.Entries)
SelectedPackage.InstallProgressChanged += SelectedPackageOnProgressChanged;
SelectedPackage.InstallComplete += (_, _) => InstalledText = "Install Complete";
InstalledText = "Installing package...";
await SelectedPackage.InstallPackage();
}
private void SelectedPackageOnProgressChanged(object? sender, int progress)
{
if (progress == -1)
{
if (string.IsNullOrWhiteSpace(entry.Name) && entry.FullName.EndsWith("/"))
{
if (string.IsNullOrWhiteSpace(zipDirName))
{
zipDirName = entry.FullName;
continue;
}
var folderPath = Path.Combine(SelectedPackage.InstallLocation,
entry.FullName.Replace(zipDirName, string.Empty));
Directory.CreateDirectory(folderPath);
continue;
}
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);
IsIndeterminate = true;
}
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