Browse Source

Merge branch 'main' into package-stuff

pull/5/head
Ionite 1 year ago committed by GitHub
parent
commit
851acc480e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      StabilityMatrix.Tests/StabilityMatrix.Tests.csproj
  2. 7
      StabilityMatrix/Api/IGithubApi.cs
  3. 24
      StabilityMatrix/App.xaml.cs
  4. 25
      StabilityMatrix/Converters/BoolNegationConverter.cs
  5. 61
      StabilityMatrix/Helper/Cache/GithubApiCache.cs
  6. 18
      StabilityMatrix/Helper/Cache/IGithubApiCache.cs
  7. 89
      StabilityMatrix/InstallerWindow.xaml
  8. 13
      StabilityMatrix/Models/Api/GithubAuthor.cs
  9. 12
      StabilityMatrix/Models/Api/GithubBranch.cs
  10. 12
      StabilityMatrix/Models/Api/GithubCommit.cs
  11. 12
      StabilityMatrix/Models/Api/GithubCommitCommit.cs
  12. 7
      StabilityMatrix/Models/PackageVersion.cs
  13. 37
      StabilityMatrix/Models/Packages/A3WebUI.cs
  14. 46
      StabilityMatrix/Models/Packages/BaseGitPackage.cs
  15. 11
      StabilityMatrix/Models/Packages/BasePackage.cs
  16. 28
      StabilityMatrix/Models/Packages/DankDiffusion.cs
  17. 22
      StabilityMatrix/Models/Packages/VladAutomatic.cs
  18. 12
      StabilityMatrix/Properties/launchSettings.json
  19. 1
      StabilityMatrix/Python/PyVenvRunner.cs
  20. 8
      StabilityMatrix/StabilityMatrix.csproj
  21. 121
      StabilityMatrix/ViewModels/InstallerViewModel.cs
  22. 5
      StabilityMatrix/ViewModels/LaunchViewModel.cs
  23. 3
      StabilityMatrix/appsettings.Development.json
  24. 3
      StabilityMatrix/appsettings.json

1
StabilityMatrix.Tests/StabilityMatrix.Tests.csproj

@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="DotNext" Version="4.12.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.16" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.18.4" />

7
StabilityMatrix/Api/IGithubApi.cs

@ -13,4 +13,11 @@ public interface IGithubApi
[Get("/repos/{username}/{repository}/releases")]
Task<IEnumerable<GithubRelease>> GetAllReleases(string username, string repository);
[Get("/repos/{username}/{repository}/branches")]
Task<IEnumerable<GithubBranch>> GetAllBranches(string username, string repository);
[Get("/repos/{username}/{repository}/commits?sha={branch}")]
Task<IEnumerable<GithubCommit>> GetAllCommits(string username, string repository, string branch, int page = 1,
[AliasAs("per_page")] int perPage = 10);
}

24
StabilityMatrix/App.xaml.cs

@ -5,6 +5,7 @@ using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Windows;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
@ -15,6 +16,7 @@ using Polly.Timeout;
using Refit;
using StabilityMatrix.Api;
using StabilityMatrix.Helper;
using StabilityMatrix.Helper.Cache;
using StabilityMatrix.Models;
using StabilityMatrix.Models.Packages;
using StabilityMatrix.Python;
@ -31,6 +33,17 @@ namespace StabilityMatrix
public partial class App : Application
{
private ServiceProvider? serviceProvider;
public static IConfiguration Config { get; set; }
public App()
{
Config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
.Build();
}
private void App_OnStartup(object sender, StartupEventArgs e)
{
@ -66,10 +79,12 @@ namespace StabilityMatrix
serviceCollection.AddTransient<InstallerViewModel>();
serviceCollection.AddSingleton<BasePackage, A3WebUI>();
serviceCollection.AddSingleton<BasePackage, DankDiffusion>();
serviceCollection.AddSingleton<BasePackage, VladAutomatic>();
serviceCollection.AddSingleton<ISnackbarService, SnackbarService>();
serviceCollection.AddSingleton<ISettingsManager, SettingsManager>();
serviceCollection.AddSingleton<IDialogErrorHandler, DialogErrorHandler>();
serviceCollection.AddMemoryCache();
serviceCollection.AddSingleton<IGithubApiCache, GithubApiCache>();
var defaultRefitSettings = new RefitSettings
{
@ -93,6 +108,12 @@ namespace StabilityMatrix
{
c.BaseAddress = new Uri("https://api.github.com");
c.Timeout = TimeSpan.FromSeconds(5);
var githubApiKey = Config["GithubApiKey"];
if (!string.IsNullOrEmpty(githubApiKey))
{
c.DefaultRequestHeaders.Add("Authorization", $"Bearer {githubApiKey}");
}
})
.AddPolicyHandler(retryPolicy);
serviceCollection.AddRefitClient<IA3WebApi>(defaultRefitSettings)
@ -149,3 +170,4 @@ namespace StabilityMatrix
}
}
}

25
StabilityMatrix/Converters/BoolNegationConverter.cs

@ -0,0 +1,25 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace StabilityMatrix.Converters;
[ValueConversion(typeof(bool), typeof(bool))]
public class BoolNegationConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool?)
{
var boolVal = value as bool?;
return !boolVal ?? false;
}
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Convert(value, targetType, parameter, culture);
}
}

61
StabilityMatrix/Helper/Cache/GithubApiCache.cs

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using StabilityMatrix.Api;
using StabilityMatrix.Models.Api;
namespace StabilityMatrix.Helper.Cache;
public class GithubApiCache : IGithubApiCache
{
private readonly IMemoryCache memoryCache;
private readonly IGithubApi githubApi;
private readonly TimeSpan cacheDuration = TimeSpan.FromMinutes(5);
public GithubApiCache(IMemoryCache memoryCache, IGithubApi githubApi)
{
this.memoryCache = memoryCache;
this.githubApi = githubApi;
}
public Task<GithubRelease> GetLatestRelease(string username, string repository)
{
var cacheKey = $"LatestRelease-{username}-{repository}";
return memoryCache.GetOrCreateAsync(cacheKey, async entry =>
{
entry.SlidingExpiration = cacheDuration;
return await githubApi.GetLatestRelease(username, repository);
})!;
}
public Task<IEnumerable<GithubRelease>> GetAllReleases(string username, string repository)
{
var cacheKey = $"Releases-{username}-{repository}";
return memoryCache.GetOrCreateAsync(cacheKey, async entry =>
{
entry.SlidingExpiration = cacheDuration;
return await githubApi.GetAllReleases(username, repository);
})!;
}
public Task<IEnumerable<GithubBranch>> GetAllBranches(string username, string repository)
{
var cacheKey = $"Branches-{username}-{repository}";
return memoryCache.GetOrCreateAsync(cacheKey, async entry =>
{
entry.SlidingExpiration = cacheDuration;
return await githubApi.GetAllBranches(username, repository);
})!;
}
public Task<IEnumerable<GithubCommit>> GetAllCommits(string username, string repository, string branch, int page = 1, int perPage = 10)
{
var cacheKey = $"Commits-{username}-{repository}-{branch}-{page}-{perPage}";
return memoryCache.GetOrCreateAsync(cacheKey, async entry =>
{
entry.SlidingExpiration = cacheDuration;
return await githubApi.GetAllCommits(username, repository, branch, page, perPage);
})!;
}
}

18
StabilityMatrix/Helper/Cache/IGithubApiCache.cs

@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Refit;
using StabilityMatrix.Models.Api;
namespace StabilityMatrix.Helper.Cache;
public interface IGithubApiCache
{
Task<GithubRelease> GetLatestRelease(string username, string repository);
Task<IEnumerable<GithubRelease>> GetAllReleases(string username, string repository);
Task<IEnumerable<GithubBranch>> GetAllBranches(string username, string repository);
Task<IEnumerable<GithubCommit>> GetAllCommits(string username, string repository, string branch, int page = 1,
[AliasAs("per_page")] int perPage = 10);
}

89
StabilityMatrix/InstallerWindow.xaml

@ -24,19 +24,27 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xaml="clr-namespace:Markdown.Xaml;assembly=Markdown.Xaml"
xmlns:api="clr-namespace:StabilityMatrix.Models.Api"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:converters="clr-namespace:StabilityMatrix.Converters">
<ui:FluentWindow.Resources>
<converters:ValueConverterGroup x:Key="InvertAndVisibilitate">
<converters:BoolNegationConverter/>
<BooleanToVisibilityConverter/>
</converters:ValueConverterGroup>
<converters:BoolNegationConverter x:Key="BoolNegationConverter"/>
<xaml:Markdown x:Key="Markdown"
DocumentStyle="{StaticResource DocumentStyle}"
Heading1Style="{StaticResource H1Style}"
Heading2Style="{StaticResource H2Style}"
Heading3Style="{StaticResource H3Style}"
Heading4Style="{StaticResource H4Style}"
LinkStyle="{StaticResource LinkStyle}"
ImageStyle="{StaticResource ImageStyle}"
SeparatorStyle="{StaticResource SeparatorStyle}"
AssetPathRoot="{x:Static system:Environment.CurrentDirectory}"/>
DocumentStyle="{StaticResource DocumentStyle}"
Heading1Style="{StaticResource H1Style}"
Heading2Style="{StaticResource H2Style}"
Heading3Style="{StaticResource H3Style}"
Heading4Style="{StaticResource H4Style}"
LinkStyle="{StaticResource LinkStyle}"
ImageStyle="{StaticResource ImageStyle}"
SeparatorStyle="{StaticResource SeparatorStyle}"
AssetPathRoot="{x:Static system:Environment.CurrentDirectory}"/>
<xaml:TextToFlowDocumentConverter x:Key="TextToFlowDocumentConverter"
Markdown="{StaticResource Markdown}"/>
</ui:FluentWindow.Resources>
@ -111,20 +119,53 @@
</TextBlock>
</ui:Hyperlink>
<Label Content="Version" Margin="0,16,0,0"/>
<ComboBox ItemsSource="{Binding AvailableVersions}"
SelectedItem="{Binding SelectedVersion}">
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type api:GithubRelease}">
<StackPanel Margin="10,0,0,0" VerticalAlignment="Top">
<TextBlock
Margin="0,5,0,5"
Name="NameTextBlock"
Text="{Binding TagName}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<StackPanel Orientation="Horizontal">
<ToggleButton IsEnabled="{Binding IsReleaseModeEnabled, FallbackValue=true}"
Content="Releases" IsChecked="{Binding IsReleaseMode}"/>
<ToggleButton Content="Branches" Margin="8,0,0,0"
IsChecked="{Binding IsReleaseMode,
Converter={StaticResource BoolNegationConverter}}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0, 16, 0, 0">
<StackPanel Orientation="Vertical">
<Label Content="{Binding ReleaseLabelText, FallbackValue=Version}"/>
<ComboBox ItemsSource="{Binding AvailableVersions}"
SelectedItem="{Binding SelectedVersion}"
MinWidth="200">
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type models:PackageVersion}">
<StackPanel Margin="8,0,0,0" VerticalAlignment="Top">
<TextBlock
Margin="0,4,0,4"
Name="NameTextBlock"
Text="{Binding TagName}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="8, 0, 0, 0"
Visibility="{Binding IsReleaseMode,
Converter={StaticResource InvertAndVisibilitate}}">
<Label Content="Commit"/>
<ComboBox ItemsSource="{Binding AvailableCommits}"
SelectedItem="{Binding SelectedCommit}"
MinWidth="100">
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type api:GithubCommit}">
<StackPanel Margin="8,0,0,0" VerticalAlignment="Top">
<TextBlock
Margin="0,4,0,4"
Name="NameTextBlock"
Text="{Binding ShaHash}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</StackPanel>
<Label Content="Install Location" Margin="0,16,0,0"/>
<ui:TextBox Text="{Binding InstallPath}" Margin="0,0,0,8"/>

13
StabilityMatrix/Models/Api/GithubAuthor.cs

@ -0,0 +1,13 @@
using System;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class GithubAuthor
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("date")]
public DateTimeOffset DateCommitted { get; set; }
}

12
StabilityMatrix/Models/Api/GithubBranch.cs

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class GithubBranch
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("commit")]
public GithubCommit Commit { get; set; }
}

12
StabilityMatrix/Models/Api/GithubCommit.cs

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class GithubCommit
{
[JsonPropertyName("sha")]
public string ShaHash { get; set; }
[JsonPropertyName("commit")]
public GithubCommitCommit? Commit { get; set; }
}

12
StabilityMatrix/Models/Api/GithubCommitCommit.cs

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Models.Api;
public class GithubCommitCommit
{
[JsonPropertyName("message")]
public string Message { get; set; }
[JsonPropertyName("author")]
public GithubAuthor Author { get; set; }
}

7
StabilityMatrix/Models/PackageVersion.cs

@ -0,0 +1,7 @@
namespace StabilityMatrix.Models;
public class PackageVersion
{
public string TagName { get; set; }
public string ReleaseNotesMarkdown { get; set; }
}

37
StabilityMatrix/Models/Packages/A3WebUI.cs

@ -2,9 +2,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using StabilityMatrix.Api;
using StabilityMatrix.Helper;
using StabilityMatrix.Helper.Cache;
namespace StabilityMatrix.Models.Packages;
@ -17,14 +19,8 @@ public class A3WebUI : BaseGitPackage, IArgParsable
public override string DefaultLaunchArguments => $"{GetVramOption()} {GetXformersOption()}";
public string RelativeArgsDefinitionScriptPath => "modules.cmd_args";
public A3WebUI(IGithubApi githubApi, ISettingsManager settingsManager) : base(githubApi, settingsManager)
{
}
public IEnumerable<LaunchOptionDefinition> ParseLaunchOptions()
{
throw new NotImplementedException();
}
public A3WebUI(IGithubApiCache githubApi, ISettingsManager settingsManager) : base(githubApi, settingsManager) { }
public override List<LaunchOptionDefinition> LaunchOptions => new()
{
@ -60,6 +56,30 @@ public class A3WebUI : BaseGitPackage, IArgParsable
}
};
public override async Task<string> GetLatestVersion()
{
var release = await GetLatestRelease();
return release.TagName!;
}
public override async Task<IEnumerable<PackageVersion>> GetAllVersions(bool isReleaseMode = true)
{
if (isReleaseMode)
{
var allReleases = await GetAllReleases();
return allReleases.Select(r => new PackageVersion {TagName = r.TagName!, ReleaseNotesMarkdown = r.Body});
}
else // branch mode1
{
var allBranches = await GetAllBranches();
return allBranches.Select(b => new PackageVersion
{
TagName = $"{b.Name}",
ReleaseNotesMarkdown = string.Empty
});
}
}
public override async Task RunPackage(string installedPackagePath, string arguments)
{
await SetupVenv(installedPackagePath);
@ -85,6 +105,7 @@ public class A3WebUI : BaseGitPackage, IArgParsable
{
Debug.WriteLine($"Venv process exited with code {i}");
OnConsoleOutput($"Venv process exited with code {i}");
OnExit(i);
}
var args = $"\"{Path.Combine(installedPackagePath, LaunchCommand)}\" {arguments}";

46
StabilityMatrix/Models/Packages/BaseGitPackage.cs

@ -12,6 +12,7 @@ using NLog;
using Refit;
using StabilityMatrix.Api;
using StabilityMatrix.Helper;
using StabilityMatrix.Helper.Cache;
using StabilityMatrix.Models.Api;
using StabilityMatrix.Python;
@ -25,7 +26,7 @@ namespace StabilityMatrix.Models.Packages;
public abstract class BaseGitPackage : BasePackage
{
protected static readonly Logger Logger = LogManager.GetCurrentClassLogger();
protected readonly IGithubApi GithubApi;
protected readonly IGithubApiCache GithubApi;
protected readonly ISettingsManager SettingsManager;
protected PyVenvRunner? VenvRunner;
@ -44,7 +45,7 @@ public abstract class BaseGitPackage : BasePackage
protected string GetDownloadUrl(string tagName) => $"https://api.github.com/repos/{Author}/{Name}/zipball/{tagName}";
protected BaseGitPackage(IGithubApi githubApi, ISettingsManager settingsManager)
protected BaseGitPackage(IGithubApiCache githubApi, ISettingsManager settingsManager)
{
this.GithubApi = githubApi;
this.SettingsManager = settingsManager;
@ -54,6 +55,21 @@ public abstract class BaseGitPackage : BasePackage
{
return GithubApi.GetLatestRelease(Author, Name);
}
public override Task<IEnumerable<GithubBranch>> GetAllBranches()
{
return GithubApi.GetAllBranches(Author, Name);
}
public override Task<IEnumerable<GithubRelease>> GetAllReleases()
{
return GithubApi.GetAllReleases(Author, Name);
}
public override Task<IEnumerable<GithubCommit>> GetAllCommits(string branch, int page = 1, int perPage = 10)
{
return GithubApi.GetAllCommits(Author, Name, branch, page, perPage);
}
/// <summary>
/// Setup the virtual environment for the package.
@ -73,22 +89,15 @@ public abstract class BaseGitPackage : BasePackage
return VenvRunner;
}
public override async Task<IEnumerable<GithubRelease>> GetVersions()
public override async Task<IEnumerable<GithubRelease>> GetReleaseTags()
{
var allReleases = await GithubApi.GetAllReleases(Author, Name);
return allReleases;
}
public override async Task<string?> DownloadPackage(bool isUpdate = false, string? version = null)
public override async Task<string?> DownloadPackage(string version, bool isUpdate = false)
{
var latestRelease = await GetLatestRelease();
var latestTagName = latestRelease.TagName;
if (string.IsNullOrWhiteSpace(latestTagName) && string.IsNullOrWhiteSpace(version))
{
throw new Exception("Could not find latest release. Both latest release and version are null or empty.");
}
var tagName = version ?? latestTagName!;
var downloadUrl = GetDownloadUrl(tagName);
var downloadUrl = GetDownloadUrl(version);
if (!Directory.Exists(DownloadLocation.Replace($"{Name}.zip", "")))
{
@ -154,7 +163,7 @@ public abstract class BaseGitPackage : BasePackage
await file.FlushAsync();
OnDownloadComplete(DownloadLocation);
return tagName;
return version;
}
private void UnzipPackage(bool isUpdate = false)
@ -237,9 +246,9 @@ public abstract class BaseGitPackage : BasePackage
try
{
var latestRelease = await GetLatestRelease();
UpdateAvailable = latestRelease.TagName != currentVersion;
return latestRelease.TagName != currentVersion;
var latestVersion = await GetLatestVersion();
UpdateAvailable = latestVersion != currentVersion;
return latestVersion != currentVersion;
}
catch (ApiException e)
{
@ -248,9 +257,10 @@ public abstract class BaseGitPackage : BasePackage
}
}
public override async Task<string?> Update()
public override async Task<string> Update()
{
var version = await DownloadPackage(true);
var version = await GetLatestVersion();
await DownloadPackage(version, true);
await InstallPackage(true);
return version;
}

11
StabilityMatrix/Models/Packages/BasePackage.cs

@ -14,15 +14,20 @@ public abstract class BasePackage
public abstract string LaunchCommand { get; }
public abstract string DefaultLaunchArguments { get; }
public virtual bool UpdateAvailable { get; set; }
public abstract Task<string?> DownloadPackage(bool isUpdate = false, string? version = null);
public abstract Task<string?> DownloadPackage(string version, bool isUpdate = false);
public abstract Task InstallPackage(bool isUpdate = false);
public abstract Task RunPackage(string installedPackagePath, string arguments);
public abstract Task Shutdown();
public abstract Task<bool> CheckForUpdates(string installedPackageName);
public abstract Task<string?> Update();
public abstract Task<IEnumerable<GithubRelease>> GetVersions();
public abstract Task<string> Update();
public abstract Task<IEnumerable<GithubRelease>> GetReleaseTags();
public abstract List<LaunchOptionDefinition> LaunchOptions { get; }
public abstract Task<string> GetLatestVersion();
public abstract Task<IEnumerable<PackageVersion>> GetAllVersions(bool isReleaseMode = true);
public abstract Task<IEnumerable<GithubCommit>> GetAllCommits(string branch, int page = 1, int perPage = 10);
public abstract Task<IEnumerable<GithubBranch>> GetAllBranches();
public abstract Task<IEnumerable<GithubRelease>> GetAllReleases();
public abstract string DownloadLocation { get; }
public abstract string InstallLocation { get; set; }

28
StabilityMatrix/Models/Packages/DankDiffusion.cs

@ -12,7 +12,7 @@ public class DankDiffusion : BasePackage
public override string GithubUrl => "https://github.com/mohnjiles/dank-diffusion";
public override string LaunchCommand => "";
public override Task<IEnumerable<GithubRelease>> GetVersions()
public override Task<IEnumerable<GithubRelease>> GetReleaseTags()
{
throw new System.NotImplementedException();
}
@ -36,10 +36,34 @@ public class DankDiffusion : BasePackage
}
};
public override Task<string> GetLatestVersion()
{
throw new System.NotImplementedException();
}
public override Task<IEnumerable<PackageVersion>> GetAllVersions(bool isReleaseMode = true)
{
throw new System.NotImplementedException();
}
public override Task<IEnumerable<GithubCommit>> GetAllCommits(string branch, int page = 1, int perPage = 10)
{
throw new System.NotImplementedException();
}
public override Task<IEnumerable<GithubRelease>> GetAllReleases()
{
throw new System.NotImplementedException();
}
public override string DownloadLocation { get; }
public override string InstallLocation { get; set; }
public override Task<IEnumerable<GithubBranch>> GetAllBranches()
{
throw new System.NotImplementedException();
}
public override Task<string?> DownloadPackage(bool isUpdate = false, string? version = null)
public override Task<string?> DownloadPackage(string version, bool isUpdate = false)
{
throw new System.NotImplementedException();
}

22
StabilityMatrix/Models/Packages/VladAutomatic.cs

@ -2,9 +2,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using StabilityMatrix.Api;
using StabilityMatrix.Helper;
using StabilityMatrix.Helper.Cache;
namespace StabilityMatrix.Models.Packages;
@ -16,7 +18,7 @@ public class VladAutomatic : BaseGitPackage
public override string LaunchCommand => "launch.py";
public override string DefaultLaunchArguments => $"{GetVramOption()} {GetXformersOption()}";
public VladAutomatic(IGithubApi githubApi, ISettingsManager settingsManager) : base(githubApi, settingsManager)
public VladAutomatic(IGithubApiCache githubApi, ISettingsManager settingsManager) : base(githubApi, settingsManager)
{
}
@ -38,7 +40,19 @@ public class VladAutomatic : BaseGitPackage
Options = new() { "--xformers" }
}
};
public override Task<string> GetLatestVersion() => Task.FromResult("master");
public override async Task<IEnumerable<PackageVersion>> GetAllVersions(bool isReleaseMode = true)
{
var allBranches = await GetAllBranches();
return allBranches.Select(b => new PackageVersion
{
TagName = $"{b.Name}",
ReleaseNotesMarkdown = string.Empty
});
}
public override async Task RunPackage(string installedPackagePath, string arguments)
{
await SetupVenv(installedPackagePath);
@ -61,12 +75,12 @@ public class VladAutomatic : BaseGitPackage
void HandleExit(int i)
{
Debug.WriteLine($"Venv process exited with code {i}");
OnConsoleOutput($"Venv process exited with code {i}");
OnExit(i);
}
var args = $"\"{Path.Combine(installedPackagePath, LaunchCommand)}\" {arguments}";
VenvRunner.RunDetached(args.TrimEnd(), HandleConsoleOutput, HandleExit, workingDirectory: installedPackagePath);
VenvRunner?.RunDetached(args.TrimEnd(), HandleConsoleOutput, HandleExit, workingDirectory: installedPackagePath);
}
private static string GetVramOption()

12
StabilityMatrix/Properties/launchSettings.json

@ -1,10 +1,16 @@
{
"profiles": {
"StabilityMatrix (Package)": {
"commandName": "MsixPackage"
"commandName": "MsixPackage",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Production"
}
},
"StabilityMatrix (Unpackaged)": {
"commandName": "Project"
"commandName": "Project",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}
}

1
StabilityMatrix/Python/PyVenvRunner.cs

@ -95,6 +95,7 @@ public class PyVenvRunner : IDisposable
if (onExit != null)
{
Process.EnableRaisingEvents = true;
Process.Exited += (_, _) => onExit(Process.ExitCode);
}
}

8
StabilityMatrix/StabilityMatrix.csproj

@ -13,6 +13,8 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" />
<PackageReference Include="Markdown.Xaml" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.16" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
@ -44,6 +46,12 @@
<Content Include="Assets\Git-2.40.1-64-bit.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>

121
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging;
@ -48,19 +49,34 @@ public partial class InstallerViewModel : ObservableObject
private string installName;
[ObservableProperty]
private ObservableCollection<GithubRelease> availableVersions;
private ObservableCollection<PackageVersion> availableVersions;
[ObservableProperty]
private GithubRelease selectedVersion;
private PackageVersion selectedVersion;
[ObservableProperty]
private ObservableCollection<BasePackage> availablePackages;
[ObservableProperty]
private ObservableCollection<GithubCommit> availableCommits;
[ObservableProperty]
private GithubCommit selectedCommit;
[ObservableProperty]
private string releaseNotes;
[ObservableProperty]
private bool isReleaseMode;
[ObservableProperty]
private bool isReleaseModeEnabled;
public Visibility ProgressBarVisibility => ProgressValue > 0 || IsIndeterminate ? Visibility.Visible : Visibility.Collapsed;
public string ReleaseLabelText => IsReleaseMode ? "Version" : "Branch";
public InstallerViewModel(ISettingsManager settingsManager, ILogger<InstallerViewModel> logger, IPyRunner pyRunner,
IPackageFactory packageFactory)
{
@ -74,6 +90,8 @@ public partial class InstallerViewModel : ObservableObject
ProgressValue = 0;
InstallPath =
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\StabilityMatrix\\Packages";
IsReleaseMode = true;
IsReleaseModeEnabled = true;
AvailablePackages = new ObservableCollection<BasePackage>(packageFactory.GetAllAvailablePackages());
if (!AvailablePackages.Any()) return;
@ -93,27 +111,102 @@ public partial class InstallerViewModel : ObservableObject
if (SelectedPackage == null)
return;
var releases = (await SelectedPackage.GetVersions()).ToList();
var releases = (await SelectedPackage.GetAllReleases()).ToList();
if (!releases.Any())
return;
AvailableVersions = new ObservableCollection<GithubRelease>(releases);
{
IsReleaseMode = false;
}
var versions = (await SelectedPackage.GetAllVersions()).ToList();
AvailableVersions = new ObservableCollection<PackageVersion>(versions);
if (!AvailableVersions.Any())
return;
SelectedVersion = AvailableVersions[0];
ReleaseNotes = releases.First().Body;
ReleaseNotes = versions.First().ReleaseNotesMarkdown;
}
partial void OnSelectedPackageChanged(BasePackage value)
partial void OnSelectedPackageChanged(BasePackage? value)
{
InstallName = $"{value.DisplayName}-{SelectedVersion}";
if (value == null) return;
InstallName = value.DisplayName;
ReleaseNotes = string.Empty;
AvailableVersions?.Clear();
// This can swallow exceptions if you don't explicity try/catch
// Idk how to make it better tho
Task.Run(async () =>
{
var releases = (await SelectedPackage.GetAllReleases()).ToList();
if (!releases.Any())
{
Application.Current.Dispatcher.Invoke(() =>
{
IsReleaseMode = false;
IsReleaseModeEnabled = false;
});
}
else
{
Application.Current.Dispatcher.Invoke(() => { IsReleaseModeEnabled = true; });
}
var versions = (await value.GetAllVersions(IsReleaseMode)).ToList();
if (!versions.Any())
return;
Application.Current.Dispatcher.Invoke(() =>
{
AvailableVersions = new ObservableCollection<PackageVersion>(versions);
SelectedVersion = AvailableVersions[0];
ReleaseNotes = versions.First().ReleaseNotesMarkdown;
});
if (!IsReleaseMode)
{
var commits = await value.GetAllCommits(SelectedVersion.TagName);
Application.Current.Dispatcher.Invoke(() =>
{
AvailableCommits = new ObservableCollection<GithubCommit>(commits);
SelectedCommit = AvailableCommits[0];
SelectedVersion = AvailableVersions.First(x => x.TagName == "master");
});
}
});
}
partial void OnSelectedVersionChanged(GithubRelease? value)
partial void OnIsReleaseModeChanged(bool oldValue, bool newValue)
{
InstallName = $"{SelectedPackage.DisplayName}-{value?.TagName}";
ReleaseNotes = value?.Body ?? string.Empty;
OnSelectedPackageChanged(SelectedPackage);
}
partial void OnSelectedVersionChanged(PackageVersion? value)
{
ReleaseNotes = value?.ReleaseNotesMarkdown ?? string.Empty;
if (value == null) return;
SelectedCommit = null;
AvailableCommits?.Clear();
if (!IsReleaseMode)
{
Task.Run(async () =>
{
try
{
var hashes = await SelectedPackage.GetAllCommits(value.TagName);
AvailableCommits = new ObservableCollection<GithubCommit>(hashes);
await Task.Delay(10); // or it doesn't work sometimes? lolwut?
SelectedCommit = AvailableCommits[0];
}
catch (Exception e)
{
logger.LogError(e, "Error getting commits");
}
});
}
}
private async Task ActuallyInstall()

5
StabilityMatrix/ViewModels/LaunchViewModel.cs

@ -262,6 +262,11 @@ public partial class LaunchViewModel : ObservableObject
private void OnExit(object? sender, int exitCode)
{
var basePackage = packageFactory.FindPackageByName(SelectedPackage.PackageName);
basePackage.ConsoleOutput -= OnConsoleOutput;
basePackage.Exited -= OnExit;
basePackage.StartupComplete -= RunningPackageOnStartupComplete;
Dispatcher.CurrentDispatcher.Invoke(() =>
{
ConsoleOutput += $"Venv process exited with code {exitCode}";

3
StabilityMatrix/appsettings.Development.json

@ -0,0 +1,3 @@
{
"GithubApiKey": ""
}

3
StabilityMatrix/appsettings.json

@ -0,0 +1,3 @@
{
"GithubApiKey": ""
}
Loading…
Cancel
Save