mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Eco tweaks
This commit is contained in:
1
app/Extra.Designer.cs
generated
1
app/Extra.Designer.cs
generated
@@ -234,6 +234,7 @@ namespace GHelper
|
||||
// numericBacklightTime
|
||||
//
|
||||
numericBacklightTime.Location = new Point(477, 131);
|
||||
numericBacklightTime.Maximum = new decimal(new int[] { 3600, 0, 0, 0 });
|
||||
numericBacklightTime.Name = "numericBacklightTime";
|
||||
numericBacklightTime.Size = new Size(240, 39);
|
||||
numericBacklightTime.TabIndex = 47;
|
||||
|
||||
@@ -90,10 +90,10 @@ public class NvidiaGpuControl : IGpuControl
|
||||
}
|
||||
|
||||
|
||||
public void RestartGPU()
|
||||
public bool RestartGPU()
|
||||
{
|
||||
|
||||
if (!IsValid) return;
|
||||
if (!IsValid) return false;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -104,10 +104,12 @@ public class NvidiaGpuControl : IGpuControl
|
||||
Thread.Sleep(3000);
|
||||
RunCMD("pnputil", $"/enable-device /deviceid \"{pnpDeviceId}\"");
|
||||
Thread.Sleep(2000);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex )
|
||||
{
|
||||
Logger.WriteLine(ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,9 +81,9 @@ public static class HardwareControl
|
||||
cpuTemp = ct.NextValue() - 273;
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine("Failed reading CPU temp");
|
||||
Debug.WriteLine("Failed reading CPU temp :" + ex.Message);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -94,8 +94,7 @@ public static class HardwareControl
|
||||
catch (Exception ex)
|
||||
{
|
||||
gpuTemp = -1;
|
||||
Debug.WriteLine("Failed reading GPU temp");
|
||||
Debug.WriteLine(ex.ToString());
|
||||
Debug.WriteLine("Failed reading GPU temp :" + ex.Message);
|
||||
}
|
||||
|
||||
if (gpuTemp is null || gpuTemp < 0)
|
||||
|
||||
@@ -1453,19 +1453,20 @@ namespace GHelper
|
||||
|
||||
}
|
||||
|
||||
public void RestartGPU()
|
||||
public bool RestartGPU()
|
||||
{
|
||||
if (HardwareControl.GpuControl is null) return;
|
||||
if (!HardwareControl.GpuControl!.IsNvidia) return;
|
||||
if (HardwareControl.GpuControl is null) return false;
|
||||
if (!HardwareControl.GpuControl!.IsNvidia) return false;
|
||||
|
||||
DialogResult dialogResult = MessageBox.Show("Something is using dGPU. Restart it in a device manager and try to set Eco again?", Properties.Strings.EcoMode, MessageBoxButtons.YesNo);
|
||||
if (dialogResult == DialogResult.No) return;
|
||||
DialogResult dialogResult = MessageBox.Show("Something is using dGPU and blocking Eco mode. Restart dGPU in a device manager and try to set Eco again?", Properties.Strings.EcoMode, MessageBoxButtons.YesNo);
|
||||
if (dialogResult == DialogResult.No) return false;
|
||||
|
||||
Program.RunAsAdmin();
|
||||
|
||||
Logger.WriteLine("Trying to restart GPU");
|
||||
var nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
|
||||
nvControl.RestartGPU();
|
||||
return nvControl.RestartGPU();
|
||||
|
||||
}
|
||||
|
||||
public void SetGPUEco(int eco, bool hardWay = false)
|
||||
@@ -1480,24 +1481,24 @@ namespace GHelper
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
|
||||
|
||||
int status;
|
||||
|
||||
if (eco == 1)
|
||||
{
|
||||
string[] tokill = { "EADesktop", "RadeonSoftware" };
|
||||
foreach (string kill in tokill)
|
||||
foreach (var process in Process.GetProcessesByName(kill)) process.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
int status = Program.wmi.SetGPUEco(eco);
|
||||
status = Program.wmi.SetGPUEco(eco);
|
||||
|
||||
if (status == 0 && eco == 1 && hardWay)
|
||||
{
|
||||
RestartGPU();
|
||||
Program.wmi.SetGPUEco(eco);
|
||||
if (RestartGPU()) Program.wmi.SetGPUEco(1);
|
||||
}
|
||||
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(500));
|
||||
Program.settingsForm.BeginInvoke(delegate
|
||||
{
|
||||
InitGPUMode();
|
||||
@@ -1506,7 +1507,7 @@ namespace GHelper
|
||||
|
||||
if (eco == 0)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(1000));
|
||||
HardwareControl.RecreateGpuControl();
|
||||
SetGPUClocks(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user