WingMan – Diff between revs 23 and 24

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 23 Rev 24
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Collections.ObjectModel; 3 using System.Collections.ObjectModel;
-   4 using System.ComponentModel;
4 using System.Drawing; 5 using System.Drawing;
5 using System.IO; 6 using System.IO;
6 using System.Linq; 7 using System.Linq;
7 using System.Net; 8 using System.Net;
8 using System.Threading; 9 using System.Threading;
9 using System.Threading.Tasks; 10 using System.Threading.Tasks;
10 using System.Windows.Forms; 11 using System.Windows.Forms;
11 using Gma.System.MouseKeyHook; 12 using Gma.System.MouseKeyHook;
12 using MQTTnet.Extensions.ManagedClient; 13 using MQTTnet.Extensions.ManagedClient;
13 using MQTTnet.Server; 14 using MQTTnet.Server;
14 using WingMan.AutoCompletion; 15 using WingMan.AutoCompletion;
15 using WingMan.Bindings; 16 using WingMan.Bindings;
16 using WingMan.Communication; 17 using WingMan.Communication;
17 using WingMan.Lobby; 18 using WingMan.Lobby;
18 using WingMan.Properties; 19 using WingMan.Properties;
19 using WingMan.Utilities; 20 using WingMan.Utilities;
20   21  
21 namespace WingMan 22 namespace WingMan
22 { 23 {
23 public partial class WingManForm : Form 24 public partial class WingManForm : Form
24 { 25 {
25 public WingManForm() 26 public WingManForm()
26 { 27 {
27 InitializeComponent(); 28 InitializeComponent();
28   29  
29 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); 30 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
30 FormCancellationTokenSource = new CancellationTokenSource(); 31 FormCancellationTokenSource = new CancellationTokenSource();
31   32  
32 // Set up autocompletion. 33 // Set up autocompletion.
33 AutoCompletion = new AutoCompletion.AutoCompletion(FormTaskScheduler, FormCancellationTokenSource.Token); 34 AutoCompletion = new AutoCompletion.AutoCompletion(FormTaskScheduler, FormCancellationTokenSource.Token);
34 AutoCompletion.OnSaveFailed += AutoCompletionOnSaveFailed; 35 AutoCompletion.OnSaveFailed += AutoCompletionOnSaveFailed;
35 AutoCompletion.OnLoadFailed += AutoCompletionOnLoadFailed; 36 AutoCompletion.OnLoadFailed += AutoCompletionOnLoadFailed;
36   37  
37 Task.Run(() => AutoCompletion.Load(Address.Name, Address.AutoCompleteCustomSource)); 38 Task.Run(() => AutoCompletion.Load(Address.Name, Address.AutoCompleteCustomSource));
38 Task.Run(() => AutoCompletion.Load(Port.Name, Address.AutoCompleteCustomSource)); 39 Task.Run(() => AutoCompletion.Load(Port.Name, Address.AutoCompleteCustomSource));
39 Task.Run(() => AutoCompletion.Load(Nick.Name, Nick.AutoCompleteCustomSource)); 40 Task.Run(() => AutoCompletion.Load(Nick.Name, Nick.AutoCompleteCustomSource));
40   41  
41 MqttCommunication = new MqttCommunication(FormTaskScheduler, FormCancellationTokenSource.Token); 42 MqttCommunication = new MqttCommunication(FormTaskScheduler, FormCancellationTokenSource.Token);
42 MqttCommunication.OnClientAuthenticationFailed += OnMqttClientAuthenticationFailed; 43 MqttCommunication.OnClientAuthenticationFailed += OnMqttClientAuthenticationFailed;
43 MqttCommunication.OnClientConnectionFailed += OnMqttClientConnectionFailed; 44 MqttCommunication.OnClientConnectionFailed += OnMqttClientConnectionFailed;
44 MqttCommunication.OnClientDisconnected += OnMqttClientDisconnected; 45 MqttCommunication.OnClientDisconnected += OnMqttClientDisconnected;
45 MqttCommunication.OnClientConnected += OnMqttClientConnected; 46 MqttCommunication.OnClientConnected += OnMqttClientConnected;
46 MqttCommunication.OnServerAuthenticationFailed += OnMqttServerAuthenticationFailed; 47 MqttCommunication.OnServerAuthenticationFailed += OnMqttServerAuthenticationFailed;
47 MqttCommunication.OnServerStopped += OnMqttServerStopped; 48 MqttCommunication.OnServerStopped += OnMqttServerStopped;
48 MqttCommunication.OnServerStarted += OnMqttServerStarted; 49 MqttCommunication.OnServerStarted += OnMqttServerStarted;
49 MqttCommunication.OnServerClientConnected += OnMqttServerClientConnected; 50 MqttCommunication.OnServerClientConnected += OnMqttServerClientConnected;
50 MqttCommunication.OnServerClientDisconnected += OnMqttServerClientDisconnected; 51 MqttCommunication.OnServerClientDisconnected += OnMqttServerClientDisconnected;
51   52  
52 LocalKeyBindings = new LocalKeyBindings(new List<KeyBinding>()); 53 LocalKeyBindings = new LocalKeyBindings(new List<KeyBinding>());
53 RemoteKeyBindings = new RemoteKeyBindings(new ObservableCollection<RemoteKeyBinding>()); 54 RemoteKeyBindings = new RemoteKeyBindings(new ObservableCollection<RemoteKeyBinding>());
54   55  
55 LocalListBoxBindingSource = new BindingSource 56 LocalCheckedListBoxBindingSource = new BindingSource
56 { 57 {
57 DataSource = LocalKeyBindings.Bindings 58 DataSource = LocalKeyBindings.Bindings
58 }; 59 };
-   60 LocalCheckedListBoxBindingSource.ListChanged += LocalCheckedListBoxBindingSourceOnListChanged;
59 LocalBindingsListBox.DisplayMember = "DisplayName"; 61 LocalBindingsCheckedListBox.DisplayMember = "DisplayName";
60 LocalBindingsListBox.ValueMember = "Keys"; 62 LocalBindingsCheckedListBox.ValueMember = "Keys";
61 LocalBindingsListBox.DataSource = LocalListBoxBindingSource; 63 LocalBindingsCheckedListBox.DataSource = LocalCheckedListBoxBindingSource;
62   64  
63 KeyBindingsExchange = new KeyBindingsExchange 65 KeyBindingsExchange = new KeyBindingsExchange
64 { 66 {
65 ExchangeBindings = new List<KeyBindingExchange>() 67 ExchangeBindings = new List<KeyBindingExchange>()
66 }; 68 };
67   69  
68 RemoteBindingsComboBoxSource = new BindingSource 70 RemoteBindingsComboBoxSource = new BindingSource
69 { 71 {
70 DataSource = KeyBindingsExchange.ExchangeBindings 72 DataSource = KeyBindingsExchange.ExchangeBindings
71 }; 73 };
72 RemoteBindingsComboBox.DisplayMember = "Nick"; 74 RemoteBindingsComboBox.DisplayMember = "Nick";
73 RemoteBindingsComboBox.ValueMember = "KeyBindings"; 75 RemoteBindingsComboBox.ValueMember = "KeyBindings";
74 RemoteBindingsComboBox.DataSource = RemoteBindingsComboBoxSource; 76 RemoteBindingsComboBox.DataSource = RemoteBindingsComboBoxSource;
75   77  
76 // Start lobby message synchronizer. 78 // Start lobby message synchronizer.
77 LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MqttCommunication, FormTaskScheduler, 79 LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MqttCommunication, FormTaskScheduler,
78 FormCancellationTokenSource.Token); 80 FormCancellationTokenSource.Token);
79 LobbyMessageSynchronizer.OnLobbyMessageReceived += OnLobbyMessageReceived; 81 LobbyMessageSynchronizer.OnLobbyMessageReceived += OnLobbyMessageReceived;
80   82  
81 // Start mouse key bindings synchronizer. 83 // Start mouse key bindings synchronizer.
82 KeyBindingsSynchronizer = new KeyBindingsSynchronizer(LocalKeyBindings, MqttCommunication, 84 KeyBindingsSynchronizer = new KeyBindingsSynchronizer(LocalKeyBindings, MqttCommunication,
83 FormTaskScheduler, FormCancellationTokenSource.Token); 85 FormTaskScheduler, FormCancellationTokenSource.Token);
84 KeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized; 86 KeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized;
85   87  
86 // Start mouse key interceptor. 88 // Start mouse key interceptor.
87 KeyInterceptor = new KeyInterceptor(RemoteKeyBindings, MqttCommunication, FormTaskScheduler, 89 KeyInterceptor = new KeyInterceptor(RemoteKeyBindings, MqttCommunication, FormTaskScheduler,
88 FormCancellationTokenSource.Token); 90 FormCancellationTokenSource.Token);
89 KeyInterceptor.OnMouseKeyBindingMatched += OnMouseKeyBindingMatched; 91 KeyInterceptor.OnMouseKeyBindingMatched += OnMouseKeyBindingMatched;
90   92  
91 // Start mouse key simulator. 93 // Start mouse key simulator.
92 KeySimulator = new KeySimulator(LocalKeyBindings, MqttCommunication, FormTaskScheduler, 94 KeySimulator = new KeySimulator(LocalKeyBindings, MqttCommunication, FormTaskScheduler,
93 FormCancellationTokenSource.Token); 95 FormCancellationTokenSource.Token);
94 KeySimulator.OnMouseKeyBindingExecuting += OnMouseKeyBindingExecuting; 96 KeySimulator.OnMouseKeyBindingExecuting += OnMouseKeyBindingExecuting;
95 } 97 }
96   98  
97 private static AutoCompletion.AutoCompletion AutoCompletion { get; set; } 99 private static AutoCompletion.AutoCompletion AutoCompletion { get; set; }
98 private static CancellationTokenSource FormCancellationTokenSource { get; set; } 100 private static CancellationTokenSource FormCancellationTokenSource { get; set; }
99   101  
100 private static TaskScheduler FormTaskScheduler { get; set; } 102 private static TaskScheduler FormTaskScheduler { get; set; }
101   103  
102 private static IKeyboardMouseEvents MouseKeyApplicationHook { get; set; } 104 private static IKeyboardMouseEvents MouseKeyApplicationHook { get; set; }
103   105  
104 private List<string> MouseKeyCombo { get; set; } 106 private List<string> MouseKeyCombo { get; set; }
105   107  
106 private LocalKeyBindings LocalKeyBindings { get; } 108 private LocalKeyBindings LocalKeyBindings { get; }
107   109  
108 private RemoteKeyBindings RemoteKeyBindings { get; } 110 private RemoteKeyBindings RemoteKeyBindings { get; }
109   111  
110 private BindingSource LocalListBoxBindingSource { get; } 112 private BindingSource LocalCheckedListBoxBindingSource { get; }
111   113  
112 private BindingSource RemoteBindingsComboBoxSource { get; } 114 private BindingSource RemoteBindingsComboBoxSource { get; }
113   115  
114 private KeyBindingsExchange KeyBindingsExchange { get; } 116 private KeyBindingsExchange KeyBindingsExchange { get; }
115   117  
116 public MqttCommunication MqttCommunication { get; set; } 118 public MqttCommunication MqttCommunication { get; set; }
117   119  
118 public LobbyMessageSynchronizer LobbyMessageSynchronizer { get; set; } 120 public LobbyMessageSynchronizer LobbyMessageSynchronizer { get; set; }
119   121  
120 public KeyBindingsSynchronizer KeyBindingsSynchronizer { get; set; } 122 public KeyBindingsSynchronizer KeyBindingsSynchronizer { get; set; }
121   123  
122 public KeyInterceptor KeyInterceptor { get; set; } 124 public KeyInterceptor KeyInterceptor { get; set; }
123   125  
124 public KeySimulator KeySimulator { get; set; } 126 public KeySimulator KeySimulator { get; set; }
-   127  
-   128 private void LocalCheckedListBoxBindingSourceOnListChanged(object sender, ListChangedEventArgs e)
-   129 {
-   130 // Check items
-   131 LocalBindingsCheckedListBox.ItemCheck -= LocalBindingsCheckedListBoxItemCheck;
-   132  
-   133 for (var i = 0; i < LocalKeyBindings.Bindings.Count; ++i)
-   134 switch (LocalKeyBindings.Bindings[i].Enabled)
-   135 {
-   136 case true:
-   137 LocalBindingsCheckedListBox.SetItemCheckState(i, CheckState.Checked);
-   138 break;
-   139 default:
-   140 LocalBindingsCheckedListBox.SetItemCheckState(i, CheckState.Unchecked);
-   141 break;
-   142 }
-   143  
-   144 LocalBindingsCheckedListBox.ItemCheck += LocalBindingsCheckedListBoxItemCheck;
-   145 }
125   146  
126 private void AutoCompletionOnLoadFailed(object sender, AutoCompletionFailedEventArgs args) 147 private void AutoCompletionOnLoadFailed(object sender, AutoCompletionFailedEventArgs args)
127 { 148 {
128 ActivityTextBox.AppendText( 149 ActivityTextBox.AppendText(
129 $"{Strings.Failed_loading_autocomplete_source} : {args.Name} : {args.Exception.Message}{Environment.NewLine}"); 150 $"{Strings.Failed_loading_autocomplete_source} : {args.Name} : {args.Exception.Message}{Environment.NewLine}");
130 } 151 }
131   152  
132 private void AutoCompletionOnSaveFailed(object sender, AutoCompletionFailedEventArgs args) 153 private void AutoCompletionOnSaveFailed(object sender, AutoCompletionFailedEventArgs args)
133 { 154 {
134 ActivityTextBox.AppendText( 155 ActivityTextBox.AppendText(
135 $"{Strings.Failed_saving_autocomplete_source} : {args.Name} : {args.Exception.Message}{Environment.NewLine}"); 156 $"{Strings.Failed_saving_autocomplete_source} : {args.Name} : {args.Exception.Message}{Environment.NewLine}");
136 } 157 }
137   158  
138 /// <inheritdoc /> 159 /// <inheritdoc />
139 /// <summary> 160 /// <summary>
140 /// Clean up any resources being used. 161 /// Clean up any resources being used.
141 /// </summary> 162 /// </summary>
142 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 163 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
143 protected override void Dispose(bool disposing) 164 protected override void Dispose(bool disposing)
144 { 165 {
145 FormCancellationTokenSource?.Dispose(); 166 FormCancellationTokenSource?.Dispose();
146 FormCancellationTokenSource = null; 167 FormCancellationTokenSource = null;
147   168  
148 if (disposing && components != null) 169 if (disposing && components != null)
149 { 170 {
150 components.Dispose(); 171 components.Dispose();
151 components = null; 172 components = null;
152 } 173 }
153   174  
154 base.Dispose(disposing); 175 base.Dispose(disposing);
155 } 176 }
156   177  
157 private void OnMouseKeyBindingExecuting(object sender, KeyBindingExecutingEventArgs args) 178 private void OnMouseKeyBindingExecuting(object sender, KeyBindingExecutingEventArgs args)
158 { 179 {
159 ActivityTextBox.AppendText( 180 ActivityTextBox.AppendText(
160 $"{Strings.Executing_binding_from_remote_client} : {args.Nick} : {args.Name}{Environment.NewLine}"); 181 $"{Strings.Executing_binding_from_remote_client} : {args.Nick} : {args.Name}{Environment.NewLine}");
161 } 182 }
162   183  
163 private void OnMouseKeyBindingMatched(object sender, KeyBindingMatchedEventArgs args) 184 private void OnMouseKeyBindingMatched(object sender, KeyBindingMatchedEventArgs args)
164 { 185 {
165 ActivityTextBox.AppendText( 186 ActivityTextBox.AppendText(
166 $"{Strings.Matched_remote_key_binding} : {args.Nick} : {args.Name} : {string.Join(" + ", args.KeyCombo)}{Environment.NewLine}"); 187 $"{Strings.Matched_remote_key_binding} : {args.Nick} : {args.Name} : {string.Join(" + ", args.KeyCombo)}{Environment.NewLine}");
167 } 188 }
168   189  
169 private void OnMqttServerClientDisconnected(object sender, MqttClientDisconnectedEventArgs e) 190 private void OnMqttServerClientDisconnected(object sender, MqttClientDisconnectedEventArgs e)
170 { 191 {
171 ActivityTextBox.AppendText( 192 ActivityTextBox.AppendText(
172 $"{Strings.Client_disconnected}{Environment.NewLine}"); 193 $"{Strings.Client_disconnected}{Environment.NewLine}");
173 } 194 }
174   195  
175 private void OnMqttServerClientConnected(object sender, MqttClientConnectedEventArgs e) 196 private void OnMqttServerClientConnected(object sender, MqttClientConnectedEventArgs e)
176 { 197 {
177 ActivityTextBox.AppendText( 198 ActivityTextBox.AppendText(
178 $"{Strings.Client_connected}{Environment.NewLine}"); 199 $"{Strings.Client_connected}{Environment.NewLine}");
179 } 200 }
180   201  
181 private void OnMqttServerStarted(object sender, EventArgs e) 202 private void OnMqttServerStarted(object sender, EventArgs e)
182 { 203 {
183 ActivityTextBox.AppendText( 204 ActivityTextBox.AppendText(
184 $"{Strings.Server_started}{Environment.NewLine}"); 205 $"{Strings.Server_started}{Environment.NewLine}");
185 } 206 }
186   207  
187 private void OnMqttServerStopped(object sender, EventArgs e) 208 private void OnMqttServerStopped(object sender, EventArgs e)
188 { 209 {
189 ActivityTextBox.AppendText( 210 ActivityTextBox.AppendText(
190 $"{Strings.Server_stopped}{Environment.NewLine}"); 211 $"{Strings.Server_stopped}{Environment.NewLine}");
191 } 212 }
192   213  
193 private void OnMqttClientConnected(object sender, MQTTnet.Client.MqttClientConnectedEventArgs e) 214 private void OnMqttClientConnected(object sender, MQTTnet.Client.MqttClientConnectedEventArgs e)
194 { 215 {
195 ActivityTextBox.AppendText( 216 ActivityTextBox.AppendText(
196 $"{Strings.Client_connected}{Environment.NewLine}"); 217 $"{Strings.Client_connected}{Environment.NewLine}");
197 } 218 }
198   219  
199 private void OnMqttClientDisconnected(object sender, MQTTnet.Client.MqttClientDisconnectedEventArgs e) 220 private void OnMqttClientDisconnected(object sender, MQTTnet.Client.MqttClientDisconnectedEventArgs e)
200 { 221 {
201 ActivityTextBox.AppendText( 222 ActivityTextBox.AppendText(
202 $"{Strings.Client_disconnected}{Environment.NewLine}"); 223 $"{Strings.Client_disconnected}{Environment.NewLine}");
203 } 224 }
204   225  
205 private void OnMqttClientConnectionFailed(object sender, MqttManagedProcessFailedEventArgs e) 226 private void OnMqttClientConnectionFailed(object sender, MqttManagedProcessFailedEventArgs e)
206 { 227 {
207 ActivityTextBox.AppendText( 228 ActivityTextBox.AppendText(
208 $"{Strings.Client_connection_failed}{Environment.NewLine}"); 229 $"{Strings.Client_connection_failed}{Environment.NewLine}");
209 } 230 }
210   231  
211 private void OnMqttServerAuthenticationFailed(object sender, MqttAuthenticationFailureEventArgs e) 232 private void OnMqttServerAuthenticationFailed(object sender, MqttAuthenticationFailureEventArgs e)
212 { 233 {
213 ActivityTextBox.AppendText( 234 ActivityTextBox.AppendText(
214 $"{Strings.Failed_to_authenticate_client} : {e.Exception}{Environment.NewLine}"); 235 $"{Strings.Failed_to_authenticate_client} : {e.Exception}{Environment.NewLine}");
215 } 236 }
216   237  
217 private void OnMqttClientAuthenticationFailed(object sender, MqttAuthenticationFailureEventArgs e) 238 private void OnMqttClientAuthenticationFailed(object sender, MqttAuthenticationFailureEventArgs e)
218 { 239 {
219 ActivityTextBox.AppendText( 240 ActivityTextBox.AppendText(
220 $"{Strings.Failed_to_authenticate_with_server} : {e.Exception}{Environment.NewLine}"); 241 $"{Strings.Failed_to_authenticate_with_server} : {e.Exception}{Environment.NewLine}");
221 } 242 }
222   243  
223 private void OnMouseKeyBindingsSynchronized(object sender, KeyBindingsSynchronizerEventArgs e) 244 private void OnMouseKeyBindingsSynchronized(object sender, KeyBindingsSynchronizerEventArgs e)
224 { 245 {
225 ActivityTextBox.AppendText( 246 ActivityTextBox.AppendText(
226 $"{Strings.Synchronized_bindings_with_client} : {e.Bindings.Nick} : {e.Bindings.KeyBindings.Count}{Environment.NewLine}"); 247 $"{Strings.Synchronized_bindings_with_client} : {e.Bindings.Nick} : {e.Bindings.KeyBindings.Count}{Environment.NewLine}");
227   248  
228 var exchangeBindings = KeyBindingsExchange.ExchangeBindings.FirstOrDefault(exchangeBinding => 249 var exchangeBindings = KeyBindingsExchange.ExchangeBindings.FirstOrDefault(exchangeBinding =>
229 string.Equals(exchangeBinding.Nick, e.Bindings.Nick, StringComparison.Ordinal)); 250 string.Equals(exchangeBinding.Nick, e.Bindings.Nick, StringComparison.Ordinal));
230   251  
231 // If the nick does not exist then add it. 252 // If the nick does not exist then add it.
232 if (exchangeBindings == null) 253 if (exchangeBindings == null)
233 { 254 {
234 KeyBindingsExchange.ExchangeBindings.Add(e.Bindings); 255 KeyBindingsExchange.ExchangeBindings.Add(e.Bindings);
235 RemoteBindingsComboBoxSource.ResetBindings(false); 256 RemoteBindingsComboBoxSource.ResetBindings(false);
236 UpdateRemoteItems(); 257 UpdateRemoteItems();
237 return; 258 return;
238 } 259 }
239   260  
240 // If the bindings for the nick have not changed then do not update. 261 // If the bindings for the nick have not changed then do not update.
241 if (exchangeBindings.KeyBindings.SequenceEqual(e.Bindings.KeyBindings)) 262 if (exchangeBindings.KeyBindings.SequenceEqual(e.Bindings.KeyBindings))
242 { 263 {
243 RemoteBindingsComboBoxSource.ResetBindings(false); 264 RemoteBindingsComboBoxSource.ResetBindings(false);
244 UpdateRemoteItems(); 265 UpdateRemoteItems();
245 return; 266 return;
246 } 267 }
247   268  
248 // Update the bindings. 269 // Update the bindings.
249 exchangeBindings.KeyBindings = e.Bindings.KeyBindings; 270 exchangeBindings.KeyBindings = e.Bindings.KeyBindings;
250 RemoteBindingsComboBoxSource.ResetBindings(false); 271 RemoteBindingsComboBoxSource.ResetBindings(false);
251 UpdateRemoteItems(); 272 UpdateRemoteItems();
252 } 273 }
253   274  
254 private void UpdateRemoteItems() 275 private void UpdateRemoteItems()
255 { 276 {
256 var exchangeBindings = (List<KeyBinding>) RemoteBindingsComboBox.SelectedValue; 277 var exchangeBindings = (List<KeyBinding>) RemoteBindingsComboBox.SelectedValue;
257 if (exchangeBindings == null) 278 if (exchangeBindings == null)
258 return; 279 return;
259   280  
260 var replaceMouseBindings = new ObservableCollection<RemoteKeyBinding>(); 281 var replaceMouseBindings = new ObservableCollection<RemoteKeyBinding>();
261 foreach (var remoteBinding in RemoteKeyBindings.Bindings) 282 foreach (var remoteBinding in RemoteKeyBindings.Bindings)
262 { 283 {
263 if (!exchangeBindings.Any(binding => 284 if (!exchangeBindings.Any(binding =>
264 string.Equals(binding.Name, remoteBinding.Name, StringComparison.Ordinal))) 285 string.Equals(binding.Name, remoteBinding.Name, StringComparison.Ordinal)))
265 continue; 286 continue;
266   287  
267 replaceMouseBindings.Add(remoteBinding); 288 replaceMouseBindings.Add(remoteBinding);
268 } 289 }
269   290  
270 RemoteKeyBindings.Bindings.Clear(); 291 RemoteKeyBindings.Bindings.Clear();
271 foreach (var binding in replaceMouseBindings) RemoteKeyBindings.Bindings.Add(binding); 292 foreach (var binding in replaceMouseBindings) RemoteKeyBindings.Bindings.Add(binding);
272   293  
273 RemoteBindingsListBox.Items.Clear(); 294 RemoteBindingsListBox.Items.Clear();
274 RemoteBindingsListBox.DisplayMember = "Name"; 295 RemoteBindingsListBox.DisplayMember = "Name";
275 RemoteBindingsListBox.ValueMember = "Name"; 296 RemoteBindingsListBox.ValueMember = "Name";
276 var bindings = exchangeBindings.Select(binding => (object) binding.Name).ToArray(); 297 var bindings = exchangeBindings.Select(binding => (object) binding.Name).ToArray();
277 if (bindings.Length == 0) 298 if (bindings.Length == 0)
278 return; 299 return;
279   300  
280 RemoteBindingsListBox.Items.AddRange(bindings); 301 RemoteBindingsListBox.Items.AddRange(bindings);
281 } 302 }
282   303  
283 private void OnLobbyMessageReceived(object sender, LobbyMessageReceivedEventArgs e) 304 private void OnLobbyMessageReceived(object sender, LobbyMessageReceivedEventArgs e)
284 { 305 {
285 LobbyTextBox.AppendText($"{e.Nick} : {e.Message}{Environment.NewLine}"); 306 LobbyTextBox.AppendText($"{e.Nick} : {e.Message}{Environment.NewLine}");
286 } 307 }
287   308  
288 private void AddressTextBoxClick(object sender, EventArgs e) 309 private void AddressTextBoxClick(object sender, EventArgs e)
289 { 310 {
290 Address.BackColor = Color.Empty; 311 Address.BackColor = Color.Empty;
291 } 312 }
292   313  
293 private void PortTextBoxClick(object sender, EventArgs e) 314 private void PortTextBoxClick(object sender, EventArgs e)
294 { 315 {
295 Port.BackColor = Color.Empty; 316 Port.BackColor = Color.Empty;
296 } 317 }
297   318  
298 private async void HostButtonClickAsync(object sender, EventArgs e) 319 private async void HostButtonClickAsync(object sender, EventArgs e)
299 { 320 {
300 // Stop the MQTT server if it is running. 321 // Stop the MQTT server if it is running.
301 if (MqttCommunication.Running) 322 if (MqttCommunication.Running)
302 { 323 {
303 await MqttCommunication.Stop(); 324 await MqttCommunication.Stop();
304 HostButton.BackColor = Color.Empty; 325 HostButton.BackColor = Color.Empty;
305   326  
306 // Enable controls. 327 // Enable controls.
307 ConnectButton.Enabled = true; 328 ConnectButton.Enabled = true;
308 Address.Enabled = true; 329 Address.Enabled = true;
309 Port.Enabled = true; 330 Port.Enabled = true;
310 Nick.Enabled = true; 331 Nick.Enabled = true;
311 Password.Enabled = true; 332 Password.Enabled = true;
312 return; 333 return;
313 } 334 }
314   335  
315 if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password)) 336 if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password))
316 return; 337 return;
317   338  
318 StoreConnectionAutocomplete(); 339 StoreConnectionAutocomplete();
319   340  
320 // Start the MQTT server. 341 // Start the MQTT server.
321 if (!await MqttCommunication 342 if (!await MqttCommunication
322 .Start(MqttCommunicationType.Server, ipAddress, port, nick, password)) 343 .Start(MqttCommunicationType.Server, ipAddress, port, nick, password))
323 { 344 {
324 ActivityTextBox.AppendText( 345 ActivityTextBox.AppendText(
325 $"{Strings.Failed_starting_server}{Environment.NewLine}"); 346 $"{Strings.Failed_starting_server}{Environment.NewLine}");
326 return; 347 return;
327 } 348 }
328   349  
329 HostButton.BackColor = Color.Aquamarine; 350 HostButton.BackColor = Color.Aquamarine;
330   351  
331 // Disable controls 352 // Disable controls
332 ConnectButton.Enabled = false; 353 ConnectButton.Enabled = false;
333 Address.Enabled = false; 354 Address.Enabled = false;
334 Port.Enabled = false; 355 Port.Enabled = false;
335 Nick.Enabled = false; 356 Nick.Enabled = false;
336 Password.Enabled = false; 357 Password.Enabled = false;
337 } 358 }
338   359  
339 private async void StoreConnectionAutocomplete() 360 private async void StoreConnectionAutocomplete()
340 { 361 {
341 Address.AutoCompleteCustomSource.Add(Address.Text); 362 Address.AutoCompleteCustomSource.Add(Address.Text);
342   363  
343 await AutoCompletion.Save(Address.Name, Address.AutoCompleteCustomSource); 364 await AutoCompletion.Save(Address.Name, Address.AutoCompleteCustomSource);
344   365  
345 Port.AutoCompleteCustomSource.Add(Port.Text); 366 Port.AutoCompleteCustomSource.Add(Port.Text);
346   367  
347 await AutoCompletion.Save(Port.Name, Port.AutoCompleteCustomSource); 368 await AutoCompletion.Save(Port.Name, Port.AutoCompleteCustomSource);
348   369  
349 Nick.AutoCompleteCustomSource.Add(Nick.Text); 370 Nick.AutoCompleteCustomSource.Add(Nick.Text);
350   371  
351 await AutoCompletion.Save(Nick.Name, Nick.AutoCompleteCustomSource); 372 await AutoCompletion.Save(Nick.Name, Nick.AutoCompleteCustomSource);
352 } 373 }
353   374  
354 private bool ValidateConnectionParameters( 375 private bool ValidateConnectionParameters(
355 out IPAddress address, 376 out IPAddress address,
356 out int port, 377 out int port,
357 out string nick, 378 out string nick,
358 out string password) 379 out string password)
359 { 380 {
360 address = IPAddress.Any; 381 address = IPAddress.Any;
361 port = 0; 382 port = 0;
362 nick = string.Empty; 383 nick = string.Empty;
363 password = string.Empty; 384 password = string.Empty;
364   385  
365 if (string.IsNullOrEmpty(Address.Text) && 386 if (string.IsNullOrEmpty(Address.Text) &&
366 string.IsNullOrEmpty(Port.Text) && 387 string.IsNullOrEmpty(Port.Text) &&
367 string.IsNullOrEmpty(Nick.Text) && 388 string.IsNullOrEmpty(Nick.Text) &&
368 string.IsNullOrEmpty(Password.Text)) 389 string.IsNullOrEmpty(Password.Text))
369 { 390 {
370 Address.BackColor = Color.LightPink; 391 Address.BackColor = Color.LightPink;
371 Port.BackColor = Color.LightPink; 392 Port.BackColor = Color.LightPink;
372 Nick.BackColor = Color.LightPink; 393 Nick.BackColor = Color.LightPink;
373 Password.BackColor = Color.LightPink; 394 Password.BackColor = Color.LightPink;
374 return false; 395 return false;
375 } 396 }
376   397  
377 if (!IPAddress.TryParse(Address.Text, out address)) 398 if (!IPAddress.TryParse(Address.Text, out address))
378 try 399 try
379 { 400 {
380 address = Dns.GetHostAddresses(Address.Text).FirstOrDefault(); 401 address = Dns.GetHostAddresses(Address.Text).FirstOrDefault();
381 } 402 }
382 catch (Exception ex) 403 catch (Exception ex)
383 { 404 {
384 ActivityTextBox.AppendText( 405 ActivityTextBox.AppendText(
385 $"{Strings.Could_not_resolve_hostname} : {ex.Message}{Environment.NewLine}"); 406 $"{Strings.Could_not_resolve_hostname} : {ex.Message}{Environment.NewLine}");
386   407  
387 Address.BackColor = Color.LightPink; 408 Address.BackColor = Color.LightPink;
388 return false; 409 return false;
389 } 410 }
390   411  
391 if (!uint.TryParse(Port.Text, out var uPort)) 412 if (!uint.TryParse(Port.Text, out var uPort))
392 { 413 {
393 Port.BackColor = Color.LightPink; 414 Port.BackColor = Color.LightPink;
394 return false; 415 return false;
395 } 416 }
396   417  
397 port = (int) uPort; 418 port = (int) uPort;
398   419  
399 if (string.IsNullOrEmpty(Nick.Text)) 420 if (string.IsNullOrEmpty(Nick.Text))
400 { 421 {
401 Nick.BackColor = Color.LightPink; 422 Nick.BackColor = Color.LightPink;
402 return false; 423 return false;
403 } 424 }
404   425  
405 nick = Nick.Text; 426 nick = Nick.Text;
406   427  
407 if (string.IsNullOrEmpty(Password.Text)) 428 if (string.IsNullOrEmpty(Password.Text))
408 { 429 {
409 Password.BackColor = Color.LightPink; 430 Password.BackColor = Color.LightPink;
410 return false; 431 return false;
411 } 432 }
412   433  
413 password = AES.ExpandKey(Password.Text); 434 password = AES.ExpandKey(Password.Text);
414   435  
415 Address.BackColor = Color.Empty; 436 Address.BackColor = Color.Empty;
416 Port.BackColor = Color.Empty; 437 Port.BackColor = Color.Empty;
417 Nick.BackColor = Color.Empty; 438 Nick.BackColor = Color.Empty;
418 Password.BackColor = Color.Empty; 439 Password.BackColor = Color.Empty;
419   440  
420 return true; 441 return true;
421 } 442 }
422   443  
423 private async void ConnectButtonClickAsync(object sender, EventArgs e) 444 private async void ConnectButtonClickAsync(object sender, EventArgs e)
424 { 445 {
425 if (MqttCommunication.Running) 446 if (MqttCommunication.Running)
426 { 447 {
427 await MqttCommunication.Stop(); 448 await MqttCommunication.Stop();
428 ConnectButton.Text = Strings.Connect; 449 ConnectButton.Text = Strings.Connect;
429 ConnectButton.BackColor = Color.Empty; 450 ConnectButton.BackColor = Color.Empty;
430   451  
431 Address.Enabled = true; 452 Address.Enabled = true;
432 Port.Enabled = true; 453 Port.Enabled = true;
433 Nick.Enabled = true; 454 Nick.Enabled = true;
434 Password.Enabled = true; 455 Password.Enabled = true;
435 HostButton.Enabled = true; 456 HostButton.Enabled = true;
436 return; 457 return;
437 } 458 }
438   459  
439 if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password)) 460 if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password))
440 return; 461 return;
441   462  
442 StoreConnectionAutocomplete(); 463 StoreConnectionAutocomplete();
443   464  
444 if (!await MqttCommunication 465 if (!await MqttCommunication
445 .Start(MqttCommunicationType.Client, ipAddress, port, nick, password)) 466 .Start(MqttCommunicationType.Client, ipAddress, port, nick, password))
446 { 467 {
447 ActivityTextBox.AppendText( 468 ActivityTextBox.AppendText(
448 $"{Strings.Failed_starting_client}{Environment.NewLine}"); 469 $"{Strings.Failed_starting_client}{Environment.NewLine}");
449 return; 470 return;
450 } 471 }
451   472  
452 ConnectButton.Text = Strings.Disconnect; 473 ConnectButton.Text = Strings.Disconnect;
453 ConnectButton.BackColor = Color.Aquamarine; 474 ConnectButton.BackColor = Color.Aquamarine;
454   475  
455 HostButton.Enabled = false; 476 HostButton.Enabled = false;
456 Address.Enabled = false; 477 Address.Enabled = false;
457 Port.Enabled = false; 478 Port.Enabled = false;
458 Nick.Enabled = false; 479 Nick.Enabled = false;
459 Password.Enabled = false; 480 Password.Enabled = false;
460 } 481 }
461   482  
462 private async void LobbySayTextBoxKeyDown(object sender, KeyEventArgs e) 483 private async void LobbySayTextBoxKeyDown(object sender, KeyEventArgs e)
463 { 484 {
464 if (e.KeyCode != Keys.Enter) 485 if (e.KeyCode != Keys.Enter)
465 return; 486 return;
466   487  
467 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text); 488 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text);
468   489  
469 LobbySayTextBox.Text = string.Empty; 490 LobbySayTextBox.Text = string.Empty;
470 } 491 }
471   492  
472 private void LocalAddBindingButtonClick(object sender, EventArgs e) 493 private void LocalAddBindingButtonClick(object sender, EventArgs e)
473 { 494 {
474 if (string.IsNullOrEmpty(LocalNameTextBox.Text)) 495 if (string.IsNullOrEmpty(LocalNameTextBox.Text))
475 { 496 {
476 LocalNameTextBox.BackColor = Color.LightPink; 497 LocalNameTextBox.BackColor = Color.LightPink;
477 return; 498 return;
478 } 499 }
479   500  
480 // Only unique names allowed. 501 // Only unique names allowed.
481 if (LocalKeyBindings.Bindings.Any(binding => 502 if (LocalKeyBindings.Bindings.Any(binding =>
482 string.Equals(binding.Name, LocalNameTextBox.Text, StringComparison.Ordinal))) 503 string.Equals(binding.Name, LocalNameTextBox.Text, StringComparison.Ordinal)))
483 { 504 {
484 LocalNameTextBox.BackColor = Color.LightPink; 505 LocalNameTextBox.BackColor = Color.LightPink;
485 LocalBindingsListBox.BackColor = Color.LightPink; 506 LocalBindingsCheckedListBox.BackColor = Color.LightPink;
486 return; 507 return;
487 } 508 }
488   509  
489 LocalNameTextBox.BackColor = Color.Empty; 510 LocalNameTextBox.BackColor = Color.Empty;
490 LocalBindingsListBox.BackColor = Color.Empty; 511 LocalBindingsCheckedListBox.BackColor = Color.Empty;
491   512  
492 ShowOverlayPanel(); 513 ShowOverlayPanel();
493   514  
494 MouseKeyCombo = new List<string>(); 515 MouseKeyCombo = new List<string>();
495   516  
496 MouseKeyApplicationHook = Hook.GlobalEvents(); 517 MouseKeyApplicationHook = Hook.GlobalEvents();
497 MouseKeyApplicationHook.KeyUp += LocalMouseKeyHookOnKeyUp; 518 MouseKeyApplicationHook.KeyUp += LocalMouseKeyHookOnKeyUp;
498 MouseKeyApplicationHook.KeyDown += LocalMouseKeyHookOnKeyDown; 519 MouseKeyApplicationHook.KeyDown += LocalMouseKeyHookOnKeyDown;
499 } 520 }
500   521  
501 private void ShowOverlayPanel() 522 private void ShowOverlayPanel()
502 { 523 {
503 OverlayPanel.BringToFront(); 524 OverlayPanel.BringToFront();
504 OverlayPanel.Visible = true; 525 OverlayPanel.Visible = true;
505 OverlayPanel.Invalidate(); 526 OverlayPanel.Invalidate();
506 } 527 }
507   528  
508 private async void LocalMouseKeyHookOnKeyUp(object sender, KeyEventArgs e) 529 private async void LocalMouseKeyHookOnKeyUp(object sender, KeyEventArgs e)
509 { 530 {
510 LocalKeyBindings.Bindings.Add(new KeyBinding(LocalNameTextBox.Text, MouseKeyCombo)); 531 LocalKeyBindings.Bindings.Add(new KeyBinding(LocalNameTextBox.Text, MouseKeyCombo));
511   532  
512 LocalListBoxBindingSource.ResetBindings(false); 533 LocalCheckedListBoxBindingSource.ResetBindings(false);
513   534  
514 MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown; 535 MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown;
515 MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp; 536 MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp;
516   537  
517 MouseKeyApplicationHook.Dispose(); 538 MouseKeyApplicationHook.Dispose();
518   539  
519 LocalNameTextBox.Text = string.Empty; 540 LocalNameTextBox.Text = string.Empty;
520 HideOverlayPanel(); 541 HideOverlayPanel();
521   542  
522 await SaveLocalMouseKeyBindings(); 543 await SaveLocalMouseKeyBindings();
523 } 544 }
524   545  
525 private void HideOverlayPanel() 546 private void HideOverlayPanel()
526 { 547 {
527 OverlayPanel.SendToBack(); 548 OverlayPanel.SendToBack();
528 OverlayPanel.Visible = false; 549 OverlayPanel.Visible = false;
529 OverlayPanel.Invalidate(); 550 OverlayPanel.Invalidate();
530 } 551 }
531   552  
532 private void LocalMouseKeyHookOnKeyDown(object sender, KeyEventArgs e) 553 private void LocalMouseKeyHookOnKeyDown(object sender, KeyEventArgs e)
533 { 554 {
534 e.SuppressKeyPress = true; 555 e.SuppressKeyPress = true;
535   556  
536 KeyConversion.KeysToString.TryGetValue((byte) e.KeyCode, out var key); 557 KeyConversion.KeysToString.TryGetValue((byte) e.KeyCode, out var key);
537   558  
538 MouseKeyCombo.Add(key); 559 MouseKeyCombo.Add(key);
539 } 560 }
540   561  
541 private void LocalNameTextBoxClick(object sender, EventArgs e) 562 private void LocalNameTextBoxClick(object sender, EventArgs e)
542 { 563 {
543 LocalNameTextBox.BackColor = Color.Empty; 564 LocalNameTextBox.BackColor = Color.Empty;
544 } 565 }
545   566  
546 private async void LocalBindingsRemoveButtonClick(object sender, EventArgs e) 567 private async void LocalBindingsRemoveButtonClick(object sender, EventArgs e)
547 { 568 {
548 var helmBinding = (KeyBinding) LocalBindingsListBox.SelectedItem; 569 var helmBinding = (KeyBinding) LocalBindingsCheckedListBox.SelectedItem;
549 if (helmBinding == null) 570 if (helmBinding == null)
550 return; 571 return;
551   572  
552 LocalKeyBindings.Bindings.Remove(helmBinding); 573 LocalKeyBindings.Bindings.Remove(helmBinding);
553 LocalListBoxBindingSource.ResetBindings(false); 574 LocalCheckedListBoxBindingSource.ResetBindings(false);
554   575  
555 await SaveLocalMouseKeyBindings(); 576 await SaveLocalMouseKeyBindings();
556 } 577 }
557   578  
558 private async void LobbySayButtonClick(object sender, EventArgs e) 579 private async void LobbySayButtonClick(object sender, EventArgs e)
559 { 580 {
560 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text); 581 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text);
561   582  
562 LobbySayTextBox.Text = string.Empty; 583 LobbySayTextBox.Text = string.Empty;
563 } 584 }
564   585  
565 private void RemoteBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e) 586 private void RemoteBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e)
566 { 587 {
567 UpdateRemoteItems(); 588 UpdateRemoteItems();
568 } 589 }
569   590  
570 private async void WingManFormOnLoad(object sender, EventArgs e) 591 private async void WingManFormOnLoad(object sender, EventArgs e)
571 { 592 {
572 await LoadLocalMouseKeyBindings(); 593 await LoadLocalMouseKeyBindings();
573   594  
574 await LoadRemoteMouseKeyBindings(); 595 await LoadRemoteMouseKeyBindings();
575 } 596 }
576   597  
577 private void RemoteBindingsBindButtonClicked(object sender, EventArgs e) 598 private void RemoteBindingsBindButtonClicked(object sender, EventArgs e)
578 { 599 {
579 if (string.IsNullOrEmpty((string) RemoteBindingsListBox.SelectedItem)) 600 if (string.IsNullOrEmpty((string) RemoteBindingsListBox.SelectedItem))
580 { 601 {
581 RemoteBindingsListBox.BackColor = Color.LightPink; 602 RemoteBindingsListBox.BackColor = Color.LightPink;
582 return; 603 return;
583 } 604 }
584   605  
585 RemoteBindingsListBox.BackColor = Color.Empty; 606 RemoteBindingsListBox.BackColor = Color.Empty;
586   607  
587 ShowOverlayPanel(); 608 ShowOverlayPanel();
588   609  
589 MouseKeyCombo = new List<string>(); 610 MouseKeyCombo = new List<string>();
590   611  
591 MouseKeyApplicationHook = Hook.GlobalEvents(); 612 MouseKeyApplicationHook = Hook.GlobalEvents();
592 MouseKeyApplicationHook.KeyUp += RemoteKeyHookOnKeyUp; 613 MouseKeyApplicationHook.KeyUp += RemoteKeyHookOnKeyUp;
593 MouseKeyApplicationHook.KeyDown += RemoteKeyHookOnKeyDown; 614 MouseKeyApplicationHook.KeyDown += RemoteKeyHookOnKeyDown;
594 } 615 }
595   616  
596 private void RemoteBindingsUnbindButtonClicked(object sender, EventArgs e) 617 private void RemoteBindingsUnbindButtonClicked(object sender, EventArgs e)
597 { 618 {
598 var item = (string) RemoteBindingsListBox.SelectedItem; 619 var item = (string) RemoteBindingsListBox.SelectedItem;
599 if (string.IsNullOrEmpty(item)) 620 if (string.IsNullOrEmpty(item))
600 { 621 {
601 RemoteBindingsListBox.BackColor = Color.LightPink; 622 RemoteBindingsListBox.BackColor = Color.LightPink;
602 return; 623 return;
603 } 624 }
604   625  
605 RemoteBindingsListBox.BackColor = Color.Empty; 626 RemoteBindingsListBox.BackColor = Color.Empty;
606   627  
607 var remoteKeyBinding = RemoteKeyBindings.Bindings.FirstOrDefault(binding => 628 var remoteKeyBinding = RemoteKeyBindings.Bindings.FirstOrDefault(binding =>
608 string.Equals(binding.Name, item, StringComparison.Ordinal)); 629 string.Equals(binding.Name, item, StringComparison.Ordinal));
609   630  
610 if (remoteKeyBinding == null) 631 if (remoteKeyBinding == null)
611 return; 632 return;
612   633  
613 RemoteKeyBindings.Bindings.Remove(remoteKeyBinding); 634 RemoteKeyBindings.Bindings.Remove(remoteKeyBinding);
614 RemoteBindingsBindToBox.Text = string.Empty; 635 RemoteBindingsBindToBox.Text = string.Empty;
615 } 636 }
616   637  
617 private void RemoteKeyHookOnKeyDown(object sender, KeyEventArgs e) 638 private void RemoteKeyHookOnKeyDown(object sender, KeyEventArgs e)
618 { 639 {
619 e.SuppressKeyPress = true; 640 e.SuppressKeyPress = true;
620   641  
621 if (!KeyConversion.KeysToString.TryGetValue((byte) e.KeyCode, out var key)) 642 if (!KeyConversion.KeysToString.TryGetValue((byte) e.KeyCode, out var key))
622 return; 643 return;
623   644  
624 MouseKeyCombo.Add(key); 645 MouseKeyCombo.Add(key);
625 } 646 }
626   647  
627 private async void RemoteKeyHookOnKeyUp(object sender, KeyEventArgs e) 648 private async void RemoteKeyHookOnKeyUp(object sender, KeyEventArgs e)
628 { 649 {
629 RemoteKeyBindings.Bindings.Add(new RemoteKeyBinding(RemoteBindingsComboBox.Text, 650 RemoteKeyBindings.Bindings.Add(new RemoteKeyBinding(RemoteBindingsComboBox.Text,
630 (string) RemoteBindingsListBox.SelectedItem, MouseKeyCombo)); 651 (string) RemoteBindingsListBox.SelectedItem, MouseKeyCombo));
631   652  
632 MouseKeyApplicationHook.KeyDown -= RemoteKeyHookOnKeyDown; 653 MouseKeyApplicationHook.KeyDown -= RemoteKeyHookOnKeyDown;
633 MouseKeyApplicationHook.KeyUp -= RemoteKeyHookOnKeyUp; 654 MouseKeyApplicationHook.KeyUp -= RemoteKeyHookOnKeyUp;
634   655  
635 MouseKeyApplicationHook.Dispose(); 656 MouseKeyApplicationHook.Dispose();
636   657  
637 RemoteBindingsBindToBox.Text = string.Join(" + ", MouseKeyCombo); 658 RemoteBindingsBindToBox.Text = string.Join(" + ", MouseKeyCombo);
638 HideOverlayPanel(); 659 HideOverlayPanel();
639   660  
640 await SaveRemoteMouseKeyBindings(); 661 await SaveRemoteMouseKeyBindings();
641 } 662 }
642   663  
643 private void RemoteBindingsListBoxSelectedValueChanged(object sender, EventArgs e) 664 private void RemoteBindingsListBoxSelectedValueChanged(object sender, EventArgs e)
644 { 665 {
645 RemoteBindingsBindToBox.Text = ""; 666 RemoteBindingsBindToBox.Text = "";
646   667  
647 var name = (string) RemoteBindingsListBox.SelectedItem; 668 var name = (string) RemoteBindingsListBox.SelectedItem;
648 if (string.IsNullOrEmpty(name)) 669 if (string.IsNullOrEmpty(name))
649 return; 670 return;
650   671  
651 var nick = RemoteBindingsComboBox.Text; 672 var nick = RemoteBindingsComboBox.Text;
652 if (string.IsNullOrEmpty(nick)) 673 if (string.IsNullOrEmpty(nick))
653 return; 674 return;
654   675  
655 foreach (var binding in RemoteKeyBindings.Bindings) 676 foreach (var binding in RemoteKeyBindings.Bindings)
656 { 677 {
657 if (!string.Equals(binding.Nick, nick) || !string.Equals(binding.Name, name)) 678 if (!string.Equals(binding.Nick, nick) || !string.Equals(binding.Name, name))
658 continue; 679 continue;
659   680  
660 RemoteBindingsBindToBox.Text = string.Join(" + ", binding.Keys); 681 RemoteBindingsBindToBox.Text = string.Join(" + ", binding.Keys);
661 break; 682 break;
662 } 683 }
663 } 684 }
664   685  
665 private void WingManFormResized(object sender, EventArgs e) 686 private void WingManFormResized(object sender, EventArgs e)
666 { 687 {
667 if (WindowState == FormWindowState.Minimized) 688 if (WindowState == FormWindowState.Minimized)
668 { 689 {
669 Hide(); 690 Hide();
670 notifyIcon1.Visible = true; 691 notifyIcon1.Visible = true;
671 } 692 }
672 } 693 }
673   694  
674 private void NotifyIconDoubleClick(object sender, EventArgs e) 695 private void NotifyIconDoubleClick(object sender, EventArgs e)
675 { 696 {
676 Show(); 697 Show();
677 WindowState = FormWindowState.Normal; 698 WindowState = FormWindowState.Normal;
678 notifyIcon1.Visible = false; 699 notifyIcon1.Visible = false;
679 } 700 }
-   701  
-   702 private async void LocalBindingsCheckedListBoxItemCheck(object sender, ItemCheckEventArgs e)
-   703 {
-   704 var helmBinding = (KeyBinding) LocalBindingsCheckedListBox.Items[e.Index];
-   705 if (helmBinding == null)
-   706 return;
-   707  
-   708 switch (e.NewValue)
-   709 {
-   710 case CheckState.Checked:
-   711 helmBinding.Enabled = true;
-   712 break;
-   713 case CheckState.Unchecked:
-   714 helmBinding.Enabled = false;
-   715 break;
-   716 }
-   717  
-   718 await SaveLocalMouseKeyBindings();
-   719 }
680   720  
681 #region Saving and loading 721 #region Saving and loading
682   722  
683 private async Task SaveLocalMouseKeyBindings() 723 private async Task SaveLocalMouseKeyBindings()
684 { 724 {
685 try 725 try
686 { 726 {
687 using (var memoryStream = new MemoryStream()) 727 using (var memoryStream = new MemoryStream())
688 { 728 {
689 LocalKeyBindings.XmlSerializer.Serialize(memoryStream, LocalKeyBindings); 729 LocalKeyBindings.XmlSerializer.Serialize(memoryStream, LocalKeyBindings);
690   730  
691 memoryStream.Position = 0L; 731 memoryStream.Position = 0L;
692   732  
693 using (var fileStream = new FileStream("LocalKeyBindings.xml", FileMode.Create)) 733 using (var fileStream = new FileStream("LocalKeyBindings.xml", FileMode.Create))
694 { 734 {
695 await memoryStream.CopyToAsync(fileStream); 735 await memoryStream.CopyToAsync(fileStream);
696 } 736 }
697 } 737 }
698 } 738 }
699 catch (Exception) 739 catch (Exception)
700 { 740 {
701 ActivityTextBox.AppendText( 741 ActivityTextBox.AppendText(
702 $"{Strings.Failed_saving_local_bindings}{Environment.NewLine}"); 742 $"{Strings.Failed_saving_local_bindings}{Environment.NewLine}");
703 } 743 }
704 } 744 }
705   745  
706 private async Task LoadLocalMouseKeyBindings() 746 private async Task LoadLocalMouseKeyBindings()
707 { 747 {
708 try 748 try
709 { 749 {
710 using (var fileStream = new FileStream("LocalKeyBindings.xml", FileMode.Open)) 750 using (var fileStream = new FileStream("LocalKeyBindings.xml", FileMode.Open))
711 { 751 {
712 using (var memoryStream = new MemoryStream()) 752 using (var memoryStream = new MemoryStream())
713 { 753 {
714 await fileStream.CopyToAsync(memoryStream); 754 await fileStream.CopyToAsync(memoryStream);
715   755  
716 memoryStream.Position = 0L; 756 memoryStream.Position = 0L;
717   757  
718 var loadedBindings = 758 var loadedBindings =
719 (LocalKeyBindings) LocalKeyBindings.XmlSerializer.Deserialize(memoryStream); 759 (LocalKeyBindings) LocalKeyBindings.XmlSerializer.Deserialize(memoryStream);
720   760  
721 foreach (var binding in loadedBindings.Bindings) 761 foreach (var binding in loadedBindings.Bindings)
722 LocalKeyBindings.Bindings.Add(binding); 762 LocalKeyBindings.Bindings.Add(binding);
-   763  
723   764  
724 LocalListBoxBindingSource.ResetBindings(false); 765 LocalCheckedListBoxBindingSource.ResetBindings(false);
725 } 766 }
726 } 767 }
727 } 768 }
728 catch (Exception) 769 catch (Exception)
729 { 770 {
730 ActivityTextBox.AppendText( 771 ActivityTextBox.AppendText(
731 $"{Strings.Failed_loading_local_bindings}{Environment.NewLine}"); 772 $"{Strings.Failed_loading_local_bindings}{Environment.NewLine}");
732 } 773 }
733 } 774 }
734   775  
735 private async Task SaveRemoteMouseKeyBindings() 776 private async Task SaveRemoteMouseKeyBindings()
736 { 777 {
737 try 778 try
738 { 779 {
739 using (var memoryStream = new MemoryStream()) 780 using (var memoryStream = new MemoryStream())
740 { 781 {
741 RemoteKeyBindings.XmlSerializer.Serialize(memoryStream, RemoteKeyBindings); 782 RemoteKeyBindings.XmlSerializer.Serialize(memoryStream, RemoteKeyBindings);
742   783  
743 memoryStream.Position = 0L; 784 memoryStream.Position = 0L;
744   785  
745 using (var fileStream = new FileStream("RemoteKeyBindings.xml", FileMode.Create)) 786 using (var fileStream = new FileStream("RemoteKeyBindings.xml", FileMode.Create))
746 { 787 {
747 await memoryStream.CopyToAsync(fileStream); 788 await memoryStream.CopyToAsync(fileStream);
748 } 789 }
749 } 790 }
750 } 791 }
751 catch (Exception) 792 catch (Exception)
752 { 793 {
753 ActivityTextBox.AppendText( 794 ActivityTextBox.AppendText(
754 $"{Strings.Failed_saving_remote_bindings}{Environment.NewLine}"); 795 $"{Strings.Failed_saving_remote_bindings}{Environment.NewLine}");
755 } 796 }
756 } 797 }
757   798  
758 private async Task LoadRemoteMouseKeyBindings() 799 private async Task LoadRemoteMouseKeyBindings()
759 { 800 {
760 try 801 try
761 { 802 {
762 using (var fileStream = new FileStream("RemoteKeyBindings.xml", FileMode.Open)) 803 using (var fileStream = new FileStream("RemoteKeyBindings.xml", FileMode.Open))
763 { 804 {
764 using (var memoryStream = new MemoryStream()) 805 using (var memoryStream = new MemoryStream())
765 { 806 {
766 await fileStream.CopyToAsync(memoryStream); 807 await fileStream.CopyToAsync(memoryStream);
767   808  
768 memoryStream.Position = 0L; 809 memoryStream.Position = 0L;
769   810  
770 var loadedBindings = 811 var loadedBindings =
771 (RemoteKeyBindings) RemoteKeyBindings.XmlSerializer.Deserialize(memoryStream); 812 (RemoteKeyBindings) RemoteKeyBindings.XmlSerializer.Deserialize(memoryStream);
772   813  
773 foreach (var binding in loadedBindings.Bindings) 814 foreach (var binding in loadedBindings.Bindings)
774 RemoteKeyBindings.Bindings.Add(binding); 815 RemoteKeyBindings.Bindings.Add(binding);
775 } 816 }
776 } 817 }
777 } 818 }
778 catch (Exception) 819 catch (Exception)
779 { 820 {
780 ActivityTextBox.AppendText( 821 ActivityTextBox.AppendText(
781 $"{Strings.Failed_loading_remote_bindings}{Environment.NewLine}"); 822 $"{Strings.Failed_loading_remote_bindings}{Environment.NewLine}");
782 } 823 }
783 } 824 }
784   825  
785 #endregion 826 #endregion
786 } 827 }
787 } 828 }
788   829