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