diff --git a/GPDWin2XTUManager/GPDWin2XTUManager.csproj b/GPDWin2XTUManager/GPDWin2XTUManager.csproj
index 4da3e8a..9cee7c4 100644
--- a/GPDWin2XTUManager/GPDWin2XTUManager.csproj
+++ b/GPDWin2XTUManager/GPDWin2XTUManager.csproj
@@ -73,12 +73,16 @@
+
+ ..\packages\TaskScheduler.2.8.6\lib\net452\Microsoft.Win32.TaskScheduler.dll
+
..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll
True
+
@@ -109,6 +113,7 @@
+
diff --git a/GPDWin2XTUManager/Options.Designer.cs b/GPDWin2XTUManager/Options.Designer.cs
index dbe33eb..9fea2b4 100644
--- a/GPDWin2XTUManager/Options.Designer.cs
+++ b/GPDWin2XTUManager/Options.Designer.cs
@@ -42,14 +42,14 @@ private void InitializeComponent()
this.numGPUuv = new System.Windows.Forms.NumericUpDown();
this.label5 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.cmbProfileImage = new System.Windows.Forms.ComboBox();
- this.cmbProfileLogOn = new System.Windows.Forms.ComboBox();
- this.chkProfileLogOn = new System.Windows.Forms.CheckBox();
this.label6 = new System.Windows.Forms.Label();
- this.btnSettingsOK = new System.Windows.Forms.Button();
this.picIcon = new System.Windows.Forms.PictureBox();
+ this.cmbProfileImage = new System.Windows.Forms.ComboBox();
this.btnDeleteProfile = new System.Windows.Forms.Button();
this.btnAddProfile = new System.Windows.Forms.Button();
+ this.cmbProfileLogOn = new System.Windows.Forms.ComboBox();
+ this.chkProfileLogOn = new System.Windows.Forms.CheckBox();
+ this.btnSettingsOK = new System.Windows.Forms.Button();
this.chkIntelDriver = new System.Windows.Forms.CheckBox();
this.tooltipSettings = new System.Windows.Forms.ToolTip(this.components);
((System.ComponentModel.ISupportInitialize)(this.numMinW)).BeginInit();
@@ -246,6 +246,25 @@ private void InitializeComponent()
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Profiles";
//
+ // label6
+ //
+ this.label6.AutoSize = true;
+ this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.label6.Location = new System.Drawing.Point(188, 214);
+ this.label6.Name = "label6";
+ this.label6.Size = new System.Drawing.Size(40, 20);
+ this.label6.TabIndex = 20;
+ this.label6.Text = "Icon";
+ //
+ // picIcon
+ //
+ this.picIcon.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.picIcon.Location = new System.Drawing.Point(511, 189);
+ this.picIcon.Name = "picIcon";
+ this.picIcon.Size = new System.Drawing.Size(50, 50);
+ this.picIcon.TabIndex = 19;
+ this.picIcon.TabStop = false;
+ //
// cmbProfileImage
//
this.cmbProfileImage.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
@@ -258,6 +277,28 @@ private void InitializeComponent()
this.cmbProfileImage.TabIndex = 18;
this.cmbProfileImage.SelectedIndexChanged += new System.EventHandler(this.cmbProfileImage_SelectedIndexChanged);
//
+ // btnDeleteProfile
+ //
+ this.btnDeleteProfile.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.btnDeleteProfile.Image = ((System.Drawing.Image)(resources.GetObject("btnDeleteProfile.Image")));
+ this.btnDeleteProfile.Location = new System.Drawing.Point(108, 232);
+ this.btnDeleteProfile.Name = "btnDeleteProfile";
+ this.btnDeleteProfile.Size = new System.Drawing.Size(74, 59);
+ this.btnDeleteProfile.TabIndex = 8;
+ this.btnDeleteProfile.UseVisualStyleBackColor = true;
+ this.btnDeleteProfile.Click += new System.EventHandler(this.btnDeleteProfile_Click);
+ //
+ // btnAddProfile
+ //
+ this.btnAddProfile.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.btnAddProfile.Image = global::GPDWin2XTUManager.Properties.Resources.Plus;
+ this.btnAddProfile.Location = new System.Drawing.Point(9, 232);
+ this.btnAddProfile.Name = "btnAddProfile";
+ this.btnAddProfile.Size = new System.Drawing.Size(74, 59);
+ this.btnAddProfile.TabIndex = 7;
+ this.btnAddProfile.UseVisualStyleBackColor = true;
+ this.btnAddProfile.Click += new System.EventHandler(this.btnAddProfile_Click);
+ //
// cmbProfileLogOn
//
this.cmbProfileLogOn.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
@@ -283,23 +324,13 @@ private void InitializeComponent()
this.chkProfileLogOn.UseVisualStyleBackColor = true;
this.chkProfileLogOn.CheckedChanged += new System.EventHandler(this.chkProfileLogOn_CheckedChanged);
//
- // label6
- //
- this.label6.AutoSize = true;
- this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.label6.Location = new System.Drawing.Point(188, 214);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(40, 20);
- this.label6.TabIndex = 20;
- this.label6.Text = "Icon";
- //
// btnSettingsOK
//
this.btnSettingsOK.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnSettingsOK.Image = global::GPDWin2XTUManager.Properties.Resources.OK;
this.btnSettingsOK.Location = new System.Drawing.Point(426, 308);
this.btnSettingsOK.Name = "btnSettingsOK";
- this.btnSettingsOK.Size = new System.Drawing.Size(146, 65);
+ this.btnSettingsOK.Size = new System.Drawing.Size(146, 85);
this.btnSettingsOK.TabIndex = 6;
this.btnSettingsOK.Text = "OK";
this.btnSettingsOK.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
@@ -307,37 +338,6 @@ private void InitializeComponent()
this.btnSettingsOK.UseVisualStyleBackColor = true;
this.btnSettingsOK.Click += new System.EventHandler(this.btnSettingsOK_Click);
//
- // picIcon
- //
- this.picIcon.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.picIcon.Location = new System.Drawing.Point(511, 189);
- this.picIcon.Name = "picIcon";
- this.picIcon.Size = new System.Drawing.Size(50, 50);
- this.picIcon.TabIndex = 19;
- this.picIcon.TabStop = false;
- //
- // btnDeleteProfile
- //
- this.btnDeleteProfile.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.btnDeleteProfile.Image = ((System.Drawing.Image)(resources.GetObject("btnDeleteProfile.Image")));
- this.btnDeleteProfile.Location = new System.Drawing.Point(108, 232);
- this.btnDeleteProfile.Name = "btnDeleteProfile";
- this.btnDeleteProfile.Size = new System.Drawing.Size(74, 59);
- this.btnDeleteProfile.TabIndex = 8;
- this.btnDeleteProfile.UseVisualStyleBackColor = true;
- this.btnDeleteProfile.Click += new System.EventHandler(this.btnDeleteProfile_Click);
- //
- // btnAddProfile
- //
- this.btnAddProfile.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.btnAddProfile.Image = global::GPDWin2XTUManager.Properties.Resources.Plus;
- this.btnAddProfile.Location = new System.Drawing.Point(9, 232);
- this.btnAddProfile.Name = "btnAddProfile";
- this.btnAddProfile.Size = new System.Drawing.Size(74, 59);
- this.btnAddProfile.TabIndex = 7;
- this.btnAddProfile.UseVisualStyleBackColor = true;
- this.btnAddProfile.Click += new System.EventHandler(this.btnAddProfile_Click);
- //
// chkIntelDriver
//
this.chkIntelDriver.AutoSize = true;
@@ -346,9 +346,9 @@ private void InitializeComponent()
this.chkIntelDriver.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.chkIntelDriver.Location = new System.Drawing.Point(17, 349);
this.chkIntelDriver.Name = "chkIntelDriver";
- this.chkIntelDriver.Size = new System.Drawing.Size(370, 24);
+ this.chkIntelDriver.Size = new System.Drawing.Size(370, 44);
this.chkIntelDriver.TabIndex = 21;
- this.chkIntelDriver.Text = "Check Intel Graphics driver at application startup";
+ this.chkIntelDriver.Text = "Check Intel Graphics driver at application startup\r\n(EXPERIMENTAL)";
this.tooltipSettings.SetToolTip(this.chkIntelDriver, "Warn about performance issues when having a bad performing Intel Graphics driver " +
"installed.");
this.chkIntelDriver.UseVisualStyleBackColor = true;
@@ -358,7 +358,7 @@ private void InitializeComponent()
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(584, 385);
+ this.ClientSize = new System.Drawing.Size(584, 399);
this.Controls.Add(this.chkIntelDriver);
this.Controls.Add(this.chkProfileLogOn);
this.Controls.Add(this.cmbProfileLogOn);
@@ -369,7 +369,7 @@ private void InitializeComponent()
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(600, 450);
this.MinimizeBox = false;
- this.MinimumSize = new System.Drawing.Size(600, 320);
+ this.MinimumSize = new System.Drawing.Size(600, 438);
this.Name = "Options";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
diff --git a/GPDWin2XTUManager/Options.cs b/GPDWin2XTUManager/Options.cs
index e7eab5c..20166e8 100644
--- a/GPDWin2XTUManager/Options.cs
+++ b/GPDWin2XTUManager/Options.cs
@@ -18,33 +18,42 @@ public Options()
private void Options_Load(object sender, EventArgs e)
{
UpdateProfileList();
- CheckForLogonKey();
+ RemoveRegistryKey();
+ CheckForLogonTask();
FillIconList();
lstOptionsProfiles.SelectedIndex = 0;
chkIntelDriver.Checked = Settings.Default.CheckIntelDriver;
}
+ ///
+ /// Removes existing reg key left by previous versions
+ ///
+ private void RemoveRegistryKey()
+ {
+ RegistryManager.ClearLogonProfileKey();
+ }
+
private void FillIconList()
{
cmbProfileImage.Items.AddRange(Enum.GetNames(typeof(ProfileImage)));
}
- private void CheckForLogonKey()
+ private void CheckForLogonTask()
{
- if (RegistryManager.LogonRegistryKeyExists())
+ if (StartupTaskManager.TaskExists())
{
- // A logon key is defined
+ // A logon task is defined
- if (Profiles.Exists(pr => pr.Name == RegistryManager.GetLogonProfileKeyValue()))
+ if (Profiles.Exists(pr => pr.Name == StartupTaskManager.GetTaskParameter()))
{
// The logon profile still exists
chkProfileLogOn.Checked = true;
- cmbProfileLogOn.SelectedItem = Profiles.Find(pr => pr.Name == RegistryManager.GetLogonProfileKeyValue());
+ cmbProfileLogOn.SelectedItem = Profiles.Find(pr => pr.Name == StartupTaskManager.GetTaskParameter());
}
else
{
- // The logon profile doesn't exist anymore, clear the key
- RegistryManager.ClearLogonProfileKey();
+ // The logon profile doesn't exist anymore, delete the task
+ StartupTaskManager.DeleteTask();
chkProfileLogOn.Checked = false;
cmbProfileLogOn.Enabled = false;
cmbProfileLogOn.SelectedIndex = 0;
@@ -52,7 +61,7 @@ private void CheckForLogonKey()
}
else
{
- // No logon key defined
+ // No logon task defined
chkProfileLogOn.Checked = false;
cmbProfileLogOn.Enabled = false;
cmbProfileLogOn.SelectedIndex = 0;
@@ -151,7 +160,7 @@ private void CreateAndAddNewProfile()
Profiles.Add(newProfile);
UpdateProfileList();
- CheckForLogonKey();
+ CheckForLogonTask();
lstOptionsProfiles.SelectedIndex = lstOptionsProfiles.Items.Count - 1;
}
}
@@ -170,7 +179,7 @@ private void DeleteSelectedProfile()
Profiles.RemoveAt(lstOptionsProfiles.SelectedIndex);
UpdateProfileList();
lstOptionsProfiles.SelectedIndex = 0;
- CheckForLogonKey();
+ CheckForLogonTask();
}
}
else
@@ -193,7 +202,7 @@ private void txtName_TextChanged(object sender, EventArgs e)
// Check for logon key if enabled
if (chkProfileLogOn.Checked)
{
- CheckForLogonKey();
+ CheckForLogonTask();
}
if (selectedProfileIndex > 0)
@@ -246,7 +255,7 @@ private void chkProfileLogOn_CheckedChanged(object sender, EventArgs e)
else
{
cmbProfileLogOn.Enabled = false;
- RegistryManager.ClearLogonProfileKey();
+ StartupTaskManager.DeleteTask();
}
}
@@ -266,7 +275,7 @@ private void AddSelectedProfileInComboboxToLogon()
}
XTUProfile selectedProfile = Profiles[cmbProfileLogOn.SelectedIndex];
- RegistryManager.AddLogonProfileKey(selectedProfile);
+ StartupTaskManager.CreateTask(selectedProfile.Name);
}
private void cmbProfileImage_SelectedIndexChanged(object sender, EventArgs e)
diff --git a/GPDWin2XTUManager/Options.resx b/GPDWin2XTUManager/Options.resx
index dc486cc..1c5bf3f 100644
--- a/GPDWin2XTUManager/Options.resx
+++ b/GPDWin2XTUManager/Options.resx
@@ -138,6 +138,9 @@
17, 17
+
+ 17, 17
+
AAABAAgAgIAAAAEAIAAoCAEAhgAAAGBgAAABACAAqJQAAK4IAQBISAAAAQAgAIhUAABWnQEAQEAAAAEA
diff --git a/GPDWin2XTUManager/Program.cs b/GPDWin2XTUManager/Program.cs
index 9204de1..574808b 100644
--- a/GPDWin2XTUManager/Program.cs
+++ b/GPDWin2XTUManager/Program.cs
@@ -14,9 +14,18 @@ static class Program
[STAThread]
static void Main(string[] args)
{
+ System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm(args));
}
+
+ static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
+ {
+ Console.WriteLine(e.ExceptionObject.ToString());
+ Console.WriteLine("Press Enter to continue");
+ Console.ReadLine();
+ Environment.Exit(1);
+ }
}
}
diff --git a/GPDWin2XTUManager/RegistryManager.cs b/GPDWin2XTUManager/RegistryManager.cs
index 946ac0d..e7764c6 100644
--- a/GPDWin2XTUManager/RegistryManager.cs
+++ b/GPDWin2XTUManager/RegistryManager.cs
@@ -13,13 +13,13 @@ public static class RegistryManager
public static bool LogonRegistryKeyExists()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(Shared.RUN_AT_LOGON_PATH, true);
- return key.GetValue(Shared.APP_REG_KEY_VALUE) != null;
+ return key.GetValue(Shared.APP_NAME_VALUE) != null;
}
public static string GetLogonProfileKeyValue()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(Shared.RUN_AT_LOGON_PATH, true);
- string[] valueArray = key.GetValue(Shared.APP_REG_KEY_VALUE).ToString().Split(' ');
+ string[] valueArray = key.GetValue(Shared.APP_NAME_VALUE).ToString().Split(' ');
//MessageBox.Show(valueArray[valueArray.Length - 1]);//todo: debug, remove
return valueArray[valueArray.Length-1]; // Get profile name by extracting name after last space
}
@@ -28,13 +28,13 @@ public static void AddLogonProfileKey(XTUProfile profile)
{
ClearLogonProfileKey();
RegistryKey key = Registry.CurrentUser.OpenSubKey(Shared.RUN_AT_LOGON_PATH, true);
- key.SetValue(Shared.APP_REG_KEY_VALUE, '"' + Application.ExecutablePath + '"' + " " + profile.Name);
+ key.SetValue(Shared.APP_NAME_VALUE, '"' + Application.ExecutablePath + '"' + " " + profile.Name);
}
public static void ClearLogonProfileKey()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(Shared.RUN_AT_LOGON_PATH, true);
- key.DeleteValue(Shared.APP_REG_KEY_VALUE, false);
+ key.DeleteValue(Shared.APP_NAME_VALUE, false);
}
}
}
diff --git a/GPDWin2XTUManager/Shared.cs b/GPDWin2XTUManager/Shared.cs
index cb7aa9f..f3b949a 100644
--- a/GPDWin2XTUManager/Shared.cs
+++ b/GPDWin2XTUManager/Shared.cs
@@ -17,7 +17,7 @@ public static class Shared
public static readonly decimal VERSION = 1.06m;
public static readonly string SETTINGS_PATH = "Settings.json";
public static readonly string RUN_AT_LOGON_PATH = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
- public static readonly string APP_REG_KEY_VALUE = "GPDWin2XTUManager";
+ public static readonly string APP_NAME_VALUE = "GPDWin2XTUManager";
public static readonly string XTU_PATH = @"C:\Program Files (x86)\Intel\Intel(R) Extreme Tuning Utility\Client\xtucli.exe";
public static Dictionary IMAGE_RESOURCES_DICTIONARY = new Dictionary();
diff --git a/GPDWin2XTUManager/StartupTaskManager.cs b/GPDWin2XTUManager/StartupTaskManager.cs
new file mode 100644
index 0000000..0e7db72
--- /dev/null
+++ b/GPDWin2XTUManager/StartupTaskManager.cs
@@ -0,0 +1,73 @@
+using Microsoft.Win32.TaskScheduler;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Task = Microsoft.Win32.TaskScheduler.Task;
+
+namespace GPDWin2XTUManager
+{
+ public static class StartupTaskManager
+ {
+ public static bool TaskExists()
+ {
+ bool exists = false;
+
+ using (TaskService ts = new TaskService())
+ {
+ Task t = ts.GetTask("GPDWin2XTUManager");
+ exists = (t != null);
+ }
+
+ return exists;
+ }
+
+ public static string GetTaskParameter()
+ {
+ string profile = "";
+
+ using (TaskService ts = new TaskService())
+ {
+ Task t = ts.GetTask(Shared.APP_NAME_VALUE);
+ profile = ((ExecAction)t.Definition.Actions[0]).Arguments;
+ }
+
+ return profile;
+ }
+
+ public static void CreateTask(string profileName)
+ {
+ using (TaskService ts = new TaskService())
+ {
+ // Create a new task definition and assign properties
+ TaskDefinition td = ts.NewTask();
+ td.RegistrationInfo.Description = Shared.APP_NAME_VALUE;
+ td.Principal.LogonType = TaskLogonType.InteractiveToken;
+
+
+ // Add a trigger that will fire the task at logon
+ td.Triggers.Add(new LogonTrigger());
+
+ // Add an action that will launch Notepad whenever the trigger fires
+ td.Actions.Add(new ExecAction(Application.ExecutablePath, profileName , null));
+
+ td.Settings.DisallowStartIfOnBatteries = false;
+ td.Principal.RunLevel = TaskRunLevel.Highest;
+
+ // Register the task in the root folder
+ string taskName = Shared.APP_NAME_VALUE;
+ ts.RootFolder.RegisterTaskDefinition(taskName, td);
+ }
+ }
+
+ public static void DeleteTask()
+ {
+ using (TaskService ts = new TaskService())
+ {
+ ts.RootFolder.DeleteTask(Shared.APP_NAME_VALUE);
+ }
+ }
+ }
+}
diff --git a/GPDWin2XTUManager/packages.config b/GPDWin2XTUManager/packages.config
index 466ab76..1aec224 100644
--- a/GPDWin2XTUManager/packages.config
+++ b/GPDWin2XTUManager/packages.config
@@ -1,4 +1,5 @@
+
\ No newline at end of file