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 00000000..24d0a72b Binary files /dev/null and b/app/Resources/icons8-charged-battery-96.png differ diff --git a/app/Resources/icons8-electrical-96.png b/app/Resources/icons8-electrical-96.png new file mode 100644 index 00000000..ccd7a87c Binary files /dev/null and b/app/Resources/icons8-electrical-96.png differ diff --git a/app/Settings.cs b/app/Settings.cs index 7fa332c0..da354054 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -176,7 +176,7 @@ namespace GHelper labelModel.Text = model + (ProcessHelper.IsUserAdministrator() ? "." : ""); - TopMost = AppConfig.getConfig("topmost") == 1; + TopMost = AppConfig.isConfig("topmost"); SetContextMenu(); @@ -1260,24 +1260,25 @@ namespace GHelper { case AsusACPI.PerformanceSilent: buttonSilent.Activated = true; + menuSilent.Checked = true; perfName = Properties.Strings.Silent; break; case AsusACPI.PerformanceTurbo: buttonTurbo.Activated = true; + menuTurbo.Checked = true; perfName = Properties.Strings.Turbo; break; default: buttonBalanced.Activated = true; + menuBalanced.Checked = true; PerformanceMode = AsusACPI.PerformanceBalanced; perfName = Properties.Strings.Balanced; break; } - menuSilent.Checked = buttonSilent.Activated; - menuBalanced.Checked = buttonBalanced.Activated; - menuTurbo.Checked = buttonTurbo.Activated; + var powerStatus = SystemInformation.PowerStatus.PowerLineStatus; - AppConfig.setConfig("performance_" + (int)SystemInformation.PowerStatus.PowerLineStatus, PerformanceMode); + AppConfig.setConfig("performance_" + (int)powerStatus, PerformanceMode); AppConfig.setConfig("performance_mode", PerformanceMode); if (isManualModeRequired()) @@ -1287,11 +1288,11 @@ namespace GHelper if (AppConfig.isConfig("xgm_fan") && Program.acpi.IsXGConnected()) AsusUSB.ResetXGM(); - if (notify && (oldMode != PerformanceMode)) + if (notify) { try { - toast.RunToast(perfName); + toast.RunToast(perfName, powerStatus == PowerLineStatus.Online ? ToastIcon.Charger : ToastIcon.Battery); } catch { @@ -1352,13 +1353,13 @@ namespace GHelper } - public void AutoPerformance() + public void AutoPerformance(bool powerChanged = false) { var Plugged = SystemInformation.PowerStatus.PowerLineStatus; int mode = AppConfig.getConfig("performance_" + (int)Plugged); if (mode != -1) - SetPerformanceMode(mode, true); + SetPerformanceMode(mode, powerChanged); else SetPerformanceMode(AppConfig.getConfig("performance_mode")); } @@ -1724,10 +1725,13 @@ namespace GHelper break; } - menuEco.Checked = buttonEco.Activated; - menuStandard.Checked = buttonStandard.Activated; - menuUltimate.Checked = buttonUltimate.Activated; - menuOptimized.Checked = buttonOptimized.Activated; + if (isGpuSection) + { + menuEco.Checked = buttonEco.Activated; + menuStandard.Checked = buttonStandard.Activated; + menuUltimate.Checked = buttonUltimate.Activated; + menuOptimized.Checked = buttonOptimized.Activated; + } } diff --git a/app/ToastForm.cs b/app/ToastForm.cs index d8b38d7b..93a07d91 100644 --- a/app/ToastForm.cs +++ b/app/ToastForm.cs @@ -52,7 +52,9 @@ namespace GHelper Touchpad, Microphone, MicrophoneMute, - FnLock + FnLock, + Battery, + Charger } public class ToastForm : OSDNativeForm @@ -107,6 +109,12 @@ namespace GHelper case ToastIcon.FnLock: icon = Properties.Resources.icons8_function; break; + case ToastIcon.Battery: + icon = Properties.Resources.icons8_charged_battery_96; + break; + case ToastIcon.Charger: + icon = Properties.Resources.icons8_electrical_96; + break; } diff --git a/app/Updates.cs b/app/Updates.cs index 464e1fba..e950cc4f 100644 --- a/app/Updates.cs +++ b/app/Updates.cs @@ -1,10 +1,22 @@ using CustomControls; +using HidSharp; using System.Diagnostics; using System.Management; +using System.Net; using System.Text.Json; namespace GHelper { + + struct DriverDownload + { + public string categoryName; + public string title; + public string version; + public string downloadUrl; + public JsonElement hardwares; + } + public partial class Updates : RForm { //static int rowCount = 0; @@ -30,7 +42,7 @@ namespace GHelper Task.Run(async () => { - 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()); }