Browse Source

update vlad update to switch back to branch before updating

pull/109/head
JT 1 year ago
parent
commit
c9130c4067
  1. 8
      StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs
  2. 2
      StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs
  3. 8
      StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs
  4. 2
      StabilityMatrix.Core/Models/Packages/BasePackage.cs
  5. 2
      StabilityMatrix.Core/Models/Packages/InvokeAI.cs
  6. 45
      StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

8
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<string> DownloadPackage(string version, bool isCommitHash)
private Task<string> 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()

2
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;
}

8
StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs

@ -139,7 +139,7 @@ public abstract class BaseGitPackage : BasePackage
}
public override async Task<string> DownloadPackage(string version, bool isCommitHash,
IProgress<ProgressReport>? progress = null)
string? branch, IProgress<ProgressReport>? progress = null)
{
var downloadUrl = GetDownloadUrl(version, isCommitHash);
@ -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;
}
@ -261,7 +262,8 @@ 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;
}

2
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<string> DownloadPackage(string version, bool isCommitHash,
public abstract Task<string> DownloadPackage(string version, bool isCommitHash, string? branch,
IProgress<ProgressReport>? progress = null);
public abstract Task InstallPackage(IProgress<ProgressReport>? progress = null);
public abstract Task RunPackage(string installedPackagePath, string command, string arguments);

2
StabilityMatrix.Core/Models/Packages/InvokeAI.cs

@ -116,7 +116,7 @@ public class InvokeAI : BaseGitPackage
public override Task<string> GetLatestVersion() => Task.FromResult("main");
public override Task<string> DownloadPackage(string version, bool isCommitHash,
public override Task<string> DownloadPackage(string version, bool isCommitHash, string? branch,
IProgress<ProgressReport>? progress = null)
{
return Task.FromResult(version);

45
StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

@ -188,16 +188,18 @@ public class VladAutomatic : BaseGitPackage
progress?.Report(new ProgressReport(1, isIndeterminate: false));
}
public override async Task<string> DownloadPackage(string version, bool isCommitHash, IProgress<ProgressReport>? progress = null)
public override async Task<string> DownloadPackage(string version, bool isCommitHash,
string? branch, IProgress<ProgressReport>? 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);
@ -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);
finally
{
progress?.Report(new ProgressReport(1f, message: "Update Complete", isIndeterminate: false,
type: ProgressType.Generic));
type: ProgressType.Update));
}
return latest.Sha;
return installedPackage.InstalledBranch;
}
}

Loading…
Cancel
Save