mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
GPU Settings will be saved and auto-applied for each mode
This commit is contained in:
38
app/Fans.Designer.cs
generated
38
app/Fans.Designer.cs
generated
@@ -31,12 +31,12 @@ namespace GHelper
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
ChartArea chartArea4 = new ChartArea();
|
||||
Title title4 = new Title();
|
||||
ChartArea chartArea5 = new ChartArea();
|
||||
Title title5 = new Title();
|
||||
ChartArea chartArea6 = new ChartArea();
|
||||
Title title6 = new Title();
|
||||
ChartArea chartArea1 = new ChartArea();
|
||||
Title title1 = new Title();
|
||||
ChartArea chartArea2 = new ChartArea();
|
||||
Title title2 = new Title();
|
||||
ChartArea chartArea3 = new ChartArea();
|
||||
Title title3 = new Title();
|
||||
panelFans = new Panel();
|
||||
labelFansResult = new Label();
|
||||
labelTip = new Label();
|
||||
@@ -211,8 +211,8 @@ namespace GHelper
|
||||
//
|
||||
// chartGPU
|
||||
//
|
||||
chartArea4.Name = "ChartArea1";
|
||||
chartGPU.ChartAreas.Add(chartArea4);
|
||||
chartArea1.Name = "ChartArea1";
|
||||
chartGPU.ChartAreas.Add(chartArea1);
|
||||
chartGPU.Dock = DockStyle.Fill;
|
||||
chartGPU.Location = new Point(2, 350);
|
||||
chartGPU.Margin = new Padding(2, 10, 2, 10);
|
||||
@@ -220,13 +220,13 @@ namespace GHelper
|
||||
chartGPU.Size = new Size(760, 320);
|
||||
chartGPU.TabIndex = 17;
|
||||
chartGPU.Text = "chartGPU";
|
||||
title4.Name = "Title1";
|
||||
chartGPU.Titles.Add(title4);
|
||||
title1.Name = "Title1";
|
||||
chartGPU.Titles.Add(title1);
|
||||
//
|
||||
// chartCPU
|
||||
//
|
||||
chartArea5.Name = "ChartArea1";
|
||||
chartCPU.ChartAreas.Add(chartArea5);
|
||||
chartArea2.Name = "ChartArea1";
|
||||
chartCPU.ChartAreas.Add(chartArea2);
|
||||
chartCPU.Dock = DockStyle.Fill;
|
||||
chartCPU.Location = new Point(2, 10);
|
||||
chartCPU.Margin = new Padding(2, 10, 2, 10);
|
||||
@@ -234,13 +234,13 @@ namespace GHelper
|
||||
chartCPU.Size = new Size(760, 320);
|
||||
chartCPU.TabIndex = 14;
|
||||
chartCPU.Text = "chartCPU";
|
||||
title5.Name = "Title1";
|
||||
chartCPU.Titles.Add(title5);
|
||||
title2.Name = "Title1";
|
||||
chartCPU.Titles.Add(title2);
|
||||
//
|
||||
// chartMid
|
||||
//
|
||||
chartArea6.Name = "ChartArea3";
|
||||
chartMid.ChartAreas.Add(chartArea6);
|
||||
chartArea3.Name = "ChartArea3";
|
||||
chartMid.ChartAreas.Add(chartArea3);
|
||||
chartMid.Dock = DockStyle.Fill;
|
||||
chartMid.Location = new Point(2, 690);
|
||||
chartMid.Margin = new Padding(2, 10, 2, 10);
|
||||
@@ -248,8 +248,8 @@ namespace GHelper
|
||||
chartMid.Size = new Size(760, 322);
|
||||
chartMid.TabIndex = 14;
|
||||
chartMid.Text = "chartMid";
|
||||
title6.Name = "Title3";
|
||||
chartMid.Titles.Add(title6);
|
||||
title3.Name = "Title3";
|
||||
chartMid.Titles.Add(title3);
|
||||
chartMid.Visible = false;
|
||||
//
|
||||
// labelFans
|
||||
@@ -352,7 +352,7 @@ namespace GHelper
|
||||
labelInfo.Margin = new Padding(4, 0, 4, 0);
|
||||
labelInfo.Name = "labelInfo";
|
||||
labelInfo.Padding = new Padding(5);
|
||||
labelInfo.Size = new Size(523, 92);
|
||||
labelInfo.Size = new Size(523, 149);
|
||||
labelInfo.TabIndex = 43;
|
||||
labelInfo.Text = "Experimental Feature";
|
||||
//
|
||||
|
||||
59
app/Fans.cs
59
app/Fans.cs
@@ -97,9 +97,8 @@ namespace GHelper
|
||||
|
||||
trackGPUCore.MouseUp += TrackGPU_MouseUp;
|
||||
trackGPUMemory.MouseUp += TrackGPU_MouseUp;
|
||||
|
||||
trackGPUBoost.MouseUp += TrackGPUBoost_MouseUp;
|
||||
trackGPUTemp.MouseUp += TrackGPUBoost_MouseUp;
|
||||
trackGPUBoost.MouseUp += TrackGPU_MouseUp;
|
||||
trackGPUTemp.MouseUp += TrackGPU_MouseUp;
|
||||
|
||||
//labelInfo.MaximumSize = new Size(280, 0);
|
||||
labelInfo.Text = Properties.Strings.PPTExperimental;
|
||||
@@ -108,41 +107,22 @@ namespace GHelper
|
||||
InitFans();
|
||||
InitPower();
|
||||
InitBoost();
|
||||
InitGPU();
|
||||
|
||||
comboBoost.SelectedValueChanged += ComboBoost_Changed;
|
||||
|
||||
Shown += Fans_Shown;
|
||||
|
||||
InitGPUControl();
|
||||
|
||||
}
|
||||
|
||||
private void TrackGPUBoost_MouseUp(object? sender, MouseEventArgs e)
|
||||
{
|
||||
Program.config.setConfig("gpu_boost", trackGPUBoost.Value);
|
||||
Program.config.setConfig("gpu_temp", trackGPUTemp.Value);
|
||||
Program.settingsForm.SetGPUPower();
|
||||
}
|
||||
|
||||
private void TrackGPU_MouseUp(object? sender, MouseEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Program.config.setConfig("gpu_core", trackGPUCore.Value);
|
||||
Program.config.setConfig("gpu_memory", trackGPUMemory.Value);
|
||||
|
||||
int status = nvControl.SetClocks(trackGPUCore.Value, trackGPUMemory.Value);
|
||||
if (status == -1) Program.RunAsAdmin("gpu");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine("F:" + ex.ToString());
|
||||
}
|
||||
|
||||
InitGPUControl();
|
||||
Program.settingsForm.AutoGPUSettings(true);
|
||||
}
|
||||
|
||||
private void InitGPUControl()
|
||||
public void InitGPU()
|
||||
{
|
||||
if (HardwareControl.GpuControl is not null && HardwareControl.GpuControl.IsNvidia)
|
||||
{
|
||||
@@ -164,8 +144,8 @@ namespace GHelper
|
||||
trackGPUMemory.Value = Math.Max(Math.Min(memory, NvidiaGpuControl.MaxMemoryOffset), NvidiaGpuControl.MinMemoryOffset);
|
||||
labelGPU.Text = gpuTitle;
|
||||
|
||||
int gpu_boost = Program.config.getConfig("gpu_boost");
|
||||
int gpu_temp = Program.config.getConfig("gpu_temp");
|
||||
int gpu_boost = Program.config.getConfigPerf("gpu_boost");
|
||||
int gpu_temp = Program.config.getConfigPerf("gpu_temp");
|
||||
|
||||
if (gpu_boost < 0) gpu_boost = ASUSWmi.MaxGPUBoost;
|
||||
if (gpu_temp < 0) gpu_temp = ASUSWmi.MaxGPUTemp;
|
||||
@@ -198,15 +178,21 @@ namespace GHelper
|
||||
private void trackGPU_Scroll(object? sender, EventArgs e)
|
||||
{
|
||||
if (sender is null) return;
|
||||
|
||||
TrackBar track = (TrackBar)sender;
|
||||
track.Value = (int)Math.Round((float)track.Value / 5) * 5;
|
||||
|
||||
Program.config.setConfigPerf("gpu_core", trackGPUCore.Value);
|
||||
Program.config.setConfigPerf("gpu_memory", trackGPUMemory.Value);
|
||||
|
||||
VisualiseGPUSettings();
|
||||
|
||||
}
|
||||
|
||||
private void trackGPUPower_Scroll(object? sender, EventArgs e)
|
||||
{
|
||||
Program.config.setConfigPerf("gpu_boost", trackGPUBoost.Value);
|
||||
Program.config.setConfigPerf("gpu_temp", trackGPUTemp.Value);
|
||||
|
||||
VisualiseGPUSettings();
|
||||
}
|
||||
|
||||
@@ -367,7 +353,7 @@ namespace GHelper
|
||||
// Yes, that's stupid, but Total slider on 2021 model actually adjusts CPU PPT
|
||||
if (!cpuBmode)
|
||||
{
|
||||
labelPlatform.Text = "CPU SPPT";
|
||||
labelPlatform.Text = "CPU PPT";
|
||||
}
|
||||
|
||||
int limit_total;
|
||||
@@ -506,20 +492,17 @@ namespace GHelper
|
||||
checkApplyFans.Checked = false;
|
||||
checkApplyPower.Checked = false;
|
||||
|
||||
/*
|
||||
Program.config.setConfigPerf("auto_apply", 0);
|
||||
Program.config.setConfigPerf("auto_apply_power", 0);
|
||||
|
||||
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, Program.config.getConfig("performance_mode"), "PerfMode");
|
||||
|
||||
trackGPUCore.Value = 0;
|
||||
trackGPUMemory.Value = 0;
|
||||
trackGPUBoost.Value = ASUSWmi.MaxGPUBoost;
|
||||
trackGPUTemp.Value = ASUSWmi.MaxGPUTemp;
|
||||
|
||||
Program.config.setConfig("gpu_core", ASUSWmi.MaxGPUBoost);
|
||||
Program.config.setConfig("gpu_memory", ASUSWmi.MaxGPUTemp);
|
||||
*/
|
||||
|
||||
Program.config.setConfigPerf("auto_apply", 0);
|
||||
Program.config.setConfigPerf("auto_apply_power", 0);
|
||||
|
||||
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, Program.config.getConfig("performance_mode"), "PerfMode");
|
||||
Program.settingsForm.AutoGPUSettings(true);
|
||||
}
|
||||
|
||||
private void ChartCPU_MouseUp(object? sender, MouseEventArgs e)
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace GHelper
|
||||
|
||||
private static long lastAuto;
|
||||
private static long lastTheme;
|
||||
private static long lastAdmin;
|
||||
|
||||
private static PowerLineStatus isPlugged = PowerLineStatus.Unknown;
|
||||
|
||||
// The main entry point for the application
|
||||
@@ -62,7 +64,7 @@ namespace GHelper
|
||||
}
|
||||
|
||||
Logger.WriteLine("------------");
|
||||
Logger.WriteLine("App launched: " + config.GetModel() + " :" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + (IsUserAdministrator()?"A":"N"));
|
||||
Logger.WriteLine("App launched: " + config.GetModel() + " :" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + (IsUserAdministrator()?"A":""));
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
|
||||
@@ -292,7 +294,7 @@ namespace GHelper
|
||||
|
||||
if (action == "gpu")
|
||||
{
|
||||
HardwareControl.GetNvidiaGpuControl()?.SetClocksFromConfig();
|
||||
Startup.ReScheduleAdmin();
|
||||
settingsForm.FansToggle();
|
||||
}
|
||||
}
|
||||
@@ -352,6 +354,10 @@ namespace GHelper
|
||||
|
||||
public static void RunAsAdmin(string? param = null)
|
||||
{
|
||||
|
||||
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastAdmin) < 2000) return;
|
||||
lastAdmin = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
|
||||
// Check if the current user is an administrator
|
||||
if (!IsUserAdministrator())
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using CustomControls;
|
||||
using GHelper.Gpu;
|
||||
using Starlight.AnimeMatrix;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
@@ -7,6 +8,7 @@ using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using System.Timers;
|
||||
using System.Windows.Forms;
|
||||
using Tools;
|
||||
|
||||
namespace GHelper
|
||||
@@ -140,7 +142,7 @@ namespace GHelper
|
||||
int trim = model.LastIndexOf("_");
|
||||
if (trim > 0) model = model.Substring(0, trim);
|
||||
|
||||
labelModel.Text = model;
|
||||
labelModel.Text = model+(Program.IsUserAdministrator()?".":"");
|
||||
|
||||
TopMost = Program.config.getConfig("topmost") == 1;
|
||||
|
||||
@@ -1043,11 +1045,14 @@ namespace GHelper
|
||||
|
||||
}
|
||||
|
||||
public void SetGPUPower()
|
||||
public void AutoGPUSettings(bool launchAsAdmin = false)
|
||||
{
|
||||
|
||||
int gpu_boost = Program.config.getConfig("gpu_boost");
|
||||
int gpu_temp = Program.config.getConfig("gpu_temp");
|
||||
int gpu_boost = Program.config.getConfigPerf("gpu_boost");
|
||||
int gpu_temp = Program.config.getConfigPerf("gpu_temp");
|
||||
|
||||
int gpu_core = Program.config.getConfigPerf("gpu_core");
|
||||
int gpu_memory = Program.config.getConfigPerf("gpu_memory");
|
||||
|
||||
if (gpu_boost < ASUSWmi.MinGPUBoost || gpu_boost > ASUSWmi.MaxGPUBoost ) return;
|
||||
if (gpu_temp < ASUSWmi.MinGPUTemp || gpu_temp > ASUSWmi.MaxGPUTemp) return;
|
||||
@@ -1062,6 +1067,23 @@ namespace GHelper
|
||||
Program.wmi.DeviceSet(ASUSWmi.PPT_GPUC2, gpu_temp, "PowerLimit C2");
|
||||
}
|
||||
|
||||
if (gpu_core == -1 && gpu_memory == -1) return;
|
||||
|
||||
if (HardwareControl.GpuControl is not null && HardwareControl.GpuControl.IsNvidia)
|
||||
{
|
||||
using NvidiaGpuControl nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
|
||||
try
|
||||
{
|
||||
int status = nvControl.SetClocks(gpu_core, gpu_memory);
|
||||
if (launchAsAdmin && status == -1) Program.RunAsAdmin("gpu");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void LabelFansResult(string text)
|
||||
@@ -1136,14 +1158,12 @@ namespace GHelper
|
||||
timer.Stop();
|
||||
timer.Dispose();
|
||||
SetPower();
|
||||
SetGPUPower();
|
||||
};
|
||||
timer.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetPower();
|
||||
SetGPUPower();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1201,8 +1221,10 @@ namespace GHelper
|
||||
}
|
||||
|
||||
AutoFans();
|
||||
AutoGPUSettings();
|
||||
AutoPower(1000);
|
||||
|
||||
|
||||
if (Program.config.getConfigPerfString("scheme") is not null)
|
||||
NativeMethods.SetPowerScheme(Program.config.getConfigPerfString("scheme"));
|
||||
else
|
||||
@@ -1223,6 +1245,7 @@ namespace GHelper
|
||||
fans.InitFans();
|
||||
fans.InitPower();
|
||||
fans.InitBoost();
|
||||
fans.InitGPU();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1424,10 +1447,10 @@ namespace GHelper
|
||||
|
||||
labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUChanging + " ...";
|
||||
|
||||
Thread t = new Thread(() =>
|
||||
{
|
||||
Thread.CurrentThread.IsBackground = true;
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
|
||||
if (eco == 1)
|
||||
{
|
||||
string[] tokill = { "EADesktop", "RadeonSoftware" };
|
||||
@@ -1437,18 +1460,18 @@ namespace GHelper
|
||||
|
||||
Program.wmi.DeviceSet(ASUSWmi.GPUEco, eco, "GPUEco");
|
||||
|
||||
if (eco == 0)
|
||||
HardwareControl.RecreateGpuControlWithDelay();
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
Program.settingsForm.BeginInvoke(delegate
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
InitGPUMode();
|
||||
AutoScreen();
|
||||
});
|
||||
|
||||
if (eco == 0)
|
||||
HardwareControl.RecreateGpuControlWithDelay();
|
||||
|
||||
});
|
||||
|
||||
t.Start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,15 @@ public class Startup
|
||||
return (taskService.RootFolder.AllTasks.Any(t => t.Name == taskName));
|
||||
}
|
||||
|
||||
public static void ReScheduleAdmin()
|
||||
{
|
||||
if (Program.IsUserAdministrator() && IsScheduled())
|
||||
{
|
||||
UnSchedule();
|
||||
Schedule();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Schedule()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user