From cc63c1e239918fe116774d1139892d505503a126 Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 23 May 2023 22:19:42 -0700 Subject: [PATCH] Added helpers to deal with hardware info & A1111 ui settings. also removed unused usings --- StabilityMatrix/App.xaml.cs | 15 -------- StabilityMatrix/Helper/A1111Helper.cs | 29 ++++++++++++++++ StabilityMatrix/Helper/HardwareHelper.cs | 34 +++++++++++++++++++ StabilityMatrix/Helper/ProcessRunner.cs | 10 +++--- StabilityMatrix/InstallPage.xaml | 3 +- StabilityMatrix/InstallPage.xaml.cs | 14 -------- StabilityMatrix/LaunchPage.xaml.cs | 11 ------ StabilityMatrix/MainWindow.xaml.cs | 13 +------ .../ViewModels/InstallerViewModel.cs | 34 +++++++++++++------ 9 files changed, 93 insertions(+), 70 deletions(-) create mode 100644 StabilityMatrix/Helper/A1111Helper.cs create mode 100644 StabilityMatrix/Helper/HardwareHelper.cs diff --git a/StabilityMatrix/App.xaml.cs b/StabilityMatrix/App.xaml.cs index ccb2a215..a2a9b217 100644 --- a/StabilityMatrix/App.xaml.cs +++ b/StabilityMatrix/App.xaml.cs @@ -1,22 +1,7 @@ using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; -using Microsoft.UI.Xaml.Data; -using Microsoft.UI.Xaml.Input; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Navigation; -using Microsoft.UI.Xaml.Shapes; using System; -using System.Collections.Generic; using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.ApplicationModel; -using Windows.ApplicationModel.Activation; using Windows.ApplicationModel.Core; -using Windows.Foundation; -using Windows.Foundation.Collections; namespace StabilityMatrix { diff --git a/StabilityMatrix/Helper/A1111Helper.cs b/StabilityMatrix/Helper/A1111Helper.cs new file mode 100644 index 00000000..27f0f0c0 --- /dev/null +++ b/StabilityMatrix/Helper/A1111Helper.cs @@ -0,0 +1,29 @@ +using System; + +namespace StabilityMatrix.Helper; + +public static class A1111Helper +{ + public static string GetVramOption() + { + var vramGb = HardwareHelper.GetGpuMemoryBytes() / 1024 / 1024 / 1024; + + return vramGb switch + { + < 4 => "--lowvram", + < 8 => "--medvram", + _ => string.Empty + }; + } + + public static string GetXformersOption() + { + var gpuName = HardwareHelper.GetGpuChipName(); + if (gpuName.Contains("NVIDIA", StringComparison.OrdinalIgnoreCase)) + { + return "--xformers"; + } + + return string.Empty; + } +} diff --git a/StabilityMatrix/Helper/HardwareHelper.cs b/StabilityMatrix/Helper/HardwareHelper.cs new file mode 100644 index 00000000..12c075ac --- /dev/null +++ b/StabilityMatrix/Helper/HardwareHelper.cs @@ -0,0 +1,34 @@ +using System; +using Microsoft.Win32; + +namespace StabilityMatrix.Helper; + +public class HardwareHelper +{ + public static ulong GetGpuMemoryBytes() + { + var registry = Registry.LocalMachine; + var key = registry.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000", false); + if (key == null) + { + return 0; + } + + var vram = key.GetValue("HardwareInformation.qwMemorySize"); + var vramLong = Convert.ToUInt64(vram); + return vramLong; + } + + public static string GetGpuChipName() + { + var registry = Registry.LocalMachine; + var key = registry.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000", false); + if (key == null) + { + return "Unknown"; + } + + var gpuName = key.GetValue("HardwareInformation.ChipType"); + return gpuName?.ToString() ?? "Unknown"; + } +} diff --git a/StabilityMatrix/Helper/ProcessRunner.cs b/StabilityMatrix/Helper/ProcessRunner.cs index 5cfeb0ac..377acf24 100644 --- a/StabilityMatrix/Helper/ProcessRunner.cs +++ b/StabilityMatrix/Helper/ProcessRunner.cs @@ -1,13 +1,11 @@ -using System; -using System.Diagnostics; -using System.IO; +using System.Diagnostics; using System.Threading.Tasks; namespace StabilityMatrix.Helper; public static class ProcessRunner { - public static async Task RunProcessAsync(string fileName, string arguments) + public static async Task GetProcessOutputAsync(string fileName, string arguments) { using var process = new Process(); process.StartInfo.FileName = fileName; @@ -23,10 +21,10 @@ public static class ProcessRunner return output; } - public static Process RunProcess(string fileName, string arguments) + public static Process StartProcess(string fileName, string arguments) { - using var process = new Process(); + var process = new Process(); process.StartInfo.FileName = fileName; process.StartInfo.Arguments = arguments; process.StartInfo.UseShellExecute = false; diff --git a/StabilityMatrix/InstallPage.xaml b/StabilityMatrix/InstallPage.xaml index 31f7d3e8..da83e9cf 100644 --- a/StabilityMatrix/InstallPage.xaml +++ b/StabilityMatrix/InstallPage.xaml @@ -42,7 +42,8 @@