From 0fed74e069345c4cd135b4c364222e46de65ea0f Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 24 Sep 2023 12:23:31 +0200 Subject: [PATCH] M16 Fan fix for older BIOS only --- app/AppConfig.cs | 43 +++++++++++++++++++++++++++++++++++++++++-- app/GHelper.csproj | 2 +- app/Updates.cs | 29 ++--------------------------- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/app/AppConfig.cs b/app/AppConfig.cs index c9509072..dcedd42a 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -7,7 +7,9 @@ public static class AppConfig { private static string configFile; + private static string? _model; + private static string? _bios; private static Dictionary config = new Dictionary(); @@ -69,6 +71,34 @@ public static class AppConfig return _model; } + public static (string, string) GetBiosAndModel() + { + if (_bios is not null && _model is not null) return (_bios, _model); + + using (ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_BIOS")) + { + using (ManagementObjectCollection objCollection = objSearcher.Get()) + { + foreach (ManagementObject obj in objCollection) + if (obj["SMBIOSBIOSVersion"] is not null) + { + string[] results = obj["SMBIOSBIOSVersion"].ToString().Split("."); + if (results.Length > 1) + { + _model = results[0]; + _bios = results[1]; + } + else + { + _model = obj["SMBIOSBIOSVersion"].ToString(); + } + } + + return (_bios, _model); + } + } + } + public static string GetModelShort() { string model = GetModel(); @@ -363,12 +393,21 @@ public static class AppConfig public static bool IsFanScale() { - return ContainsModel("GU604"); + if (!ContainsModel("GU604")) return false; + + try + { + var (bios, model) = GetBiosAndModel(); + return (Int32.Parse(bios) < 312); + } catch + { + return false; + } } public static bool IsFanRequired() { - return ContainsModel("GA402X") || ContainsModel("G513") || ContainsModel("G713R"); + return ContainsModel("GA402X") || ContainsModel("G513") || ContainsModel("G713R") || ContainsModel("G713P"); } public static bool IsPowerRequired() diff --git a/app/GHelper.csproj b/app/GHelper.csproj index 1b96b195..5db6da27 100644 --- a/app/GHelper.csproj +++ b/app/GHelper.csproj @@ -15,7 +15,7 @@ AnyCPU False True - 0.125 + 0.126 diff --git a/app/Updates.cs b/app/Updates.cs index 780eceef..19526029 100644 --- a/app/Updates.cs +++ b/app/Updates.cs @@ -13,8 +13,8 @@ namespace GHelper const int DRIVER_NEWER = 1; //static int rowCount = 0; - static string model; static string bios; + static string model; static int updatesCount = 0; private static long lastUpdate; @@ -33,7 +33,7 @@ namespace GHelper if (!force && (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastUpdate) < 5000)) return; lastUpdate = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - InitBiosAndModel(); + (bios, model) = AppConfig.GetBiosAndModel(); updatesCount = 0; labelUpdates.ForeColor = colorEco; @@ -116,31 +116,6 @@ namespace GHelper } } - private string InitBiosAndModel() - { - using (ManagementObjectSearcher objSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS")) - { - using (ManagementObjectCollection objCollection = objSearcher.Get()) - { - foreach (ManagementObject obj in objCollection) - if (obj["SMBIOSBIOSVersion"] is not null) - { - string[] results = obj["SMBIOSBIOSVersion"].ToString().Split("."); - if (results.Length > 1) - { - model = results[0]; - bios = results[1]; - } - else - { - model = obj["SMBIOSBIOSVersion"].ToString(); - } - } - - return ""; - } - } - } public void VisualiseDriver(DriverDownload driver, TableLayoutPanel table) {