From 1ff445b949ba5d899f52038952060f001320e40a Mon Sep 17 00:00:00 2001 From: JT Date: Thu, 1 Jun 2023 20:00:10 -0700 Subject: [PATCH] Fix Branch Mode - Switch to Octokit instead of manually calling Github API - Add DisplayVersion & InstalledBranch to InstalledPackage for update checks & display - Fixed branch mode install now actually uses the commit hash - Update check updated for branch mode --- StabilityMatrix/Api/IGithubApi.cs | 23 ----- StabilityMatrix/App.xaml.cs | 25 +++-- .../Helper/Cache/GithubApiCache.cs | 31 ++++-- .../Helper/Cache/IGithubApiCache.cs | 10 +- StabilityMatrix/Helper/ISettingsManager.cs | 2 +- StabilityMatrix/Helper/SettingsManager.cs | 11 ++- StabilityMatrix/InstallerWindow.xaml | 7 +- StabilityMatrix/Models/Api/GithubAuthor.cs | 13 --- StabilityMatrix/Models/Api/GithubBranch.cs | 12 --- StabilityMatrix/Models/Api/GithubCommit.cs | 12 --- .../Models/Api/GithubCommitCommit.cs | 12 --- StabilityMatrix/Models/Api/GithubRelease.cs | 12 --- StabilityMatrix/Models/InstalledPackage.cs | 4 + StabilityMatrix/Models/Packages/A3WebUI.cs | 1 + .../Models/Packages/BaseGitPackage.cs | 75 ++++++++++----- .../Models/Packages/BasePackage.cs | 15 +-- StabilityMatrix/Models/Packages/ComfyUI.cs | 1 + .../Models/Packages/DankDiffusion.cs | 96 ------------------- .../Models/Packages/VladAutomatic.cs | 1 + StabilityMatrix/PackageManagerPage.xaml | 4 +- StabilityMatrix/StabilityMatrix.csproj | 1 + .../ViewModels/InstallerViewModel.cs | 71 ++++++++++---- .../ViewModels/OneClickInstallViewModel.cs | 2 +- .../ViewModels/PackageManagerViewModel.cs | 4 +- 24 files changed, 177 insertions(+), 268 deletions(-) delete mode 100644 StabilityMatrix/Api/IGithubApi.cs delete mode 100644 StabilityMatrix/Models/Api/GithubAuthor.cs delete mode 100644 StabilityMatrix/Models/Api/GithubBranch.cs delete mode 100644 StabilityMatrix/Models/Api/GithubCommit.cs delete mode 100644 StabilityMatrix/Models/Api/GithubCommitCommit.cs delete mode 100644 StabilityMatrix/Models/Api/GithubRelease.cs delete mode 100644 StabilityMatrix/Models/Packages/DankDiffusion.cs diff --git a/StabilityMatrix/Api/IGithubApi.cs b/StabilityMatrix/Api/IGithubApi.cs deleted file mode 100644 index 43843a7b..00000000 --- a/StabilityMatrix/Api/IGithubApi.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Refit; -using StabilityMatrix.Models.Api; - -namespace StabilityMatrix.Api; - -[Headers("User-Agent: StabilityMatrix")] -public interface IGithubApi -{ - [Get("/repos/{username}/{repository}/releases/latest")] - Task GetLatestRelease(string username, string repository); - - [Get("/repos/{username}/{repository}/releases")] - Task> GetAllReleases(string username, string repository); - - [Get("/repos/{username}/{repository}/branches")] - Task> GetAllBranches(string username, string repository); - - [Get("/repos/{username}/{repository}/commits?sha={branch}")] - Task> GetAllCommits(string username, string repository, string branch, int page = 1, - [AliasAs("per_page")] int perPage = 10); -} diff --git a/StabilityMatrix/App.xaml.cs b/StabilityMatrix/App.xaml.cs index 11c2fdf3..a4c549a9 100644 --- a/StabilityMatrix/App.xaml.cs +++ b/StabilityMatrix/App.xaml.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using Octokit; using Polly; using Polly.Contrib.WaitAndRetry; using Polly.Extensions.Http; @@ -24,6 +25,7 @@ using StabilityMatrix.Services; using StabilityMatrix.ViewModels; using Wpf.Ui.Contracts; using Wpf.Ui.Services; +using Application = System.Windows.Application; namespace StabilityMatrix { @@ -86,6 +88,16 @@ namespace StabilityMatrix serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); + serviceCollection.AddTransient(_ => + { + var client = new GitHubClient(new ProductHeaderValue("StabilityMatrix")); + var githubApiKey = Config["GithubApiKey"]; + if (string.IsNullOrWhiteSpace(githubApiKey)) + return client; + + client.Credentials = new Credentials(githubApiKey); + return client; + }); serviceCollection.AddMemoryCache(); serviceCollection.AddSingleton(); @@ -106,19 +118,6 @@ namespace StabilityMatrix .WaitAndRetryAsync(delay); // Add Refit clients - serviceCollection.AddRefitClient(defaultRefitSettings) - .ConfigureHttpClient(c => - { - 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(defaultRefitSettings) .ConfigureHttpClient(c => { diff --git a/StabilityMatrix/Helper/Cache/GithubApiCache.cs b/StabilityMatrix/Helper/Cache/GithubApiCache.cs index 2dfc811e..1581256d 100644 --- a/StabilityMatrix/Helper/Cache/GithubApiCache.cs +++ b/StabilityMatrix/Helper/Cache/GithubApiCache.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Memory; +using Octokit; using StabilityMatrix.Api; using StabilityMatrix.Models.Api; @@ -10,52 +12,61 @@ namespace StabilityMatrix.Helper.Cache; public class GithubApiCache : IGithubApiCache { private readonly IMemoryCache memoryCache; - private readonly IGithubApi githubApi; + private readonly IGitHubClient githubApi; private readonly TimeSpan cacheDuration = TimeSpan.FromMinutes(5); - public GithubApiCache(IMemoryCache memoryCache, IGithubApi githubApi) + public GithubApiCache(IMemoryCache memoryCache, IGitHubClient githubApi) { this.memoryCache = memoryCache; this.githubApi = githubApi; } - public Task GetLatestRelease(string username, string repository) + public Task 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); + return await githubApi.Repository.Release.GetLatest(username, repository); })!; } - public Task> GetAllReleases(string username, string repository) + public Task> 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); + var allReleases = await githubApi.Repository.Release.GetAll(username, repository); + + return allReleases.OrderByDescending(x => x.CreatedAt); })!; } - public Task> GetAllBranches(string username, string repository) + public Task> 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); + var allReleases = await githubApi.Repository.Branch.GetAll(username, repository); + return allReleases; })!; } - public Task> GetAllCommits(string username, string repository, string branch, int page = 1, int perPage = 10) + public Task?> 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); + return await githubApi.Repository.Commit.GetAll(username, repository, new CommitRequest {Sha = branch}, + new ApiOptions + { + PageCount = page, + PageSize = perPage, + StartPage = page + }); })!; } } diff --git a/StabilityMatrix/Helper/Cache/IGithubApiCache.cs b/StabilityMatrix/Helper/Cache/IGithubApiCache.cs index f0f52c39..997869ca 100644 --- a/StabilityMatrix/Helper/Cache/IGithubApiCache.cs +++ b/StabilityMatrix/Helper/Cache/IGithubApiCache.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using Octokit; using Refit; using StabilityMatrix.Models.Api; @@ -7,12 +9,12 @@ namespace StabilityMatrix.Helper.Cache; public interface IGithubApiCache { - Task GetLatestRelease(string username, string repository); + Task GetLatestRelease(string username, string repository); - Task> GetAllReleases(string username, string repository); + Task> GetAllReleases(string username, string repository); - Task> GetAllBranches(string username, string repository); + Task> GetAllBranches(string username, string repository); - Task> GetAllCommits(string username, string repository, string branch, int page = 1, + Task?> GetAllCommits(string username, string repository, string branch, int page = 1, [AliasAs("per_page")] int perPage = 10); } diff --git a/StabilityMatrix/Helper/ISettingsManager.cs b/StabilityMatrix/Helper/ISettingsManager.cs index 84140b7a..97e5b652 100644 --- a/StabilityMatrix/Helper/ISettingsManager.cs +++ b/StabilityMatrix/Helper/ISettingsManager.cs @@ -12,7 +12,7 @@ public interface ISettingsManager void RemoveInstalledPackage(InstalledPackage p); void SetActiveInstalledPackage(InstalledPackage? p); void SetNavExpanded(bool navExpanded); - void UpdatePackageVersionNumber(string name, string? newVersion); + void UpdatePackageVersionNumber(Guid id, string? newVersion); void SetLastUpdateCheck(InstalledPackage package); List GetLaunchArgs(Guid packageId); void SaveLaunchArgs(Guid packageId, List launchArgs); diff --git a/StabilityMatrix/Helper/SettingsManager.cs b/StabilityMatrix/Helper/SettingsManager.cs index 9f4ba331..568d1533 100644 --- a/StabilityMatrix/Helper/SettingsManager.cs +++ b/StabilityMatrix/Helper/SettingsManager.cs @@ -63,15 +63,20 @@ public class SettingsManager : ISettingsManager SaveSettings(); } - public void UpdatePackageVersionNumber(string name, string? newVersion) + public void UpdatePackageVersionNumber(Guid id, string? newVersion) { - var package = Settings.InstalledPackages.FirstOrDefault(x => x.DisplayName == name); + var package = Settings.InstalledPackages.FirstOrDefault(x => x.Id == id); if (package == null || newVersion == null) { return; } - + package.PackageVersion = newVersion; + + package.DisplayVersion = string.IsNullOrWhiteSpace(package.InstalledBranch) + ? newVersion + : $"{package.InstalledBranch}@{newVersion[..7]}"; + SaveSettings(); } diff --git a/StabilityMatrix/InstallerWindow.xaml b/StabilityMatrix/InstallerWindow.xaml index 4728f1b8..10cf1c24 100644 --- a/StabilityMatrix/InstallerWindow.xaml +++ b/StabilityMatrix/InstallerWindow.xaml @@ -26,7 +26,8 @@ xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:viewModels="clr-namespace:StabilityMatrix.ViewModels" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:xaml="clr-namespace:Markdown.Xaml;assembly=Markdown.Xaml"> + xmlns:xaml="clr-namespace:Markdown.Xaml;assembly=Markdown.Xaml" + xmlns:octokit="clr-namespace:Octokit;assembly=Octokit"> @@ -173,12 +174,12 @@ MinWidth="100" SelectedItem="{Binding SelectedCommit}"> - + + Text="{Binding Sha}" /> diff --git a/StabilityMatrix/Models/Api/GithubAuthor.cs b/StabilityMatrix/Models/Api/GithubAuthor.cs deleted file mode 100644 index d1577688..00000000 --- a/StabilityMatrix/Models/Api/GithubAuthor.cs +++ /dev/null @@ -1,13 +0,0 @@ -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; } -} diff --git a/StabilityMatrix/Models/Api/GithubBranch.cs b/StabilityMatrix/Models/Api/GithubBranch.cs deleted file mode 100644 index 0712d981..00000000 --- a/StabilityMatrix/Models/Api/GithubBranch.cs +++ /dev/null @@ -1,12 +0,0 @@ -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; } -} diff --git a/StabilityMatrix/Models/Api/GithubCommit.cs b/StabilityMatrix/Models/Api/GithubCommit.cs deleted file mode 100644 index bca39043..00000000 --- a/StabilityMatrix/Models/Api/GithubCommit.cs +++ /dev/null @@ -1,12 +0,0 @@ -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; } -} diff --git a/StabilityMatrix/Models/Api/GithubCommitCommit.cs b/StabilityMatrix/Models/Api/GithubCommitCommit.cs deleted file mode 100644 index 57d45c75..00000000 --- a/StabilityMatrix/Models/Api/GithubCommitCommit.cs +++ /dev/null @@ -1,12 +0,0 @@ -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; } -} diff --git a/StabilityMatrix/Models/Api/GithubRelease.cs b/StabilityMatrix/Models/Api/GithubRelease.cs deleted file mode 100644 index b108f506..00000000 --- a/StabilityMatrix/Models/Api/GithubRelease.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; - -namespace StabilityMatrix.Models.Api; - -public class GithubRelease -{ - [JsonPropertyName("tag_name")] - public string? TagName { get; set; } - - [JsonPropertyName("body")] - public string Body { get; set; } -} diff --git a/StabilityMatrix/Models/InstalledPackage.cs b/StabilityMatrix/Models/InstalledPackage.cs index a34e3dcf..e8495e56 100644 --- a/StabilityMatrix/Models/InstalledPackage.cs +++ b/StabilityMatrix/Models/InstalledPackage.cs @@ -17,6 +17,10 @@ public class InstalledPackage public string? PackageName { get; set; } // Package version public string? PackageVersion { get; set; } + public string? InstalledBranch { get; set; } + + public string? DisplayVersion { get; set; } + // Install path public string? Path { get; set; } public string? LaunchCommand { get; set; } diff --git a/StabilityMatrix/Models/Packages/A3WebUI.cs b/StabilityMatrix/Models/Packages/A3WebUI.cs index cef95b8d..febcda0f 100644 --- a/StabilityMatrix/Models/Packages/A3WebUI.cs +++ b/StabilityMatrix/Models/Packages/A3WebUI.cs @@ -16,6 +16,7 @@ public class A3WebUI : BaseGitPackage public override string DisplayName { get; set; } = "stable-diffusion-webui"; public override string Author => "AUTOMATIC1111"; public override string LaunchCommand => "launch.py"; + public override bool ShouldIgnoreReleases => false; public string RelativeArgsDefinitionScriptPath => "modules.cmd_args"; diff --git a/StabilityMatrix/Models/Packages/BaseGitPackage.cs b/StabilityMatrix/Models/Packages/BaseGitPackage.cs index 0281d59f..4be78a84 100644 --- a/StabilityMatrix/Models/Packages/BaseGitPackage.cs +++ b/StabilityMatrix/Models/Packages/BaseGitPackage.cs @@ -9,11 +9,13 @@ using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; using NLog; -using Refit; +using Octokit; using StabilityMatrix.Helper; using StabilityMatrix.Helper.Cache; using StabilityMatrix.Models.Api; using StabilityMatrix.Python; +using ApiException = Refit.ApiException; +using FileMode = System.IO.FileMode; namespace StabilityMatrix.Models.Packages; @@ -42,30 +44,35 @@ public abstract class BaseGitPackage : BasePackage public override string InstallLocation { get; set; } = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\StabilityMatrix\\Packages"; - protected string GetDownloadUrl(string tagName) => $"https://api.github.com/repos/{Author}/{Name}/zipball/{tagName}"; + protected string GetDownloadUrl(string tagName, bool isCommitHash = false) + { + return isCommitHash + ? $"https://github.com/{Author}/{Name}/archive/{tagName}.zip" + : $"https://api.github.com/repos/{Author}/{Name}/zipball/{tagName}"; + } protected BaseGitPackage(IGithubApiCache githubApi, ISettingsManager settingsManager) { - this.GithubApi = githubApi; - this.SettingsManager = settingsManager; + GithubApi = githubApi; + SettingsManager = settingsManager; } - protected Task GetLatestRelease() + protected Task GetLatestRelease() { return GithubApi.GetLatestRelease(Author, Name); } - public override Task> GetAllBranches() + public override Task> GetAllBranches() { return GithubApi.GetAllBranches(Author, Name); } - public override Task> GetAllReleases() + public override Task> GetAllReleases() { return GithubApi.GetAllReleases(Author, Name); } - public override Task> GetAllCommits(string branch, int page = 1, int perPage = 10) + public override Task?> GetAllCommits(string branch, int page = 1, int perPage = 10) { return GithubApi.GetAllCommits(Author, Name, branch, page, perPage); } @@ -88,15 +95,15 @@ public abstract class BaseGitPackage : BasePackage return VenvRunner; } - public override async Task> GetReleaseTags() + public override async Task> GetReleaseTags() { var allReleases = await GithubApi.GetAllReleases(Author, Name); return allReleases; } - public override async Task DownloadPackage(string version, bool isUpdate = false) + public override async Task DownloadPackage(string version, bool isCommitHash, bool isUpdate = false) { - var downloadUrl = GetDownloadUrl(version); + var downloadUrl = GetDownloadUrl(version, isCommitHash); if (!Directory.Exists(DownloadLocation.Replace($"{Name}.zip", ""))) { @@ -107,7 +114,6 @@ public abstract class BaseGitPackage : BasePackage client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("StabilityMatrix", "1.0")); await using var file = new FileStream(DownloadLocation, FileMode.Create, FileAccess.Write, FileShare.None); - long contentLength = 0; var retryCount = 0; var response = await client.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead); @@ -236,18 +242,29 @@ public abstract class BaseGitPackage : BasePackage public override async Task CheckForUpdates(string installedPackageName) { - var currentVersion = SettingsManager.Settings.InstalledPackages.FirstOrDefault(x => x.DisplayName == installedPackageName) - ?.PackageVersion; - if (string.IsNullOrWhiteSpace(currentVersion)) + var package = + SettingsManager.Settings.InstalledPackages.FirstOrDefault(x => x.DisplayName == installedPackageName); + var currentVersion = package?.PackageVersion; + if (package == null || string.IsNullOrWhiteSpace(currentVersion)) { return false; } try { - var latestVersion = await GetLatestVersion(); - UpdateAvailable = latestVersion != currentVersion; - return latestVersion != currentVersion; + if (string.IsNullOrWhiteSpace(package.InstalledBranch)) + { + var latestVersion = await GetLatestVersion(); + UpdateAvailable = latestVersion != currentVersion; + return latestVersion != currentVersion; + } + else + { + var allCommits = await GetAllCommits(package.InstalledBranch); + var latestCommitHash = allCommits.First().Sha; + return latestCommitHash != currentVersion; + } + } catch (ApiException e) { @@ -256,12 +273,24 @@ public abstract class BaseGitPackage : BasePackage } } - public override async Task Update() + public override async Task Update(InstalledPackage installedPackage) { - var version = await GetLatestVersion(); - await DownloadPackage(version, true); - await InstallPackage(true); - return version; + if (string.IsNullOrWhiteSpace(installedPackage.InstalledBranch)) + { + var releases = await GetAllReleases(); + var latestRelease = releases.First(); + await DownloadPackage(latestRelease.TagName, false); + await InstallPackage(true); + return latestRelease.TagName; + } + else + { + var allCommits = await GetAllCommits(installedPackage.InstalledBranch); + var latestCommit = allCommits.First(); + await DownloadPackage(latestCommit.Sha, true, true); + await InstallPackage(true); + return latestCommit.Sha; + } } diff --git a/StabilityMatrix/Models/Packages/BasePackage.cs b/StabilityMatrix/Models/Packages/BasePackage.cs index c575e123..24dff47c 100644 --- a/StabilityMatrix/Models/Packages/BasePackage.cs +++ b/StabilityMatrix/Models/Packages/BasePackage.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using Octokit; using StabilityMatrix.Models.Api; namespace StabilityMatrix.Models; @@ -12,23 +14,24 @@ public abstract class BasePackage public abstract string Author { get; } public abstract string GithubUrl { get; } public abstract string LaunchCommand { get; } + public abstract bool ShouldIgnoreReleases { get; } public virtual bool UpdateAvailable { get; set; } - public abstract Task DownloadPackage(string version, bool isUpdate = false); + public abstract Task DownloadPackage(string version, bool isCommitHash, 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 CheckForUpdates(string installedPackageName); - public abstract Task Update(); - public abstract Task> GetReleaseTags(); + public abstract Task Update(InstalledPackage installedPackage); + public abstract Task> GetReleaseTags(); public abstract List LaunchOptions { get; } public virtual string? ExtraLaunchArguments { get; set; } = null; public abstract Task GetLatestVersion(); public abstract Task> GetAllVersions(bool isReleaseMode = true); - public abstract Task> GetAllCommits(string branch, int page = 1, int perPage = 10); - public abstract Task> GetAllBranches(); - public abstract Task> GetAllReleases(); + public abstract Task?> GetAllCommits(string branch, int page = 1, int perPage = 10); + public abstract Task> GetAllBranches(); + public abstract Task> GetAllReleases(); public abstract string DownloadLocation { get; } public abstract string InstallLocation { get; set; } diff --git a/StabilityMatrix/Models/Packages/ComfyUI.cs b/StabilityMatrix/Models/Packages/ComfyUI.cs index 9dd913f3..cb46ef2e 100644 --- a/StabilityMatrix/Models/Packages/ComfyUI.cs +++ b/StabilityMatrix/Models/Packages/ComfyUI.cs @@ -19,6 +19,7 @@ public class ComfyUI : BaseGitPackage public override string DisplayName { get; set; } = "ComfyUI"; public override string Author => "comfyanonymous"; public override string LaunchCommand => "main.py"; + public override bool ShouldIgnoreReleases => true; public ComfyUI(IGithubApiCache githubApi, ISettingsManager settingsManager) : base(githubApi, settingsManager) { diff --git a/StabilityMatrix/Models/Packages/DankDiffusion.cs b/StabilityMatrix/Models/Packages/DankDiffusion.cs deleted file mode 100644 index f36416f8..00000000 --- a/StabilityMatrix/Models/Packages/DankDiffusion.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using StabilityMatrix.Models.Api; - -namespace StabilityMatrix.Models.Packages; - -public class DankDiffusion : BasePackage -{ - public override string Name => "dank-diffusion"; - public override string DisplayName { get; set; } = "dank-diffusion"; - public override string Author => "mohnjiles"; - public override string GithubUrl => "https://github.com/mohnjiles/dank-diffusion"; - public override string LaunchCommand => ""; - - public override Task> GetReleaseTags() - { - throw new System.NotImplementedException(); - } - - public override List LaunchOptions => new() - { - new LaunchOptionDefinition - { - Name = "API", - Options = new List { "--api" } - }, - new LaunchOptionDefinition - { - Name = "VRAM", - Options = new List { "--lowvram", "--medvram" } - }, - new LaunchOptionDefinition - { - Name = "Xformers", - Options = new List { "--xformers" } - }, - LaunchOptionDefinition.Extras - }; - - public override Task GetLatestVersion() - { - throw new System.NotImplementedException(); - } - - public override Task> GetAllVersions(bool isReleaseMode = true) - { - throw new System.NotImplementedException(); - } - - public override Task> GetAllCommits(string branch, int page = 1, int perPage = 10) - { - throw new System.NotImplementedException(); - } - - public override Task> GetAllReleases() - { - throw new System.NotImplementedException(); - } - - public override string DownloadLocation { get; } - public override string InstallLocation { get; set; } - public override Task> GetAllBranches() - { - throw new System.NotImplementedException(); - } - - public override Task DownloadPackage(string version, bool isUpdate = false) - { - throw new System.NotImplementedException(); - } - - public override Task InstallPackage(bool isUpdate = false) - { - throw new System.NotImplementedException(); - } - - public override Task RunPackage(string installedPackagePath, string arguments) - { - throw new System.NotImplementedException(); - } - - public override Task Shutdown() - { - throw new System.NotImplementedException(); - } - - public override Task CheckForUpdates(string installedPackageName) - { - throw new System.NotImplementedException(); - } - - public override Task Update() - { - throw new System.NotImplementedException(); - } -} diff --git a/StabilityMatrix/Models/Packages/VladAutomatic.cs b/StabilityMatrix/Models/Packages/VladAutomatic.cs index a3b3c196..c5b16b02 100644 --- a/StabilityMatrix/Models/Packages/VladAutomatic.cs +++ b/StabilityMatrix/Models/Packages/VladAutomatic.cs @@ -15,6 +15,7 @@ public class VladAutomatic : BaseGitPackage public override string DisplayName { get; set; } = "SD.Next Web UI"; public override string Author => "vladmandic"; public override string LaunchCommand => "launch.py"; + public override bool ShouldIgnoreReleases => true; public VladAutomatic(IGithubApiCache githubApi, ISettingsManager settingsManager) : base(githubApi, settingsManager) { diff --git a/StabilityMatrix/PackageManagerPage.xaml b/StabilityMatrix/PackageManagerPage.xaml index 2c4461f2..411e11a3 100644 --- a/StabilityMatrix/PackageManagerPage.xaml +++ b/StabilityMatrix/PackageManagerPage.xaml @@ -92,7 +92,7 @@ - + @@ -106,7 +106,7 @@ Text="{Binding SelectedPackage.DisplayName, FallbackValue=Stable Diffusion Web UI}" /> - + + diff --git a/StabilityMatrix/ViewModels/InstallerViewModel.cs b/StabilityMatrix/ViewModels/InstallerViewModel.cs index 197e515f..7bf849c6 100644 --- a/StabilityMatrix/ViewModels/InstallerViewModel.cs +++ b/StabilityMatrix/ViewModels/InstallerViewModel.cs @@ -9,11 +9,14 @@ using System.Windows.Threading; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.Logging; +using Octokit; using StabilityMatrix.Helper; using StabilityMatrix.Models; using StabilityMatrix.Models.Api; using StabilityMatrix.Python; +using Application = System.Windows.Application; using EventManager = StabilityMatrix.Helper.EventManager; +using PackageVersion = StabilityMatrix.Models.PackageVersion; namespace StabilityMatrix.ViewModels; @@ -59,10 +62,10 @@ public partial class InstallerViewModel : ObservableObject private ObservableCollection availablePackages; [ObservableProperty] - private ObservableCollection availableCommits; + private ObservableCollection availableCommits; [ObservableProperty] - private GithubCommit selectedCommit; + private GitHubCommit selectedCommit; [ObservableProperty] private string releaseNotes; @@ -117,20 +120,32 @@ public partial class InstallerViewModel : ObservableObject { if (SelectedPackage == null) return; - - var releases = (await SelectedPackage.GetAllReleases()).ToList(); - if (!releases.Any()) + + if (SelectedPackage.ShouldIgnoreReleases) { IsReleaseMode = false; } - var versions = (await SelectedPackage.GetAllVersions()).ToList(); - AvailableVersions = new ObservableCollection(versions); - if (!AvailableVersions.Any()) - return; + if (IsReleaseMode) + { + var versions = (await SelectedPackage.GetAllVersions()).ToList(); + AvailableVersions = new ObservableCollection(versions); + if (!AvailableVersions.Any()) + return; + SelectedVersion = AvailableVersions[0]; + } + else + { + var branches = (await SelectedPackage.GetAllBranches()).ToList(); + AvailableVersions = new ObservableCollection(branches.Select(b => new PackageVersion + { + TagName = b.Name, + ReleaseNotesMarkdown = b.Commit.Label + })); + SelectedVersion = AvailableVersions.FirstOrDefault(x => x.TagName == "master") ?? AvailableVersions[0]; + } - SelectedVersion = AvailableVersions[0]; - ReleaseNotes = versions.First().ReleaseNotesMarkdown; + ReleaseNotes = SelectedVersion.ReleaseNotesMarkdown; } partial void OnSelectedPackageChanged(BasePackage? value) @@ -140,13 +155,13 @@ public partial class InstallerViewModel : ObservableObject InstallName = value.DisplayName; ReleaseNotes = string.Empty; AvailableVersions?.Clear(); + AvailableCommits?.Clear(); // This can swallow exceptions if you don't explicitly try/catch // Idk how to make it better tho Task.Run(async () => { - var releases = (await SelectedPackage.GetAllReleases()).ToList(); - if (!releases.Any()) + if (SelectedPackage.ShouldIgnoreReleases) { Application.Current.Dispatcher.Invoke(() => { @@ -175,7 +190,7 @@ public partial class InstallerViewModel : ObservableObject var commits = await value.GetAllCommits(SelectedVersion.TagName); Application.Current.Dispatcher.Invoke(() => { - AvailableCommits = new ObservableCollection(commits); + AvailableCommits = new ObservableCollection(commits); SelectedCommit = AvailableCommits[0]; SelectedVersion = AvailableVersions.First(x => x.TagName == "master"); }); @@ -216,9 +231,12 @@ public partial class InstallerViewModel : ObservableObject try { var hashes = await SelectedPackage.GetAllCommits(value.TagName); - AvailableCommits = new ObservableCollection(hashes); - await Task.Delay(10); // or it doesn't work sometimes? lolwut? - SelectedCommit = AvailableCommits[0]; + + Application.Current.Dispatcher.Invoke(() => + { + AvailableCommits = new ObservableCollection(hashes); + SelectedCommit = AvailableCommits[0]; + }); } catch (Exception e) { @@ -230,6 +248,8 @@ public partial class InstallerViewModel : ObservableObject private async Task ActuallyInstall() { + var isCurrentlyReleaseMode = IsReleaseMode; + var installSuccess = await InstallGitIfNecessary(); if (!installSuccess) { @@ -254,7 +274,9 @@ public partial class InstallerViewModel : ObservableObject } } - var version = await DownloadPackage(SelectedVersion.TagName); + var version = isCurrentlyReleaseMode + ? await DownloadPackage(SelectedVersion.TagName, false) + : await DownloadPackage(SelectedCommit.Sha, true); await InstallPackage(); ProgressText = "Done"; @@ -262,6 +284,8 @@ public partial class InstallerViewModel : ObservableObject IsIndeterminate = false; SelectedPackageOnProgressChanged(this, 100); + var branch = isCurrentlyReleaseMode ? null : SelectedVersion.TagName; + var package = new InstalledPackage { DisplayName = SelectedPackage.DisplayName, @@ -269,6 +293,8 @@ public partial class InstallerViewModel : ObservableObject Id = Guid.NewGuid(), PackageName = SelectedPackage.Name, PackageVersion = version, + DisplayVersion = GetDisplayVersion(version, branch), + InstalledBranch = branch, LaunchCommand = SelectedPackage.LaunchCommand, LastUpdateCheck = DateTimeOffset.Now }; @@ -277,13 +303,18 @@ public partial class InstallerViewModel : ObservableObject ProgressValue = 0; } + + private string GetDisplayVersion(string version, string? branch) + { + return branch == null ? version : $"{branch}@{version[..7]}"; + } - private Task DownloadPackage(string version) + private Task DownloadPackage(string version, bool isCommitHash) { SelectedPackage.DownloadProgressChanged += SelectedPackageOnProgressChanged; SelectedPackage.DownloadComplete += (_, _) => ProgressText = "Download Complete"; ProgressText = "Downloading package..."; - return SelectedPackage.DownloadPackage(version: version); + return SelectedPackage.DownloadPackage(version, isCommitHash); } private async Task InstallPackage() diff --git a/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs b/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs index 9d5bfb78..ce293e85 100644 --- a/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs +++ b/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs @@ -136,7 +136,7 @@ public partial class OneClickInstallViewModel : ObservableObject selectedPackage.DownloadProgressChanged += SelectedPackageOnProgressChanged; selectedPackage.DownloadComplete += (_, _) => SubHeaderText = "Download Complete"; SubHeaderText = "Downloading package..."; - return selectedPackage.DownloadPackage(version: version); + return selectedPackage.DownloadPackage(version, false); } private async Task InstallPackage(BasePackage selectedPackage) diff --git a/StabilityMatrix/ViewModels/PackageManagerViewModel.cs b/StabilityMatrix/ViewModels/PackageManagerViewModel.cs index 696fbeeb..f8f03af2 100644 --- a/StabilityMatrix/ViewModels/PackageManagerViewModel.cs +++ b/StabilityMatrix/ViewModels/PackageManagerViewModel.cs @@ -252,8 +252,8 @@ public partial class PackageManagerViewModel : ObservableObject SelectedPackage.UpdateAvailable = false; UpdateAvailable = false; }; - var updateResult = await package.Update(); - settingsManager.UpdatePackageVersionNumber(SelectedPackage.DisplayName!, updateResult!); + var updateResult = await package.Update(SelectedPackage); + settingsManager.UpdatePackageVersionNumber(SelectedPackage.Id, updateResult); await OnLoaded(); }