Browse Source

Install vcredist & some bug fixes

- Install VCRedist if missing
- Refactored environment setup into PrerequisiteHelper
- Do a git init on vlad install to fix git error
pull/5/head
JT 1 year ago
parent
commit
dd4f814a9b
  1. 2
      Jenkinsfile
  2. 4
      StabilityMatrix/Helper/IPrerequisiteHelper.cs
  3. 76
      StabilityMatrix/Helper/PrerequisiteHelper.cs
  4. 30
      StabilityMatrix/Models/Packages/A3WebUI.cs
  5. 7
      StabilityMatrix/Models/Packages/BaseGitPackage.cs
  6. 2
      StabilityMatrix/Models/Packages/BasePackage.cs
  7. 35
      StabilityMatrix/Models/Packages/ComfyUI.cs
  8. 5
      StabilityMatrix/Models/Packages/DankDiffusion.cs
  9. 20
      StabilityMatrix/Models/Packages/VladAutomatic.cs
  10. 5
      StabilityMatrix/ViewModels/InstallerViewModel.cs
  11. 21
      StabilityMatrix/ViewModels/OneClickInstallViewModel.cs

2
Jenkinsfile vendored

@ -16,7 +16,7 @@ node("Windows") {
}
stage('Publish') {
bat "dotnet publish -c Release -o out -r win-x64 --self-contained true"
bat "dotnet publish .\\StabilityMatrix\\StabilityMatrix.csproj -c Release -o out -r win-x64 --self-contained true"
}
stage('Set Version') {

4
StabilityMatrix/Helper/IPrerequisiteHelper.cs

@ -7,4 +7,8 @@ namespace StabilityMatrix.Helper;
public interface IPrerequisiteHelper
{
Task InstallGitIfNecessary(IProgress<ProgressReport>? progress = null);
Task InstallVcRedistIfNecessary(IProgress<ProgressReport>? progress = null);
Task SetupPythonDependencies(string installLocation, string requirementsFileName,
IProgress<ProgressReport>? progress = null, Action<string?>? onConsoleOutput = null);
}

76
StabilityMatrix/Helper/PrerequisiteHelper.cs

@ -1,10 +1,13 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Win32;
using Octokit;
using StabilityMatrix.Models;
using StabilityMatrix.Python;
using StabilityMatrix.Services;
namespace StabilityMatrix.Helper;
@ -15,6 +18,11 @@ public class PrerequisiteHelper : IPrerequisiteHelper
private readonly IGitHubClient gitHubClient;
private readonly IDownloadService downloadService;
private readonly ISettingsManager settingsManager;
private const string VcRedistDownloadUrl = "https://aka.ms/vs/16/release/vc_redist.x64.exe";
private static readonly string VcRedistDownloadPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StabilityMatrix",
"vcredist.x64.exe");
private static readonly string PortableGitInstallDir =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StabilityMatrix",
@ -59,7 +67,73 @@ public class PrerequisiteHelper : IPrerequisiteHelper
await UnzipGit(progress);
}
public async Task InstallVcRedistIfNecessary(IProgress<ProgressReport>? progress = null)
{
var registry = Registry.LocalMachine;
var key = registry.OpenSubKey(
@"SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64", false);
if (key != null)
{
var buildId = Convert.ToUInt32(key.GetValue("Bld"));
if (buildId >= 30139)
{
return;
}
}
logger.LogInformation("Downloading VC Redist");
await downloadService.DownloadToFileAsync(VcRedistDownloadUrl, VcRedistDownloadPath, progress: progress);
progress?.Report(new ProgressReport(progress: 1f, message: "Visual C++ download complete",
type: ProgressType.Download));
logger.LogInformation("Installing VC Redist");
progress?.Report(new ProgressReport(progress: 0.5f, isIndeterminate: true, type: ProgressType.Generic, message: "Installing prerequisites..."));
var process = ProcessRunner.StartProcess(VcRedistDownloadPath, "/install /quiet /norestart");
await process.WaitForExitAsync();
progress?.Report(new ProgressReport(progress: 1f, message: "Visual C++ install complete",
type: ProgressType.Generic));
File.Delete(VcRedistDownloadPath);
}
public async Task SetupPythonDependencies(string installLocation, string requirementsFileName,
IProgress<ProgressReport>? progress = null, Action<string?>? onConsoleOutput = null)
{
// Setup dependencies
progress?.Report(new ProgressReport(-1, isIndeterminate: true));
var venvRunner = new PyVenvRunner(Path.Combine(installLocation, "venv"));
if (!venvRunner.Exists())
{
await venvRunner.Setup();
}
void HandleConsoleOutput(string? s)
{
Debug.WriteLine($"venv stdout: {s}");
onConsoleOutput?.Invoke(s);
}
// Install torch
logger.LogDebug("Starting torch install...");
await venvRunner.PipInstall(venvRunner.GetTorchInstallCommand(), installLocation, HandleConsoleOutput);
// Install xformers if nvidia
if (HardwareHelper.HasNvidiaGpu())
{
await venvRunner.PipInstall("xformers", installLocation, HandleConsoleOutput);
}
// Install requirements
logger.LogDebug("Starting requirements install...");
await venvRunner.PipInstall($"-r {requirementsFileName}", installLocation, HandleConsoleOutput);
logger.LogDebug("Finished installing requirements!");
progress?.Report(new ProgressReport(1, isIndeterminate: false));
}
private async Task UnzipGit(IProgress<ProgressReport>? progress = null)
{
if (progress == null)

30
StabilityMatrix/Models/Packages/A3WebUI.cs

@ -23,8 +23,9 @@ public class A3WebUI : BaseGitPackage
public string RelativeArgsDefinitionScriptPath => "modules.cmd_args";
public A3WebUI(IGithubApiCache githubApi, ISettingsManager settingsManager, IDownloadService downloadService) :
base(githubApi, settingsManager, downloadService)
public A3WebUI(IGithubApiCache githubApi, ISettingsManager settingsManager, IDownloadService downloadService,
IPrerequisiteHelper prerequisiteHelper) :
base(githubApi, settingsManager, downloadService, prerequisiteHelper)
{
}
@ -115,29 +116,8 @@ public class A3WebUI : BaseGitPackage
public override async Task InstallPackage(IProgress<ProgressReport>? progress = null)
{
await UnzipPackage(progress);
progress?.Report(new ProgressReport(-1, isIndeterminate: true));
Logger.Debug("Setting up venv");
await SetupVenv(InstallLocation);
var venvRunner = new PyVenvRunner(Path.Combine(InstallLocation, "venv"));
void HandleConsoleOutput(string? s)
{
Debug.WriteLine($"venv stdout: {s}");
OnConsoleOutput(s);
}
// install prereqs
await venvRunner.PipInstall(venvRunner.GetTorchInstallCommand(), InstallLocation, HandleConsoleOutput);
if (HardwareHelper.HasNvidiaGpu())
{
await venvRunner.PipInstall("xformers", InstallLocation, HandleConsoleOutput);
}
await venvRunner.PipInstall("-r requirements_versions.txt", InstallLocation, HandleConsoleOutput);
Logger.Debug("Finished installing requirements");
progress?.Report(new ProgressReport(1f, "Install complete"));
await PrerequisiteHelper.SetupPythonDependencies(InstallLocation, "requirements_versions.txt", progress,
OnConsoleOutput);
}
public override async Task RunPackage(string installedPackagePath, string arguments)

7
StabilityMatrix/Models/Packages/BaseGitPackage.cs

@ -26,6 +26,7 @@ public abstract class BaseGitPackage : BasePackage
protected readonly IGithubApiCache GithubApi;
protected readonly ISettingsManager SettingsManager;
protected readonly IDownloadService DownloadService;
protected readonly IPrerequisiteHelper PrerequisiteHelper;
protected PyVenvRunner? VenvRunner;
/// <summary>
@ -48,11 +49,13 @@ public abstract class BaseGitPackage : BasePackage
: $"https://api.github.com/repos/{Author}/{Name}/zipball/{tagName}";
}
protected BaseGitPackage(IGithubApiCache githubApi, ISettingsManager settingsManager, IDownloadService downloadService)
protected BaseGitPackage(IGithubApiCache githubApi, ISettingsManager settingsManager,
IDownloadService downloadService, IPrerequisiteHelper prerequisiteHelper)
{
GithubApi = githubApi;
SettingsManager = settingsManager;
this.DownloadService = downloadService;
DownloadService = downloadService;
PrerequisiteHelper = prerequisiteHelper;
}
protected Task<Release> GetLatestRelease()

2
StabilityMatrix/Models/Packages/BasePackage.cs

@ -50,7 +50,7 @@ public abstract class BasePackage
public event EventHandler<int>? Exited;
public event EventHandler<string>? StartupComplete;
public void OnConsoleOutput(string output) => ConsoleOutput?.Invoke(this, output);
public void OnConsoleOutput(string? output) => ConsoleOutput?.Invoke(this, output);
public void OnExit(int exitCode) => Exited?.Invoke(this, exitCode);
public void OnStartupComplete(string url) => StartupComplete?.Invoke(this, url);
}

35
StabilityMatrix/Models/Packages/ComfyUI.cs

@ -25,8 +25,9 @@ public class ComfyUI : BaseGitPackage
new("https://github.com/comfyanonymous/ComfyUI/raw/master/comfyui_screenshot.png");
public override bool ShouldIgnoreReleases => true;
public ComfyUI(IGithubApiCache githubApi, ISettingsManager settingsManager, IDownloadService downloadService) :
base(githubApi, settingsManager, downloadService)
public ComfyUI(IGithubApiCache githubApi, ISettingsManager settingsManager, IDownloadService downloadService,
IPrerequisiteHelper prerequisiteHelper) :
base(githubApi, settingsManager, downloadService, prerequisiteHelper)
{
}
@ -88,34 +89,8 @@ public class ComfyUI : BaseGitPackage
public override async Task InstallPackage(IProgress<ProgressReport>? progress = null)
{
await UnzipPackage(progress);
// Setup dependencies
progress?.Report(new ProgressReport(-1, isIndeterminate: true));
await SetupVenv(InstallLocation);
var venvRunner = new PyVenvRunner(Path.Combine(InstallLocation, "venv"));
void HandleConsoleOutput(string? s)
{
Debug.WriteLine($"venv stdout: {s}");
OnConsoleOutput(s);
}
// Install torch
Logger.Debug("Starting torch install...");
await venvRunner.PipInstall(venvRunner.GetTorchInstallCommand(), InstallLocation, HandleConsoleOutput);
// Install xformers if nvidia
if (HardwareHelper.HasNvidiaGpu())
{
await venvRunner.PipInstall("xformers", InstallLocation, HandleConsoleOutput);
}
// Install requirements
Logger.Debug("Starting requirements install...");
await venvRunner.PipInstall("-r requirements.txt", InstallLocation, HandleConsoleOutput);
Logger.Debug("Finished installing requirements!");
progress?.Report(new ProgressReport(1, isIndeterminate: false));
await PrerequisiteHelper.SetupPythonDependencies(InstallLocation, "requirements.txt", progress,
OnConsoleOutput);
}
public override async Task RunPackage(string installedPackagePath, string arguments)

5
StabilityMatrix/Models/Packages/DankDiffusion.cs

@ -9,8 +9,9 @@ namespace StabilityMatrix.Models.Packages;
public class DankDiffusion : BaseGitPackage
{
public DankDiffusion(IGithubApiCache githubApi, ISettingsManager settingsManager, IDownloadService downloadService) :
base(githubApi, settingsManager, downloadService)
public DankDiffusion(IGithubApiCache githubApi, ISettingsManager settingsManager, IDownloadService downloadService,
IPrerequisiteHelper prerequisiteHelper) :
base(githubApi, settingsManager, downloadService, prerequisiteHelper)
{
}

20
StabilityMatrix/Models/Packages/VladAutomatic.cs

@ -21,11 +21,12 @@ public class VladAutomatic : BaseGitPackage
new("https://github.com/vladmandic/automatic/raw/master/html/black-orange.jpg");
public override bool ShouldIgnoreReleases => true;
public VladAutomatic(IGithubApiCache githubApi, ISettingsManager settingsManager, IDownloadService downloadService) :
base(githubApi, settingsManager, downloadService)
public VladAutomatic(IGithubApiCache githubApi, ISettingsManager settingsManager, IDownloadService downloadService,
IPrerequisiteHelper prerequisiteHelper) :
base(githubApi, settingsManager, downloadService, prerequisiteHelper)
{
}
// https://github.com/vladmandic/automatic/blob/master/modules/shared.py#L324
public override Dictionary<SharedFolderType, string> SharedFolders => new()
{
@ -87,6 +88,19 @@ public class VladAutomatic : BaseGitPackage
ReleaseNotesMarkdown = string.Empty
});
}
public override async Task InstallPackage(IProgress<ProgressReport>? progress = null)
{
await UnzipPackage(progress);
var gitInitProcess =
ProcessRunner.StartProcess(Path.Combine(Helper.PrerequisiteHelper.GitBinPath, "git.exe"), "init",
InstallLocation);
await gitInitProcess.WaitForExitAsync();
await PrerequisiteHelper.SetupPythonDependencies(InstallLocation, "requirements.txt", progress,
OnConsoleOutput);
}
public override async Task RunPackage(string installedPackagePath, string arguments)
{

5
StabilityMatrix/ViewModels/InstallerViewModel.cs

@ -395,11 +395,11 @@ public partial class InstallerViewModel : ObservableObject
{
if (progress.Message != null && progress.Message.Contains("Downloading"))
{
ProgressText = $"Downloading Git... {progress.Percentage:N0}%";
ProgressText = $"Downloading prerequisites... {progress.Percentage:N0}%";
}
else if (progress.Type == ProgressType.Extract)
{
ProgressText = $"Installing Git... {progress.Percentage:N0}%";
ProgressText = $"Installing git... {progress.Percentage:N0}%";
}
else
{
@ -409,6 +409,7 @@ public partial class InstallerViewModel : ObservableObject
ProgressValue = Convert.ToInt32(progress.Percentage);
});
await prerequisiteHelper.InstallVcRedistIfNecessary(progressHandler);
await prerequisiteHelper.InstallGitIfNecessary(progressHandler);
}

21
StabilityMatrix/ViewModels/OneClickInstallViewModel.cs

@ -79,11 +79,11 @@ public partial class OneClickInstallViewModel : ObservableObject
{
if (progress.Message != null && progress.Message.Contains("Downloading"))
{
SubHeaderText = $"Downloading Git... {progress.Percentage:N0}%";
SubHeaderText = $"Downloading prerequisites... {progress.Percentage:N0}%";
}
else if (progress.Type == ProgressType.Extract)
{
SubHeaderText = $"Installing Git... {progress.Percentage:N0}%";
SubHeaderText = $"Installing git... {progress.Percentage:N0}%";
}
else if (progress.Message != null)
{
@ -92,8 +92,9 @@ public partial class OneClickInstallViewModel : ObservableObject
OneClickInstallProgress = Convert.ToInt32(progress.Percentage);
});
await prerequisiteHelper.InstallGitIfNecessary(progressHandler);
await prerequisiteHelper.InstallVcRedistIfNecessary(progressHandler);
SubHeaderText = "Installing prerequisites...";
IsIndeterminate = true;
@ -178,18 +179,4 @@ public partial class OneClickInstallViewModel : ObservableObject
await selectedPackage.InstallPackage(progress);
}
private void SelectedPackageOnProgressChanged(object? sender, int progress)
{
if (progress == -1)
{
IsIndeterminate = true;
}
else
{
IsIndeterminate = false;
OneClickInstallProgress = progress;
}
}
}

Loading…
Cancel
Save