corrade-vassal – Diff between revs 13 and 16

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 13 Rev 16
Line 3... Line 3...
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 ///////////////////////////////////////////////////////////////////////////
Line 6... Line 6...
6   6  
7 using System; -  
8 using System.ComponentModel; 7 using System;
9 using System.Drawing; -  
10 using System.IO; 8 using System.Drawing;
-   9 using System.Linq;
-   10 using System.Net;
11 using System.Linq; 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;
Line 16... Line 17...
16 using OpenMetaverse; 17 using wasSharp;
17   18  
18 namespace Vassal 19 namespace Vassal
19 { 20 {
Line 26... Line 27...
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);
Line 33... Line 34...
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 }
Line 54... Line 55...
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";
-   78 mainForm.ENIGMAReflector.Text = Vassal.vassalConfiguration.ENIGMA.reflector.ToString();
-   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
77 mainForm.ENIGMAReflector.Text = Vassal.vassalConfiguration.ENIGMA.reflector.ToString(); 93 Vassal.HTTPClient = new Web.wasHTTPClient(new ProductInfoHeaderValue(@"Vassal",
Line 78... Line 94...
78 mainForm.VIGENERESecret.Text = Vassal.vassalConfiguration.VIGENERESecret; 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))
Line 111... Line 127...
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 };
Line 114... Line 130...
114   130  
-   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",
115 Vassal.vassalConfiguration.VIGENERESecret = mainForm.VIGENERESecret.Text; 146 Vassal.VASSAL_VERSION), new CookieContainer(), mediaType, 60000);
Line 116... Line 147...
116 }; 147 };
117   148  
118 public SettingsForm() 149 public SettingsForm()
119 { 150 {
120 InitializeComponent(); 151 InitializeComponent();
Line 121... Line -...
121 mainForm = this; -  
122 } -  
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; 152 mainForm = this;
158 } 153 }
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 {
Line 199... Line 194...
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
Line 244... Line 239...
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 }
Line 253... Line 248...
253   248  
Line 262... Line 257...
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 }
Line 271... Line 266...
271   266  
Line 280... Line 275...
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 }
Line 289... Line 284...
289   284  
Line 298... Line 293...
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 }
Line 307... Line 302...
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;
Line 322... Line 317...
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;
Line 355... Line 350...
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;
Line 388... Line 383...
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;
Line 413... Line 408...
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) (() =>
Line 460... Line 455...
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