From 0702f95e0c5202e0158fa4bce9aad88bf349399c Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Wed, 7 Jun 2023 15:16:32 +0200 Subject: [PATCH] Driver Updater improvements --- app/Program.cs | 8 +- app/Properties/Resources.Designer.cs | 20 ++++ app/Properties/Resources.resx | 6 + app/Resources/icons8-charged-battery-96.png | Bin 0 -> 406 bytes app/Resources/icons8-electrical-96.png | Bin 0 -> 1000 bytes app/Settings.cs | 30 ++--- app/ToastForm.cs | 10 +- app/Updates.cs | 121 +++++++++++++------- 8 files changed, 132 insertions(+), 63 deletions(-) create mode 100644 app/Resources/icons8-charged-battery-96.png create mode 100644 app/Resources/icons8-electrical-96.png diff --git a/app/Program.cs b/app/Program.cs index 4d8c4280..1aa44cb3 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -135,7 +135,7 @@ namespace GHelper - public static void SetAutoModes() + public static void SetAutoModes(bool powerChanged = false) { if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastAuto) < 3000) return; @@ -147,7 +147,7 @@ namespace GHelper inputDispatcher.Init(); settingsForm.SetBatteryChargeLimit(AppConfig.getConfig("charge_limit")); - settingsForm.AutoPerformance(); + settingsForm.AutoPerformance(powerChanged); bool switched = settingsForm.AutoGPUMode(); @@ -163,11 +163,9 @@ namespace GHelper private static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e) { - if (SystemInformation.PowerStatus.PowerLineStatus == isPlugged) return; - Logger.WriteLine("Power Mode Changed"); - SetAutoModes(); + SetAutoModes(true); } diff --git a/app/Properties/Resources.Designer.cs b/app/Properties/Resources.Designer.cs index c7c33cd6..5634fc23 100644 --- a/app/Properties/Resources.Designer.cs +++ b/app/Properties/Resources.Designer.cs @@ -130,6 +130,16 @@ namespace GHelper.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap icons8_charged_battery_96 { + get { + object obj = ResourceManager.GetObject("icons8_charged_battery_96", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -140,6 +150,16 @@ namespace GHelper.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap icons8_electrical_96 { + get { + object obj = ResourceManager.GetObject("icons8_electrical_96", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/app/Properties/Resources.resx b/app/Properties/Resources.resx index 1e205fa7..34db2fdc 100644 --- a/app/Properties/Resources.resx +++ b/app/Properties/Resources.resx @@ -238,4 +238,10 @@ ..\Resources\icons8-software-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\icons8-charged-battery-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\icons8-electrical-96.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/app/Resources/icons8-charged-battery-96.png b/app/Resources/icons8-charged-battery-96.png new file mode 100644 index 0000000000000000000000000000000000000000..24d0a72be4366ae71e04a6093c4cb86729477598 GIT binary patch literal 406 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGooCO|{#S9GG!XV7ZFl&wk0|TRn zr;B4q#hkYn9l4ktd6*sl|G#`r@q5Dp_O~g!^{0b5@i;gVLSyT-V`#wI1T5WVf}@Dxwx Y&%M!8vqO+A1sKo_p00i_>zopr08?D1l>h($ literal 0 HcmV?d00001 diff --git a/app/Resources/icons8-electrical-96.png b/app/Resources/icons8-electrical-96.png new file mode 100644 index 0000000000000000000000000000000000000000..ccd7a87cc88e2522f4ad6c215cfe1577176abaf7 GIT binary patch literal 1000 zcmV>P))}|D<8~*tlsCX?{O9_L*7Wh2;ASVHQ}o2>o{@CZ2Qt|=WG9x z05}6|J6s7HmTgQ~n(6v@f&w@We55}Al`7$YeMh=Mvtvb>>&R65?%T1Gm~f^DABnd$AsD*)ag8fj?c!uMtAHHGc$fql>cR zp&WVbq;>}IX2Jp9?r@)6Z_MG={SmjBY+ zP|#P|1omhB3E_Q|Apn;P4r;LvA(%&Di~Mjy0FDB``Wgc6^2b96Yc@nai-Ep{KzaFw zg)B6HeZajwg@9fDb`_r;{PHu6y@eq8 ze&v@6LGp`d8b6?zTK5Fi{Ngiz*&^4>vp-Vx=}2e(Wch4K&u#G3| z=B=3!oTWxn>#7(I>RbVSTK@KL;AZes3Twz;YjRN=!!hPdd0G0B&pY}CyauiVr?M1r zl)oD6(w;u!xS}xJbya=F@hL^}o51mnHT*gDeMIv6FW>uj^@tt$w&k3X-vpB1A&v`~ z!<#)EP)m6u>gAk)&v4e6-(d)^qFBxuXb6(uVF;4nB~i{A7D5Oigb+dqA%qYj^UGiL W8|K;S=UadP0000 { - DriversAsync($"https://rog.asus.com/support/webapi/product/GetPDDrivers?website=global&model={model}&osid=52", 0, tableDrivers); + DriversAsync($"https://rog.asus.com/support/webapi/product/GetPDDrivers?website=global&model={model}&cpu={model}&osid=52", 0, tableDrivers); }); Shown += Updates_Shown; @@ -86,23 +98,20 @@ namespace GHelper try { - Dictionary devices = new(); - string biosVersion = ""; - - if (type == 0) devices = GetDeviceVersions(); - else biosVersion = GetBiosVersion(); - - //Debug.WriteLine(biosVersion); - - using (var httpClient = new HttpClient()) + using (var httpClient = new HttpClient(new HttpClientHandler { + AutomaticDecompression = DecompressionMethods.All + })) + { + httpClient.DefaultRequestHeaders.AcceptEncoding.ParseAdd("gzip, deflate, br"); httpClient.DefaultRequestHeaders.Add("User-Agent", "C# App"); var json = await httpClient.GetStringAsync(url); var data = JsonSerializer.Deserialize(json); var groups = data.GetProperty("Result").GetProperty("Obj"); - List skipList = new() { "Armoury Crate & Aura Creator Installer", "MyASUS", "ASUS Smart Display Control", "Aura Wallpaper" }; + List skipList = new() { "Armoury Crate & Aura Creator Installer", "MyASUS", "ASUS Smart Display Control", "Aura Wallpaper", "Virtual Pet","ROG Font V1.5" }; + List drivers = new(); for (int i = 0; i < groups.GetArrayLength(); i++) { @@ -116,62 +125,43 @@ namespace GHelper var file = files[j]; var title = file.GetProperty("Title").ToString(); - var version = file.GetProperty("Version").ToString().Replace("V", ""); - var downloadUrl = file.GetProperty("DownloadUrl").GetProperty("Global").ToString(); - - //Debug.WriteLine(" - " + title + " " + version + " " + downloadUrl); if (oldTitle != title && !skipList.Contains(title)) { - JsonElement hardwares = file.GetProperty("HardwareInfoList"); - bool newer = false; - if (type == 0 && hardwares.ToString().Length > 0) - for (int k = 0; k < hardwares.GetArrayLength(); k++) - { - var deviceID = hardwares[k].GetProperty("hardwareid").ToString(); - var localVersion = devices.Where(p => p.Key.Contains(deviceID)).Select(p => p.Value).FirstOrDefault(); - if (localVersion is not null) - { - newer = (new Version(version).CompareTo(new Version(localVersion)) > 0); - break; - } - } - - if (type == 1) - { - newer = Int32.Parse(version) > Int32.Parse(biosVersion); - } + var driver = new DriverDownload(); + driver.categoryName = categoryName; + driver.title = title; + driver.version = file.GetProperty("Version").ToString().Replace("V", ""); + driver.downloadUrl = file.GetProperty("DownloadUrl").GetProperty("Global").ToString(); + driver.hardwares = file.GetProperty("HardwareInfoList"); + drivers.Add(driver); BeginInvoke(delegate { - string versionText = version.Replace("latest version at the ", ""); + string versionText = driver.version.Replace("latest version at the ", ""); Label versionLabel = new Label { Text = versionText, Anchor = AnchorStyles.Left, Dock = DockStyle.Fill, Height = 50 }; versionLabel.Cursor = Cursors.Hand; - versionLabel.Font = new Font(versionLabel.Font, newer ? FontStyle.Underline | FontStyle.Bold : FontStyle.Underline); - versionLabel.ForeColor = newer ? colorTurbo : colorEco; + versionLabel.Font = new Font(versionLabel.Font, FontStyle.Underline); + versionLabel.ForeColor = colorEco; versionLabel.Padding = new Padding(5, 5, 5, 5); versionLabel.Click += delegate { - Process.Start(new ProcessStartInfo(downloadUrl) { UseShellExecute = true }); + Process.Start(new ProcessStartInfo(driver.downloadUrl) { UseShellExecute = true }); }; table.RowStyles.Add(new RowStyle(SizeType.AutoSize)); - table.Controls.Add(new Label { Text = categoryName, Anchor = AnchorStyles.Left, Dock = DockStyle.Fill, Padding = new Padding(5, 5, 5, 5) }, 0, table.RowCount); - table.Controls.Add(new Label { Text = title, Anchor = AnchorStyles.Left, Dock = DockStyle.Fill, Padding = new Padding(5, 5, 5, 5) }, 1, table.RowCount); + table.Controls.Add(new Label { Text = driver.categoryName, Anchor = AnchorStyles.Left, Dock = DockStyle.Fill, Padding = new Padding(5, 5, 5, 5) }, 0, table.RowCount); + table.Controls.Add(new Label { Text = driver.title, Anchor = AnchorStyles.Left, Dock = DockStyle.Fill, Padding = new Padding(5, 5, 5, 5) }, 1, table.RowCount); table.Controls.Add(versionLabel, 2, table.RowCount); table.RowCount++; }); } oldTitle = title; - } - - } - BeginInvoke(delegate { table.Visible = true; @@ -179,11 +169,54 @@ namespace GHelper PerformLayout(); }); + Dictionary devices = new(); + string biosVersion = "0"; + + if (type == 0) devices = GetDeviceVersions(); + else biosVersion = GetBiosVersion(); + + //Debug.WriteLine(biosVersion); + + int count = 0; + foreach (var driver in drivers) + { + int newer = -2; + if (type == 0 && driver.hardwares.ToString().Length > 0) + for (int k = 0; k < driver.hardwares.GetArrayLength(); k++) + { + var deviceID = driver.hardwares[k].GetProperty("hardwareid").ToString(); + var localVersion = devices.Where(p => p.Key.Contains(deviceID)).Select(p => p.Value).FirstOrDefault(); + if (localVersion is not null) + { + newer = new Version(driver.version).CompareTo(new Version(localVersion)); + break; + } + } + + if (type == 1) + newer = Int32.Parse(driver.version) > Int32.Parse(biosVersion) ? 1 : -1; + + if (newer > 0) + { + var label = table.GetControlFromPosition(2, count) as Label; + if (label != null) + { + BeginInvoke(delegate + { + label.Font = new Font(label.Font, FontStyle.Underline | FontStyle.Bold); + label.ForeColor = colorTurbo; + }); + } + } + + count++; + } + } } catch (Exception ex) { - Debug.WriteLine(ex.ToString()); + Logger.WriteLine(ex.ToString()); }