corrade-vassal – Diff between revs 13 and 16

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 13 Rev 16
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // 3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. // 4 // rights of fair usage, the disclaimer and warranty conditions. //
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
6   6  
7 using System; 7 using System;
8 using System.ComponentModel; -  
9 using System.Drawing; 8 using System.Drawing;
10 using System.IO; -  
11 using System.Linq; 9 using System.Linq;
-   10 using System.Net;
-   11 using System.Net.Http.Headers;
12 using System.Net.Sockets; 12 using System.Net.Sockets;
13 using System.Reflection; 13 using System.Reflection;
14 using System.Threading; 14 using System.Threading;
15 using System.Windows.Forms; 15 using System.Windows.Forms;
16 using OpenMetaverse; 16 using OpenMetaverse;
-   17 using wasSharp;
17   18  
18 namespace Vassal 19 namespace Vassal
19 { 20 {
20 public partial class SettingsForm : Form 21 public partial class SettingsForm : Form
21 { 22 {
22 private static SettingsForm mainForm; 23 private static SettingsForm mainForm;
23   24  
24 private readonly Action GetUserConfiguration = () => 25 private readonly Action GetUserConfiguration = () =>
25 { 26 {
26 // general 27 // general
27 mainForm.HTTPServerURL.Text = Vassal.vassalConfiguration.HTTPServerURL; 28 mainForm.HTTPServerURL.Text = Vassal.vassalConfiguration.HTTPServerURL;
28 mainForm.Group.Text = Vassal.vassalConfiguration.Group; 29 mainForm.Group.Text = Vassal.vassalConfiguration.Group;
29 mainForm.Password.Text = Vassal.vassalConfiguration.Password; 30 mainForm.Password.Text = Vassal.vassalConfiguration.Password;
30 mainForm.TeleportTimeout.Text = Vassal.vassalConfiguration.TeleportTimeout.ToString(Utils.EnUsCulture); 31 mainForm.TeleportTimeout.Text = Vassal.vassalConfiguration.TeleportTimeout.ToString(Utils.EnUsCulture);
31 mainForm.DataTimeout.Text = Vassal.vassalConfiguration.DataTimeout.ToString(Utils.EnUsCulture); 32 mainForm.ServicesTimeout.Text = Vassal.vassalConfiguration.ServicesTimeout.ToString(Utils.EnUsCulture);
32 mainForm.RegionRestartDelay.Text = Vassal.vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture); 33 mainForm.RegionRestartDelay.Text = Vassal.vassalConfiguration.RegionRestartDelay.ToString(Utils.EnUsCulture);
33   34  
34 // filters 35 // filters
35 mainForm.ActiveInputFilters.Items.Clear(); 36 mainForm.ActiveInputFilters.Items.Clear();
36 foreach (Filter filter in Vassal.vassalConfiguration.InputFilters) 37 foreach (var filter in Vassal.vassalConfiguration.InputFilters)
37 { 38 {
38 mainForm.ActiveInputFilters.Items.Add(new ListViewItem 39 mainForm.ActiveInputFilters.Items.Add(new ListViewItem
39 { 40 {
40 Text = wasGetDescriptionFromEnumValue(filter), 41 Text = Reflection.GetDescriptionFromEnumValue(filter),
41 Tag = filter 42 Tag = filter
42 }); 43 });
43 } 44 }
44 mainForm.ActiveOutputFilters.Items.Clear(); 45 mainForm.ActiveOutputFilters.Items.Clear();
45 mainForm.ActiveInputFilters.DisplayMember = "Text"; 46 mainForm.ActiveInputFilters.DisplayMember = "Text";
46 foreach (Filter filter in Vassal.vassalConfiguration.OutputFilters) 47 foreach (var filter in Vassal.vassalConfiguration.OutputFilters)
47 { 48 {
48 mainForm.ActiveOutputFilters.Items.Add(new ListViewItem 49 mainForm.ActiveOutputFilters.Items.Add(new ListViewItem
49 { 50 {
50 Text = wasGetDescriptionFromEnumValue(filter), 51 Text = Reflection.GetDescriptionFromEnumValue(filter),
51 Tag = filter 52 Tag = filter
52 }); 53 });
53 } 54 }
54 mainForm.ActiveOutputFilters.DisplayMember = "Text"; 55 mainForm.ActiveOutputFilters.DisplayMember = "Text";
55   56  
56 // cryptography 57 // cryptography
57 mainForm.ENIGMARotorSequence.Items.Clear(); 58 mainForm.ENIGMARotorSequence.Items.Clear();
58 foreach (char rotor in Vassal.vassalConfiguration.ENIGMA.rotors) 59 foreach (var rotor in Vassal.vassalConfiguration.ENIGMA.rotors)
59 { 60 {
60 mainForm.ENIGMARotorSequence.Items.Add(new ListViewItem 61 mainForm.ENIGMARotorSequence.Items.Add(new ListViewItem
61 { 62 {
62 Text = rotor.ToString(), 63 Text = rotor.ToString(),
63 Tag = rotor 64 Tag = rotor
64 }); 65 });
65 } 66 }
66 mainForm.ENIGMARotorSequence.DisplayMember = "Text"; 67 mainForm.ENIGMARotorSequence.DisplayMember = "Text";
67 mainForm.ENIGMAPlugSequence.Items.Clear(); 68 mainForm.ENIGMAPlugSequence.Items.Clear();
68 foreach (char plug in Vassal.vassalConfiguration.ENIGMA.plugs) 69 foreach (var plug in Vassal.vassalConfiguration.ENIGMA.plugs)
69 { 70 {
70 mainForm.ENIGMAPlugSequence.Items.Add(new ListViewItem 71 mainForm.ENIGMAPlugSequence.Items.Add(new ListViewItem
71 { 72 {
72 Text = plug.ToString(), 73 Text = plug.ToString(),
73 Tag = plug 74 Tag = plug
74 }); 75 });
75 } 76 }
76 mainForm.ENIGMAPlugSequence.DisplayMember = "Text"; 77 mainForm.ENIGMAPlugSequence.DisplayMember = "Text";
77 mainForm.ENIGMAReflector.Text = Vassal.vassalConfiguration.ENIGMA.reflector.ToString(); 78 mainForm.ENIGMAReflector.Text = Vassal.vassalConfiguration.ENIGMA.reflector.ToString();
78 mainForm.VIGENERESecret.Text = Vassal.vassalConfiguration.VIGENERESecret; 79 mainForm.VIGENERESecret.Text = Vassal.vassalConfiguration.VIGENERESecret;
-   80  
-   81 // HTTP
-   82 string mediaType;
-   83 switch (Vassal.vassalConfiguration.InputFilters.LastOrDefault())
-   84 {
-   85 case Filter.RFC1738:
-   86 mediaType = @"application/x-www-form-urlencoded";
-   87 break;
-   88 default:
-   89 mediaType = @"text/plain";
-   90 break;
-   91 }
-   92 // Create HTTP Client
-   93 Vassal.HTTPClient = new Web.wasHTTPClient(new ProductInfoHeaderValue(@"Vassal",
-   94 Vassal.VASSAL_VERSION), new CookieContainer(), mediaType, 60000);
79 }; 95 };
80   96  
81 private readonly Action SetUserConfiguration = () => 97 private readonly Action SetUserConfiguration = () =>
82 { 98 {
83 // general 99 // general
84 Vassal.vassalConfiguration.HTTPServerURL = mainForm.HTTPServerURL.Text; 100 Vassal.vassalConfiguration.HTTPServerURL = mainForm.HTTPServerURL.Text;
85 Vassal.vassalConfiguration.Group = mainForm.Group.Text; 101 Vassal.vassalConfiguration.Group = mainForm.Group.Text;
86 Vassal.vassalConfiguration.Password = mainForm.Password.Text; 102 Vassal.vassalConfiguration.Password = mainForm.Password.Text;
87 uint outUint; 103 uint outUint;
88 if (uint.TryParse(mainForm.TeleportTimeout.Text, out outUint)) 104 if (uint.TryParse(mainForm.ServicesTimeout.Text, out outUint))
89 { 105 {
90 Vassal.vassalConfiguration.TeleportTimeout = outUint; 106 Vassal.vassalConfiguration.ServicesTimeout = outUint;
91 } 107 }
92 if (uint.TryParse(mainForm.DataTimeout.Text, out outUint)) 108 if (uint.TryParse(mainForm.TeleportTimeout.Text, out outUint))
93 { 109 {
94 Vassal.vassalConfiguration.DataTimeout = outUint; 110 Vassal.vassalConfiguration.TeleportTimeout = outUint;
95 } 111 }
96 if (uint.TryParse(mainForm.RegionRestartDelay.Text, out outUint)) 112 if (uint.TryParse(mainForm.RegionRestartDelay.Text, out outUint))
97 { 113 {
98 Vassal.vassalConfiguration.RegionRestartDelay = outUint; 114 Vassal.vassalConfiguration.RegionRestartDelay = outUint;
99 } 115 }
100   116  
101 // filters 117 // filters
102 Vassal.vassalConfiguration.InputFilters = 118 Vassal.vassalConfiguration.InputFilters =
103 mainForm.ActiveInputFilters.Items.Cast<ListViewItem>().Select(o => (Filter) o.Tag).ToList(); 119 mainForm.ActiveInputFilters.Items.Cast<ListViewItem>().Select(o => (Filter) o.Tag).ToList();
104 Vassal.vassalConfiguration.OutputFilters = 120 Vassal.vassalConfiguration.OutputFilters =
105 mainForm.ActiveOutputFilters.Items.Cast<ListViewItem>().Select(o => (Filter) o.Tag).ToList(); 121 mainForm.ActiveOutputFilters.Items.Cast<ListViewItem>().Select(o => (Filter) o.Tag).ToList();
106   122  
107 // cryptography 123 // cryptography
108 Vassal.vassalConfiguration.ENIGMA = new ENIGMA 124 Vassal.vassalConfiguration.ENIGMA = new ENIGMA
109 { 125 {
110 rotors = mainForm.ENIGMARotorSequence.Items.Cast<ListViewItem>().Select(o => (char) o.Tag).ToArray(), 126 rotors = mainForm.ENIGMARotorSequence.Items.Cast<ListViewItem>().Select(o => (char) o.Tag).ToArray(),
111 plugs = mainForm.ENIGMAPlugSequence.Items.Cast<ListViewItem>().Select(o => (char) o.Tag).ToArray(), 127 plugs = mainForm.ENIGMAPlugSequence.Items.Cast<ListViewItem>().Select(o => (char) o.Tag).ToArray(),
112 reflector = mainForm.ENIGMAReflector.Text[0] 128 reflector = mainForm.ENIGMAReflector.Text[0]
113 }; 129 };
114   130  
115 Vassal.vassalConfiguration.VIGENERESecret = mainForm.VIGENERESecret.Text; 131 Vassal.vassalConfiguration.VIGENERESecret = mainForm.VIGENERESecret.Text;
-   132  
-   133 // HTTP
-   134 string mediaType;
-   135 switch (Vassal.vassalConfiguration.InputFilters.LastOrDefault())
-   136 {
-   137 case Filter.RFC1738:
-   138 mediaType = @"application/x-www-form-urlencoded";
-   139 break;
-   140 default:
-   141 mediaType = @"text/plain";
-   142 break;
-   143 }
-   144 // Create HTTP Client
-   145 Vassal.HTTPClient = new Web.wasHTTPClient(new ProductInfoHeaderValue(@"Vassal",
-   146 Vassal.VASSAL_VERSION), new CookieContainer(), mediaType, 60000);
116 }; 147 };
117   148  
118 public SettingsForm() 149 public SettingsForm()
119 { 150 {
120 InitializeComponent(); 151 InitializeComponent();
121 mainForm = this; 152 mainForm = this;
122 } 153 }
123   -  
124 /////////////////////////////////////////////////////////////////////////// -  
125 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // -  
126 /////////////////////////////////////////////////////////////////////////// -  
127 /// <summary> -  
128 /// Get enumeration value from its description. -  
129 /// </summary> -  
130 /// <typeparam name="T">the enumeration type</typeparam> -  
131 /// <param name="description">the description of a member</param> -  
132 /// <returns>the value or the default of T if case no description found</returns> -  
133 private static T wasGetEnumValueFromDescription<T>(string description) -  
134 { -  
135 var field = typeof (T).GetFields() -  
136 .AsParallel().SelectMany(f => f.GetCustomAttributes( -  
137 typeof (DescriptionAttribute), false), ( -  
138 f, a) => new {Field = f, Att = a}).SingleOrDefault(a => ((DescriptionAttribute) a.Att) -  
139 .Description.Equals(description)); -  
140 return field != null ? (T) field.Field.GetRawConstantValue() : default(T); -  
141 } -  
142   -  
143 /////////////////////////////////////////////////////////////////////////// -  
144 // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // -  
145 /////////////////////////////////////////////////////////////////////////// -  
146 /// <summary> -  
147 /// Get the description from an enumeration value. -  
148 /// </summary> -  
149 /// <param name="value">an enumeration value</param> -  
150 /// <returns>the description or the empty string</returns> -  
151 private static string wasGetDescriptionFromEnumValue(Enum value) -  
152 { -  
153 DescriptionAttribute attribute = value.GetType() -  
154 .GetField(value.ToString()) -  
155 .GetCustomAttributes(typeof (DescriptionAttribute), false) -  
156 .SingleOrDefault() as DescriptionAttribute; -  
157 return attribute != null ? attribute.Description : string.Empty; -  
158 } -  
159   154  
160 private void LoadSettingsRequested(object sender, EventArgs e) 155 private void LoadSettingsRequested(object sender, EventArgs e)
161 { 156 {
162 mainForm.BeginInvoke((MethodInvoker) (() => 157 mainForm.BeginInvoke((MethodInvoker) (() =>
163 { 158 {
164 switch (mainForm.LoadSettingsDialog.ShowDialog()) 159 switch (mainForm.LoadSettingsDialog.ShowDialog())
165 { 160 {
166 case DialogResult.OK: 161 case DialogResult.OK:
167 string file = mainForm.LoadSettingsDialog.FileName; 162 var file = mainForm.LoadSettingsDialog.FileName;
168 new Thread(() => 163 new Thread(() =>
169 { 164 {
170 mainForm.BeginInvoke((MethodInvoker) (() => 165 mainForm.BeginInvoke((MethodInvoker) (() =>
171 { 166 {
172 try 167 try
173 { 168 {
174 mainForm.StatusText.Text = @"loading settings..."; 169 mainForm.StatusText.Text = @"loading settings...";
175 mainForm.StatusProgress.Value = 0; 170 mainForm.StatusProgress.Value = 0;
176   171  
177 // load settings 172 // load settings
178 VassalConfiguration.Load(file, ref Vassal.vassalConfiguration); 173 VassalConfiguration.Load(file, ref Vassal.vassalConfiguration);
179 mainForm.StatusProgress.Value = 50; 174 mainForm.StatusProgress.Value = 50;
180 GetUserConfiguration.Invoke(); 175 GetUserConfiguration.Invoke();
181   176  
182 mainForm.StatusText.Text = @"settings loaded"; 177 mainForm.StatusText.Text = @"settings loaded";
183 mainForm.StatusProgress.Value = 100; 178 mainForm.StatusProgress.Value = 100;
184 } 179 }
185 catch (Exception ex) 180 catch (Exception ex)
186 { 181 {
187 mainForm.StatusText.Text = ex.Message; 182 mainForm.StatusText.Text = ex.Message;
188 } 183 }
189 })); 184 }));
190 }) 185 })
191 {IsBackground = true, Priority = ThreadPriority.Normal}.Start(); 186 {IsBackground = true, Priority = ThreadPriority.Normal}.Start();
192 break; 187 break;
193 } 188 }
194 })); 189 }));
195 } 190 }
196   191  
197 private void SaveSettingsRequested(object sender, EventArgs e) 192 private void SaveSettingsRequested(object sender, EventArgs e)
198 { 193 {
199 mainForm.BeginInvoke((MethodInvoker) (() => 194 mainForm.BeginInvoke((MethodInvoker) (() =>
200 { 195 {
201 switch (mainForm.SaveSettingsDialog.ShowDialog()) 196 switch (mainForm.SaveSettingsDialog.ShowDialog())
202 { 197 {
203 case DialogResult.OK: 198 case DialogResult.OK:
204 string file = mainForm.SaveSettingsDialog.FileName; 199 var file = mainForm.SaveSettingsDialog.FileName;
205 new Thread(() => 200 new Thread(() =>
206 { 201 {
207 mainForm.BeginInvoke((MethodInvoker) (() => 202 mainForm.BeginInvoke((MethodInvoker) (() =>
208 { 203 {
209 try 204 try
210 { 205 {
211 mainForm.StatusText.Text = @"saving settings..."; 206 mainForm.StatusText.Text = @"saving settings...";
212 mainForm.StatusProgress.Value = 0; 207 mainForm.StatusProgress.Value = 0;
213   208  
214 // apply configuration 209 // apply configuration
215 SetUserConfiguration.Invoke(); 210 SetUserConfiguration.Invoke();
216 mainForm.StatusProgress.Value = 50; 211 mainForm.StatusProgress.Value = 50;
217   212  
218 // save settings 213 // save settings
219 VassalConfiguration.Save(file, ref Vassal.vassalConfiguration); 214 VassalConfiguration.Save(file, ref Vassal.vassalConfiguration);
220   215  
221 mainForm.StatusText.Text = @"settings saved"; 216 mainForm.StatusText.Text = @"settings saved";
222 mainForm.StatusProgress.Value = 100; 217 mainForm.StatusProgress.Value = 100;
223 } 218 }
224 catch (Exception ex) 219 catch (Exception ex)
225 { 220 {
226 mainForm.StatusText.Text = ex.Message; 221 mainForm.StatusText.Text = ex.Message;
227 } 222 }
228 })); 223 }));
229 }) 224 })
230 {IsBackground = true, Priority = ThreadPriority.Normal}.Start(); 225 {IsBackground = true, Priority = ThreadPriority.Normal}.Start();
231 break; 226 break;
232 } 227 }
233 })); 228 }));
234 } 229 }
235   230  
236 private void AddInputDecoderRequested(object sender, EventArgs e) 231 private void AddInputDecoderRequested(object sender, EventArgs e)
237 { 232 {
238 mainForm.BeginInvoke((MethodInvoker) (() => 233 mainForm.BeginInvoke((MethodInvoker) (() =>
239 { 234 {
240 if (string.IsNullOrEmpty(InputDecode.Text)) 235 if (string.IsNullOrEmpty(InputDecode.Text))
241 { 236 {
242 InputDecode.BackColor = Color.MistyRose; 237 InputDecode.BackColor = Color.MistyRose;
243 return; 238 return;
244 } 239 }
245 InputDecode.BackColor = Color.Empty; 240 InputDecode.BackColor = Color.Empty;
246 ActiveInputFilters.Items.Add(new ListViewItem 241 ActiveInputFilters.Items.Add(new ListViewItem
247 { 242 {
248 Text = InputDecode.Text, 243 Text = InputDecode.Text,
249 Tag = wasGetEnumValueFromDescription<Filter>(InputDecode.Text) 244 Tag = Reflection.GetEnumValueFromDescription<Filter>(InputDecode.Text)
250 }); 245 });
251 })); 246 }));
252 } 247 }
253   248  
254 private void AddInputDecryptionRequested(object sender, EventArgs e) 249 private void AddInputDecryptionRequested(object sender, EventArgs e)
255 { 250 {
256 mainForm.BeginInvoke((MethodInvoker) (() => 251 mainForm.BeginInvoke((MethodInvoker) (() =>
257 { 252 {
258 if (string.IsNullOrEmpty(InputDecryption.Text)) 253 if (string.IsNullOrEmpty(InputDecryption.Text))
259 { 254 {
260 InputDecryption.BackColor = Color.MistyRose; 255 InputDecryption.BackColor = Color.MistyRose;
261 return; 256 return;
262 } 257 }
263 InputDecryption.BackColor = Color.Empty; 258 InputDecryption.BackColor = Color.Empty;
264 ActiveInputFilters.Items.Add(new ListViewItem 259 ActiveInputFilters.Items.Add(new ListViewItem
265 { 260 {
266 Text = InputDecryption.Text, 261 Text = InputDecryption.Text,
267 Tag = wasGetEnumValueFromDescription<Filter>(InputDecryption.Text) 262 Tag = Reflection.GetEnumValueFromDescription<Filter>(InputDecryption.Text)
268 }); 263 });
269 })); 264 }));
270 } 265 }
271   266  
272 private void AddOutputEncryptionRequested(object sender, EventArgs e) 267 private void AddOutputEncryptionRequested(object sender, EventArgs e)
273 { 268 {
274 mainForm.BeginInvoke((MethodInvoker) (() => 269 mainForm.BeginInvoke((MethodInvoker) (() =>
275 { 270 {
276 if (string.IsNullOrEmpty(OutputEncrypt.Text)) 271 if (string.IsNullOrEmpty(OutputEncrypt.Text))
277 { 272 {
278 OutputEncrypt.BackColor = Color.MistyRose; 273 OutputEncrypt.BackColor = Color.MistyRose;
279 return; 274 return;
280 } 275 }
281 OutputEncrypt.BackColor = Color.Empty; 276 OutputEncrypt.BackColor = Color.Empty;
282 ActiveOutputFilters.Items.Add(new ListViewItem 277 ActiveOutputFilters.Items.Add(new ListViewItem
283 { 278 {
284 Text = OutputEncrypt.Text, 279 Text = OutputEncrypt.Text,
285 Tag = wasGetEnumValueFromDescription<Filter>(OutputEncrypt.Text) 280 Tag = Reflection.GetEnumValueFromDescription<Filter>(OutputEncrypt.Text)
286 }); 281 });
287 })); 282 }));
288 } 283 }
289   284  
290 private void AddOutputEncoderRequested(object sender, EventArgs e) 285 private void AddOutputEncoderRequested(object sender, EventArgs e)
291 { 286 {
292 mainForm.BeginInvoke((MethodInvoker) (() => 287 mainForm.BeginInvoke((MethodInvoker) (() =>
293 { 288 {
294 if (string.IsNullOrEmpty(OutputEncode.Text)) 289 if (string.IsNullOrEmpty(OutputEncode.Text))
295 { 290 {
296 OutputEncode.BackColor = Color.MistyRose; 291 OutputEncode.BackColor = Color.MistyRose;
297 return; 292 return;
298 } 293 }
299 OutputEncode.BackColor = Color.Empty; 294 OutputEncode.BackColor = Color.Empty;
300 ActiveOutputFilters.Items.Add(new ListViewItem 295 ActiveOutputFilters.Items.Add(new ListViewItem
301 { 296 {
302 Text = OutputEncode.Text, 297 Text = OutputEncode.Text,
303 Tag = wasGetEnumValueFromDescription<Filter>(OutputEncode.Text) 298 Tag = Reflection.GetEnumValueFromDescription<Filter>(OutputEncode.Text)
304 }); 299 });
305 })); 300 }));
306 } 301 }
307   302  
308 private void DeleteSelectedOutputFilterRequested(object sender, EventArgs e) 303 private void DeleteSelectedOutputFilterRequested(object sender, EventArgs e)
309 { 304 {
310 mainForm.BeginInvoke((MethodInvoker) (() => 305 mainForm.BeginInvoke((MethodInvoker) (() =>
311 { 306 {
312 ListViewItem listViewItem = ActiveOutputFilters.SelectedItem as ListViewItem; 307 var listViewItem = ActiveOutputFilters.SelectedItem as ListViewItem;
313 if (listViewItem == null) 308 if (listViewItem == null)
314 { 309 {
315 ActiveOutputFilters.BackColor = Color.MistyRose; 310 ActiveOutputFilters.BackColor = Color.MistyRose;
316 return; 311 return;
317 } 312 }
318 ActiveOutputFilters.BackColor = Color.Empty; 313 ActiveOutputFilters.BackColor = Color.Empty;
319 ActiveOutputFilters.Items.RemoveAt(ActiveOutputFilters.SelectedIndex); 314 ActiveOutputFilters.Items.RemoveAt(ActiveOutputFilters.SelectedIndex);
320 })); 315 }));
321 } 316 }
322   317  
323 private void DeleteSelectedInputFilterRequested(object sender, EventArgs e) 318 private void DeleteSelectedInputFilterRequested(object sender, EventArgs e)
324 { 319 {
325 mainForm.BeginInvoke((MethodInvoker) (() => 320 mainForm.BeginInvoke((MethodInvoker) (() =>
326 { 321 {
327 ListViewItem listViewItem = ActiveInputFilters.SelectedItem as ListViewItem; 322 var listViewItem = ActiveInputFilters.SelectedItem as ListViewItem;
328 if (listViewItem == null) 323 if (listViewItem == null)
329 { 324 {
330 ActiveInputFilters.BackColor = Color.MistyRose; 325 ActiveInputFilters.BackColor = Color.MistyRose;
331 return; 326 return;
332 } 327 }
333 ActiveInputFilters.BackColor = Color.Empty; 328 ActiveInputFilters.BackColor = Color.Empty;
334 ActiveInputFilters.Items.RemoveAt(ActiveInputFilters.SelectedIndex); 329 ActiveInputFilters.Items.RemoveAt(ActiveInputFilters.SelectedIndex);
335 })); 330 }));
336 } 331 }
337   332  
338 private void AddENIGMARotorRequested(object sender, EventArgs e) 333 private void AddENIGMARotorRequested(object sender, EventArgs e)
339 { 334 {
340 mainForm.BeginInvoke((MethodInvoker) (() => 335 mainForm.BeginInvoke((MethodInvoker) (() =>
341 { 336 {
342 if (string.IsNullOrEmpty(ENIGMARotor.Text)) 337 if (string.IsNullOrEmpty(ENIGMARotor.Text))
343 { 338 {
344 ENIGMARotor.BackColor = Color.MistyRose; 339 ENIGMARotor.BackColor = Color.MistyRose;
345 return; 340 return;
346 } 341 }
347 ENIGMARotor.BackColor = Color.Empty; 342 ENIGMARotor.BackColor = Color.Empty;
348 ENIGMARotorSequence.Items.Add(new ListViewItem 343 ENIGMARotorSequence.Items.Add(new ListViewItem
349 { 344 {
350 Text = ENIGMARotor.Text, 345 Text = ENIGMARotor.Text,
351 Tag = ENIGMARotor.Text[0] 346 Tag = ENIGMARotor.Text[0]
352 }); 347 });
353 })); 348 }));
354 } 349 }
355   350  
356 private void DeleteENIGMARotorRequested(object sender, EventArgs e) 351 private void DeleteENIGMARotorRequested(object sender, EventArgs e)
357 { 352 {
358 mainForm.BeginInvoke((MethodInvoker) (() => 353 mainForm.BeginInvoke((MethodInvoker) (() =>
359 { 354 {
360 ListViewItem listViewItem = ENIGMARotorSequence.SelectedItem as ListViewItem; 355 var listViewItem = ENIGMARotorSequence.SelectedItem as ListViewItem;
361 if (listViewItem == null) 356 if (listViewItem == null)
362 { 357 {
363 ENIGMARotorSequence.BackColor = Color.MistyRose; 358 ENIGMARotorSequence.BackColor = Color.MistyRose;
364 return; 359 return;
365 } 360 }
366 ENIGMARotorSequence.BackColor = Color.Empty; 361 ENIGMARotorSequence.BackColor = Color.Empty;
367 ENIGMARotorSequence.Items.RemoveAt(ENIGMARotorSequence.SelectedIndex); 362 ENIGMARotorSequence.Items.RemoveAt(ENIGMARotorSequence.SelectedIndex);
368 })); 363 }));
369 } 364 }
370   365  
371 private void AddENIGMAPlugRequested(object sender, EventArgs e) 366 private void AddENIGMAPlugRequested(object sender, EventArgs e)
372 { 367 {
373 mainForm.BeginInvoke((MethodInvoker) (() => 368 mainForm.BeginInvoke((MethodInvoker) (() =>
374 { 369 {
375 if (string.IsNullOrEmpty(ENIGMARing.Text)) 370 if (string.IsNullOrEmpty(ENIGMARing.Text))
376 { 371 {
377 ENIGMARing.BackColor = Color.MistyRose; 372 ENIGMARing.BackColor = Color.MistyRose;
378 return; 373 return;
379 } 374 }
380 ENIGMARing.BackColor = Color.Empty; 375 ENIGMARing.BackColor = Color.Empty;
381 ENIGMAPlugSequence.Items.Add(new ListViewItem 376 ENIGMAPlugSequence.Items.Add(new ListViewItem
382 { 377 {
383 Text = ENIGMARing.Text, 378 Text = ENIGMARing.Text,
384 Tag = ENIGMARing.Text[0] 379 Tag = ENIGMARing.Text[0]
385 }); 380 });
386 })); 381 }));
387 } 382 }
388   383  
389 private void DeleteENIGMAPlugRequested(object sender, EventArgs e) 384 private void DeleteENIGMAPlugRequested(object sender, EventArgs e)
390 { 385 {
391 mainForm.BeginInvoke((MethodInvoker) (() => 386 mainForm.BeginInvoke((MethodInvoker) (() =>
392 { 387 {
393 ListViewItem listViewItem = ENIGMAPlugSequence.SelectedItem as ListViewItem; 388 var listViewItem = ENIGMAPlugSequence.SelectedItem as ListViewItem;
394 if (listViewItem == null) 389 if (listViewItem == null)
395 { 390 {
396 ENIGMAPlugSequence.BackColor = Color.MistyRose; 391 ENIGMAPlugSequence.BackColor = Color.MistyRose;
397 return; 392 return;
398 } 393 }
399 ENIGMAPlugSequence.BackColor = Color.Empty; 394 ENIGMAPlugSequence.BackColor = Color.Empty;
400 ENIGMAPlugSequence.Items.RemoveAt(ENIGMAPlugSequence.SelectedIndex); 395 ENIGMAPlugSequence.Items.RemoveAt(ENIGMAPlugSequence.SelectedIndex);
401 })); 396 }));
402 } 397 }
403   398  
404 private void SettingsFormShown(object sender, EventArgs e) 399 private void SettingsFormShown(object sender, EventArgs e)
405 { 400 {
406 GetUserConfiguration.Invoke(); 401 GetUserConfiguration.Invoke();
407 } 402 }
408   403  
409 private void SettingsFormClosing(object sender, FormClosingEventArgs e) 404 private void SettingsFormClosing(object sender, FormClosingEventArgs e)
410 { 405 {
411 // apply configuration 406 // apply configuration
412 SetUserConfiguration.Invoke(); 407 SetUserConfiguration.Invoke();
413 // save settings 408 // save settings
414 VassalConfiguration.Save(Vassal.VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE, ref Vassal.vassalConfiguration); 409 VassalConfiguration.Save(Vassal.VASSAL_CONSTANTS.VASSAL_CONFIGURATION_FILE, ref Vassal.vassalConfiguration);
415 // Spawn a thread to check Corrade's connection status. 410 // Spawn a thread to check Corrade's connection status.
416 new Thread(() => 411 new Thread(() =>
417 { 412 {
418 TcpClient tcpClient = new TcpClient(); 413 var tcpClient = new TcpClient();
419 try 414 try
420 { 415 {
421 Uri uri = new Uri(Vassal.vassalConfiguration.HTTPServerURL); 416 var uri = new Uri(Vassal.vassalConfiguration.HTTPServerURL);
422 tcpClient.Connect(uri.Host, uri.Port); 417 tcpClient.Connect(uri.Host, uri.Port);
423 // port open 418 // port open
424 Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => { Vassal.vassalForm.Tabs.Enabled = true; })); 419 Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => { Vassal.vassalForm.Tabs.Enabled = true; }));
425 // set the loading spinner 420 // set the loading spinner
426 if (Vassal.vassalForm.RegionAvatarsMap.Image == null) 421 if (Vassal.vassalForm.RegionAvatarsMap.Image == null)
427 { 422 {
428 Assembly thisAssembly = Assembly.GetExecutingAssembly(); 423 var thisAssembly = Assembly.GetExecutingAssembly();
429 Stream file = 424 var file =
430 thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif"); 425 thisAssembly.GetManifestResourceStream("Vassal.img.loading.gif");
431 switch (file != null) 426 switch (file != null)
432 { 427 {
433 case true: 428 case true:
434 Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => 429 Vassal.vassalForm.BeginInvoke((MethodInvoker) (() =>
435 { 430 {
436 Vassal.vassalForm.RegionAvatarsMap.SizeMode = PictureBoxSizeMode.CenterImage; 431 Vassal.vassalForm.RegionAvatarsMap.SizeMode = PictureBoxSizeMode.CenterImage;
437 Vassal.vassalForm.RegionAvatarsMap.Image = Image.FromStream(file); 432 Vassal.vassalForm.RegionAvatarsMap.Image = Image.FromStream(file);
438 Vassal.vassalForm.RegionAvatarsMap.Refresh(); 433 Vassal.vassalForm.RegionAvatarsMap.Refresh();
439 })); 434 }));
440 break; 435 break;
441 } 436 }
442 } 437 }
443 } 438 }
444 catch (Exception) 439 catch (Exception)
445 { 440 {
446 // port closed 441 // port closed
447 Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => { Vassal.vassalForm.Tabs.Enabled = false; })); 442 Vassal.vassalForm.BeginInvoke((MethodInvoker) (() => { Vassal.vassalForm.Tabs.Enabled = false; }));
448 } 443 }
449 }) 444 })
450 {IsBackground = true}.Start(); 445 {IsBackground = true}.Start();
451   446  
452 // set parameters for Vassal 447 // set parameters for Vassal
453 mainForm.Invoke((MethodInvoker) (() => 448 mainForm.Invoke((MethodInvoker) (() =>
454 { 449 {
455 Vassal.vassalForm.Invoke((MethodInvoker) (() => 450 Vassal.vassalForm.Invoke((MethodInvoker) (() =>
456 { 451 {
457 if (string.IsNullOrEmpty(Vassal.vassalForm.RegionRestartDelayBox.Text)) 452 if (string.IsNullOrEmpty(Vassal.vassalForm.RegionRestartDelayBox.Text))
458 { 453 {
459 Vassal.vassalForm.RegionRestartDelayBox.Text = mainForm.RegionRestartDelay.Text; 454 Vassal.vassalForm.RegionRestartDelayBox.Text = mainForm.RegionRestartDelay.Text;
460 } 455 }
461 Vassal.vassalForm.VassalStatusGroup.Enabled = true; 456 Vassal.vassalForm.VassalStatusGroup.Enabled = true;
462 })); 457 }));
463 })); 458 }));
464 } 459 }
-   460  
-   461 private void ShowToolTip(object sender, EventArgs e)
-   462 {
-   463 mainForm.BeginInvoke(
-   464 (Action) (() =>
-   465 {
-   466 var pictureBox = sender as PictureBox;
-   467 if (pictureBox != null)
-   468 {
-   469 toolTip1.Show(toolTip1.GetToolTip(pictureBox), pictureBox);
-   470 }
-   471 }));
-   472 }
465 } 473 }
466 } 474 }
467   475  
468
Generated by GNU Enscript 1.6.5.90.
476
Generated by GNU Enscript 1.6.5.90.
469   477  
470   478  
471   479