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