Skip to content

Commit

Permalink
added icon, cleaned up hotkeycode
Browse files Browse the repository at this point in the history
  • Loading branch information
DejayRezme committed Dec 3, 2020
1 parent f6cfd82 commit 34b60cc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
obj/
Logs/
bin/
res/
WoWStarter.json
1 change: 1 addition & 0 deletions WoWStarter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>false</SelfContained>
<DebugType>embedded</DebugType>
<ApplicationIcon>WoWStarter.ico</ApplicationIcon>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
1 change: 1 addition & 0 deletions WoWStarterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class WoWStarterConfig
public bool subtractTaskbarHeight = false;
public bool closeWoWWithApp = false;
public String maximizeHotkeyString = "Control-Tab";
public String unsecureClipboardString;
public Rectangle PIPPosition = new Rectangle(800, 800, 240, 135);
public Rectangle[] customLayout;

Expand Down
63 changes: 50 additions & 13 deletions WoWStarterForm.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using CryptoTool;

namespace WoWStarter
{
Expand All @@ -25,11 +28,12 @@ public class WoWStarterForm : Form
protected CheckBox taskbarAutohideCheckBox;
protected CheckBox maximizeHotkeyCheckBox;
protected TextBox installPathTextBox;
protected Button clipboardButton;
protected Button launchButton;

int cellPadding = 10;

private bool isHotkeyRegistered = false;
private Dictionary<String, int> hotkeys = new Dictionary<String, int>();

public WoWStarterForm()
{
Expand All @@ -39,6 +43,14 @@ public WoWStarterForm()
this.Text = "WoW Starter";
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
//this.ClientSize = new System.Drawing.Size(800, 450);
try
{ // try setting the app icon from the launched executable
this.Icon = Icon.ExtractAssociatedIcon(AppDomain.CurrentDomain.BaseDirectory + AppDomain.CurrentDomain.FriendlyName + ".exe");
}
catch (System.Exception)
{
this.ShowIcon = false;
}

this.StartPosition = FormStartPosition.Manual;
Point startPosition = System.Windows.Forms.Control.MousePosition;
Expand Down Expand Up @@ -132,7 +144,7 @@ public WoWStarterForm()
maximizeHotkeyCheckBox.AutoSize = true;
maximizeHotkeyCheckBox.Checked = config.maximizeHotkey;
maximizeHotkeyCheckBox.CheckedChanged += new EventHandler(OnMaximizeHotkeyChanged);
AddTableLabelControl("Ctrl+Tab hotkey: ", 0, row++, maximizeHotkeyCheckBox);
AddTableLabelControl("Maximize hotkey: ", 0, row++, maximizeHotkeyCheckBox);
updateHotkeyRegistry(config.maximizeHotkey);

// type in path to wow install. Fun!
Expand All @@ -158,6 +170,18 @@ public WoWStarterForm()

AddTableLabelControl("Install path wow.exe:", 0, row++, installPathTextBox, installFileSelectorButton, 3);

// nothing to see here, move along
if (config.unsecureClipboardString != null)
{
clipboardButton = new Button();
clipboardButton.Text = "Copy";
clipboardButton.AutoSize = true;
clipboardButton.Dock = DockStyle.Right;
clipboardButton.Click += new EventHandler(OnClipboardButtonClicked);
layoutPanel.Controls.Add(clipboardButton);
layoutPanel.SetCellPosition(clipboardButton, new TableLayoutPanelCellPosition(4, row++));
}

// Button to launch wow
launchButton = new Button();
launchButton.Dock = DockStyle.Top;
Expand All @@ -174,6 +198,15 @@ public WoWStarterForm()
this.MinimumSize = new Size(layoutPanel.PreferredSize.Width, layoutPanel.PreferredSize.Height + 50);
}

private void OnClipboardButtonClicked(object sender, EventArgs e)
{
String passphrase = "asldfjasökdlhaeföascnklelökshv";
if (!config.unsecureClipboardString.StartsWith("crypto"))
config.unsecureClipboardString = "crypto" + Crypto.Encrypt(Crypto.GetMACAddress() + config.unsecureClipboardString, passphrase);
String clipboardString = Crypto.Decrypt(config.unsecureClipboardString.Substring(6), passphrase).Substring(12);
System.Windows.Forms.Clipboard.SetText(clipboardString);
}

private void OnInstallFileSelectorClicked(object sender, EventArgs e)
{
FolderBrowserDialog fileDialog = new FolderBrowserDialog();
Expand Down Expand Up @@ -208,12 +241,17 @@ private void OnMaximizeHotkeyChanged(object sender, EventArgs e)
updateHotkeyRegistry(config.maximizeHotkey);
}

private void updateHotkeyRegistry(bool registerHotkey)
private void updateHotkeyRegistry(bool enableHotkey)
{
registerHotkey(enableHotkey, config.maximizeHotkeyString, 1);
}

private void registerHotkey(bool enableHotkey, String hotkeyString, int idCode)
{
// try to read the hotkey definition of the config file
int keyModifier = 0;
int key = -1;
foreach (String hotkeyPart in config.maximizeHotkeyString.Split("-"))
foreach (String hotkeyPart in hotkeyString.Split("-"))
{
try
{
Expand All @@ -229,23 +267,22 @@ private void updateHotkeyRegistry(bool registerHotkey)

if (key == -1)
{
if (registerHotkey)
if (enableHotkey)
MessageBox.Show("Infalid hotkey specified in config file");
return;
}
else
{
if (registerHotkey && !isHotkeyRegistered)
bool isHotkeyRegistered = hotkeys.ContainsKey(hotkeyString);
if (enableHotkey && !isHotkeyRegistered)
{ // hotkey should be active but hasn't been registered
Win32Util.RegisterHotKey(this.Handle, 1, keyModifier, key);
//Win32Util.RegisterHotKey(this.Handle, 2, (int)KeyModifier.Control | (int)KeyModifier.Shift, Keys.Tab.GetHashCode());
isHotkeyRegistered = true;
Win32Util.RegisterHotKey(this.Handle, idCode, keyModifier, key);
hotkeys.Add(hotkeyString, idCode);
}
else if (!registerHotkey && isHotkeyRegistered)
else if (!enableHotkey && isHotkeyRegistered)
{ // hotkey shouldn't be active but still is registered
Win32Util.UnregisterHotKey(this.Handle, 1);
//Win32Util.UnregisterHotKey(this.Handle, 2);
isHotkeyRegistered = false;
Win32Util.UnregisterHotKey(this.Handle, idCode);
hotkeys.Remove(hotkeyString);
}
}
}
Expand Down

0 comments on commit 34b60cc

Please sign in to comment.