Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
Actually fixed profile logon applying
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDragonBE committed Dec 23, 2018
1 parent 65fb8d7 commit 5156c33
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 69 deletions.
5 changes: 5 additions & 0 deletions GPDWin2XTUManager/GPDWin2XTUManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Win32.TaskScheduler, Version=2.8.6.0, Culture=neutral, PublicKeyToken=c416bc1b32d97233, processorArchitecture=MSIL">
<HintPath>..\packages\TaskScheduler.2.8.6\lib\net452\Microsoft.Win32.TaskScheduler.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Management" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -109,6 +113,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RegistryManager.cs" />
<Compile Include="Shared.cs" />
<Compile Include="StartupTaskManager.cs" />
<Compile Include="UpdateChecks\GithubRelease.cs" />
<Compile Include="UpdateChecks\UpdateChecker.cs" />
<Compile Include="XTUProfile.cs" />
Expand Down
100 changes: 50 additions & 50 deletions GPDWin2XTUManager/Options.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 23 additions & 14 deletions GPDWin2XTUManager/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,50 @@ public Options()
private void Options_Load(object sender, EventArgs e)
{
UpdateProfileList();
CheckForLogonKey();
RemoveRegistryKey();
CheckForLogonTask();
FillIconList();
lstOptionsProfiles.SelectedIndex = 0;
chkIntelDriver.Checked = Settings.Default.CheckIntelDriver;
}

/// <summary>
/// Removes existing reg key left by previous versions
/// </summary>
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;
}
}
else
{
// No logon key defined
// No logon task defined
chkProfileLogOn.Checked = false;
cmbProfileLogOn.Enabled = false;
cmbProfileLogOn.SelectedIndex = 0;
Expand Down Expand Up @@ -151,7 +160,7 @@ private void CreateAndAddNewProfile()

Profiles.Add(newProfile);
UpdateProfileList();
CheckForLogonKey();
CheckForLogonTask();
lstOptionsProfiles.SelectedIndex = lstOptionsProfiles.Items.Count - 1;
}
}
Expand All @@ -170,7 +179,7 @@ private void DeleteSelectedProfile()
Profiles.RemoveAt(lstOptionsProfiles.SelectedIndex);
UpdateProfileList();
lstOptionsProfiles.SelectedIndex = 0;
CheckForLogonKey();
CheckForLogonTask();
}
}
else
Expand All @@ -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)
Expand Down Expand Up @@ -246,7 +255,7 @@ private void chkProfileLogOn_CheckedChanged(object sender, EventArgs e)
else
{
cmbProfileLogOn.Enabled = false;
RegistryManager.ClearLogonProfileKey();
StartupTaskManager.DeleteTask();
}
}

Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions GPDWin2XTUManager/Options.resx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
<metadata name="tooltipSettings.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="tooltipSettings.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAgAgIAAAAEAIAAoCAEAhgAAAGBgAAABACAAqJQAAK4IAQBISAAAAQAgAIhUAABWnQEAQEAAAAEA
Expand Down
9 changes: 9 additions & 0 deletions GPDWin2XTUManager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
8 changes: 4 additions & 4 deletions GPDWin2XTUManager/RegistryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion GPDWin2XTUManager/Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProfileImage, Bitmap> IMAGE_RESOURCES_DICTIONARY = new Dictionary<ProfileImage, Bitmap>();

Expand Down
Loading

0 comments on commit 5156c33

Please sign in to comment.