Added Screen Toggle feature for M3 button

This commit is contained in:
Serge
2023-05-01 15:12:08 +02:00
parent 3173c2e688
commit e810adb358
14 changed files with 388 additions and 79 deletions

View File

@@ -316,4 +316,5 @@ public class ASUSWmi
} }
} }
} }

217
app/Fans.Designer.cs generated
View File

@@ -38,6 +38,7 @@ namespace GHelper
ChartArea chartArea3 = new ChartArea(); ChartArea chartArea3 = new ChartArea();
Title title3 = new Title(); Title title3 = new Title();
panelFans = new Panel(); panelFans = new Panel();
labelFansResult = new Label();
labelTip = new Label(); labelTip = new Label();
labelBoost = new Label(); labelBoost = new Label();
comboBoost = new RComboBox(); comboBoost = new RComboBox();
@@ -63,7 +64,16 @@ namespace GHelper
trackTotal = new TrackBar(); trackTotal = new TrackBar();
pictureFine = new PictureBox(); pictureFine = new PictureBox();
labelInfo = new Label(); labelInfo = new Label();
labelFansResult = new Label(); panelGPU = new Panel();
buttonResetGPU = new RButton();
labelGPUMemory = new Label();
trackGPUMemory = new TrackBar();
labelGPUMemoryTitle = new Label();
pictureBox2 = new PictureBox();
labelGPUCore = new Label();
labelGPU = new Label();
trackGPUCore = new TrackBar();
labelGPUCoreTitle = new Label();
panelFans.SuspendLayout(); panelFans.SuspendLayout();
((System.ComponentModel.ISupportInitialize)picturePerf).BeginInit(); ((System.ComponentModel.ISupportInitialize)picturePerf).BeginInit();
tableFanCharts.SuspendLayout(); tableFanCharts.SuspendLayout();
@@ -77,6 +87,10 @@ namespace GHelper
panelTotal.SuspendLayout(); panelTotal.SuspendLayout();
((System.ComponentModel.ISupportInitialize)trackTotal).BeginInit(); ((System.ComponentModel.ISupportInitialize)trackTotal).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureFine).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureFine).BeginInit();
panelGPU.SuspendLayout();
((System.ComponentModel.ISupportInitialize)trackGPUMemory).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBox2).BeginInit();
((System.ComponentModel.ISupportInitialize)trackGPUCore).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// panelFans // panelFans
@@ -91,13 +105,24 @@ namespace GHelper
panelFans.Controls.Add(checkApplyFans); panelFans.Controls.Add(checkApplyFans);
panelFans.Controls.Add(buttonReset); panelFans.Controls.Add(buttonReset);
panelFans.Dock = DockStyle.Left; panelFans.Dock = DockStyle.Left;
panelFans.Location = new Point(364, 0); panelFans.Location = new Point(711, 0);
panelFans.Margin = new Padding(0); panelFans.Margin = new Padding(0);
panelFans.Name = "panelFans"; panelFans.Name = "panelFans";
panelFans.Padding = new Padding(10); panelFans.Padding = new Padding(10);
panelFans.Size = new Size(824, 1159); panelFans.Size = new Size(824, 1189);
panelFans.TabIndex = 12; panelFans.TabIndex = 12;
// //
// labelFansResult
//
labelFansResult.Anchor = AnchorStyles.Top | AnchorStyles.Right;
labelFansResult.ForeColor = Color.Red;
labelFansResult.Location = new Point(30, 1073);
labelFansResult.Name = "labelFansResult";
labelFansResult.Size = new Size(760, 32);
labelFansResult.TabIndex = 41;
labelFansResult.TextAlign = ContentAlignment.TopRight;
labelFansResult.Visible = false;
//
// labelTip // labelTip
// //
labelTip.AutoSize = true; labelTip.AutoSize = true;
@@ -160,7 +185,7 @@ namespace GHelper
tableFanCharts.RowStyles.Add(new RowStyle(SizeType.Percent, 33F)); tableFanCharts.RowStyles.Add(new RowStyle(SizeType.Percent, 33F));
tableFanCharts.RowStyles.Add(new RowStyle(SizeType.Percent, 33F)); tableFanCharts.RowStyles.Add(new RowStyle(SizeType.Percent, 33F));
tableFanCharts.RowStyles.Add(new RowStyle(SizeType.Percent, 33F)); tableFanCharts.RowStyles.Add(new RowStyle(SizeType.Percent, 33F));
tableFanCharts.Size = new Size(764, 992); tableFanCharts.Size = new Size(764, 1022);
tableFanCharts.TabIndex = 36; tableFanCharts.TabIndex = 36;
// //
// chartGPU // chartGPU
@@ -168,10 +193,10 @@ namespace GHelper
chartArea1.Name = "ChartArea1"; chartArea1.Name = "ChartArea1";
chartGPU.ChartAreas.Add(chartArea1); chartGPU.ChartAreas.Add(chartArea1);
chartGPU.Dock = DockStyle.Fill; chartGPU.Dock = DockStyle.Fill;
chartGPU.Location = new Point(2, 340); chartGPU.Location = new Point(2, 350);
chartGPU.Margin = new Padding(2, 10, 2, 10); chartGPU.Margin = new Padding(2, 10, 2, 10);
chartGPU.Name = "chartGPU"; chartGPU.Name = "chartGPU";
chartGPU.Size = new Size(760, 310); chartGPU.Size = new Size(760, 320);
chartGPU.TabIndex = 17; chartGPU.TabIndex = 17;
chartGPU.Text = "chartGPU"; chartGPU.Text = "chartGPU";
title1.Name = "Title1"; title1.Name = "Title1";
@@ -185,7 +210,7 @@ namespace GHelper
chartCPU.Location = new Point(2, 10); chartCPU.Location = new Point(2, 10);
chartCPU.Margin = new Padding(2, 10, 2, 10); chartCPU.Margin = new Padding(2, 10, 2, 10);
chartCPU.Name = "chartCPU"; chartCPU.Name = "chartCPU";
chartCPU.Size = new Size(760, 310); chartCPU.Size = new Size(760, 320);
chartCPU.TabIndex = 14; chartCPU.TabIndex = 14;
chartCPU.Text = "chartCPU"; chartCPU.Text = "chartCPU";
title2.Name = "Title1"; title2.Name = "Title1";
@@ -196,10 +221,10 @@ namespace GHelper
chartArea3.Name = "ChartArea3"; chartArea3.Name = "ChartArea3";
chartMid.ChartAreas.Add(chartArea3); chartMid.ChartAreas.Add(chartArea3);
chartMid.Dock = DockStyle.Fill; chartMid.Dock = DockStyle.Fill;
chartMid.Location = new Point(2, 670); chartMid.Location = new Point(2, 690);
chartMid.Margin = new Padding(2, 10, 2, 10); chartMid.Margin = new Padding(2, 10, 2, 10);
chartMid.Name = "chartMid"; chartMid.Name = "chartMid";
chartMid.Size = new Size(760, 312); chartMid.Size = new Size(760, 322);
chartMid.TabIndex = 14; chartMid.TabIndex = 14;
chartMid.Text = "chartMid"; chartMid.Text = "chartMid";
title3.Name = "Title3"; title3.Name = "Title3";
@@ -222,7 +247,7 @@ namespace GHelper
checkApplyFans.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; checkApplyFans.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
checkApplyFans.AutoSize = true; checkApplyFans.AutoSize = true;
checkApplyFans.BackColor = SystemColors.ControlLight; checkApplyFans.BackColor = SystemColors.ControlLight;
checkApplyFans.Location = new Point(449, 1088); checkApplyFans.Location = new Point(449, 1118);
checkApplyFans.Margin = new Padding(4, 2, 4, 2); checkApplyFans.Margin = new Padding(4, 2, 4, 2);
checkApplyFans.Name = "checkApplyFans"; checkApplyFans.Name = "checkApplyFans";
checkApplyFans.Padding = new Padding(15, 5, 15, 5); checkApplyFans.Padding = new Padding(15, 5, 15, 5);
@@ -239,7 +264,7 @@ namespace GHelper
buttonReset.BorderColor = Color.Transparent; buttonReset.BorderColor = Color.Transparent;
buttonReset.BorderRadius = 2; buttonReset.BorderRadius = 2;
buttonReset.FlatStyle = FlatStyle.Flat; buttonReset.FlatStyle = FlatStyle.Flat;
buttonReset.Location = new Point(30, 1082); buttonReset.Location = new Point(30, 1112);
buttonReset.Margin = new Padding(4, 2, 4, 2); buttonReset.Margin = new Padding(4, 2, 4, 2);
buttonReset.Name = "buttonReset"; buttonReset.Name = "buttonReset";
buttonReset.Secondary = true; buttonReset.Secondary = true;
@@ -258,11 +283,11 @@ namespace GHelper
panelPower.Controls.Add(pictureFine); panelPower.Controls.Add(pictureFine);
panelPower.Controls.Add(labelInfo); panelPower.Controls.Add(labelInfo);
panelPower.Dock = DockStyle.Left; panelPower.Dock = DockStyle.Left;
panelPower.Location = new Point(0, 0); panelPower.Location = new Point(347, 0);
panelPower.Margin = new Padding(10); panelPower.Margin = new Padding(10);
panelPower.Name = "panelPower"; panelPower.Name = "panelPower";
panelPower.Padding = new Padding(10); panelPower.Padding = new Padding(10);
panelPower.Size = new Size(364, 1159); panelPower.Size = new Size(364, 1189);
panelPower.TabIndex = 13; panelPower.TabIndex = 13;
// //
// pictureBox1 // pictureBox1
@@ -293,7 +318,7 @@ namespace GHelper
checkApplyPower.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; checkApplyPower.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
checkApplyPower.AutoSize = true; checkApplyPower.AutoSize = true;
checkApplyPower.BackColor = SystemColors.ControlLight; checkApplyPower.BackColor = SystemColors.ControlLight;
checkApplyPower.Location = new Point(20, 1088); checkApplyPower.Location = new Point(20, 1118);
checkApplyPower.Margin = new Padding(4, 2, 4, 2); checkApplyPower.Margin = new Padding(4, 2, 4, 2);
checkApplyPower.Name = "checkApplyPower"; checkApplyPower.Name = "checkApplyPower";
checkApplyPower.Padding = new Padding(15, 5, 15, 5); checkApplyPower.Padding = new Padding(15, 5, 15, 5);
@@ -418,24 +443,147 @@ namespace GHelper
labelInfo.TabIndex = 19; labelInfo.TabIndex = 19;
labelInfo.Text = "label"; labelInfo.Text = "label";
// //
// labelFansResult // panelGPU
// //
labelFansResult.Anchor = AnchorStyles.Top | AnchorStyles.Right; panelGPU.Controls.Add(buttonResetGPU);
labelFansResult.ForeColor = Color.Red; panelGPU.Controls.Add(labelGPUMemory);
labelFansResult.Location = new Point(30, 1073); panelGPU.Controls.Add(trackGPUMemory);
labelFansResult.Name = "labelFansResult"; panelGPU.Controls.Add(labelGPUMemoryTitle);
labelFansResult.Size = new Size(760, 32); panelGPU.Controls.Add(pictureBox2);
labelFansResult.TabIndex = 41; panelGPU.Controls.Add(labelGPUCore);
labelFansResult.TextAlign = ContentAlignment.TopRight; panelGPU.Controls.Add(labelGPU);
panelGPU.Controls.Add(trackGPUCore);
panelGPU.Controls.Add(labelGPUCoreTitle);
panelGPU.Dock = DockStyle.Left;
panelGPU.Location = new Point(0, 0);
panelGPU.Name = "panelGPU";
panelGPU.Size = new Size(347, 1189);
panelGPU.TabIndex = 14;
//
// buttonResetGPU
//
buttonResetGPU.Activated = false;
buttonResetGPU.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonResetGPU.BackColor = SystemColors.ControlLight;
buttonResetGPU.BorderColor = Color.Transparent;
buttonResetGPU.BorderRadius = 2;
buttonResetGPU.FlatStyle = FlatStyle.Flat;
buttonResetGPU.Location = new Point(48, 1110);
buttonResetGPU.Margin = new Padding(4, 2, 4, 2);
buttonResetGPU.Name = "buttonResetGPU";
buttonResetGPU.Secondary = true;
buttonResetGPU.Size = new Size(232, 54);
buttonResetGPU.TabIndex = 43;
buttonResetGPU.Text = "Reset Clocks";
buttonResetGPU.UseVisualStyleBackColor = false;
//
// labelGPUMemory
//
labelGPUMemory.AutoSize = true;
labelGPUMemory.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
labelGPUMemory.Location = new Point(184, 112);
labelGPUMemory.Name = "labelGPUMemory";
labelGPUMemory.Size = new Size(130, 32);
labelGPUMemory.TabIndex = 42;
labelGPUMemory.Text = "2000 MHz";
labelGPUMemory.TextAlign = ContentAlignment.MiddleCenter;
//
// trackGPUMemory
//
trackGPUMemory.LargeChange = 100;
trackGPUMemory.Location = new Point(216, 160);
trackGPUMemory.Margin = new Padding(4, 2, 4, 2);
trackGPUMemory.Maximum = 300;
trackGPUMemory.Minimum = 0;
trackGPUMemory.Name = "trackGPUMemory";
trackGPUMemory.Orientation = Orientation.Vertical;
trackGPUMemory.Size = new Size(90, 454);
trackGPUMemory.SmallChange = 10;
trackGPUMemory.TabIndex = 41;
trackGPUMemory.TickFrequency = 50;
trackGPUMemory.Value = 0;
//
// labelGPUMemoryTitle
//
labelGPUMemoryTitle.AutoSize = true;
labelGPUMemoryTitle.Location = new Point(167, 72);
labelGPUMemoryTitle.Name = "labelGPUMemoryTitle";
labelGPUMemoryTitle.Size = new Size(169, 32);
labelGPUMemoryTitle.TabIndex = 40;
labelGPUMemoryTitle.Text = "Memory Clock";
labelGPUMemoryTitle.TextAlign = ContentAlignment.MiddleCenter;
//
// pictureBox2
//
pictureBox2.BackgroundImage = Properties.Resources.icons8_video_card_48;
pictureBox2.BackgroundImageLayout = ImageLayout.Zoom;
pictureBox2.ErrorImage = null;
pictureBox2.InitialImage = null;
pictureBox2.Location = new Point(25, 17);
pictureBox2.Margin = new Padding(4, 2, 4, 2);
pictureBox2.Name = "pictureBox2";
pictureBox2.Size = new Size(36, 38);
pictureBox2.TabIndex = 39;
pictureBox2.TabStop = false;
//
// labelGPUCore
//
labelGPUCore.AutoSize = true;
labelGPUCore.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
labelGPUCore.Location = new Point(20, 112);
labelGPUCore.Name = "labelGPUCore";
labelGPUCore.Size = new Size(130, 32);
labelGPUCore.TabIndex = 28;
labelGPUCore.Text = "1500 MHz";
labelGPUCore.TextAlign = ContentAlignment.MiddleCenter;
//
// labelGPU
//
labelGPU.AutoSize = true;
labelGPU.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point);
labelGPU.Location = new Point(60, 19);
labelGPU.Margin = new Padding(4, 0, 4, 0);
labelGPU.Name = "labelGPU";
labelGPU.Size = new Size(162, 32);
labelGPU.TabIndex = 27;
labelGPU.Text = "GPU Settings";
//
// trackGPUCore
//
trackGPUCore.LargeChange = 100;
trackGPUCore.Location = new Point(48, 160);
trackGPUCore.Margin = new Padding(4, 2, 4, 2);
trackGPUCore.Maximum = 300;
trackGPUCore.Minimum = 0;
trackGPUCore.Name = "trackGPUCore";
trackGPUCore.Orientation = Orientation.Vertical;
trackGPUCore.RightToLeft = RightToLeft.No;
trackGPUCore.Size = new Size(90, 454);
trackGPUCore.SmallChange = 10;
trackGPUCore.TabIndex = 17;
trackGPUCore.TickFrequency = 50;
trackGPUCore.TickStyle = TickStyle.TopLeft;
trackGPUCore.Value = 0;
//
// labelGPUCoreTitle
//
labelGPUCoreTitle.AutoSize = true;
labelGPUCoreTitle.Location = new Point(22, 72);
labelGPUCoreTitle.Name = "labelGPUCoreTitle";
labelGPUCoreTitle.Size = new Size(129, 32);
labelGPUCoreTitle.TabIndex = 16;
labelFansResult.Visible = false; labelFansResult.Visible = false;
// labelGPUCoreTitle.TextAlign = ContentAlignment.MiddleCenter;
// Fans labelGPUCoreTitle.Text = "Core Clock";
// //
AutoScaleDimensions = new SizeF(192F, 192F); // Fans
//
AutoScaleDimensions = new SizeF(192F, 192F);
AutoScaleMode = AutoScaleMode.Dpi; AutoScaleMode = AutoScaleMode.Dpi;
AutoSize = true; AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink; AutoSizeMode = AutoSizeMode.GrowAndShrink;
ClientSize = new Size(1178, 1159); ClientSize = new Size(1542, 1189);
Controls.Add(panelGPU);
Controls.Add(panelFans); Controls.Add(panelFans);
Controls.Add(panelPower); Controls.Add(panelPower);
Margin = new Padding(4, 2, 4, 2); Margin = new Padding(4, 2, 4, 2);
@@ -465,6 +613,11 @@ namespace GHelper
panelTotal.PerformLayout(); panelTotal.PerformLayout();
((System.ComponentModel.ISupportInitialize)trackTotal).EndInit(); ((System.ComponentModel.ISupportInitialize)trackTotal).EndInit();
((System.ComponentModel.ISupportInitialize)pictureFine).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureFine).EndInit();
panelGPU.ResumeLayout(false);
panelGPU.PerformLayout();
((System.ComponentModel.ISupportInitialize)trackGPUMemory).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBox2).EndInit();
((System.ComponentModel.ISupportInitialize)trackGPUCore).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
@@ -496,5 +649,15 @@ namespace GHelper
private Label labelBoost; private Label labelBoost;
private Label labelTip; private Label labelTip;
private Label labelFansResult; private Label labelFansResult;
private Panel panelGPU;
private Label labelGPUCore;
private Label labelGPU;
private TrackBar trackGPUCore;
private Label labelGPUCoreTitle;
private PictureBox pictureBox2;
private Label labelGPUMemory;
private TrackBar trackGPUMemory;
private Label labelGPUMemoryTitle;
private RButton buttonResetGPU;
} }
} }

View File

@@ -1,6 +1,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.Windows.Forms.DataVisualization.Charting; using System.Windows.Forms.DataVisualization.Charting;
using CustomControls; using CustomControls;
using GHelper.Gpu;
namespace GHelper namespace GHelper
{ {
@@ -63,6 +64,11 @@ namespace GHelper
checkApplyFans.Click += CheckApplyFans_Click; checkApplyFans.Click += CheckApplyFans_Click;
checkApplyPower.Click += CheckApplyPower_Click; checkApplyPower.Click += CheckApplyPower_Click;
trackGPUCore.Scroll += trackGPU_Scroll;
trackGPUMemory.Scroll += trackGPU_Scroll;
buttonResetGPU.Click += ButtonResetGPU_Click;
//labelInfo.MaximumSize = new Size(280, 0); //labelInfo.MaximumSize = new Size(280, 0);
labelInfo.Text = Properties.Strings.PPTExperimental; labelInfo.Text = Properties.Strings.PPTExperimental;
@@ -74,6 +80,57 @@ namespace GHelper
Shown += Fans_Shown; Shown += Fans_Shown;
InitGPUClocks();
}
private void InitGPUClocks()
{
panelGPU.Visible = HardwareMonitor.GpuControl.IsNvidia;
trackGPUCore.Value = Math.Min(Program.config.getConfig("GPUCore"), 300);
trackGPUMemory.Value = Math.Min(Program.config.getConfig("GPUMemory"), 300);
VisualiseGPUClocks();
}
private void ButtonResetGPU_Click(object? sender, EventArgs e)
{
Program.RunAsAdmin();
try
{
trackGPUCore.Value = 0;
trackGPUMemory.Value = 0;
VisualiseGPUClocks();
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
}
}
private void VisualiseGPUClocks()
{
labelGPUCore.Text = $"+{trackGPUCore.Value} MHz";
labelGPUMemory.Text = $"+{trackGPUMemory.Value} MHz";
}
private void trackGPU_Scroll(object? sender, EventArgs e)
{
VisualiseGPUClocks();
try
{
Program.config.setConfig("GPUCore", trackGPUCore.Value);
Program.config.setConfig("GPUMemory", trackGPUMemory.Value);
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
}
} }
static string ChartPercToRPM(int percentage, string unit = "") static string ChartPercToRPM(int percentage, string unit = "")
@@ -532,6 +589,7 @@ namespace GHelper
} }
} }
} }
} }
} }

View File

@@ -13,26 +13,26 @@
<Platforms>AnyCPU;x64</Platforms> <Platforms>AnyCPU;x64</Platforms>
<SupportedOSPlatformVersion>8.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion>8.0</SupportedOSPlatformVersion>
<AssemblyName>GHelper</AssemblyName> <AssemblyName>GHelper</AssemblyName>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly> <ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.56</AssemblyVersion> <AssemblyVersion>0.56</AssemblyVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>none</DebugType> <DebugType>embedded</DebugType>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType> <DebugType>embedded</DebugType>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DebugType>none</DebugType> <DebugType>embedded</DebugType>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebugType>none</DebugType> <DebugType>embedded</DebugType>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -4,12 +4,15 @@ using AmdAdl2;
namespace GHelper.Gpu; namespace GHelper.Gpu;
// Reference: https://github.com/GPUOpen-LibrariesAndSDKs/display-library/blob/master/Sample-Managed/Program.cs // Reference: https://github.com/GPUOpen-LibrariesAndSDKs/display-library/blob/master/Sample-Managed/Program.cs
public class AmdGpuTemperatureProvider : IGpuTemperatureProvider { public class AmdGpuControl : IGpuControl {
private bool _isReady; private bool _isReady;
private IntPtr _adlContextHandle; private IntPtr _adlContextHandle;
private readonly ADLAdapterInfo _internalDiscreteAdapter; private readonly ADLAdapterInfo _internalDiscreteAdapter;
public AmdGpuTemperatureProvider() { public bool IsNvidia => false;
public AmdGpuControl() {
if (!Adl2.Load()) if (!Adl2.Load())
return; return;
@@ -104,7 +107,7 @@ public class AmdGpuTemperatureProvider : IGpuTemperatureProvider {
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
~AmdGpuTemperatureProvider() { ~AmdGpuControl() {
ReleaseUnmanagedResources(); ReleaseUnmanagedResources();
} }
} }

View File

@@ -1,6 +1,7 @@
namespace GHelper.Gpu; namespace GHelper.Gpu;
public interface IGpuTemperatureProvider : IDisposable { public interface IGpuControl : IDisposable {
bool IsNvidia { get; }
bool IsValid { get; } bool IsValid { get; }
int? GetCurrentTemperature(); int? GetCurrentTemperature();
int? GetGpuUse(); int? GetGpuUse();

View File

@@ -5,17 +5,19 @@ using NvAPIWrapper.Native.Interfaces.GPU;
namespace GHelper.Gpu; namespace GHelper.Gpu;
public class NvidiaGpuTemperatureProvider : IGpuTemperatureProvider public class NvidiaGpuControl : IGpuControl
{ {
private readonly PhysicalGPU? _internalGpu; private readonly PhysicalGPU? _internalGpu;
public NvidiaGpuTemperatureProvider() public NvidiaGpuControl()
{ {
_internalGpu = GetInternalDiscreteGpu(); _internalGpu = GetInternalDiscreteGpu();
} }
public bool IsValid => _internalGpu != null; public bool IsValid => _internalGpu != null;
public bool IsNvidia => IsValid;
public int? GetCurrentTemperature() public int? GetCurrentTemperature()
{ {
if (!IsValid) if (!IsValid)

View File

@@ -1,11 +1,10 @@
using GHelper; using GHelper;
using GHelper.Gpu; using GHelper.Gpu;
using System.Diagnostics; using System.Diagnostics;
using System.Management;
public static class HardwareMonitor public static class HardwareMonitor
{ {
private static IGpuTemperatureProvider? GpuTemperatureProvider; public static IGpuControl? GpuControl;
public static float? cpuTemp = -1; public static float? cpuTemp = -1;
public static float? batteryDischarge = -1; public static float? batteryDischarge = -1;
@@ -51,7 +50,7 @@ public static class HardwareMonitor
{ {
try try
{ {
int? gpuUse = GpuTemperatureProvider?.GetGpuUse(); int? gpuUse = GpuControl?.GetGpuUse();
if (gpuUse is not null) return (int)gpuUse; if (gpuUse is not null) return (int)gpuUse;
} }
catch (Exception ex) catch (Exception ex)
@@ -76,20 +75,20 @@ public static class HardwareMonitor
cpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_CPU); cpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_CPU);
if (cpuTemp < 0) try if (cpuTemp < 0) try
{
using (var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true))
{ {
cpuTemp = ct.NextValue() - 273; using (var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true))
{
cpuTemp = ct.NextValue() - 273;
}
}
catch
{
Debug.WriteLine("Failed reading CPU temp");
} }
}
catch
{
Debug.WriteLine("Failed reading CPU temp");
}
try try
{ {
gpuTemp = GpuTemperatureProvider?.GetCurrentTemperature(); gpuTemp = GpuControl?.GetCurrentTemperature();
} }
catch (Exception ex) catch (Exception ex)
@@ -144,28 +143,28 @@ public static class HardwareMonitor
{ {
try try
{ {
GpuTemperatureProvider?.Dispose(); GpuControl?.Dispose();
// Detect valid GPU temperature provider. // Detect valid GPU temperature provider.
// We start with NVIDIA because there's always at least an integrated AMD GPU // We start with NVIDIA because there's always at least an integrated AMD GPU
IGpuTemperatureProvider gpuTemperatureProvider = new NvidiaGpuTemperatureProvider(); IGpuControl _gpuControl = new NvidiaGpuControl();
if (gpuTemperatureProvider.IsValid) if (_gpuControl.IsValid)
{ {
GpuTemperatureProvider = gpuTemperatureProvider; GpuControl = _gpuControl;
return; return;
} }
gpuTemperatureProvider.Dispose(); _gpuControl.Dispose();
gpuTemperatureProvider = new AmdGpuTemperatureProvider(); _gpuControl = new AmdGpuControl();
if (gpuTemperatureProvider.IsValid) if (_gpuControl.IsValid)
{ {
GpuTemperatureProvider = gpuTemperatureProvider; GpuControl = _gpuControl;
return; return;
} }
gpuTemperatureProvider.Dispose(); _gpuControl.Dispose();
GpuTemperatureProvider = null; GpuControl = null;
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -14,6 +14,7 @@ namespace GHelper
{"play", Properties.Strings.PlayPause}, {"play", Properties.Strings.PlayPause},
{"aura", Properties.Strings.ToggleAura}, {"aura", Properties.Strings.ToggleAura},
{"ghelper", Properties.Strings.OpenGHelper}, {"ghelper", Properties.Strings.OpenGHelper},
{"screen", Properties.Strings.ToggleScreen},
{"custom", Properties.Strings.Custom} {"custom", Properties.Strings.Custom}
}; };

View File

@@ -351,6 +351,33 @@ namespace Tools
public class NativeMethods public class NativeMethods
{ {
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MONITORPOWER = 0xF170;
private const int MONITOR_OFF = 2;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern uint FormatMessage(uint dwFlags, IntPtr lpSource, uint dwMessageId, uint dwLanguageId, out string lpBuffer, uint nSize, IntPtr Arguments);
public static void TurnOffScreen(IntPtr handle)
{
IntPtr result = SendMessage(handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)MONITOR_OFF);
if (result == IntPtr.Zero)
{
int error = Marshal.GetLastWin32Error();
string message = "";
uint formatFlags = 0x00001000 | 0x00000200 | 0x00000100 | 0x00000080;
uint formatResult = FormatMessage(formatFlags, IntPtr.Zero, (uint)error, 0, out message, 0, IntPtr.Zero);
if (formatResult == 0)
{
message = "Unknown error.";
}
Logger.WriteLine($"Failed to turn off screen. Error code: {error}. {message}");
}
}
// Monitor Power detection // Monitor Power detection
internal const uint DEVICE_NOTIFY_WINDOW_HANDLE = 0x0; internal const uint DEVICE_NOTIFY_WINDOW_HANDLE = 0x0;

View File

@@ -2,6 +2,7 @@ using Microsoft.Win32;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Management; using System.Management;
using System.Security.Principal;
using Tools; using Tools;
namespace GHelper namespace GHelper
@@ -27,23 +28,62 @@ namespace GHelper
private static long lastTheme; private static long lastTheme;
private static PowerLineStatus isPlugged = PowerLineStatus.Unknown; private static PowerLineStatus isPlugged = PowerLineStatus.Unknown;
static void CheckProcesses()
{
Process currentProcess = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(currentProcess.ProcessName);
if (processes.Length > 1)
{
foreach (Process process in processes)
if (process.Id != currentProcess.Id)
try
{
process.Kill();
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
MessageBox.Show(Properties.Strings.AppAlreadyRunningText, Properties.Strings.AppAlreadyRunning, MessageBoxButtons.OK);
Application.Exit();
return;
}
}
}
static bool IsUserAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
public static void RunAsAdmin()
{
// Check if the current user is an administrator
if (!IsUserAdministrator())
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = Environment.CurrentDirectory;
startInfo.FileName = Application.ExecutablePath;
startInfo.Verb = "runas";
Process.Start(startInfo);
//Application.Exit();
}
}
// The main entry point for the application // The main entry point for the application
public static void Main() public static void Main()
{ {
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture;
Debug.WriteLine(CultureInfo.CurrentUICulture); Debug.WriteLine(CultureInfo.CurrentUICulture);
//Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("es"); //Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("es");
if (Process.GetProcesses().Count(p => p.ProcessName == "GHelper") > 1) CheckProcesses();
{
MessageBox.Show(Properties.Strings.AppAlreadyRunningText, Properties.Strings.AppAlreadyRunning, MessageBoxButtons.OK);
Application.Exit();
return;
}
try try
{ {
@@ -99,8 +139,6 @@ namespace GHelper
SettingsToggle(); SettingsToggle();
} }
Application.Run(); Application.Run();
@@ -167,19 +205,18 @@ namespace GHelper
} }
static void LaunchProcess(string fileName = "") static void LaunchProcess(string command = "")
{ {
ProcessStartInfo start = new ProcessStartInfo(); string executable = command.Split(' ')[0];
start.FileName = fileName; string arguments = command.Substring(executable.Length).Trim();
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
try try
{ {
Process proc = Process.Start(start); Process proc = Process.Start(executable, arguments);
} }
catch catch
{ {
Logger.WriteLine("Failed to run " + fileName); Logger.WriteLine("Failed to run " + command);
} }
@@ -230,6 +267,9 @@ namespace GHelper
case "screenshot": case "screenshot":
NativeMethods.KeyPress(NativeMethods.VK_SNAPSHOT); NativeMethods.KeyPress(NativeMethods.VK_SNAPSHOT);
break; break;
case "screen":
NativeMethods.TurnOffScreen(Program.settingsForm.Handle);
break;
case "aura": case "aura":
settingsForm.BeginInvoke(settingsForm.CycleAuraMode); settingsForm.BeginInvoke(settingsForm.CycleAuraMode);
break; break;

View File

@@ -861,6 +861,15 @@ namespace GHelper.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Toggle Screen.
/// </summary>
internal static string ToggleScreen {
get {
return ResourceManager.GetString("ToggleScreen", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Turbo. /// Looks up a localized string similar to Turbo.
/// </summary> /// </summary>

View File

@@ -384,6 +384,9 @@
<data name="ToggleAura" xml:space="preserve"> <data name="ToggleAura" xml:space="preserve">
<value>Toggle Aura</value> <value>Toggle Aura</value>
</data> </data>
<data name="ToggleScreen" xml:space="preserve">
<value>Toggle Screen</value>
</data>
<data name="Turbo" xml:space="preserve"> <data name="Turbo" xml:space="preserve">
<value>Turbo</value> <value>Turbo</value>
</data> </data>

View File

@@ -4,7 +4,9 @@
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security> <security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options <requestedExecutionLevel level="asInvoker" uiAccess="false" />
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following. requestedExecutionLevel node with one of the following.