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