-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainForm.cs
732 lines (610 loc) · 25.9 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
using CockpitHardwareHUB_v2.Classes;
using Microsoft.Win32;
using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using WASimCommander.CLI.Enums;
using Timer = System.Windows.Forms.Timer;
namespace CockpitHardwareHUB_v2
{
public partial class MainForm : Form
{
// Version
private const string sVersion = "v2.1.1 - 09FEB2024";
// Store the silent mode option
private volatile bool _bSilentMode = false;
// ListView controller objects for Variables and Logging
private ListViewControllerVariables _ListViewControllerVariables;
private ListViewControllerLogging _ListViewControllerLogging;
private int maxLogLines = 1000;
// Logfile setting
private bool _bLogToFile = false;
// Connection status Virtual Device
private bool _bVirtualDeviceConnected = false;
// Timer for statistics updates
private Timer _Timer;
// Current device selected in ComboBox
private string _CurrentSelectedDevice = "";
private readonly ConcurrentDictionary<string, COMDevice> _Devices = new();
public MainForm()
{
InitializeComponent();
// initialize event handlers
Logging.UIUpdateLogging += UIOnUpdateLogging;
SimClient.UIUpdateConnectionStatus += UIOnUpdateConnectStatus;
DeviceServer.UIAddDevice += UIOnAddDevice;
DeviceServer.UIRemoveDevice += UIOnRemoveDevice;
PropertyPool.UIUpdateVariable += UIOnUpdateVariable;
}
private void MainForm_Load(object sender, EventArgs e)
{
Text = "Cockpit Hardware HUB v2 - " + sVersion;
_ListViewControllerVariables = new(lvVariables);
_ListViewControllerLogging = new(lvLogging, maxLogLines);
DeviceServer.Init();
SimClient.Init();
UpdateVirtualDeviceUIElements();
cbSilentMode.Checked = _bSilentMode;
cbLogLevel.Text = Logging.sLogLevel;
cbLogToFile.Checked = _bLogToFile;
txtLogFileName.Text = FileLogger.sFileName;
cbRW.SelectedIndex = 0;
// Load the filter values
RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\CockpitHardwareHUB");
txtVID.Text = (string)key.GetValue("FilterVID", "");
txtPID.Text = (string)key.GetValue("FilterPID", "");
txtSerial.Text = (string)key.GetValue("FilterSerial", "");
// Initialize timer
_Timer = new Timer();
_Timer.Interval = 50;
_Timer.Tick += (sender, e) => UI_UpdateStatistics();
_Timer.Start();
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
_Timer.Stop();
// de-initialize event handlers
Logging.UIUpdateLogging -= UIOnUpdateLogging;
SimClient.UIUpdateConnectionStatus -= UIOnUpdateConnectStatus;
DeviceServer.UIAddDevice -= UIOnAddDevice;
DeviceServer.UIRemoveDevice -= UIOnRemoveDevice;
PropertyPool.UIUpdateVariable -= UIOnUpdateVariable;
}
internal void UIOnUpdateConnectStatus(bool bIsConnected)
{
if (InvokeRequired)
{
Invoke(new Action(() => UIOnUpdateConnectStatus(bIsConnected)));
return;
}
if (!bIsConnected)
_bVirtualDeviceConnected = false;
cbSilentMode.Enabled = !bIsConnected; ;
btnConnectMSFS.Text = (bIsConnected) ? "Disconnect" : "Connect";
grpConnect.Text = $"MSFS2020 : {(bIsConnected ? "CONNECTED" : "DISCONNECTED")}";
UpdateVirtualDeviceUIElements();
}
internal void UI_UpdateStatistics()
{
if (_bSilentMode || cbDevices.SelectedIndex == -1)
return;
if (InvokeRequired)
{
Invoke(new Action(() => UI_UpdateStatistics()));
return;
}
COMDevice device = (COMDevice)cbDevices.SelectedItem;
lblCmdRxCntValue.Text = device.cmdRxCnt.ToString();
lblCmdTxCntValue.Text = device.cmdTxCnt.ToString();
lblNackCntValue.Text = device.nackCnt.ToString();
}
internal void UI_ResetStatistics()
{
if (_bSilentMode)
return;
if (InvokeRequired)
{
Invoke(new Action(() => UI_ResetStatistics()));
return;
}
lblCmdRxCntValue.Text = "0";
lblCmdTxCntValue.Text = "0";
lblNackCntValue.Text = "0";
}
internal void UIOnUpdateLogging(LogLevel logLevel, LoggingSource loggingSource, string sLoggingMsg, UInt64 timestamp = 0)
{
if (_bSilentMode)
return;
if (InvokeRequired)
{
BeginInvoke(new Action(() => UIOnUpdateLogging(logLevel, loggingSource, sLoggingMsg, timestamp)));
return;
}
_ListViewControllerLogging.LogLine(logLevel, loggingSource, sLoggingMsg, timestamp);
}
private void UpdateVirtualDeviceUIElements()
{
if (SimClient.IsConnected)
{
txtExecCalcCode.Enabled = !_bSilentMode;
btnSendExecCalcCode.Enabled = !_bSilentMode;
txtProperty.Enabled = _bVirtualDeviceConnected;
if (!_bVirtualDeviceConnected)
txtProperty.Text = "";
btnConnectVD.Enabled = !_bSilentMode;
btnConnectVD.Text = $"{(_bVirtualDeviceConnected ? "Disconnect" : "Connect")} Virtual Device";
grpFilterConnect.Enabled = false;
btnAddProperty.Enabled = _bVirtualDeviceConnected;
btnSaveVirtualProperties.Enabled = _bVirtualDeviceConnected;
btnLoadVirtualProperties.Enabled = _bVirtualDeviceConnected;
btnSendToDevices.Enabled = !_bSilentMode;
btnSendToMSFS.Enabled = !_bSilentMode;
}
else
{
grpFilterConnect.Enabled = true;
txtExecCalcCode.Enabled = false;
txtExecCalcCode.Text = "";
txtExecCalcCodeResult.Text = "";
btnSendExecCalcCode.Enabled = false;
txtProperty.Text = "";
txtProperty.Enabled = false;
btnConnectVD.Text = "Connect Virtual Device";
btnConnectVD.Enabled = false;
btnAddProperty.Enabled = false;
btnSaveVirtualProperties.Enabled = false;
btnLoadVirtualProperties.Enabled = false;
btnSendToDevices.Enabled = false;
btnSendToMSFS.Enabled = false;
}
}
internal void UIOnAddDevice(COMDevice device)
{
if (_bSilentMode)
return;
if (InvokeRequired)
{
Invoke(new Action(() => UIOnAddDevice(device)));
return;
}
cbDevices.Items.Add(device);
if (cbDevices.SelectedIndex == -1 && cbDevices.Items.Count > 0)
cbDevices.SelectedIndex = 0;
UI_UpdateUSBDevices();
}
internal void UIOnRemoveDevice(COMDevice device)
{
if (_bSilentMode)
return;
if (InvokeRequired)
{
Invoke(new Action(() => UIOnRemoveDevice(device)));
return;
}
cbDevices.Items.Remove(device);
if (cbDevices.SelectedIndex == -1 && cbDevices.Items.Count > 0)
cbDevices.SelectedIndex = 0;
UI_UpdateUSBDevices();
}
private void UI_UpdateUSBDevices(bool bForceUpdatePropertyList = false)
{
if (_bSilentMode)
return;
if (cbDevices.Items.Count == 0 && _CurrentSelectedDevice != "")
{
lblDeviceNameValue.Text = "";
lblProcessorTypeValue.Text = "";
lblDevicePathValue.Text = "";
txtProperties.Text = "";
UI_ResetStatistics();
_CurrentSelectedDevice = "";
return;
}
COMDevice device = (COMDevice)cbDevices.SelectedItem;
if (_CurrentSelectedDevice != device.ToString() || bForceUpdatePropertyList)
{
lock (device)
{
lblDeviceNameValue.Text = device.DeviceName;
lblProcessorTypeValue.Text = device.ProcessorType;
lblDevicePathValue.Text = device.PNPDeviceID;
txtProperties.Text = "";
int index = 1;
txtProperties.BeginUpdate();
foreach (Property property in device.Properties)
{
if (txtProperties.Text != "")
txtProperties.AppendText(Environment.NewLine);
txtProperties.AppendText($"{index++:D03}/{(property.iVarId == -1 ? "FAIL" : property.iVarId.ToString("D04"))}: {property.sPropStr}");
}
txtProperties.Select(0, 0);
txtProperties.ScrollToCaret();
txtProperties.EndUpdate();
_CurrentSelectedDevice = device.ToString();
}
}
}
internal void UIOnUpdateVariable(UpdateVariable uv, SimVar simVar)
{
if (_bSilentMode || simVar.iVarId == -1)
return;
if (InvokeRequired)
{
Invoke(new Action(() => UIOnUpdateVariable(uv, simVar)));
return;
}
switch (uv)
{
case UpdateVariable.Add:
_ListViewControllerVariables.AddSimVar(simVar);
break;
case UpdateVariable.Remove:
_ListViewControllerVariables.RemoveSimVar(simVar);
break;
case UpdateVariable.Usage:
_ListViewControllerVariables.ChangeSimVar(simVar);
break;
case UpdateVariable.Value:
_ListViewControllerVariables.ChangeSimVar(simVar);
break;
}
}
// GroupBox Connect/Disconnect
private static void MessageBoxFilter(string s)
{
MessageBox.Show($"{s} is not a correct value. Possible formats are:" + Environment.NewLine +
"- 0xHHHH where [HHHH] is a hex number" + Environment.NewLine +
"- NNNNN where [NNNNN] is a decimal number" + Environment.NewLine +
"- Only values between 1 (0x0001) and 65535 (0xFFFF) are allowed.",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private static bool IsValidFilterValue(string input, out int value)
{
value = -1;
if (string.IsNullOrEmpty(input))
return true;
bool isHex = input.StartsWith("0x", StringComparison.OrdinalIgnoreCase);
bool validParse = isHex ? int.TryParse(input[2..], System.Globalization.NumberStyles.HexNumber, null, out value)
: int.TryParse(input, out value);
return validParse && value >= 1 && value <= 0xFFFF;
}
private bool CheckFilter()
{
// check VID
if (!IsValidFilterValue(txtVID.Text, out int vidValue))
{
MessageBoxFilter("VID");
return false;
}
DeviceServer._FilterVID = txtVID.Text == "" ? 0 : (uint)vidValue;
// check PID
if (!IsValidFilterValue(txtPID.Text, out int pidValue))
{
MessageBoxFilter("PID");
return false;
}
DeviceServer._FilterPID = txtPID.Text == "" ? 0 : (uint)pidValue;
DeviceServer._FilterSerialNumber = txtSerial.Text.ToUpper();
RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\CockpitHardwareHUB");
key.SetValue("FilterVID", txtVID.Text);
key.SetValue("FilterPID", txtPID.Text);
key.SetValue("FilterSerial", txtSerial.Text);
return true;
}
private async void btnConnect_Click(object sender, EventArgs e)
{
if (!SimClient.IsConnected)
{
if (CheckFilter())
SimClient.Connect();
}
else
{
await SimClient.Disconnect();
}
UIOnUpdateConnectStatus(SimClient.IsConnected);
}
private void cbSilentMode_CheckedChanged(object sender, EventArgs e)
{
MessageBox.Show("This option can only be changed when disconnected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
_bSilentMode = cbSilentMode.Checked;
}
private void btnResetFilter_Click(object sender, EventArgs e)
{
if (!SimClient.IsConnected)
{
txtVID.Text = "";
txtPID.Text = "";
txtSerial.Text = "";
RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\CockpitHardwareHUB");
key.SetValue("FilterVID", txtVID.Text);
key.SetValue("FilterPID", txtPID.Text);
key.SetValue("FilterSerial", txtSerial.Text);
}
}
// GroupBox Devices
private void cbDevices_SelectionChangeCommitted(object sender, EventArgs e)
{
if (_bSilentMode)
return;
_Devices.TryGetValue(cbDevices.SelectedItem.ToString(), out var _SelectedDevice);
UI_UpdateUSBDevices();
}
private void btnResetStatistics_Click(object sender, EventArgs e)
{
if (_bSilentMode)
return;
DeviceServer.ResetStatistics();
UI_ResetStatistics();
}
// GroupBox Execute Calculator Code
private void btnSendExecCalcCode_Click(object sender, EventArgs e)
{
if (txtExecCalcCode.Text == "")
{
MessageBox.Show("Enter an Calculator Code in the input field.", "Input required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Execute the calculator code and show the result
HR hr = SimClient.ExecuteCalculatorCode(txtExecCalcCode.Text, out string s);
if (hr != HR.OK)
{
txtExecCalcCodeResult.Text = "";
MessageBox.Show($"execute_calculator_code failed with \"{hr}\"", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
txtExecCalcCodeResult.Text = s;
}
// GroupBox Virtual Device
private void btnConnectVD_Click(object sender, EventArgs e)
{
if (!_bVirtualDeviceConnected)
{
DeviceServer.AddDevice("VIRTUAL", "VIRTUAL");
_bVirtualDeviceConnected = true;
}
else
{
DeviceServer.RemoveDevice("VIRTUAL");
_bVirtualDeviceConnected = false;
}
UpdateVirtualDeviceUIElements();
}
private void btnAddProperty_Click(object sender, EventArgs e)
{
if (txtProperty.Text == "")
{
MessageBox.Show("Enter a Property String in the input field.", "Input required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
COMDevice device = DeviceServer.FindDeviceBasedOnPNPDeviceID("VIRTUAL");
if (device == null)
{
MessageBox.Show("VIRTUAL device seems not to exist. Something went wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
PR parseResult = device.AddProperty(txtProperty.Text);
if (parseResult != PR.Ok)
{
MessageBox.Show($"Property String parse error: {parseResult}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
UI_UpdateUSBDevices(true);
}
private void btnSaveVirtualProperties_Click(object sender, EventArgs e)
{
COMDevice device = DeviceServer.FindDeviceBasedOnPNPDeviceID("VIRTUAL");
if (device == null)
{
MessageBox.Show("VIRTUAL device seems not to exist. Something went wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (device.Properties.Count == 0)
{
MessageBox.Show("VIRTUAL device has no properties to save.", "Nothing to save", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
//string defaultFileName = "VirtualDeviceProperties.txt";
string defaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
saveFileDialog.Title = "Save Properties";
//saveFileDialog.FileName = defaultFileName;
// Retrieve the last used directory from the registry
RegistryKey key = Registry.CurrentUser.CreateSubKey("Software\\CockpitHardwareHUB");
string lastUsedDirectory = (string)key.GetValue("VirtualDeviceSaveFolder", defaultDirectory);
// Check if the directory exists
if (Directory.Exists(lastUsedDirectory))
saveFileDialog.InitialDirectory = lastUsedDirectory;
else
saveFileDialog.InitialDirectory = defaultDirectory;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
using (StreamWriter sw = new StreamWriter(saveFileDialog.FileName))
{
foreach (Property property in device.Properties)
sw.WriteLine(property.sPropStr);
}
// Save the directory back to the registry
key.SetValue("VirtualDeviceSaveFolder", Path.GetDirectoryName(saveFileDialog.FileName));
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred while saving the file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// Close the registry key
key.Close();
}
private async void btnLoadVirtualProperties_Click(object sender, EventArgs e)
{
COMDevice device = DeviceServer.FindDeviceBasedOnPNPDeviceID("VIRTUAL");
if (device == null)
{
MessageBox.Show("VIRTUAL device seems not to exist. Something went wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string defaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
openFileDialog.Title = "Load Properties";
// Retrieve the last used directory from the registry
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\CockpitHardwareHUB");
string lastUsedDirectory = (string)key.GetValue("VirtualDeviceSaveFolder", defaultDirectory);
// Check if the directory exists
if (Directory.Exists(lastUsedDirectory))
openFileDialog.InitialDirectory = lastUsedDirectory;
else
openFileDialog.InitialDirectory = defaultDirectory;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
using (StreamReader sr = new StreamReader(openFileDialog.FileName))
{
string line;
while ((line = await sr.ReadLineAsync()) != null)
{
await Task.Run(() => device.AddProperty(line));
}
UI_UpdateUSBDevices(true);
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred while loading the file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void SendSimVar(bool bRead)
{
if (txtCommand.Text == "")
{
MessageBox.Show("Enter an existing Variable number with optional data in the input field." + Environment.NewLine + Environment.NewLine +
"Accepted formats are:" + Environment.NewLine +
" NNN" + Environment.NewLine +
" NNN=" + Environment.NewLine +
" NNN=Data", "Input required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Split the txtSimVar input by '='
string[] parts = txtCommand.Text.Split(new char[] { '=' }, 2);
string sCmd = parts[0];
string sData = parts.Length > 1 ? parts[1] : "";
// Check if first part is a number
if (!int.TryParse(sCmd, out int iVarId))
{
MessageBox.Show($"[{sCmd}] is not a valid number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// Find the SimVar
SimVar simVar = SimVar.GetSimVarById(iVarId);
if (simVar == null)
{
MessageBox.Show($"SimVar [{iVarId}] does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (bRead ? !simVar.bRead : !simVar.bWrite)
{
MessageBox.Show($"SimVar with Id [{iVarId}] is not a \"{(bRead ? "Read" : "Write")}\" variable.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// If there is data available, check if it matches with the ValType of the SimVar
if (!simVar.SetValueOfSimVar(sData))
{
MessageBox.Show($"SimVar [{iVarId}] requires data of type \"{simVar.ValType}\".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (bRead)
// Dispatch SimVar to all devices that are listening
simVar.DispatchSimVar();
else
// Send SimVar to MSFS
SimClient.TriggerSimVar(simVar);
}
private void btnSendToMSFS_Click(object sender, EventArgs e)
{
// Send SimVar to MSFS
SendSimVar(false);
}
private void btnSendToDevices_Click(object sender, EventArgs e)
{
// Dispatch SimVar to all devices that are listening
SendSimVar(true);
}
// GroupBox Variables
private void txtVariablesFilter_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
_ListViewControllerVariables.FilterName = txtVariablesFilter.Text;
}
private void cbRW_SelectionChangeCommitted(object sender, EventArgs e)
{
if (cbRW.SelectedIndex <= 0)
_ListViewControllerVariables.FilterRW = "";
else
_ListViewControllerVariables.FilterRW = cbRW.SelectedItem.ToString();
}
// GroupBox Logging
private void txtLoggingFilter_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
_ListViewControllerLogging.FilterLogLine = txtLoggingFilter.Text;
}
private void cbLogLevel_SelectionChangeCommitted(object sender, EventArgs e)
{
Logging.sLogLevel = cbLogLevel.Text;
SimClient.SetLogLevel(Logging.SetLogLevel);
}
private void btnLoggingClear_Click(object sender, EventArgs e)
{
_ListViewControllerLogging.ClearLogging();
}
private void cbLogToFile_CheckedChanged(object sender, EventArgs e)
{
if (cbLogToFile.Checked)
{
if (!FileLogger.OpenFile())
cbLogToFile.Checked = false;
}
else
FileLogger.CloseFile();
txtLogFileName.Text = FileLogger.sFileName;
_bLogToFile = cbLogToFile.Checked;
}
}
}
internal class PropertyTextBox : TextBox
{
private const int WM_SETREDRAW = 0x000B;
private const int WM_PAINT = 0x000F;
private bool _updating = false;
internal void BeginUpdate()
{
_updating = true;
SendMessage(this.Handle, WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero);
}
internal void EndUpdate()
{
_updating = false;
SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);
this.Invalidate();
}
protected override void WndProc(ref Message m)
{
// If we're updating, suppress WM_PAINT messages
if (_updating && m.Msg == WM_PAINT)
return;
base.WndProc(ref m);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
}
internal enum UpdateVariable
{
Add,
Remove,
Value,
Usage
}