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