WingMan – Diff between revs 22 and 23

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