mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Initial commit, basic functionality
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="System.Management" Version="7.0.0" />
|
||||
<PackageReference Include="TaskScheduler" Version="2.10.1" />
|
||||
</ItemGroup>
|
||||
|
||||
78
Program.cs
78
Program.cs
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using System.Text.Json;
|
||||
using System.Management;
|
||||
using Microsoft.Win32.TaskScheduler;
|
||||
using System.Diagnostics;
|
||||
@@ -9,10 +8,12 @@ using System.Reflection.Emit;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Reflection;
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
using GHelper;
|
||||
using System.Dynamic;
|
||||
using System.IO;
|
||||
using System.Xml.Linq;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public class ASUSWmi
|
||||
{
|
||||
@@ -87,15 +88,61 @@ public class ASUSWmi
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class AppConfig
|
||||
{
|
||||
|
||||
string appPath;
|
||||
string configFile;
|
||||
|
||||
public dynamic Config = new ExpandoObject();
|
||||
|
||||
public AppConfig() {
|
||||
|
||||
appPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+"\\GHelper";
|
||||
configFile = appPath + "\\config.json";
|
||||
|
||||
if (!System.IO.Directory.Exists(appPath))
|
||||
System.IO.Directory.CreateDirectory(appPath);
|
||||
|
||||
if (File.Exists(configFile))
|
||||
{
|
||||
string text = File.ReadAllText(configFile);
|
||||
Config = JsonConvert.DeserializeObject<ExpandoObject>(text);
|
||||
} else
|
||||
{
|
||||
Config.performance_mode = 0;
|
||||
string jsonString = JsonConvert.SerializeObject(Config);
|
||||
File.WriteAllText(configFile, jsonString);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getConfig (string name)
|
||||
{
|
||||
var propertyInfo = Config.GetType().GetProperty(name);
|
||||
return propertyInfo.GetValue(Config, null);
|
||||
}
|
||||
|
||||
public void setConfig(string name, int value)
|
||||
{
|
||||
((IDictionary<String, Object>)Config).TryAdd(name, value);
|
||||
string jsonString = JsonConvert.SerializeObject(Config);
|
||||
File.WriteAllText(configFile, jsonString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class Program
|
||||
{
|
||||
static NotifyIcon trayIcon;
|
||||
public static NotifyIcon trayIcon;
|
||||
|
||||
public static ASUSWmi wmi;
|
||||
public static dynamic config = new System.Dynamic.ExpandoObject();
|
||||
public static AppConfig config;
|
||||
|
||||
public static SettingsForm settingsForm;
|
||||
|
||||
@@ -111,6 +158,8 @@ static class Program
|
||||
|
||||
trayIcon.MouseClick += TrayIcon_MouseClick; ;
|
||||
|
||||
config = new AppConfig();
|
||||
|
||||
wmi = new ASUSWmi();
|
||||
wmi.SubscribeToEvents(WatcherEventArrived);
|
||||
|
||||
@@ -124,41 +173,32 @@ static class Program
|
||||
|
||||
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;
|
||||
config.setConfig ("gpu_mode",GpuMode);
|
||||
|
||||
return GpuMode;
|
||||
|
||||
@@ -193,9 +233,7 @@ static class Program
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
if (settingsForm.Visible)
|
||||
{
|
||||
settingsForm.Hide();
|
||||
} else
|
||||
settingsForm.Hide(); else
|
||||
{
|
||||
settingsForm.Show();
|
||||
settingsForm.Activate();
|
||||
@@ -208,7 +246,7 @@ static class Program
|
||||
{
|
||||
settingsForm.BeginInvoke(delegate
|
||||
{
|
||||
settingsForm.SetPerformanceMode(config.PerformanceMode + 1);
|
||||
settingsForm.SetPerformanceMode(config.getConfig("performance_mode") + 1);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
BIN
Resources/eco.ico
Normal file
BIN
Resources/eco.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
BIN
Resources/icons8-charging-battery-48.png
Normal file
BIN
Resources/icons8-charging-battery-48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 421 B |
BIN
Resources/icons8-laptop-48.png
Normal file
BIN
Resources/icons8-laptop-48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 260 B |
BIN
Resources/icons8-speed-48.png
Normal file
BIN
Resources/icons8-speed-48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 885 B |
BIN
Resources/icons8-video-card-48.png
Normal file
BIN
Resources/icons8-video-card-48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 400 B |
BIN
Resources/ultimate.ico
Normal file
BIN
Resources/ultimate.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
19
Settings.cs
19
Settings.cs
@@ -116,7 +116,8 @@ namespace GHelper
|
||||
break;
|
||||
}
|
||||
|
||||
Program.config.PerformanceMode = PerformanceMode;
|
||||
|
||||
Program.config.setConfig("performance_mode", PerformanceMode);
|
||||
Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, PerformanceMode);
|
||||
|
||||
}
|
||||
@@ -125,13 +126,10 @@ namespace GHelper
|
||||
public void SetGPUMode(int GPUMode = ASUSWmi.GPUModeStandard)
|
||||
{
|
||||
|
||||
int CurrentGPU = ASUSWmi.GPUModeStandard;
|
||||
int CurrentGPU = Program.config.getConfig("gpu_mode");
|
||||
|
||||
if (((IDictionary<String, object>) Program.config).ContainsKey("gpu_mode")) {
|
||||
CurrentGPU = Program.config.gpu_mode;
|
||||
}
|
||||
|
||||
if (CurrentGPU == GPUMode) { return; }
|
||||
if (CurrentGPU == GPUMode)
|
||||
return;
|
||||
|
||||
var restart = false;
|
||||
var changed = false;
|
||||
@@ -168,9 +166,7 @@ namespace GHelper
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
Program.config.gpu_mode = GPUMode;
|
||||
}
|
||||
Program.config.setConfig("gpu_mode", GPUMode);
|
||||
|
||||
if (restart)
|
||||
{
|
||||
@@ -193,14 +189,17 @@ namespace GHelper
|
||||
case ASUSWmi.GPUModeEco:
|
||||
buttonEco.BackColor = colorActive;
|
||||
groupGPU.Text = "GPU Mode: Eco (iGPU only)";
|
||||
Program.trayIcon.Icon = new System.Drawing.Icon("Resources/eco.ico");
|
||||
break;
|
||||
case ASUSWmi.GPUModeUltimate:
|
||||
buttonUltimate.BackColor = colorActive;
|
||||
groupGPU.Text = "GPU Mode: Ultimate (dGPU exclusive)";
|
||||
Program.trayIcon.Icon = new System.Drawing.Icon("Resources/ultimate.ico");
|
||||
break;
|
||||
default:
|
||||
buttonStandard.BackColor = colorActive;
|
||||
groupGPU.Text = "GPU Mode: Eco (iGPU and dGPU)";
|
||||
Program.trayIcon.Icon = new System.Drawing.Icon("Resources/standard.ico");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user