WingMan – Diff between revs 8 and 9

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 8 Rev 9
Line 1... Line 1...
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Drawing; 3 using System.Drawing;
-   4 using System.IO;
4 using System.Linq; 5 using System.Linq;
5 using System.Net; 6 using System.Net;
6 using System.Threading; 7 using System.Threading;
7 using System.Threading.Tasks; 8 using System.Threading.Tasks;
8 using System.Windows.Forms; 9 using System.Windows.Forms;
9 using Gma.System.MouseKeyHook; 10 using Gma.System.MouseKeyHook;
-   11 using MQTTnet.Extensions.ManagedClient;
-   12 using MQTTnet.Server;
10 using WingMan.Communication; 13 using WingMan.Communication;
11 using WingMan.Lobby; 14 using WingMan.Lobby;
12 using WingMan.MouseKey; 15 using WingMan.MouseKey;
13 using WingMan.Properties; 16 using WingMan.Properties;
14 using WingMan.Utilities; 17 using WingMan.Utilities;
Line 22... Line 25...
22 InitializeComponent(); 25 InitializeComponent();
Line 23... Line 26...
23   26  
24 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); 27 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
Line 25... Line 28...
25 FormCancellationTokenSource = new CancellationTokenSource(); 28 FormCancellationTokenSource = new CancellationTokenSource();
26   29  
-   30 MqttCommunication = new MqttCommunication(FormTaskScheduler, FormCancellationTokenSource.Token);
-   31 MqttCommunication.OnClientAuthenticationFailed += OnMqttClientAuthenticationFailed;
-   32 MqttCommunication.OnClientConnectionFailed += OnMqttClientConnectionFailed;
27 MQTTCommunication = new MQTTCommunication(FormTaskScheduler, FormCancellationTokenSource.Token); 33 MqttCommunication.OnClientDisconnected += OnMqttClientDisconnected;
-   34 MqttCommunication.OnClientConnected += OnMqttClientConnected;
-   35 MqttCommunication.OnServerAuthenticationFailed += OnMqttServerAuthenticationFailed;
-   36 MqttCommunication.OnServerStopped += OnMqttServerStopped;
-   37 MqttCommunication.OnServerStarted += OnMqttServerStarted;
Line 28... Line 38...
28 MQTTCommunication.OnClientAuthenticationFailed += OnMQTTClientAuthenticationFailed; 38 MqttCommunication.OnServerClientConnected += OnMqttServerClientConnected;
-   39 MqttCommunication.OnServerClientDisconnected += OnMqttServerClientDisconnected;
Line 29... Line 40...
29 MQTTCommunication.OnServerAuthenticationFailed += OnMQTTServerAuthenticationFailed; 40  
30   41 LocalMouseKeyBindings = new MouseKeyBindings(new List<MouseKeyBinding>());
31 MouseKeyBindings = new MouseKeyBindings(new List<MouseKeyBinding>()); 42 RemoteMouseKeyBindings = new RemoteMouseKeyBindings(new List<RemoteMouseKeyBinding>());
32   43  
33 HelmListBoxBindingSource = new BindingSource 44 LocalListBoxBindingSource = new BindingSource
34 { 45 {
35 DataSource = MouseKeyBindings.Bindings 46 DataSource = LocalMouseKeyBindings.Bindings
Line 36... Line 47...
36 }; 47 };
37 HelmBindingsListBox.DisplayMember = "DisplayName"; 48 LocalBindingsListBox.DisplayMember = "DisplayName";
38 HelmBindingsListBox.ValueMember = "Keys"; 49 LocalBindingsListBox.ValueMember = "Keys";
39 HelmBindingsListBox.DataSource = HelmListBoxBindingSource; 50 LocalBindingsListBox.DataSource = LocalListBoxBindingSource;
Line 40... Line 51...
40   51  
41 MouseKeyBindingsExchange = new MouseKeyBindingsExchange 52 MouseKeyBindingsExchange = new MouseKeyBindingsExchange
42 { 53 {
43 ExchangeBindings = new List<MouseKeyBindingExchange>() 54 ExchangeBindings = new List<MouseKeyBindingExchange>()
44 }; 55 };
45   56  
46 WingBindingsComboBoxSource = new BindingSource 57 RemoteBindingsComboBoxSource = new BindingSource
Line 47... Line 58...
47 { 58 {
48 DataSource = MouseKeyBindingsExchange.ExchangeBindings 59 DataSource = MouseKeyBindingsExchange.ExchangeBindings
49 }; 60 };
50 WingBindingsComboBox.DisplayMember = "Nick"; 61 RemoteBindingsComboBox.DisplayMember = "Nick";
Line 51... Line 62...
51 WingBindingsComboBox.ValueMember = "MouseKeyBindings"; 62 RemoteBindingsComboBox.ValueMember = "MouseKeyBindings";
52 WingBindingsComboBox.DataSource = WingBindingsComboBoxSource; 63 RemoteBindingsComboBox.DataSource = RemoteBindingsComboBoxSource;
53   64  
54 // Start lobby message synchronizer. 65 // Start lobby message synchronizer.
-   66 LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MqttCommunication, FormTaskScheduler,
-   67 FormCancellationTokenSource.Token);
55 LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MQTTCommunication, FormTaskScheduler, 68 LobbyMessageSynchronizer.OnLobbyMessageReceived += OnLobbyMessageReceived;
Line 56... Line 69...
56 FormCancellationTokenSource.Token); 69  
Line 57... Line 70...
57 LobbyMessageSynchronizer.OnLobbyMessageReceived += OnLobbyMessageReceived; 70 // Start mouse key bindings synchronizer.
Line 58... Line 71...
58   71 MouseKeyBindingsSynchronizer = new MouseKeyBindingsSynchronizer(LocalMouseKeyBindings, MqttCommunication,
Line 59... Line 72...
59 // Start mouse key bindings synchronizer. 72 FormTaskScheduler, FormCancellationTokenSource.Token);
Line 60... Line 73...
60 MouseKeyBindingsSynchronizer = new MouseKeyBindingsSynchronizer(MouseKeyBindings, MQTTCommunication, 73 MouseKeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized;
-   74  
-   75 // Start key binding simulator.
Line 61... Line 76...
61 FormTaskScheduler, FormCancellationTokenSource.Token); 76 }
Line 62... Line 77...
62 MouseKeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized; 77  
Line 63... Line 78...
63 } 78 private static CancellationTokenSource FormCancellationTokenSource { get; set; }
Line 64... Line 79...
64   79  
Line 65... Line 80...
65 private static CancellationTokenSource FormCancellationTokenSource { get; set; } 80 private static TaskScheduler FormTaskScheduler { get; set; }
Line 66... Line 81...
66   81  
Line -... Line 82...
-   82 private static IKeyboardMouseEvents MouseKeyApplicationHook { get; set; }
-   83  
-   84 private List<string> MouseKeyCombo { get; set; }
-   85  
-   86 private MouseKeyBindings LocalMouseKeyBindings { get; }
-   87  
-   88 private RemoteMouseKeyBindings RemoteMouseKeyBindings { get; }
-   89  
-   90 private BindingSource LocalListBoxBindingSource { get; }
-   91  
-   92 private BindingSource RemoteBindingsComboBoxSource { get; }
-   93  
-   94 private MouseKeyBindingsExchange MouseKeyBindingsExchange { get; }
-   95  
-   96 public MqttCommunication MqttCommunication { get; set; }
-   97  
-   98 public LobbyMessageSynchronizer LobbyMessageSynchronizer { get; set; }
-   99  
-   100 public MouseKeyBindingsSynchronizer MouseKeyBindingsSynchronizer { get; set; }
-   101  
-   102 private async Task SaveLocalMouseKeyBindings()
-   103 {
-   104 try
-   105 {
-   106 using (var memoryStream = new MemoryStream())
-   107 {
-   108 MouseKeyBindings.XmlSerializer.Serialize(memoryStream, LocalMouseKeyBindings);
-   109  
-   110 memoryStream.Position = 0L;
-   111  
-   112 using (var fileStream = new FileStream("LocalMouseKeyBindings.xml", FileMode.Create))
-   113 {
-   114 await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false);
-   115 }
-   116 }
-   117 }
-   118 catch (Exception)
-   119 {
-   120 ActivityTextBox.AppendText(
-   121 $"{Strings.Failed_saving_local_bindings}{Environment.NewLine}");
-   122 }
-   123 }
-   124  
-   125 private void OnMqttServerClientDisconnected(object sender, MqttClientDisconnectedEventArgs e)
-   126 {
-   127 ActivityTextBox.AppendText(
-   128 $"{Strings.Client_disconnected}{Environment.NewLine}");
-   129 }
-   130  
-   131 private void OnMqttServerClientConnected(object sender, MqttClientConnectedEventArgs e)
-   132 {
-   133 ActivityTextBox.AppendText(
-   134 $"{Strings.Client_connected}{Environment.NewLine}");
-   135 }
-   136  
-   137 private void OnMqttServerStarted(object sender, EventArgs e)
-   138 {
-   139 ActivityTextBox.AppendText(
-   140 $"{Strings.Server_started}{Environment.NewLine}");
-   141 }
-   142  
-   143 private void OnMqttServerStopped(object sender, EventArgs e)
-   144 {
-   145 ActivityTextBox.AppendText(
-   146 $"{Strings.Server_stopped}{Environment.NewLine}");
67 private static TaskScheduler FormTaskScheduler { get; set; } 147 }
68   148  
69 private static IKeyboardMouseEvents MouseKeyApplicationHook { get; set; } 149 private void OnMqttClientConnected(object sender, MQTTnet.Client.MqttClientConnectedEventArgs e)
70   150 {
71 private List<string> MouseKeyCombo { get; set; } 151 ActivityTextBox.AppendText(
Line 72... Line 152...
72   152 $"{Strings.Client_connected}{Environment.NewLine}");
73 private MouseKeyBindings MouseKeyBindings { get; } 153 }
74   154  
75 private BindingSource HelmListBoxBindingSource { get; } 155 private void OnMqttClientDisconnected(object sender, MQTTnet.Client.MqttClientDisconnectedEventArgs e)
76   156 {
Line 123... Line 203...
123   203  
124 // If the nick does not exist then add it. 204 // If the nick does not exist then add it.
125 if (exchangeBindings == null) 205 if (exchangeBindings == null)
126 { 206 {
127 MouseKeyBindingsExchange.ExchangeBindings.Add(e.Bindings); 207 MouseKeyBindingsExchange.ExchangeBindings.Add(e.Bindings);
128 WingBindingsComboBoxSource.ResetBindings(false); 208 RemoteBindingsComboBoxSource.ResetBindings(false);
129 UpdateWingListBoxItems(); 209 UpdateRemoteListBoxItems();
130 return; 210 return;
Line 131... Line 211...
131 } 211 }
132   212  
133 // If the bindings for the nick have not changed then do not update. 213 // If the bindings for the nick have not changed then do not update.
134 if (exchangeBindings.MouseKeyBindings.SequenceEqual(e.Bindings.MouseKeyBindings)) 214 if (exchangeBindings.MouseKeyBindings.SequenceEqual(e.Bindings.MouseKeyBindings))
135 { 215 {
136 WingBindingsComboBoxSource.ResetBindings(false); 216 RemoteBindingsComboBoxSource.ResetBindings(false);
137 UpdateWingListBoxItems(); 217 UpdateRemoteListBoxItems();
Line 138... Line 218...
138 return; 218 return;
139 } 219 }
140   220  
141 // Update the bindings. 221 // Update the bindings.
142 exchangeBindings.MouseKeyBindings = e.Bindings.MouseKeyBindings; 222 exchangeBindings.MouseKeyBindings = e.Bindings.MouseKeyBindings;
Line 143... Line 223...
143 WingBindingsComboBoxSource.ResetBindings(false); 223 RemoteBindingsComboBoxSource.ResetBindings(false);
144 UpdateWingListBoxItems(); 224 UpdateRemoteListBoxItems();
145 } 225 }
146   226  
147 private void UpdateWingListBoxItems() 227 private void UpdateRemoteListBoxItems()
Line 148... Line 228...
148 { 228 {
149 var exchangeBinding = (List<MouseKeyBinding>) WingBindingsComboBox.SelectedValue; 229 var exchangeBinding = (List<MouseKeyBinding>) RemoteBindingsComboBox.SelectedValue;
150 if (exchangeBinding == null) 230 if (exchangeBinding == null)
151 return; 231 return;
152   232  
153 WingBindingsListBox.Items.Clear(); 233 RemoteBindingsListBox.Items.Clear();
Line 154... Line 234...
154 WingBindingsListBox.DisplayMember = "Name"; 234 RemoteBindingsListBox.DisplayMember = "Name";
155 WingBindingsListBox.ValueMember = "Name"; 235 RemoteBindingsListBox.ValueMember = "Name";
Line 156... Line 236...
156 var i = exchangeBinding.Select(binding => (object) binding.Name).ToArray(); 236 var i = exchangeBinding.Select(binding => (object) binding.Name).ToArray();
157 if (i.Length == 0) 237 if (i.Length == 0)
158 return; -  
159   -  
160 WingBindingsListBox.Items.AddRange(i); 238 return;
161 } -  
162   239  
Line 163... Line 240...
163 private void OnLobbyMessageReceived(object sender, LobbyMessageReceivedEventArgs e) 240 RemoteBindingsListBox.Items.AddRange(i);
164 { 241 }
165 LobbyTextBox.Invoke((MethodInvoker) delegate 242  
Line 179... Line 256...
179 } 256 }
Line 180... Line 257...
180   257  
181 private async void HostButtonClickAsync(object sender, EventArgs e) 258 private async void HostButtonClickAsync(object sender, EventArgs e)
182 { 259 {
183 // Stop the MQTT server if it is running. 260 // Stop the MQTT server if it is running.
184 if (MQTTCommunication.Running) 261 if (MqttCommunication.Running)
185 { 262 {
186 await MQTTCommunication.Stop().ConfigureAwait(false); -  
187 toolStripStatusLabel.Text = Strings.Server_stopped; 263 await MqttCommunication.Stop().ConfigureAwait(false);
Line 188... Line 264...
188 HostButton.BackColor = Color.Empty; 264 HostButton.BackColor = Color.Empty;
189   265  
190 // Enable controls. 266 // Enable controls.
Line 198... Line 274...
198   274  
199 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) 275 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password))
Line 200... Line 276...
200 return; 276 return;
201   277  
202 // Start the MQTT server. 278 // Start the MQTT server.
-   279 if (!await MqttCommunication.Start(MqttCommunicationType.Server, ipAddress, port, nick, password)
-   280 .ConfigureAwait(false))
203 await MQTTCommunication.Start(MQTTCommunicationType.Server, ipAddress, port, nick, password) 281 {
-   282 ActivityTextBox.AppendText(
-   283 $"{Strings.Failed_starting_server}{Environment.NewLine}");
-   284 return;
204 .ConfigureAwait(false); 285 }
Line 205... Line 286...
205 toolStripStatusLabel.Text = Strings.Server_started; 286  
206 HostButton.BackColor = Color.Aquamarine; 287 HostButton.BackColor = Color.Aquamarine;
207   288  
Line 269... Line 350...
269 return true; 350 return true;
270 } 351 }
Line 271... Line 352...
271   352  
272 private async void ConnectButtonClickAsync(object sender, EventArgs e) 353 private async void ConnectButtonClickAsync(object sender, EventArgs e)
273 { 354 {
274 if (MQTTCommunication.Running) 355 if (MqttCommunication.Running)
275 { 356 {
276 await MQTTCommunication.Stop().ConfigureAwait(false); 357 await MqttCommunication.Stop().ConfigureAwait(false);
277 ConnectButton.Text = Strings.Connect; 358 ConnectButton.Text = Strings.Connect;
Line 278... Line 359...
278 ConnectButton.BackColor = Color.Empty; 359 ConnectButton.BackColor = Color.Empty;
279   360  
Line 285... Line 366...
285 } 366 }
Line 286... Line 367...
286   367  
287 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) 368 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password))
Line 288... Line 369...
288 return; 369 return;
289   370  
-   371 if (!await MqttCommunication.Start(MqttCommunicationType.Client, ipAddress, port, nick, password)
-   372 .ConfigureAwait(false))
-   373 {
-   374 ActivityTextBox.AppendText(
-   375 $"{Strings.Failed_starting_client}{Environment.NewLine}");
Line 290... Line -...
290 await MQTTCommunication.Start(MQTTCommunicationType.Client, ipAddress, port, nick, password) -  
291 .ConfigureAwait(false); 376 return;
292   377 }
Line 293... Line 378...
293 toolStripStatusLabel.Text = Strings.Client_started; 378  
294 ConnectButton.Text = Strings.Disconnect; 379 ConnectButton.Text = Strings.Disconnect;
Line 310... Line 395...
310 LobbySayTextBox.Text = string.Empty; 395 LobbySayTextBox.Text = string.Empty;
311 } 396 }
Line 312... Line 397...
312   397  
313 private void HelmAddButtonClick(object sender, EventArgs e) 398 private void HelmAddButtonClick(object sender, EventArgs e)
314 { 399 {
315 if (string.IsNullOrEmpty(HelmNameTextBox.Text)) 400 if (string.IsNullOrEmpty(LocalNameTextBox.Text))
316 { 401 {
317 HelmNameTextBox.BackColor = Color.LightPink; 402 LocalNameTextBox.BackColor = Color.LightPink;
318 return; 403 return;
Line 319... Line 404...
319 } 404 }
Line 320... Line 405...
320   405  
Line 321... Line 406...
321 ShowOverlayPanel(); 406 ShowOverlayPanel();
322   407  
323 MouseKeyCombo = new List<string>(); 408 MouseKeyCombo = new List<string>();
324   409  
325 MouseKeyApplicationHook = Hook.AppEvents(); 410 MouseKeyApplicationHook = Hook.AppEvents();
326 MouseKeyApplicationHook.MouseDown += MouseKeyHookOnMouseDown; 411 MouseKeyApplicationHook.MouseDown += LocalMouseKeyHookOnMouseDown;
Line 327... Line 412...
327 MouseKeyApplicationHook.KeyUp += MouseKeyHookOnKeyUp; 412 MouseKeyApplicationHook.KeyUp += LocalMouseKeyHookOnKeyUp;
328 MouseKeyApplicationHook.KeyDown += MouseKeyHookOnKeyDown; 413 MouseKeyApplicationHook.KeyDown += LocalMouseKeyHookOnKeyDown;
329 MouseKeyApplicationHook.MouseUp += MouseKeyHookOnMouseUp; 414 MouseKeyApplicationHook.MouseUp += LocalMouseKeyHookOnMouseUp;
330 } 415 }
331   416  
332 private void ShowOverlayPanel() 417 private void ShowOverlayPanel()
Line 333... Line 418...
333 { 418 {
334 OverlayPanel.BringToFront(); 419 OverlayPanel.BringToFront();
335 OverlayPanel.Visible = true; 420 OverlayPanel.Visible = true;
Line 336... Line 421...
336 OverlayPanel.Invalidate(); 421 OverlayPanel.Invalidate();
Line 337... Line 422...
337 } 422 }
338   423  
339 private void MouseKeyHookOnKeyUp(object sender, KeyEventArgs e) 424 private async void LocalMouseKeyHookOnKeyUp(object sender, KeyEventArgs e)
340 { 425 {
Line 341... Line 426...
341 MouseKeyBindings.Bindings.Add(new MouseKeyBinding(HelmNameTextBox.Text, MouseKeyCombo)); 426 LocalMouseKeyBindings.Bindings.Add(new MouseKeyBinding(LocalNameTextBox.Text, MouseKeyCombo));
Line 342... Line 427...
342   427  
343 HelmListBoxBindingSource.ResetBindings(false); 428 LocalListBoxBindingSource.ResetBindings(false);
-   429  
-   430 MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown;
344   431 MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp;
Line 345... Line 432...
345 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; 432 MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown;
346 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; 433 MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp;
347 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; 434  
348 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; 435 MouseKeyApplicationHook.Dispose();
349   436  
350 MouseKeyApplicationHook.Dispose(); 437 LocalNameTextBox.Text = string.Empty;
Line 351... Line 438...
351   438 HideOverlayPanel();
352 HelmNameTextBox.Text = string.Empty; 439  
353 HideOverlayPanel(); 440 await SaveLocalMouseKeyBindings().ConfigureAwait(false);
Line 354... Line 441...
354 } 441 }
Line 355... Line 442...
355   442  
356 private void HideOverlayPanel() 443 private void HideOverlayPanel()
357 { 444 {
358 OverlayPanel.SendToBack(); 445 OverlayPanel.SendToBack();
Line 359... Line 446...
359 OverlayPanel.Visible = false; 446 OverlayPanel.Visible = false;
Line 360... Line 447...
360 OverlayPanel.Invalidate(); 447 OverlayPanel.Invalidate();
361 } 448 }
-   449  
-   450 private async void LocalMouseKeyHookOnMouseUp(object sender, MouseEventArgs e)
362   451 {
Line 363... Line 452...
363 private void MouseKeyHookOnMouseUp(object sender, MouseEventArgs e) 452 LocalMouseKeyBindings.Bindings.Add(new MouseKeyBinding(LocalNameTextBox.Text, MouseKeyCombo));
364 { 453  
365 MouseKeyBindings.Bindings.Add(new MouseKeyBinding(HelmNameTextBox.Text, MouseKeyCombo)); 454 LocalListBoxBindingSource.ResetBindings(false);
366   455  
Line 367... Line 456...
367 HelmListBoxBindingSource.ResetBindings(false); 456 MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown;
368   457 MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp;
369 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; 458 MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown;
Line 370... Line 459...
370 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; 459 MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp;
371 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; 460  
Line 372... Line 461...
372 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; 461 MouseKeyApplicationHook.Dispose();
373   462  
374 MouseKeyApplicationHook.Dispose(); 463 LocalNameTextBox.Text = string.Empty;
375   464 HideOverlayPanel();
Line 376... Line 465...
376 HelmNameTextBox.Text = string.Empty; 465  
377 HideOverlayPanel(); 466 await SaveLocalMouseKeyBindings().ConfigureAwait(false);
378 } 467 }
379   468  
380   469  
Line 381... Line 470...
381 private void MouseKeyHookOnMouseDown(object sender, MouseEventArgs e) 470 private void LocalMouseKeyHookOnMouseDown(object sender, MouseEventArgs e)
382 { 471 {
-   472 MouseKeyCombo.Add(e.Button.ToDisplayName());
-   473 }
383 MouseKeyCombo.Add(e.Button.ToDisplayName()); 474  
Line 384... Line 475...
384 } 475 private void LocalMouseKeyHookOnKeyDown(object sender, KeyEventArgs e)
385   476 {
386 private void MouseKeyHookOnKeyDown(object sender, KeyEventArgs e) 477 e.SuppressKeyPress = true;
Line 387... Line 478...
387 { 478  
388 e.SuppressKeyPress = true; 479 MouseKeyCombo.Add(e.KeyCode.ToDisplayName());
Line 389... Line 480...
389   480 }
-   481  
-   482 private void HelmNameTextBoxClick(object sender, EventArgs e)
-   483 {
-   484 LocalNameTextBox.BackColor = Color.Empty;
-   485 }
-   486  
-   487 private async void HelmRemoveButtonClick(object sender, EventArgs e)
-   488 {
-   489 var helmBinding = (MouseKeyBinding) LocalBindingsListBox.SelectedItem;
-   490 if (helmBinding == null)
-   491 return;
-   492  
-   493 LocalMouseKeyBindings.Bindings.Remove(helmBinding);
-   494 LocalListBoxBindingSource.ResetBindings(false);
-   495  
-   496 await SaveLocalMouseKeyBindings().ConfigureAwait(false);
-   497 }
-   498  
-   499 private async void LobbySayButtonClick(object sender, EventArgs e)
-   500 {
-   501 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text).ConfigureAwait(false);
-   502  
-   503 LobbySayTextBox.Text = string.Empty;
-   504 }
-   505  
-   506 private void RemoteBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e)
-   507 {
-   508 UpdateRemoteListBoxItems();
-   509 }
-   510  
-   511 private async void WingManFormOnLoad(object sender, EventArgs e)
-   512 {
-   513 await LoadLocalMouseKeyBindings();
-   514 await LoadRemoteMouseKeyBindings();
-   515 }
-   516  
-   517 private async Task LoadLocalMouseKeyBindings()
-   518 {
-   519 try
-   520 {
-   521 using (var fileStream = new FileStream("LocalMouseKeyBindings.xml", FileMode.Open))
-   522 {
-   523 using (var memoryStream = new MemoryStream())
-   524 {
-   525 await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false);
-   526  
-   527 memoryStream.Position = 0L;
-   528  
-   529 var loadedBindings =
-   530 (MouseKeyBindings) MouseKeyBindings.XmlSerializer.Deserialize(memoryStream);
-   531  
-   532 foreach (var binding in loadedBindings.Bindings) LocalMouseKeyBindings.Bindings.Add(binding);
-   533  
-   534 LocalListBoxBindingSource.ResetBindings(false);
-   535 }
-   536 }
-   537 }
-   538 catch (Exception)
-   539 {
-   540 ActivityTextBox.AppendText(
-   541 $"{Strings.Failed_loading_local_bindings}{Environment.NewLine}");
-   542 }
-   543 }
-   544  
-   545 private void RemoteBindingsBindButtonClicked(object sender, EventArgs e)
-   546 {
-   547 ShowOverlayPanel();
-   548  
-   549 MouseKeyCombo = new List<string>();
-   550  
-   551 MouseKeyApplicationHook = Hook.AppEvents();
-   552 MouseKeyApplicationHook.MouseDown += RemoteMouseKeyHookOnMouseDown;
-   553 MouseKeyApplicationHook.KeyUp += RemoteMouseKeyHookOnKeyUp;
-   554 MouseKeyApplicationHook.KeyDown += RemoteMouseKeyHookOnKeyDown;
-   555 MouseKeyApplicationHook.MouseUp += RemoteMouseKeyHookOnMouseUp;
-   556 }
-   557  
-   558 private void RemoteMouseKeyHookOnKeyDown(object sender, KeyEventArgs e)
-   559 {
-   560 e.SuppressKeyPress = true;
-   561  
-   562 MouseKeyCombo.Add(e.KeyCode.ToDisplayName());
390 MouseKeyCombo.Add(e.KeyCode.ToDisplayName()); 563 }
-   564  
-   565 private void RemoteMouseKeyHookOnMouseDown(object sender, MouseEventArgs e)
-   566 {
-   567 MouseKeyCombo.Add(e.Button.ToDisplayName());
-   568 }
-   569  
-   570 private async void RemoteMouseKeyHookOnMouseUp(object sender, MouseEventArgs e)
-   571 {
-   572 RemoteMouseKeyBindings.Bindings.Add(new RemoteMouseKeyBinding(RemoteBindingsComboBox.Text,
-   573 (string) RemoteBindingsListBox.SelectedItem, MouseKeyCombo));
-   574  
391 } 575 MouseKeyApplicationHook.KeyDown -= RemoteMouseKeyHookOnKeyDown;
-   576 MouseKeyApplicationHook.KeyUp -= RemoteMouseKeyHookOnKeyUp;
-   577 MouseKeyApplicationHook.KeyDown -= RemoteMouseKeyHookOnKeyDown;
392   578 MouseKeyApplicationHook.KeyUp -= RemoteMouseKeyHookOnKeyUp;
Line 393... Line 579...
393 private void HelmNameTextBoxClick(object sender, EventArgs e) 579  
394 { 580 MouseKeyApplicationHook.Dispose();
-   581  
-   582 RemoteBindingsBindToBox.Text = string.Join(" + ", MouseKeyCombo);
-   583 HideOverlayPanel();
-   584  
-   585 await SaveRemoteMouseKeyBindings().ConfigureAwait(false);
-   586 }
-   587  
-   588 private async void RemoteMouseKeyHookOnKeyUp(object sender, KeyEventArgs e)
-   589 {
-   590 RemoteMouseKeyBindings.Bindings.Add(new RemoteMouseKeyBinding(RemoteBindingsComboBox.Text,
-   591 (string) RemoteBindingsListBox.SelectedItem, MouseKeyCombo));
-   592  
-   593 MouseKeyApplicationHook.KeyDown -= RemoteMouseKeyHookOnKeyDown;
-   594 MouseKeyApplicationHook.KeyUp -= RemoteMouseKeyHookOnKeyUp;
-   595 MouseKeyApplicationHook.KeyDown -= RemoteMouseKeyHookOnKeyDown;
-   596 MouseKeyApplicationHook.KeyUp -= RemoteMouseKeyHookOnKeyUp;
-   597  
-   598 MouseKeyApplicationHook.Dispose();
-   599  
-   600 RemoteBindingsBindToBox.Text = string.Join(" + ", MouseKeyCombo);
-   601 HideOverlayPanel();
-   602  
-   603 await SaveRemoteMouseKeyBindings().ConfigureAwait(false);
-   604 }
-   605  
-   606 private async Task SaveRemoteMouseKeyBindings()
-   607 {
-   608 try
-   609 {
-   610 using (var memoryStream = new MemoryStream())
-   611 {
-   612 RemoteMouseKeyBindings.XmlSerializer.Serialize(memoryStream, RemoteMouseKeyBindings);
-   613  
-   614 memoryStream.Position = 0L;
-   615  
-   616 using (var fileStream = new FileStream("RemoteMouseKeyBindings.xml", FileMode.Create))
-   617 {
-   618 await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false);
-   619 }
-   620 }
-   621 }
-   622 catch (Exception)
-   623 {
-   624 ActivityTextBox.AppendText(
-   625 $"{Strings.Failed_saving_remote_bindings}{Environment.NewLine}");
395 HelmNameTextBox.BackColor = Color.Empty; 626 }
396 } 627 }
397   628