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

7
StabilityMatrix/Models/BasePackage.cs

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

4
StabilityMatrix/Models/InstalledPackage.cs

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

48
StabilityMatrix/Models/Packages/A3WebUI.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading; using System.Threading;
@ -17,6 +18,7 @@ public class A3WebUI : BasePackage
public override string DisplayName => "Stable Diffusion WebUI"; public override string DisplayName => "Stable Diffusion WebUI";
public override string Author => "AUTOMATIC1111"; public override string Author => "AUTOMATIC1111";
public override string GithubUrl => "https://github.com/AUTOMATIC1111/stable-diffusion-webui"; public override string GithubUrl => "https://github.com/AUTOMATIC1111/stable-diffusion-webui";
public override string LaunchCommand => "launch.py";
public override async Task DownloadPackage() public override async Task DownloadPackage()
{ {
@ -73,7 +75,53 @@ public class A3WebUI : BasePackage
OnDownloadComplete(DownloadLocation); OnDownloadComplete(DownloadLocation);
} }
public override Task InstallPackage()
{
UnzipPackage();
OnInstallComplete("Installation complete");
return Task.CompletedTask;
}
public string CommandLineArgs => $"{GetVramOption()} {GetXformersOption()}"; 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() 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 DisplayName => "Dank Diffusion";
public override string Author => "mohnjiles"; public override string Author => "mohnjiles";
public override string GithubUrl => "https://github.com/mohnjiles/dank-diffusion"; public override string GithubUrl => "https://github.com/mohnjiles/dank-diffusion";
public override string LaunchCommand => "";
public override Task DownloadPackage() public override Task DownloadPackage()
{ {
throw new System.NotImplementedException(); 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 Visibility ProgressBarVisibility => ProgressValue > 0 || IsIndeterminate ? Visibility.Visible : Visibility.Collapsed;
public AsyncRelayCommand InstallCommand => new(async () => [RelayCommand]
private async Task Install()
{ {
var installSuccess = await InstallGitIfNecessary(); var installSuccess = await InstallGitIfNecessary();
if (!installSuccess) if (!installSuccess)
@ -75,8 +76,7 @@ public partial class InstallerViewModel : ObservableObject
} }
await DownloadPackage(); await DownloadPackage();
await InstallPackage();
UnzipPackage();
InstalledText = "Installing dependencies..."; InstalledText = "Installing dependencies...";
await PyRunner.Initialize(); await PyRunner.Initialize();
@ -106,70 +106,42 @@ public partial class InstallerViewModel : ObservableObject
Path = SelectedPackage.InstallLocation, Path = SelectedPackage.InstallLocation,
Id = Guid.NewGuid(), Id = Guid.NewGuid(),
PackageName = SelectedPackage.Name, PackageName = SelectedPackage.Name,
PackageVersion = "idklol" PackageVersion = "idklol",
LaunchCommand = SelectedPackage.LaunchCommand
}; };
settingsManager.AddInstalledPackage(package); settingsManager.AddInstalledPackage(package);
settingsManager.SetActiveInstalledPackage(package); settingsManager.SetActiveInstalledPackage(package);
} }
}); }
private async Task DownloadPackage() private async Task DownloadPackage()
{ {
SelectedPackage.DownloadProgressChanged += (_, progress) => SelectedPackage.DownloadProgressChanged += SelectedPackageOnProgressChanged;
{
if (progress == -1)
{
IsIndeterminate = true;
}
else
{
IsIndeterminate = false;
ProgressValue = progress;
}
};
SelectedPackage.DownloadComplete += (_, _) => InstalledText = "Download Complete"; SelectedPackage.DownloadComplete += (_, _) => InstalledText = "Download Complete";
InstalledText = "Downloading package..."; InstalledText = "Downloading package...";
await SelectedPackage.DownloadPackage(); await SelectedPackage.DownloadPackage();
} }
private void UnzipPackage() private async Task InstallPackage()
{ {
InstalledText = "Unzipping package..."; SelectedPackage.InstallProgressChanged += SelectedPackageOnProgressChanged;
ProgressValue = 0; SelectedPackage.InstallComplete += (_, _) => InstalledText = "Install Complete";
InstalledText = "Installing package...";
Directory.CreateDirectory(SelectedPackage.InstallLocation); await SelectedPackage.InstallPackage();
}
using var zip = ZipFile.OpenRead(SelectedPackage.DownloadLocation);
var zipDirName = string.Empty; private void SelectedPackageOnProgressChanged(object? sender, int progress)
var totalEntries = zip.Entries.Count; {
var currentEntry = 0; if (progress == -1)
foreach (var entry in zip.Entries)
{ {
if (string.IsNullOrWhiteSpace(entry.Name) && entry.FullName.EndsWith("/")) IsIndeterminate = true;
{ }
if (string.IsNullOrWhiteSpace(zipDirName)) else
{ {
zipDirName = entry.FullName; IsIndeterminate = false;
continue; ProgressValue = progress;
}
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);
} }
} }
private async Task<bool> InstallGitIfNecessary() 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; 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); venvRunner.RunDetached(args, OnConsoleOutput, OnExit);
SetProcessRunning(true); SetProcessRunning(true);

Loading…
Cancel
Save