From fae1893b5d2393a18f1262dda3c8f114d2171fd7 Mon Sep 17 00:00:00 2001 From: seerge Date: Thu, 16 Feb 2023 19:26:53 +0100 Subject: [PATCH] Add project files. --- .editorconfig | 4 + App.config | 6 + GHelper.csproj | 45 ++++++ GHelper.sln | 30 ++++ Program.cs | 221 +++++++++++++++++++++++++++++ Properties/launchSettings.json | 8 ++ Resources/standard.ico | Bin 0 -> 9662 bytes Settings.Designer.cs | 250 +++++++++++++++++++++++++++++++++ Settings.cs | 237 +++++++++++++++++++++++++++++++ Settings.resx | 60 ++++++++ app.manifest | 76 ++++++++++ 11 files changed, 937 insertions(+) create mode 100644 .editorconfig create mode 100644 App.config create mode 100644 GHelper.csproj create mode 100644 GHelper.sln create mode 100644 Program.cs create mode 100644 Properties/launchSettings.json create mode 100644 Resources/standard.ico create mode 100644 Settings.Designer.cs create mode 100644 Settings.cs create mode 100644 Settings.resx create mode 100644 app.manifest diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..5a3c0432 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.{cs,vb}] + +# IDE0017: Simplify object initialization +dotnet_style_object_initializer = true diff --git a/App.config b/App.config new file mode 100644 index 00000000..6ee0905e --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/GHelper.csproj b/GHelper.csproj new file mode 100644 index 00000000..716b5e53 --- /dev/null +++ b/GHelper.csproj @@ -0,0 +1,45 @@ + + + + WinExe + net6.0-windows10.0.22621.0 + enable + true + enable + True + app.manifest + Program + Resources\standard.ico + + + + + tlbimp + 0 + 1 + 8e80422b-cac4-472b-b272-9635f1dfef3b + 0 + false + true + + + + + + + + + + + + + + + ..\..\.nuget\packages\microsoft.management.infrastructure\2.0.0\ref\net451\Microsoft.Management.Infrastructure.dll + + + ..\..\.nuget\packages\microsoft.management.infrastructure.runtime.win\2.0.0\runtimes\win10-x64\lib\netstandard1.6\Microsoft.Management.Infrastructure.Native.dll + + + + \ No newline at end of file diff --git a/GHelper.sln b/GHelper.sln new file mode 100644 index 00000000..ebb557a1 --- /dev/null +++ b/GHelper.sln @@ -0,0 +1,30 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33403.182 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GHelper", "GHelper.csproj", "{D6138BB1-8FDB-4835-87EF-2FE41A3DD604}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B6E44CC6-5D28-4CB9-8EE2-BE9D6238E2D6}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D6138BB1-8FDB-4835-87EF-2FE41A3DD604}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B1BF5148-497A-4B5A-B079-5C00CD047DAF} + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 00000000..cbe0b7aa --- /dev/null +++ b/Program.cs @@ -0,0 +1,221 @@ +using System; +using System.Windows.Forms; + +using System.Text.Json; +using System.Management; +using Microsoft.Win32.TaskScheduler; +using System.Diagnostics; +using System.Reflection.Emit; +using System.Runtime.InteropServices; +using System.Reflection; + +using System.Diagnostics; + +using GHelper; +using System.Dynamic; + +public class ASUSWmi +{ + private ManagementObject mo; + private ManagementClass classInstance; + + public const int CPU_Fan = 0x00110013; + public const int GPU_Fan = 0x00110014; + + public const int PerformanceMode = 0x00120075; + + public const int GPUEco = 0x00090020; + public const int GPUMux = 0x00090016; + + + public const int PerformanceBalanced = 0; + public const int PerformanceTurbo = 1; + public const int PerformanceSilent = 2; + + public const int GPUModeEco = 0; + public const int GPUModeStandard = 1; + public const int GPUModeUltimate = 2; + + public ASUSWmi() + { + this.classInstance = new ManagementClass(new ManagementScope("root\\wmi"), new ManagementPath("AsusAtkWmi_WMNB"), null); + foreach (ManagementObject mo in this.classInstance.GetInstances()) + { + this.mo = mo; + } + } + + private int WMICall(string MethodName, int Device_Id, int Control_status = -1) + { + ManagementBaseObject inParams = this.classInstance.Methods[MethodName].InParameters; + inParams["Device_ID"] = Device_Id; + if (Control_status != -1) + { + inParams["Control_status"] = Control_status; + } + + ManagementBaseObject outParams = this.mo.InvokeMethod(MethodName, inParams, null); + foreach (PropertyData property in outParams.Properties) + { + if (property.Name == "device_status") return int.Parse(property.Value.ToString()) - 65536; + if (property.Name == "result") return int.Parse(property.Value.ToString()); + } + + return -1; + + } + + public int DeviceGet(int Device_Id) + { + return this.WMICall("DSTS", Device_Id); + } + public int DeviceSet(int Device_Id, int Control_status) + { + return this.WMICall("DEVS", Device_Id, Control_status); + } + + public void SubscribeToEvents(Action EventHandler) + { + + ManagementEventWatcher watcher = new ManagementEventWatcher(); + + watcher.EventArrived += new EventArrivedEventHandler(EventHandler); + watcher.Scope = new ManagementScope("root\\wmi"); + watcher.Query = new WqlEventQuery("SELECT * FROM AsusAtkWmiEvent"); + + watcher.Start(); + + } + +} + + +static class Program +{ + static NotifyIcon trayIcon; + + public static ASUSWmi wmi; + public static dynamic config = new System.Dynamic.ExpandoObject(); + + public static SettingsForm settingsForm; + + // The main entry point for the application + public static void Main() + { + trayIcon = new NotifyIcon + { + Text = "G14 Helper", + Icon = new System.Drawing.Icon("Resources/standard.ico"), + Visible = true + }; + + trayIcon.MouseClick += TrayIcon_MouseClick; ; + + wmi = new ASUSWmi(); + wmi.SubscribeToEvents(WatcherEventArrived); + + settingsForm = new SettingsForm(); + //settingsForm.Show(); + + int GpuMode = GetGPUMode(); + + settingsForm.SetPerformanceMode(); + settingsForm.VisualiseGPUMode(GpuMode); + + settingsForm.FormClosed += SettingsForm_FormClosed; + + config.PerformanceMode = 0; + + Application.Run(); + + } + + public static int GetGPUMode () + { + int eco = wmi.DeviceGet(ASUSWmi.GPUEco); + int mux = wmi.DeviceGet(ASUSWmi.GPUMux); + + int GpuMode; + + if (mux == 0) + { + GpuMode = ASUSWmi.GPUModeUltimate; + } + else + { + if (eco == 1) + { + GpuMode = ASUSWmi.GPUModeEco; + } + else + { + GpuMode = ASUSWmi.GPUModeStandard; + } + + if (mux != 1) + { + settingsForm.Disable_Ultimate(); + } + } + + config.gpu_mode = GpuMode; + + return GpuMode; + + } + + private static void SettingsForm_FormClosed(object? sender, FormClosedEventArgs e) + { + trayIcon.Visible = false; + Application.Exit(); + } + + static void WatcherEventArrived(object sender, EventArrivedEventArgs e) + { + var collection = (ManagementEventWatcher)sender; + int EventID = int.Parse(e.NewEvent["EventID"].ToString()); + + Debug.WriteLine(EventID); + + switch (EventID) + { + case 56: + case 174: + CyclePerformanceMode(); + return; + } + + + } + + static void TrayIcon_MouseClick(object? sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + if (settingsForm.Visible) + { + settingsForm.Hide(); + } else + { + settingsForm.Show(); + settingsForm.Activate(); + } + } + } + + + static void CyclePerformanceMode() + { + settingsForm.BeginInvoke(delegate + { + settingsForm.SetPerformanceMode(config.PerformanceMode + 1); + }); + } + + static void OnExit(object sender, EventArgs e) + { + trayIcon.Visible = false; + Application.Exit(); + } +} + diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 00000000..1c164927 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "GHelper": { + "commandName": "Project", + "workingDirectory": "C:\\Users\\serge\\source\\GHelper" + } + } +} \ No newline at end of file diff --git a/Resources/standard.ico b/Resources/standard.ico new file mode 100644 index 0000000000000000000000000000000000000000..8f8018a804a10c026b1255a8df584d78b7a00a6f GIT binary patch literal 9662 zcmeHNTWnm#86FG8JQR_KN_|0=fdrX{KA@^?vg& zx-Z(S$L>{}<4QN(w^Hfel})-Y(gG}9pq-#`Pzodgl*IEf5P91OK5o#vS2XF~$VbkG z?q8wwa2su78R%iqX;2mvgt^{xzIzh16@1*Jdp_Hwcdxwcd|cceRZc7d+>xbNYYT|D zi=cYA8ogh@T&F;rz{hpymByNvqfxJVsGTxz1ML9Kf*Qpac6=IhKMQKpyRc^e;&_;Z zF0=bO6=c$ZIgfpWxaacsI@apc2iHOm3$v$7ko)w|D#VuP2F!K#3Szgsj6-f4G%z&k z+q!p!n(D`Ulz|&p?3`D+KWlW~4_n$5P7jlPuou@?Zw2<_3zK_95M!$;hI>= z4}J)2K@Bk-<06a!^rHsWB<2;O``g9YbC<;T-z$kj-v!-=-`@~t?-%i`!yVH&FFTxA z^m>pleENzrO!*^@#iEP_;qXJ&&hvLl^61Yb^Pd69Po0*+%m-4;IH0%`(vy;R#wGL4 z3z9nasKkfA?CK^wAB=fhbRXkj{e7+^`F$Q&|FzWNi%eQ;cg`B@2Ug&g=h zBdIqY2hX>c_z1IBbQJPmR!;|d7xvac6XzcU_7HnhM4Z9(l76!rGEU47yI2q*&DRQ9 z$-euNu`S~(q2v{P=mO+FJ&zr^vPUlB?&krrC-!wRJKiG#9Ntz)e<<1aM!?rol6rlc zq>leWW={PMwlge+B-;)x#+4r)91V^mCBCoAYi&p92NpZwIC)tFRYy zGm?3GP!cb7i5}>5@z9?w!Or6Q?veE9@1>AB?`0XbcTD0hd=+B@V-&G<8LY^~Y{MR< zrg|ewaGyD$KX&-)^vmBjK50P|vk95`*Ao@o_2ytqh0jipY?9pMN&C9#XW!c4#;1Dk zR_^bdiba~IJT}DNAm+l%Ykl!MgKH#v?m%VjVouVh|7hYSu?4+voz0~;kD|95$w z;;aT=o5R@AIP9m@YeSfm_QP`pbMyKbjO@3Vm}nQyU3|^N`w+UXo)>eaUVB(*ceWWF z_^t0gBSvDi=7ZeW;OE(>dX2f)STp_RpX_q5|D3^KY<%w6nrrIDL$GycaIIv|A1Tk5 z*JrWMeW^6g7Yp~NGX6O7R9rvikH56ug;y%;B_`l^UkmU%U>;awuoADA^uTJFIq@6J zS2S}n4u`a%ZC?Dke>L%U2jYip^3Gdj{F!t6VfU-+>kM&d=8a!L#xEN=Q`XgVSn`)f zD=`)NO#Wl58?$QkSEY~b$WzMl*S)tBzklq3zA5WM>OvWRdhF@?{zhMcKhiH7Y1}h( z@8|2w#O138=Wh@GyB3BYzEIcpfj@ERd%!;x8b0%n`q= zkj%quW3I-0v##C2ep1JODVhK7Gch-N?nU(T(E-We{>+JAi!-zy^99D?Zm<26{Fgpa z9}Azs53}bFTlkW@bjswNzUy&MW!?;54Wx2>3c!I_3+ z!ko=EH-Bqy26ol~{pT}raTCs07t1^pb4lcte{g+|`DQ&nDDzmmi7{^OQ#3gc&zB9H z0eX^&w(oj<57UC4Z(Kj1Hg|Ji{3wKnIX7^HATX*wE_|I9 ze(3;9^3@-^^%Fe?om`S)b{dpKymf@O!*dVwoA}@EF3CKU+$l%aa*#8x0lxWVZy9lQ z5WODbcYs3Zz>WbH#va5`XU`XKzWTN~XVRZ}CXNq(#od3+c{ns~yZ*DVdDPTu?cUMSnZ%>i28Ec2FYQZ!g}EQkK&*qYmedU*U!?7zZJ^B{j%l5WwKvC~S&nbB>+Ez_ zO%HtZ_Zqrt0A58v+{{p^O8-cc2(I%=b+VsTYAO2(rLJW^qSQ6)AHn}CVozT1r^x>2 zO5ruUs1#mPsv`64tWjTzL Y + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.groupPerf = new System.Windows.Forms.GroupBox(); + this.labelCPUFan = new System.Windows.Forms.Label(); + this.tablePerf = new System.Windows.Forms.TableLayoutPanel(); + this.buttonTurbo = new System.Windows.Forms.Button(); + this.buttonBalanced = new System.Windows.Forms.Button(); + this.buttonSilent = new System.Windows.Forms.Button(); + this.groupGPU = new System.Windows.Forms.GroupBox(); + this.labelGPUFan = new System.Windows.Forms.Label(); + this.tableGPU = new System.Windows.Forms.TableLayoutPanel(); + this.buttonUltimate = new System.Windows.Forms.Button(); + this.buttonStandard = new System.Windows.Forms.Button(); + this.buttonEco = new System.Windows.Forms.Button(); + this.groupPerf.SuspendLayout(); + this.tablePerf.SuspendLayout(); + this.groupGPU.SuspendLayout(); + this.tableGPU.SuspendLayout(); + this.SuspendLayout(); + // + // groupPerf + // + this.groupPerf.Controls.Add(this.labelCPUFan); + this.groupPerf.Controls.Add(this.tablePerf); + this.groupPerf.Dock = System.Windows.Forms.DockStyle.Top; + this.groupPerf.Location = new System.Drawing.Point(10, 10); + this.groupPerf.Margin = new System.Windows.Forms.Padding(10); + this.groupPerf.Name = "groupPerf"; + this.groupPerf.Padding = new System.Windows.Forms.Padding(10); + this.groupPerf.Size = new System.Drawing.Size(666, 188); + this.groupPerf.TabIndex = 0; + this.groupPerf.TabStop = false; + this.groupPerf.Text = "Performance Mode"; + // + // labelCPUFan + // + this.labelCPUFan.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.labelCPUFan.AutoSize = true; + this.labelCPUFan.Location = new System.Drawing.Point(491, 28); + this.labelCPUFan.Name = "labelCPUFan"; + this.labelCPUFan.Size = new System.Drawing.Size(154, 32); + this.labelCPUFan.TabIndex = 2; + this.labelCPUFan.Text = "CPU Fan : 0%"; + // + // tablePerf + // + this.tablePerf.ColumnCount = 3; + this.tablePerf.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tablePerf.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tablePerf.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tablePerf.Controls.Add(this.buttonTurbo, 2, 0); + this.tablePerf.Controls.Add(this.buttonBalanced, 1, 0); + this.tablePerf.Controls.Add(this.buttonSilent, 0, 0); + this.tablePerf.Dock = System.Windows.Forms.DockStyle.Bottom; + this.tablePerf.Location = new System.Drawing.Point(10, 72); + this.tablePerf.Name = "tablePerf"; + this.tablePerf.RowCount = 1; + this.tablePerf.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 106F)); + this.tablePerf.Size = new System.Drawing.Size(646, 106); + this.tablePerf.TabIndex = 0; + // + // buttonTurbo + // + this.buttonTurbo.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonTurbo.FlatAppearance.BorderSize = 0; + this.buttonTurbo.Location = new System.Drawing.Point(440, 10); + this.buttonTurbo.Margin = new System.Windows.Forms.Padding(10); + this.buttonTurbo.Name = "buttonTurbo"; + this.buttonTurbo.Size = new System.Drawing.Size(196, 86); + this.buttonTurbo.TabIndex = 2; + this.buttonTurbo.Text = "Turbo"; + this.buttonTurbo.UseVisualStyleBackColor = true; + // + // buttonBalanced + // + this.buttonBalanced.BackColor = System.Drawing.SystemColors.ButtonHighlight; + this.buttonBalanced.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonBalanced.FlatAppearance.BorderSize = 0; + this.buttonBalanced.Location = new System.Drawing.Point(225, 10); + this.buttonBalanced.Margin = new System.Windows.Forms.Padding(10); + this.buttonBalanced.Name = "buttonBalanced"; + this.buttonBalanced.Size = new System.Drawing.Size(195, 86); + this.buttonBalanced.TabIndex = 1; + this.buttonBalanced.Text = "Balanced"; + this.buttonBalanced.UseVisualStyleBackColor = false; + // + // buttonSilent + // + this.buttonSilent.CausesValidation = false; + this.buttonSilent.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonSilent.FlatAppearance.BorderSize = 0; + this.buttonSilent.Location = new System.Drawing.Point(10, 10); + this.buttonSilent.Margin = new System.Windows.Forms.Padding(10); + this.buttonSilent.Name = "buttonSilent"; + this.buttonSilent.Size = new System.Drawing.Size(195, 86); + this.buttonSilent.TabIndex = 0; + this.buttonSilent.Text = "Silent"; + this.buttonSilent.UseVisualStyleBackColor = true; + // + // groupGPU + // + this.groupGPU.Controls.Add(this.labelGPUFan); + this.groupGPU.Controls.Add(this.tableGPU); + this.groupGPU.Dock = System.Windows.Forms.DockStyle.Top; + this.groupGPU.Location = new System.Drawing.Point(10, 198); + this.groupGPU.Margin = new System.Windows.Forms.Padding(10); + this.groupGPU.Name = "groupGPU"; + this.groupGPU.Padding = new System.Windows.Forms.Padding(10); + this.groupGPU.Size = new System.Drawing.Size(666, 188); + this.groupGPU.TabIndex = 1; + this.groupGPU.TabStop = false; + this.groupGPU.Text = "GPU Mode"; + // + // labelGPUFan + // + this.labelGPUFan.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.labelGPUFan.AutoSize = true; + this.labelGPUFan.Location = new System.Drawing.Point(491, 33); + this.labelGPUFan.Name = "labelGPUFan"; + this.labelGPUFan.Size = new System.Drawing.Size(155, 32); + this.labelGPUFan.TabIndex = 3; + this.labelGPUFan.Text = "GPU Fan : 0%"; + // + // tableGPU + // + this.tableGPU.ColumnCount = 3; + this.tableGPU.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableGPU.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableGPU.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableGPU.Controls.Add(this.buttonUltimate, 2, 0); + this.tableGPU.Controls.Add(this.buttonStandard, 1, 0); + this.tableGPU.Controls.Add(this.buttonEco, 0, 0); + this.tableGPU.Dock = System.Windows.Forms.DockStyle.Bottom; + this.tableGPU.Location = new System.Drawing.Point(10, 72); + this.tableGPU.Name = "tableGPU"; + this.tableGPU.RowCount = 1; + this.tableGPU.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 106F)); + this.tableGPU.Size = new System.Drawing.Size(646, 106); + this.tableGPU.TabIndex = 0; + // + // buttonUltimate + // + this.buttonUltimate.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonUltimate.FlatAppearance.BorderSize = 0; + this.buttonUltimate.Location = new System.Drawing.Point(440, 10); + this.buttonUltimate.Margin = new System.Windows.Forms.Padding(10); + this.buttonUltimate.Name = "buttonUltimate"; + this.buttonUltimate.Size = new System.Drawing.Size(196, 86); + this.buttonUltimate.TabIndex = 2; + this.buttonUltimate.Text = "Ultimate"; + this.buttonUltimate.UseVisualStyleBackColor = true; + // + // buttonStandard + // + this.buttonStandard.BackColor = System.Drawing.SystemColors.ButtonHighlight; + this.buttonStandard.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonStandard.FlatAppearance.BorderSize = 0; + this.buttonStandard.Location = new System.Drawing.Point(225, 10); + this.buttonStandard.Margin = new System.Windows.Forms.Padding(10); + this.buttonStandard.Name = "buttonStandard"; + this.buttonStandard.Size = new System.Drawing.Size(195, 86); + this.buttonStandard.TabIndex = 1; + this.buttonStandard.Text = "Standard"; + this.buttonStandard.UseVisualStyleBackColor = false; + // + // buttonEco + // + this.buttonEco.CausesValidation = false; + this.buttonEco.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonEco.FlatAppearance.BorderSize = 0; + this.buttonEco.Location = new System.Drawing.Point(10, 10); + this.buttonEco.Margin = new System.Windows.Forms.Padding(10); + this.buttonEco.Name = "buttonEco"; + this.buttonEco.Size = new System.Drawing.Size(195, 86); + this.buttonEco.TabIndex = 0; + this.buttonEco.Text = "Eco"; + this.buttonEco.UseVisualStyleBackColor = true; + // + // SettingsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(686, 636); + this.Controls.Add(this.groupGPU); + this.Controls.Add(this.groupPerf); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MdiChildrenMinimizedAnchorBottom = false; + this.MinimizeBox = false; + this.Name = "SettingsForm"; + this.Padding = new System.Windows.Forms.Padding(10); + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "G14 Helper"; + this.Load += new System.EventHandler(this.Settings_Load); + this.groupPerf.ResumeLayout(false); + this.groupPerf.PerformLayout(); + this.tablePerf.ResumeLayout(false); + this.groupGPU.ResumeLayout(false); + this.groupGPU.PerformLayout(); + this.tableGPU.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupPerf; + private TableLayoutPanel tablePerf; + private Button buttonSilent; + private Button buttonTurbo; + private Button buttonBalanced; + private GroupBox groupGPU; + private TableLayoutPanel tableGPU; + private Button buttonUltimate; + private Button buttonStandard; + private Button buttonEco; + private Label labelCPUFan; + private Label labelGPUFan; + } +} \ No newline at end of file diff --git a/Settings.cs b/Settings.cs new file mode 100644 index 00000000..91ecc096 --- /dev/null +++ b/Settings.cs @@ -0,0 +1,237 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Dynamic; +using System.Linq; +using System.Reflection.Metadata.Ecma335; +using System.Text; +using System.Threading.Tasks; +using System.Timers; +using System.Windows.Forms; +using Windows.ApplicationModel.Store; + +namespace GHelper +{ + public partial class SettingsForm : Form + { + + static Color colorActive = Color.LightGray; + + static System.Timers.Timer aTimer; + + public SettingsForm() + { + + InitializeComponent(); + + buttonSilent.Click += ButtonSilent_Click; + buttonBalanced.Click += ButtonBalanced_Click; + buttonTurbo.Click += ButtonTurbo_Click; + + buttonEco.Click += ButtonEco_Click; + buttonStandard.Click += ButtonStandard_Click; + buttonUltimate.Click += ButtonUltimate_Click; + + VisibleChanged += SettingsForm_VisibleChanged; + + SetTimer(); + + + } + + private void ButtonUltimate_Click(object? sender, EventArgs e) + { + SetGPUMode(ASUSWmi.GPUModeUltimate); + } + + private void ButtonStandard_Click(object? sender, EventArgs e) + { + SetGPUMode(ASUSWmi.GPUModeStandard); + } + + private void ButtonEco_Click(object? sender, EventArgs e) + { + SetGPUMode(ASUSWmi.GPUModeEco); + } + + private static void SetTimer() + { + aTimer = new System.Timers.Timer(1000); + aTimer.Elapsed += OnTimedEvent; + aTimer.AutoReset = true; + } + + private static void OnTimedEvent(Object source, ElapsedEventArgs e) + { + var cpuFan = Math.Round(Program.wmi.DeviceGet(ASUSWmi.CPU_Fan)/0.6); + var gpuFan = Math.Round(Program.wmi.DeviceGet(ASUSWmi.GPU_Fan)/0.6); + + Program.settingsForm.BeginInvoke(delegate + { + Program.settingsForm.labelCPUFan.Text = "CPU Fan: " + cpuFan.ToString() + "%"; + Program.settingsForm.labelGPUFan.Text = "GPU Fan: " + gpuFan.ToString() + "%"; + }); + + } + + private void SettingsForm_VisibleChanged(object? sender, EventArgs e) + { + if (this.Visible) + { + this.Left = Screen.FromControl(this).Bounds.Width - 10 - this.Width; + this.Top = Screen.FromControl(this).Bounds.Height - 100 - this.Height; + this.Activate(); + aTimer.Enabled = true; + } else + { + aTimer.Enabled = false; + } + } + + public void SetPerformanceMode(int PerformanceMode = ASUSWmi.PerformanceBalanced) + { + + buttonSilent.UseVisualStyleBackColor = true; + buttonBalanced.UseVisualStyleBackColor = true; + buttonTurbo.UseVisualStyleBackColor = true; + + + switch (PerformanceMode) + { + case ASUSWmi.PerformanceSilent: + buttonSilent.BackColor = colorActive; + groupPerf.Text = "Peformance Mode: Silent"; + break; + case ASUSWmi.PerformanceTurbo: + buttonTurbo.BackColor = colorActive; + groupPerf.Text = "Peformance Mode: Turbo"; + break; + default: + buttonBalanced.BackColor = colorActive; + groupPerf.Text = "Peformance Mode: Balanced"; + PerformanceMode = ASUSWmi.PerformanceBalanced; + break; + } + + Program.config.PerformanceMode = PerformanceMode; + Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode); + + } + + + public void SetGPUMode(int GPUMode = ASUSWmi.GPUModeStandard) + { + + int CurrentGPU = ASUSWmi.GPUModeStandard; + + if (((IDictionary) Program.config).ContainsKey("gpu_mode")) { + CurrentGPU = Program.config.gpu_mode; + } + + if (CurrentGPU == GPUMode) { return; } + + var restart = false; + var changed = false; + + if (CurrentGPU == ASUSWmi.GPUModeUltimate) + { + DialogResult dialogResult = MessageBox.Show("Switching off Ultimate Mode requires restart", "Reboot now?", MessageBoxButtons.YesNo); + if (dialogResult == DialogResult.Yes) + { + Program.wmi.DeviceSet(ASUSWmi.GPUMux, 1); + restart = true; + changed = true; + } + } else if (GPUMode == ASUSWmi.GPUModeUltimate) + { + DialogResult dialogResult = MessageBox.Show(" Ultimate Mode requires restart", "Reboot now?", MessageBoxButtons.YesNo); + if (dialogResult == DialogResult.Yes) + { + Program.wmi.DeviceSet(ASUSWmi.GPUMux, 0); + restart = true; + changed = true; + } + + } else if (GPUMode == ASUSWmi.GPUModeEco) + { + VisualiseGPUMode(GPUMode); + Program.wmi.DeviceSet(ASUSWmi.GPUEco, 1); + changed = true; + } else if (GPUMode == ASUSWmi.GPUModeStandard) + { + VisualiseGPUMode(GPUMode); + Program.wmi.DeviceSet(ASUSWmi.GPUEco, 0); + changed = true; + } + + if (changed) + { + Program.config.gpu_mode = GPUMode; + } + + if (restart) + { + VisualiseGPUMode(GPUMode); + Process.Start("shutdown", "/r /t 1"); + } + + } + + public void VisualiseGPUMode (int GPUMode) + { + + buttonEco.UseVisualStyleBackColor = true; + buttonStandard.UseVisualStyleBackColor = true; + buttonUltimate.UseVisualStyleBackColor = true; + + + switch (GPUMode) + { + case ASUSWmi.GPUModeEco: + buttonEco.BackColor = colorActive; + groupGPU.Text = "GPU Mode: Eco (iGPU only)"; + break; + case ASUSWmi.GPUModeUltimate: + buttonUltimate.BackColor = colorActive; + groupGPU.Text = "GPU Mode: Ultimate (dGPU exclusive)"; + break; + default: + buttonStandard.BackColor = colorActive; + groupGPU.Text = "GPU Mode: Eco (iGPU and dGPU)"; + break; + } + } + + private void ButtonSilent_Click(object? sender, EventArgs e) + { + SetPerformanceMode(ASUSWmi.PerformanceSilent); + } + + private void ButtonBalanced_Click(object? sender, EventArgs e) + { + SetPerformanceMode(ASUSWmi.PerformanceBalanced); + } + + private void ButtonTurbo_Click(object? sender, EventArgs e) + { + SetPerformanceMode(ASUSWmi.PerformanceTurbo); + } + + private void Settings_Load(object sender, EventArgs e) + { + + } + + public void Disable_Ultimate() + { + buttonUltimate.Enabled= false; + } + + + } + + +} diff --git a/Settings.resx b/Settings.resx new file mode 100644 index 00000000..f298a7be --- /dev/null +++ b/Settings.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/app.manifest b/app.manifest new file mode 100644 index 00000000..9312cc7f --- /dev/null +++ b/app.manifest @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + + + + + + + + + + +