diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs index 209db2a1..d9f99a7b 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs @@ -199,14 +199,14 @@ public partial class InstallerViewModel : ContentDialogViewModelBase version = SelectedVersion?.TagName ?? throw new NullReferenceException("Selected version is null"); - await DownloadPackage(version, false); + await DownloadPackage(version, false, null); } else { version = SelectedCommit?.Sha ?? throw new NullReferenceException("Selected commit is null"); - await DownloadPackage(version, true); + await DownloadPackage(version, true, SelectedVersion!.TagName); } await InstallPackage(); @@ -271,7 +271,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase return branch == null ? version : $"{branch}@{version[..7]}"; } - private Task DownloadPackage(string version, bool isCommitHash) + private Task DownloadPackage(string version, bool isCommitHash, string? branch) { InstallProgress.Text = "Downloading package..."; @@ -282,7 +282,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase EventManager.Instance.OnGlobalProgressChanged((int) progress.Percentage); }); - return SelectedPackage.DownloadPackage(version, isCommitHash, progress); + return SelectedPackage.DownloadPackage(version, isCommitHash, branch, progress); } private async Task InstallPackage() diff --git a/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs index 854797e4..42208679 100644 --- a/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs @@ -157,7 +157,7 @@ public partial class OneClickInstallViewModel : ViewModelBase EventManager.Instance.OnGlobalProgressChanged(OneClickInstallProgress); }); - await SelectedPackage.DownloadPackage(version, false, progress); + await SelectedPackage.DownloadPackage(version, false, version, progress); SubHeaderText = "Download Complete"; OneClickInstallProgress = 100; } diff --git a/StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs b/StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs index 6dddc6ef..025f87e2 100644 --- a/StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs +++ b/StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs @@ -139,7 +139,7 @@ public abstract class BaseGitPackage : BasePackage } public override async Task DownloadPackage(string version, bool isCommitHash, - IProgress? progress = null) + string? branch, IProgress? progress = null) { var downloadUrl = GetDownloadUrl(version, isCommitHash); @@ -151,7 +151,7 @@ public abstract class BaseGitPackage : BasePackage await DownloadService .DownloadToFileAsync(downloadUrl, DownloadLocation, progress: progress) .ConfigureAwait(false); - + progress?.Report(new ProgressReport(100, message: "Download Complete")); return version; @@ -246,7 +246,8 @@ public abstract class BaseGitPackage : BasePackage { var releases = await GetAllReleases().ConfigureAwait(false); var latestRelease = releases.First(x => includePrerelease || !x.Prerelease); - await DownloadPackage(latestRelease.TagName, false, progress).ConfigureAwait(false); + await DownloadPackage(latestRelease.TagName, false, null, progress) + .ConfigureAwait(false); await InstallPackage(progress).ConfigureAwait(false); return latestRelease.TagName; } @@ -260,8 +261,9 @@ public abstract class BaseGitPackage : BasePackage { throw new Exception("No commits found for branch"); } - - await DownloadPackage(latestCommit.Sha, true, progress).ConfigureAwait(false); + + await DownloadPackage(latestCommit.Sha, true, installedPackage.InstalledBranch, progress) + .ConfigureAwait(false); await InstallPackage(progress).ConfigureAwait(false); return latestCommit.Sha; } diff --git a/StabilityMatrix.Core/Models/Packages/BasePackage.cs b/StabilityMatrix.Core/Models/Packages/BasePackage.cs index 285e5b10..06cff8a4 100644 --- a/StabilityMatrix.Core/Models/Packages/BasePackage.cs +++ b/StabilityMatrix.Core/Models/Packages/BasePackage.cs @@ -33,7 +33,7 @@ public abstract class BasePackage public virtual bool ShouldIgnoreReleases => false; public virtual bool UpdateAvailable { get; set; } - public abstract Task DownloadPackage(string version, bool isCommitHash, + public abstract Task DownloadPackage(string version, bool isCommitHash, string? branch, IProgress? progress = null); public abstract Task InstallPackage(IProgress? progress = null); public abstract Task RunPackage(string installedPackagePath, string command, string arguments); diff --git a/StabilityMatrix.Core/Models/Packages/InvokeAI.cs b/StabilityMatrix.Core/Models/Packages/InvokeAI.cs index 7ac7592a..cdc26769 100644 --- a/StabilityMatrix.Core/Models/Packages/InvokeAI.cs +++ b/StabilityMatrix.Core/Models/Packages/InvokeAI.cs @@ -116,7 +116,7 @@ public class InvokeAI : BaseGitPackage public override Task GetLatestVersion() => Task.FromResult("main"); - public override Task DownloadPackage(string version, bool isCommitHash, + public override Task DownloadPackage(string version, bool isCommitHash, string? branch, IProgress? progress = null) { return Task.FromResult(version); diff --git a/StabilityMatrix.Core/Models/Packages/VladAutomatic.cs b/StabilityMatrix.Core/Models/Packages/VladAutomatic.cs index 679840ee..636cf5ae 100644 --- a/StabilityMatrix.Core/Models/Packages/VladAutomatic.cs +++ b/StabilityMatrix.Core/Models/Packages/VladAutomatic.cs @@ -188,20 +188,22 @@ public class VladAutomatic : BaseGitPackage progress?.Report(new ProgressReport(1, isIndeterminate: false)); } - public override async Task DownloadPackage(string version, bool isCommitHash, IProgress? progress = null) + public override async Task DownloadPackage(string version, bool isCommitHash, + string? branch, IProgress? progress = null) { - progress?.Report(new ProgressReport(0.1f, message: "Downloading package...", isIndeterminate: true, type: ProgressType.Download)); - + progress?.Report(new ProgressReport(0.1f, message: "Downloading package...", + isIndeterminate: true, type: ProgressType.Download)); + var installDir = new DirectoryPath(InstallLocation); installDir.Create(); - - await PrerequisiteHelper.RunGit( - installDir.Parent ?? "", "clone", "https://github.com/vladmandic/automatic", installDir.Name) - .ConfigureAwait(false); - + + await PrerequisiteHelper + .RunGit(installDir.Parent ?? "", "clone", "https://github.com/vladmandic/automatic", + installDir.Name).ConfigureAwait(false); + await PrerequisiteHelper.RunGit( InstallLocation, "checkout", version).ConfigureAwait(false); - + return version; } @@ -244,15 +246,18 @@ public class VladAutomatic : BaseGitPackage } progress?.Report(new ProgressReport(0.1f, message: "Downloading package update...", - isIndeterminate: true, type: ProgressType.Download)); + isIndeterminate: true, type: ProgressType.Update)); - var version = await GithubApi.GetAllCommits(Author, Name, installedPackage.InstalledBranch).ConfigureAwait(false); - var latest = version?.FirstOrDefault(); + await PrerequisiteHelper.RunGit(installedPackage.FullPath, "checkout", + installedPackage.InstalledBranch).ConfigureAwait(false); + + var venvRunner = new PyVenvRunner(Path.Combine(installedPackage.FullPath!, "venv")); + venvRunner.WorkingDirectory = InstallLocation; + venvRunner.EnvironmentVariables = SettingsManager.Settings.EnvironmentVariables; + + await venvRunner.CustomInstall("launch.py --upgrade --test", OnConsoleOutput) + .ConfigureAwait(false); - if (latest?.Sha is null) - { - throw new Exception("Could not get latest version"); - } try { @@ -261,22 +266,18 @@ public class VladAutomatic : BaseGitPackage .GetGitOutput(installedPackage.FullPath, "rev-parse", "HEAD") .ConfigureAwait(false); - if (output.Replace(Environment.NewLine, "") == latest.Sha) - { - return latest.Sha; - } + return output.Replace(Environment.NewLine, "").Replace("\n", ""); } catch (Exception e) { Logger.Warn(e, "Could not get current git hash, continuing with update"); } - - await PrerequisiteHelper.RunGit(installedPackage.FullPath, "pull", - "origin", installedPackage.InstalledBranch).ConfigureAwait(false); - - progress?.Report(new ProgressReport(1f, message: "Update Complete", isIndeterminate: false, - type: ProgressType.Generic)); - - return latest.Sha; + finally + { + progress?.Report(new ProgressReport(1f, message: "Update Complete", isIndeterminate: false, + type: ProgressType.Update)); + } + + return installedPackage.InstalledBranch; } }