This repository has been archived by the owner on May 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMainForm.cs
1643 lines (1485 loc) · 61.3 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
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using PacketViewerLogViewer.Packets;
using System.IO;
using PacketViewerLogViewer.ClipboardHelper;
using PacketViewerLogViewer.PVLVHelper;
using PacketViewerLogViewer.FileExtHelper;
using PacketViewerLogViewer.FFXIUtils;
using PacketViewerLogViewer.helpers;
namespace PacketViewerLogViewer
{
public partial class MainForm : Form
{
public static MainForm thisMainForm;
List<string> AllUsedTempFiles = new List<string>();
string defaultTitle = "";
static readonly string urlGitHub = "https://github.com/ZeromusXYZ/PVLV";
static readonly string urlDiscord = "https://discord.gg/GhVfDtK";
static readonly string urlVideoLAN = "https://www.videolan.org/";
static readonly string url7Zip = "https://www.7-zip.org/";
static readonly string url7ZipRequiredVer = "https://sourceforge.net/p/sevenzip/discussion/45797/thread/adc65bfa/";
public PacketParser CurrentPP;
SearchParameters searchParameters;
const string InfoGridHeader = " | 0 1 2 3 4 5 6 7 8 9 A B C D E F | 0123456789ABCDEF\n" +
"-----+---------------------------------------------------- -+------------------\n";
public MainForm()
{
InitializeComponent();
thisMainForm = this;
searchParameters = new SearchParameters();
searchParameters.Clear();
}
private void mmFileExit_Click(object sender, EventArgs e)
{
Close();
}
private void mmAboutGithub_Click(object sender, EventArgs e)
{
Process.Start(urlGitHub);
}
private void mmAboutVideoLAN_Click(object sender, EventArgs e)
{
Process.Start(urlVideoLAN);
}
private void MmAboutDiscord_Click(object sender, EventArgs e)
{
Process.Start(urlDiscord);
}
private void mmAboutAbout_Click(object sender, EventArgs e)
{
using (AboutBoxForm ab = new AboutBoxForm())
{
ab.ShowDialog();
}
}
private void RegisterFileExt()
{
try
{
// Might also need to check
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\
FileAssociations.EnsureAssociationsSet();
//FileAssociations.EnsureURIAssociationsSet();
}
catch
{
// Set File or URI Association failed ?
}
}
private void LoadDataFromGameclient()
{
if ((Properties.Settings.Default.UseGameClientData == false) || (!Directory.Exists(FFXIHelper.FFXI_InstallationPath)))
return;
// Items
FFXIHelper.FFXI_LoadItemsFromDats(ref DataLookups.ItemsList.items);
DataLookups.ItemsList.UpdateData();
// Enabled dynamic loading for dialog text
DataLookups.DialogsList.EnableCache = true;
// NPC Names
var mobList = new Dictionary<uint, FFXI_MobListEntry>();
mobList.Add(0, new FFXI_MobListEntry()); // Id 0 = "none"
for (ushort z = 0; z < 0x1FF; z++)
FFXIHelper.FFXI_LoadMobListForZone(ref mobList, z);
DataLookups.NLUOrCreate("@actors").AddValuesFromMobList(ref mobList);
DataLookups.NLUOrCreate("npcname").AddValuesFromMobList(ref mobList); // Not sure if we're ever gonna use this, but meh
}
private void MainForm_Load(object sender, EventArgs e)
{
defaultTitle = Text;
RegisterFileExt();
PacketColors.UpdateColorsFromSettings();
Application.UseWaitCursor = true;
try
{
Directory.SetCurrentDirectory(Application.StartupPath);
if (DataLookups.LoadLookups() == false)
{
MessageBox.Show("Errors while loading lookup data: " + DataLookups.AllLoadErrors, "Error Loading Lookup Data", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
if (FFXIHelper.FindPaths())
LoadDataFromGameclient();
}
catch (Exception x)
{
MessageBox.Show("Exception: " + x.Message, "Loading Lookup Data", MessageBoxButtons.OK, MessageBoxIcon.Stop);
Close();
return;
}
tcPackets.TabPages.Clear();
Application.UseWaitCursor = false;
}
private void mmFileOpen_Click(object sender, EventArgs e)
{
openLogFileDialog.Title = "Open log file";
if (openLogFileDialog.ShowDialog() != DialogResult.OK)
return;
TryOpenFile(openLogFileDialog.FileName);
}
private void TryOpenFile(string aFileName)
{
if (Path.GetExtension(aFileName).ToLower() == ".pvlv")
{
// Open Project File
TryOpenProjectFile(aFileName);
}
else
{
TryOpenLogFile(aFileName, true);
}
}
private void TryOpenProjectFile(string ProjectFile)
{
PacketTabPage tp = CreateNewPacketsTabPage();
tp.LoadProjectFile(ProjectFile);
tp.Text = Helper.MakeTabName(ProjectFile);
using (var projectDlg = new ProjectInfoForm())
{
projectDlg.LoadFromPacketTapPage(tp);
projectDlg.btnSave.Text = "Open";
projectDlg.cbOpenedLog.Enabled = true;
if (projectDlg.ShowDialog() == DialogResult.OK)
{
projectDlg.ApplyPacketTapPage();
TryOpenLogFile(tp.LoadedLogFile, false);
tp.SaveProjectFile();
}
else
{
tcPackets.TabPages.Remove(tp);
}
}
}
private void TryOpenLogFile(string logFile, bool alsoLoadProject)
{
PacketTabPage tp;
if (alsoLoadProject)
{
tp = CreateNewPacketsTabPage();
tp.LoadProjectFileFromLogFile(logFile);
}
else
{
tp = GetCurrentPacketTabPage();
}
//tp.ProjectFolder = Helper.MakeProjectDirectoryFromLogFileName(logFile);
tp.Text = Helper.MakeTabName(logFile);
tp.PLLoaded.Clear();
tp.PLLoaded.Filter.Clear();
if (!tp.PLLoaded.LoadFromFile(logFile))
{
MessageBox.Show("Error loading file: " + logFile, "File Open Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
tp.PLLoaded.Clear();
tcPackets.TabPages.Remove(tp);
return;
}
if (tp.PLLoaded.Count() <= 0)
{
MessageBox.Show("File contains no useful data.\n" + logFile, "File Open Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
tcPackets.TabPages.Remove(tp);
return;
}
Text = defaultTitle + " - " + logFile;
tp.LoadedLogFile = logFile;
tp.PL.CopyFrom(tp.PLLoaded);
tp.FillListBox();
UpdateStatusBarAndTitle(tp);
if (Properties.Settings.Default.AutoOpenVideoForm && ((tp.LinkVideoFileName != string.Empty) || (tp.LinkYoutubeURL != string.Empty)))
{
MmVideoOpenLink_Click(null, null);
}
}
public void lbPackets_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox lb = (sender as ListBox);
if (!(lb.Parent is PacketTabPage))
return;
PacketTabPage tp = (lb.Parent as PacketTabPage);
if ((lb.SelectedIndex < 0) || (lb.SelectedIndex >= tp.PL.Count()))
{
rtInfo.SelectionColor = rtInfo.ForeColor;
rtInfo.SelectionBackColor = rtInfo.BackColor;
rtInfo.Text = "Please select a valid item from the list";
return;
}
PacketData pd = tp.PL.GetPacket(lb.SelectedIndex);
cbShowBlock.Enabled = false;
UpdatePacketDetails(tp, pd, "-");
cbShowBlock.Enabled = true;
lb.Invalidate();
if ((tp.videoLink != null) && (tp.videoLink.cbFollowPacketList.Checked))
{
tp.videoLink.MoveToDateTime(pd.VirtualTimeStamp);
}
}
private void cbOriginalData_CheckedChanged(object sender, EventArgs e)
{
PacketTabPage tp = GetCurrentPacketTabPage();
if (tp == null)
{
rtInfo.SelectionColor = rtInfo.ForeColor;
rtInfo.SelectionBackColor = rtInfo.BackColor;
rtInfo.Text = "Please select open a list first";
return;
}
PacketData pd = tp.GetSelectedPacket();
if (pd == null)
{
rtInfo.SelectionColor = rtInfo.ForeColor;
rtInfo.SelectionBackColor = rtInfo.BackColor;
rtInfo.Text = "Please select a valid item from the list";
return;
}
UpdatePacketDetails(tp, pd, "-");
}
private void mmFileClose_Click(object sender, EventArgs e)
{
if ((tcPackets.SelectedIndex >= 0) && (tcPackets.SelectedIndex < tcPackets.TabCount))
{
tcPackets.TabPages.RemoveAt(tcPackets.SelectedIndex);
}
/*
PLLoaded.Clear();
PLLoaded.ClearFilters();
PL.Clear();
PL.ClearFilters();
FillListBox(lbPackets,PL);
*/
}
private void mmFileAppend_Click(object sender, EventArgs e)
{
openLogFileDialog.Title = "Append log file";
if (openLogFileDialog.ShowDialog() != DialogResult.OK)
return;
PacketTabPage tp = GetCurrentOrNewPacketTabPage();
tp.Text = "Multi";
tp.LoadedLogFile = "?Multiple Sources";
tp.ProjectFolder = string.Empty;
if (!tp.PLLoaded.LoadFromFile(openLogFileDialog.FileName))
{
MessageBox.Show("Error loading file: " + openLogFileDialog.FileName, "File Append Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
tp.PLLoaded.Clear();
return;
}
Text = defaultTitle + " - " + tp.LoadedLogFile;
tp.PL.CopyFrom(tp.PLLoaded);
tp.FillListBox();
UpdateStatusBarAndTitle(tp);
}
private void RawDataToRichText(PacketParser pp, RichTextBox rt)
{
RichTextBox rtInfo = rt;
string rtf = string.Empty;
List<Color> colorTable = new List<Color>();
int LastForeCol = -1;
int LastBackCol = -1;
int GetRTFColor(Color col)
{
var p = colorTable.IndexOf(col);
if (p < 0)
{
p = colorTable.Count;
colorTable.Add(col);
}
return p + 1;
}
void SetRTFColor(Color Fore, Color Back)
{
var f = GetRTFColor(Fore);
var b = GetRTFColor(Back);
//rtf += "\\cf" + f.ToString() + "\\highlight" + b.ToString();
if ((f == LastForeCol) && (b == LastBackCol))
return;
if (f != LastForeCol)
rtf += "\\cf" + f.ToString();
if (b != LastBackCol)
rtf += "\\highlight" + b.ToString();
rtf += " ";
LastForeCol = f;
LastBackCol = b;
}
string BuildHeaderWithColorTable()
{
string rtfHead = string.Empty;
rtfHead += "{\\rtf1\\ansi\\ansicpg1252\\deff0\\nouicompat\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Consolas;}}";
rtfHead += "{\\colortbl;";
foreach (var col in colorTable)
{
rtfHead += "\\red" + col.R.ToString() + "\\green" + col.G.ToString() + "\\blue" + col.B.ToString() + ";";
}
rtfHead += "}";
rtfHead += "\\viewkind4\\uc1\\pard\\cf1\\highlight2\\f0\\fs18 ";
// {\colortbl ;\red169\green169\blue169;\red255\green255\blue255;\red25\green25\blue112;\red0\green0\blue0;\red210\green105\blue30;\red100\green149\blue237;\red60\green179\blue113;\red233\green150\blue122;\red165\green42\blue42;}
return rtfHead;
}
void SetColorBasic(byte n)
{
SetRTFColor(rtInfo.ForeColor, rtInfo.BackColor);
//rtInfo.SelectionFont = rtInfo.Font;
//rtInfo.SelectionColor = rtInfo.ForeColor;
//rtInfo.SelectionBackColor = rtInfo.BackColor;
}
void SetColorGrid()
{
SetRTFColor(Color.DarkGray, rtInfo.BackColor);
//rtInfo.SelectionFont = rtInfo.Font;
//rtInfo.SelectionColor = Color.DarkGray;
//rtInfo.SelectionBackColor = rtInfo.BackColor;
}
void SetColorSelect(byte n, bool forchars)
{
//if (!forchars)
//{
// rtInfo.SelectionFont = new Font(rtInfo.Font, FontStyle.Italic);
//}
//else
//{
// rtInfo.SelectionFont = rtInfo.Font;
//}
SetRTFColor(Color.Yellow, Color.DarkBlue);
//rtInfo.SelectionColor = Color.Yellow;
//rtInfo.SelectionBackColor = Color.DarkBlue;
}
void SetColorNotSelect(byte n, bool forchars)
{
//rtInfo.SelectionFont = rtInfo.Font;
if ((pp.SelectedFields.Count > 0) || forchars)
{
SetRTFColor(pp.GetDataColor(n), rtInfo.BackColor);
//rtInfo.SelectionColor = pp.GetDataColor(n);
//rtInfo.SelectionBackColor = rtInfo.BackColor;
}
else
{
SetRTFColor(rtInfo.BackColor, pp.GetDataColor(n));
//rtInfo.SelectionColor = rtInfo.BackColor;
//rtInfo.SelectionBackColor = pp.GetDataColor(n);
}
}
void AddChars(int startIndex)
{
SetColorGrid();
rtf += " | ";
//rtInfo.AppendText(" | ");
for (int c = 0; (c < 0x10) && ((startIndex + c) < pp.ParsedBytes.Count); c++)
{
var n = pp.ParsedBytes[startIndex + c];
if (pp.SelectedFields.IndexOf(n) >= 0)
{
SetColorSelect(n, true);
}
else
{
SetColorNotSelect(n, true);
}
char ch = (char)pp.PD.GetByteAtPos(startIndex + c);
if (ch == 92)
rtf += "\\\\";
else
if (ch == 64)
rtf += "\\@";
else
if (ch == 123)
rtf += "\\{";
else
if (ch == 125)
rtf += "\\}";
else
if ((ch < 32) || (ch >= 128))
rtf += '.';
else
rtf += ch.ToString();
//rtInfo.AppendText(ch.ToString());
}
}
rtInfo.SuspendLayout();
rtInfo.ForeColor = SystemColors.WindowText;
rtInfo.BackColor = SystemColors.Window;
// rtInfo.Clear();
SetColorGrid();
rtf += InfoGridHeader.Replace("\n", "\\par\n");
//rtInfo.AppendText(InfoGridHeader);
int addCharCount = 0;
byte lastFieldIndex = 0;
for (int i = 0; i < pp.PD.RawBytes.Count; i += 0x10)
{
SetColorGrid();
rtf += i.ToString("X").PadLeft(4, ' ') + " | ";
//rtInfo.AppendText(i.ToString("X").PadLeft(4, ' ') + " | ");
for (int i2 = 0; i2 < 0x10; i2++)
{
if ((i + i2) < pp.ParsedBytes.Count)
{
var n = pp.ParsedBytes[i + i2];
lastFieldIndex = n;
if (pp.SelectedFields.Count > 0)
{
if (pp.SelectedFields.IndexOf(n) >= 0)
{
// Is selected field
SetColorSelect(n, false);
}
else
{
// we have non-selected field
SetColorNotSelect(n, false);
}
}
else
{
// No fields selected
SetColorNotSelect(n, false);
}
rtf += pp.PD.GetByteAtPos(i + i2).ToString("X2");
//rtInfo.AppendText(pp.PD.GetByteAtPos(i + i2).ToString("X2"));
addCharCount++;
}
else
{
SetColorGrid();
rtf += " ";
//rtInfo.AppendText(" ");
}
if ((i + i2 + 1) < pp.ParsedBytes.Count)
{
var n = pp.ParsedBytes[i + i2 + 1];
if (n != lastFieldIndex)
{
SetColorBasic(n);
}
}
else
{
SetColorGrid();
}
rtf += " ";
// rtInfo.AppendText(" ");
if ((i2 % 0x4) == 0x3)
{
rtf += " ";
//rtInfo.AppendText(" ");
}
}
if (addCharCount > 0)
{
AddChars(i);
addCharCount = 0;
}
rtf += "\\par\n";
// rtInfo.AppendText("\r\n");
}
rtf += "}\n";
rtInfo.WordWrap = false;
rtInfo.Rtf = BuildHeaderWithColorTable() + rtf;
rtInfo.Refresh();
rtInfo.ResumeLayout();
}
public void UpdatePacketDetails(PacketTabPage tp, PacketData pd, string SwitchBlockName, bool dontReloadParser = false)
{
if ((tp == null) || (pd == null))
return;
tp.CurrentSync = pd.PacketSync;
lInfo.Text = pd.OriginalHeaderText;
rtInfo.Clear();
if ((dontReloadParser == false) || (pd.PP == null))
{
pd.PP = new PacketParser(pd.PacketID, pd.PacketLogType);
pd.PP.AssignPacket(pd);
}
if (pd.PP == null)
return;
if ((tp.PL.IsPreParsed == false) || (pd.PP.PreParsedSwitchBlock != SwitchBlockName))
pd.PP.ParseData(SwitchBlockName);
CurrentPP = pd.PP;
CurrentPP.ToGridView(dGV);
cbShowBlock.Enabled = false;
if (CurrentPP.SwitchBlocks.Count > 0)
{
cbShowBlock.Items.Clear();
cbShowBlock.Items.Add("-");
cbShowBlock.Items.AddRange(CurrentPP.SwitchBlocks.ToArray());
cbShowBlock.Show();
}
else
{
cbShowBlock.Items.Clear();
cbShowBlock.Hide();
}
for (int i = 0; i < cbShowBlock.Items.Count; i++)
{
if ((SwitchBlockName == "-") && (cbShowBlock.Items[i].ToString() == CurrentPP.LastSwitchedBlock))
{
if (cbShowBlock.SelectedIndex != i)
cbShowBlock.SelectedIndex = i;
//break;
}
else
if (cbShowBlock.Items[i].ToString() == SwitchBlockName)
{
if (cbShowBlock.SelectedIndex != i)
cbShowBlock.SelectedIndex = i;
//break;
}
}
cbShowBlock.Enabled = true;
if (cbOriginalData.Checked)
{
rtInfo.SuspendLayout();
rtInfo.SelectionColor = rtInfo.ForeColor;
rtInfo.SelectionBackColor = rtInfo.BackColor;
rtInfo.Text = "Source:\r\n" + string.Join("\r\n", pd.RawText.ToArray());
rtInfo.Refresh();
rtInfo.ResumeLayout();
}
else
{
RawDataToRichText(CurrentPP, rtInfo);
}
}
private void mmFileSettings_Click(object sender, EventArgs e)
{
using (SettingsForm settingsDialog = new SettingsForm())
{
if (settingsDialog.ShowDialog() == DialogResult.OK)
{
Properties.Settings.Default.Save();
PacketColors.UpdateColorsFromSettings();
LoadDataFromGameclient();
//MessageBox.Show("Settings saved");
}
settingsDialog.Dispose();
}
}
private void CbShowBlock_SelectedIndexChanged(object sender, EventArgs e)
{
if (!cbShowBlock.Enabled)
return;
if (!(tcPackets.SelectedTab is PacketTabPage))
return;
PacketTabPage tp = (tcPackets.SelectedTab as PacketTabPage);
cbShowBlock.Enabled = false;
if ((tp.lbPackets.SelectedIndex < 0) || (tp.lbPackets.SelectedIndex >= tp.PL.Count()))
{
rtInfo.SelectionColor = rtInfo.ForeColor;
rtInfo.SelectionBackColor = rtInfo.BackColor;
rtInfo.Text = "Please select a valid item from the list";
return;
}
PacketData pd = tp.PL.GetPacket(tp.lbPackets.SelectedIndex);
var sw = cbShowBlock.SelectedIndex;
if (sw >= 0)
{
UpdatePacketDetails(tp, pd, cbShowBlock.Items[sw].ToString(), true);
}
else
{
UpdatePacketDetails(tp, pd, "-", true);
}
cbShowBlock.Enabled = true;
tp.lbPackets.Invalidate();
}
private void dGV_SelectionChanged(object sender, EventArgs e)
{
if ((CurrentPP == null) || (CurrentPP.PD == null))
return;
if (dGV.Tag != null)
return;
CurrentPP.SelectedFields.Clear();
for (int i = 0; i < dGV.RowCount; i++)
{
if ((dGV.Rows[i].Selected) && (i < CurrentPP.ParsedView.Count))
{
var f = CurrentPP.ParsedView[i].FieldIndex;
//if (f != 0xFF)
CurrentPP.SelectedFields.Add(f);
}
}
CurrentPP.ToGridView(dGV);
RawDataToRichText(CurrentPP, rtInfo);
}
public void UpdateStatusBarAndTitle(PacketTabPage tp)
{
if (tp == null)
{
sbProjectInfo.Text = "Not a project";
sbExtraInfo.Text = "";
return;
}
var t = tp.LoadedLogFile;
if (t.StartsWith("?"))
t = t.TrimStart('?');
Text = defaultTitle + " - " + t;
if (tp.ProjectFolder != string.Empty)
sbProjectInfo.Text = "Project Folder: " + tp.ProjectFolder;
else
sbProjectInfo.Text = "Not a project";
if (File.Exists(tp.LinkVideoFileName))
sbExtraInfo.Text = "Local Video Linked";
else
if (tp.LinkYoutubeURL != string.Empty)
sbExtraInfo.Text = "Youtube Linked";
else
sbExtraInfo.Text = "";
}
private void TcPackets_SelectedIndexChanged(object sender, EventArgs e)
{
TabControl tc = (sender as TabControl);
if (!(tc.SelectedTab is PacketTabPage))
{
UpdateStatusBarAndTitle(null);
return;
}
PacketTabPage tp = (tc.SelectedTab as PacketTabPage);
UpdateStatusBarAndTitle(tp);
PacketData pd = tp.PL.GetPacket(tp.lbPackets.SelectedIndex);
cbShowBlock.Enabled = false;
UpdatePacketDetails(tp, pd, "-");
cbShowBlock.Enabled = true;
}
private void MmAddFromClipboard_Click(object sender, EventArgs e)
{
if ((!Clipboard.ContainsText()) || (Clipboard.GetText() == string.Empty))
{
MessageBox.Show("Nothing to paste", "Paste from Clipboard", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try
{
PacketTabPage tp = GetCurrentOrNewPacketTabPage();
var cText = Clipboard.GetText().Replace("\r", "");
List<string> clipText = new List<string>();
clipText.AddRange(cText.Split((char)10).ToList());
tp.Text = "Clipboard ";
tp.LoadedLogFile = "?Paste from Clipboard";
tp.ProjectFolder = string.Empty;
if (!tp.PLLoaded.LoadFromStringList(clipText, PacketLogFileFormats.Unknown, PacketLogTypes.Unknown))
{
MessageBox.Show("Error loading data from clipboard", "Clipboard Paste Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
tp.PLLoaded.Clear();
tcPackets.TabPages.Remove(tp);
return;
}
if (tp.PLLoaded.Count() <= 0)
{
MessageBox.Show("Clipboard contained no useful data.", "Clipboard Paste", MessageBoxButtons.OK, MessageBoxIcon.Error);
tcPackets.TabPages.Remove(tp);
return;
}
Text = defaultTitle + " - " + tp.LoadedLogFile;
tp.PL.CopyFrom(tp.PLLoaded);
tp.FillListBox();
UpdateStatusBarAndTitle(tp);
}
catch (Exception x)
{
MessageBox.Show("Paste Failed, Exception: " + x.Message, "Paste from Clipboard", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private PacketTabPage CreateNewPacketsTabPage()
{
PacketTabPage tp = new PacketTabPage(this);
tp.lbPackets.SelectedIndexChanged += lbPackets_SelectedIndexChanged;
tcPackets.TabPages.Add(tp);
tcPackets.SelectedTab = tp;
tp.lbPackets.Focus();
return tp;
}
private PacketTabPage GetCurrentOrNewPacketTabPage()
{
PacketTabPage tp = GetCurrentPacketTabPage();
if (tp == null)
{
tp = CreateNewPacketsTabPage();
}
return tp;
}
public PacketTabPage GetCurrentPacketTabPage()
{
if (!(tcPackets.SelectedTab is PacketTabPage))
{
return null;
}
else
{
return (tcPackets.SelectedTab as PacketTabPage);
}
}
private void MmFilterEdit_Click(object sender, EventArgs e)
{
var tp = GetCurrentPacketTabPage();
using (var filterDlg = new FilterForm())
{
filterDlg.btnOK.Enabled = (tp != null);
if (tp != null)
{
filterDlg.Filter.CopyFrom(tp.PL.Filter);
filterDlg.LoadLocalFromFilter();
}
if (filterDlg.ShowDialog(this) == DialogResult.OK)
{
filterDlg.SaveLocalToFilter();
UInt16 lastSync = tp.CurrentSync;
tp.PL.Filter.CopyFrom(filterDlg.Filter);
tp.PL.FilterFrom(tp.PLLoaded);
tp.FillListBox(lastSync);
tp.CenterListBox();
}
}
}
private void MmFilterReset_Click(object sender, EventArgs e)
{
var tp = GetCurrentPacketTabPage();
if (tp != null)
{
UInt16 lastSync = tp.CurrentSync;
tp.PL.Filter.Clear();
tp.PL.CopyFrom(tp.PLLoaded);
tp.FillListBox(lastSync);
tp.CenterListBox();
}
}
private void MmFilterApply_Click(object sender, EventArgs e)
{
}
private void MMFilterApplyItem_Click(object sender, EventArgs e)
{
var tp = GetCurrentPacketTabPage();
if (tp == null)
return;
if (sender is ToolStripMenuItem)
{
var mITem = (sender as ToolStripMenuItem);
// apply filter
UInt16 lastSync = tp.CurrentSync;
tp.PL.Filter.LoadFromFile(Path.Combine(Application.StartupPath, "data", "filter", mITem.Text + ".pfl"));
tp.PL.FilterFrom(tp.PLLoaded);
tp.FillListBox(lastSync);
tp.CenterListBox();
}
}
private void MmFilterApply_DropDownOpening(object sender, EventArgs e)
{
// generate menu
// GetFiles
try
{
mmFilterApply.DropDownItems.Clear();
var di = new DirectoryInfo(Path.Combine(Application.StartupPath, "data", "filter"));
var files = di.GetFiles("*.pfl");
foreach (var fi in files)
{
ToolStripMenuItem mi = new ToolStripMenuItem(Path.GetFileNameWithoutExtension(fi.Name));
mi.Click += MMFilterApplyItem_Click;
mmFilterApply.DropDownItems.Add(mi);
}
if (files.Length <= 0)
{
ToolStripMenuItem mi = new ToolStripMenuItem("no filters found");
mi.Enabled = false;
mmFilterApply.DropDownItems.Add(mi);
}
}
catch
{
// Do nothing
}
}
private void MmSearchSearch_Click(object sender, EventArgs e)
{
var tp = GetCurrentPacketTabPage();
if (tp == null)
return;
using (SearchForm SearchDlg = new SearchForm())
{
if (tp.PL.IsPreParsed == false)
{
searchParameters.SearchByParsedData = false;
SearchDlg.gbSearchByField.Enabled = false;
}
SearchDlg.searchParameters.CopyFrom(this.searchParameters);
var res = SearchDlg.ShowDialog();
if ((res == DialogResult.OK) || (res == DialogResult.Retry))
{
searchParameters.CopyFrom(SearchDlg.searchParameters);
if (res == DialogResult.OK)
FindNext();
else
if (res == DialogResult.Retry)
FindAsNewTab();
}
}
}
private void MmSearchNext_Click(object sender, EventArgs e)
{
var tp = GetCurrentPacketTabPage();
if (tp == null)
return;
if ((searchParameters.SearchIncoming == false) && (searchParameters.SearchOutgoing == false))
{
MmSearchSearch_Click(null, null);
return;
}
else
FindNext();
}
private void FindNext()
{
var tp = GetCurrentPacketTabPage();
if ((tp == null) || (tp.lbPackets.Items.Count <= 0))
{
MessageBox.Show("Nothing to search in !", "Search", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var startIndex = tp.lbPackets.SelectedIndex;
if ((startIndex < 0) && (startIndex >= tp.lbPackets.Items.Count))
startIndex = -1;
int i = startIndex + 1;
for (int c = 0; c < tp.lbPackets.Items.Count - 1; c++)
{
if (i >= tp.lbPackets.Items.Count)
i = 0;
var pd = tp.PL.GetPacket(i);
if (pd.MatchesSearch(searchParameters))
{
// Select index
tp.lbPackets.SelectedIndex = i;
// Move to center
var iHeight = tp.lbPackets.ItemHeight;
if (iHeight <= 0)
iHeight = 8;
var iCount = tp.lbPackets.Size.Height / iHeight;
var tPos = i - (iCount / 2);
if (tPos < 0)
tPos = 0;
tp.lbPackets.TopIndex = tPos;
tp.lbPackets.Focus();
// We're done
return;
}
i++;
}
MessageBox.Show("No matches found !", "Search", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void FindAsNewTab()
{
var tp = GetCurrentPacketTabPage();
if ((tp == null) || (tp.lbPackets.Items.Count <= 0))
{
MessageBox.Show("Nothing to search in !", "Search as New Tab", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
PacketTabPage newtp = CreateNewPacketsTabPage();
newtp.Text = "*" + tp.Text;
newtp.LoadedLogFile = "Search Result";
var count = newtp.PLLoaded.SearchFrom(tp.PL, searchParameters);
if (count <= 0)
{
MessageBox.Show("No matches found !", "Search as New Tab", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
newtp.PL.CopyFrom(newtp.PLLoaded);
newtp.FillListBox();
}
UpdateStatusBarAndTitle(newtp);
}
private void MmFilePasteNew_Click(object sender, EventArgs e)
{
if ((!Clipboard.ContainsText()) || (Clipboard.GetText() == string.Empty))
{
MessageBox.Show("Nothing to paste", "Paste from Clipboard", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try