Browse Source

Add path extensions saving and injection

pull/5/head
Ionite 1 year ago
parent
commit
98542bbb68
No known key found for this signature in database
  1. 6
      StabilityMatrix/App.xaml.cs
  2. 8
      StabilityMatrix/Helper/ISettingsManager.cs
  3. 7
      StabilityMatrix/Helper/PrerequisiteHelper.cs
  4. 25
      StabilityMatrix/Helper/SettingsManager.cs
  5. 1
      StabilityMatrix/Models/Settings.cs
  6. 2
      StabilityMatrix/Python/PyRunner.cs

6
StabilityMatrix/App.xaml.cs

@ -86,11 +86,15 @@ namespace StabilityMatrix
serviceCollection.AddTransient<OneClickInstallViewModel>(); serviceCollection.AddTransient<OneClickInstallViewModel>();
serviceCollection.AddTransient<CheckpointManagerViewModel>(); serviceCollection.AddTransient<CheckpointManagerViewModel>();
var settingsManager = new SettingsManager();
serviceCollection.AddSingleton<ISettingsManager>(settingsManager);
// Insert path extensions
settingsManager.InsertPathExtensions();
serviceCollection.AddSingleton<BasePackage, A3WebUI>(); serviceCollection.AddSingleton<BasePackage, A3WebUI>();
serviceCollection.AddSingleton<BasePackage, VladAutomatic>(); serviceCollection.AddSingleton<BasePackage, VladAutomatic>();
serviceCollection.AddSingleton<BasePackage, ComfyUI>(); serviceCollection.AddSingleton<BasePackage, ComfyUI>();
serviceCollection.AddSingleton<Wpf.Ui.Contracts.ISnackbarService, Wpf.Ui.Services.SnackbarService>(); serviceCollection.AddSingleton<Wpf.Ui.Contracts.ISnackbarService, Wpf.Ui.Services.SnackbarService>();
serviceCollection.AddSingleton<ISettingsManager, SettingsManager>();
serviceCollection.AddSingleton<IPrerequisiteHelper, PrerequisiteHelper>(); serviceCollection.AddSingleton<IPrerequisiteHelper, PrerequisiteHelper>();
serviceCollection.AddSingleton<ISnackbarService, SnackbarService>(); serviceCollection.AddSingleton<ISnackbarService, SnackbarService>();
serviceCollection.AddSingleton<IDownloadService, DownloadService>(); serviceCollection.AddSingleton<IDownloadService, DownloadService>();

8
StabilityMatrix/Helper/ISettingsManager.cs

@ -14,6 +14,14 @@ public interface ISettingsManager
void SetActiveInstalledPackage(InstalledPackage? p); void SetActiveInstalledPackage(InstalledPackage? p);
void SetNavExpanded(bool navExpanded); void SetNavExpanded(bool navExpanded);
void UpdatePackageVersionNumber(Guid id, string? newVersion); void UpdatePackageVersionNumber(Guid id, string? newVersion);
void AddPathExtension(string pathExtension);
string GetPathExtensionsAsString();
/// <summary>
/// Insert path extensions to the front of the PATH environment variable
/// </summary>
void InsertPathExtensions();
void SetLastUpdateCheck(InstalledPackage package); void SetLastUpdateCheck(InstalledPackage package);
List<LaunchOption> GetLaunchArgs(Guid packageId); List<LaunchOption> GetLaunchArgs(Guid packageId);
void SaveLaunchArgs(Guid packageId, List<LaunchOption> launchArgs); void SaveLaunchArgs(Guid packageId, List<LaunchOption> launchArgs);

7
StabilityMatrix/Helper/PrerequisiteHelper.cs

@ -22,6 +22,7 @@ public class PrerequisiteHelper : IPrerequisiteHelper
private readonly ILogger<PrerequisiteHelper> logger; private readonly ILogger<PrerequisiteHelper> logger;
private readonly IGitHubClient gitHubClient; private readonly IGitHubClient gitHubClient;
private readonly IDownloadService downloadService; private readonly IDownloadService downloadService;
private readonly ISettingsManager settingsManager;
private static readonly string PortableGitInstallDir = private static readonly string PortableGitInstallDir =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StabilityMatrix", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StabilityMatrix",
@ -36,11 +37,12 @@ public class PrerequisiteHelper : IPrerequisiteHelper
public static readonly string GitBinPath = Path.Combine(PortableGitInstallDir, "bin"); public static readonly string GitBinPath = Path.Combine(PortableGitInstallDir, "bin");
public PrerequisiteHelper(ILogger<PrerequisiteHelper> logger, IGitHubClient gitHubClient, public PrerequisiteHelper(ILogger<PrerequisiteHelper> logger, IGitHubClient gitHubClient,
IDownloadService downloadService) IDownloadService downloadService, ISettingsManager settingsManager)
{ {
this.logger = logger; this.logger = logger;
this.gitHubClient = gitHubClient; this.gitHubClient = gitHubClient;
this.downloadService = downloadService; this.downloadService = downloadService;
this.settingsManager = settingsManager;
} }
public event EventHandler<ProgressReport>? DownloadProgressChanged; public event EventHandler<ProgressReport>? DownloadProgressChanged;
@ -89,6 +91,9 @@ public class PrerequisiteHelper : IPrerequisiteHelper
OnInstallProgressChanged(this, new ProgressReport(-1, isIndeterminate: true)); OnInstallProgressChanged(this, new ProgressReport(-1, isIndeterminate: true));
File.Delete(PortableGitDownloadPath); File.Delete(PortableGitDownloadPath);
// Also add git to the path
settingsManager.AddPathExtension(GitBinPath);
settingsManager.InsertPathExtensions();
OnInstallComplete(this, new ProgressReport(progress: 1f)); OnInstallComplete(this, new ProgressReport(progress: 1f));
} }

25
StabilityMatrix/Helper/SettingsManager.cs

@ -15,6 +15,7 @@ public class SettingsManager : ISettingsManager
private static readonly string SettingsPath = private static readonly string SettingsPath =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StabilityMatrix", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StabilityMatrix",
SettingsFileName); SettingsFileName);
private readonly string? originalEnvPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);
public Settings Settings { get; private set; } = new(); public Settings Settings { get; private set; } = new();
@ -65,6 +66,30 @@ public class SettingsManager : ISettingsManager
SaveSettings(); SaveSettings();
} }
public void AddPathExtension(string pathExtension)
{
Settings.PathExtensions ??= new List<string>();
Settings.PathExtensions.Add(pathExtension);
SaveSettings();
}
public string GetPathExtensionsAsString()
{
return string.Join(";", Settings.PathExtensions ?? new List<string>());
}
/// <summary>
/// Insert path extensions to the front of the PATH environment variable
/// </summary>
public void InsertPathExtensions()
{
if (Settings.PathExtensions == null) return;
var toInsert = GetPathExtensionsAsString();
// Append the original path, if any
toInsert += originalEnvPath ?? "";
Environment.SetEnvironmentVariable("PATH", toInsert, EnvironmentVariableTarget.Process);
}
public void UpdatePackageVersionNumber(Guid id, string? newVersion) public void UpdatePackageVersionNumber(Guid id, string? newVersion)
{ {
var package = Settings.InstalledPackages.FirstOrDefault(x => x.Id == id); var package = Settings.InstalledPackages.FirstOrDefault(x => x.Id == id);

1
StabilityMatrix/Models/Settings.cs

@ -11,4 +11,5 @@ public class Settings
public List<InstalledPackage> InstalledPackages { get; set; } = new(); public List<InstalledPackage> InstalledPackages { get; set; } = new();
public Guid? ActiveInstalledPackage { get; set; } public Guid? ActiveInstalledPackage { get; set; }
public bool IsNavExpanded { get; set; } public bool IsNavExpanded { get; set; }
public List<string>? PathExtensions { get; set; }
} }

2
StabilityMatrix/Python/PyRunner.cs

@ -50,7 +50,7 @@ public class PyRunner : IPyRunner
// Get existing PATH // Get existing PATH
var currentEnvPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process); var currentEnvPath = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process);
// Append Python path to PATH // Append Python path to PATH
Environment.SetEnvironmentVariable("PATH", $"{PrerequisiteHelper.GitBinPath};{currentEnvPath};{HomePath}", EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("PATH", $"{HomePath};{currentEnvPath}", EnvironmentVariableTarget.Process);
Logger.Info("Initializing Python runtime with DLL: {DllPath}", DllPath); Logger.Info("Initializing Python runtime with DLL: {DllPath}", DllPath);
// Check PythonDLL exists // Check PythonDLL exists

Loading…
Cancel
Save