forked from uesp/skyedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SreditView.cpp
2791 lines (2220 loc) · 90.8 KB
/
SreditView.cpp
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
/*===========================================================================
*
* File: SreditView.CPP
* Author: Dave Humphrey ([email protected])
* Created On: 26 November 2011
*
* Implementation of the CSrEditView class.
*
*=========================================================================*/
/* Include Files */
#include "stdafx.h"
#include "sredit.h"
#include "sreditDoc.h"
#include "sreditView.h"
#include "srloaddlg.h"
#include "srprogressdlg.h"
#include "common/csvfile.h"
#include "srfiletreedlg.h"
#include "srfindbinarydlg.h"
#include "common/srtime.h"
#include "modfile/srexport.h"
#include "dialogs/SrRawDataDlg.h"
#include "mainfrm.h"
/*===========================================================================
*
* Begin Local Definitions
*
*=========================================================================*/
/* Debug definitions */
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CSrEditView, CFormView);
/*===========================================================================
* End of Local Definitions
*=========================================================================*/
/*===========================================================================
*
* Begin Class CSrEditView Message Map
*
*=========================================================================*/
BEGIN_MESSAGE_MAP(CSrEditView, CFormView)
ON_WM_SIZE()
ON_NOTIFY(TVN_SELCHANGED, IDC_RECORDTREE, OnSelchangedRecordtree)
ON_COMMAND(ID_FILE_IMPORT_CSV, OnFileImportCsv)
ON_COMMAND(ID_FILE_EXPORTCSV_SELECTEDITEMS, OnFileExportcsvSelecteditems)
ON_COMMAND(ID_RECORDTREE_RELOAD, OnRecordtreeReload)
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_FILE_EXPORTCSV_ITEMTYPE, OnRecordtreeExporttocsv)
ON_COMMAND(ID_VIEW_FILESTRUCTURE, OnViewFilestructure)
ON_COMMAND(ID_FILE_EXPORT_CSVEXTERIORLOCATIONS, OnFileExportCsvexteriorlocations)
ON_COMMAND(ID_FILE_EXPORT_CSVEXTMAPMARKERS, OnFileExportCsvExtMapMarkers)
ON_COMMAND(ID_HELP_TESTFIELDLOOKUP, OnHelpTestfieldlookup)
ON_COMMAND(ID_FILE_EXPORT_CSVEXPORTEXTERIORPLANTS, OnFileExportCsvexportexteriorplants)
ON_COMMAND(ID_EDIT_FINDBINARYDATA, OnEditFindbinarydata)
ON_COMMAND(ID_HELP_TESTFINDFORMID, OnHelpTestfindformid)
ON_COMMAND(ID_TEST_MEMORYSPEED, OnTestMemoryspeed)
ON_COMMAND(ID_TEST_TOKENSCRIPTS, OnTestTokenscripts)
ON_COMMAND(ID_RECORD_CLEAN, OnRecordClean)
ON_UPDATE_COMMAND_UI(ID_RECORD_CLEAN, OnUpdateHasSelectedRecords)
ON_COMMAND(ID_RECORD_MOVEACTIVE, OnRecordMoveactive)
ON_MESSAGE(ID_SRRECORDLIST_ACTIVATE, OnEditRecordMsg)
ON_WM_DESTROY()
ON_COMMAND(ID_MENU_EDITRECORD, OnMenuEditrecord)
ON_COMMAND(ID_EDIT_NEWRECORD, OnEditNewrecord)
ON_COMMAND(ID_RECORD_TOGGLEQUEST, OnRecordTogglequest)
ON_COMMAND(ID_RECORD_TOGGLEIGNORE, OnRecordToggleignore)
ON_COMMAND(ID_RECORD_TOGGLEDELETE, OnRecordToggledelete)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
ON_COMMAND(ID_RECORD_RENAME, OnRecordRename)
ON_COMMAND(ID_RECORD_CREATECOPY, OnRecordCreatecopy)
ON_COMMAND(ID_RECORD_BATCHEDIT, OnRecordBatchedit)
ON_COMMAND(ID_EDIT_FIND, OnEditFind)
ON_COMMAND(ID_HELP_TESTOUTPUTEFFECTS, OnHelpTestoutputeffects)
ON_COMMAND(ID_HELP_TESTRECORDSIZE, OnHelpTestrecordsize)
ON_COMMAND(ID_TEST_CLEANRECOMPILEALL, OnTestCleanrecompileall)
ON_COMMAND(ID_TEST_RECOMPILEALL, OnTestRecompileall)
ON_COMMAND(ID_HELP_TESTCOMPARESCRIPTS, OnHelpTestcomparescripts)
ON_COMMAND(ID_RECORDTREE_EXPORTTOCSV, OnRecordtreeExporttocsv)
ON_UPDATE_COMMAND_UI(ID_RECORD_MOVEACTIVE, OnUpdateHasSelectedRecords)
ON_UPDATE_COMMAND_UI(ID_RECORD_TOGGLEQUEST, OnUpdateHasSelectedRecords)
ON_UPDATE_COMMAND_UI(ID_RECORD_TOGGLEIGNORE, OnUpdateHasSelectedRecords)
ON_UPDATE_COMMAND_UI(ID_RECORD_TOGGLEDELETE, OnUpdateHasSelectedRecords)
ON_UPDATE_COMMAND_UI(ID_RECORD_CREATECOPY, OnUpdateHasSelectedRecords)
ON_UPDATE_COMMAND_UI(ID_RECORD_RENAME, OnUpdateHasSelectedRecords)
ON_UPDATE_COMMAND_UI(ID_RECORD_BATCHEDIT, OnUpdateHasSelectedRecords)
ON_UPDATE_COMMAND_UI(ID_MENU_VIEWRAWDATA, OnUpdateHasSelectedRecords)
ON_UPDATE_COMMAND_UI(ID_FILE_EXPORTCSV_SELECTEDITEMS, OnUpdateHasSelectedRecords)
ON_COMMAND(ID_EDIT_SELECTALL, OnEditSelectall)
ON_COMMAND(ID_MENU_VIEWRAWDATA, &CSrEditView::OnMenuViewrawdata)
ON_COMMAND(ID_HELP_TESTOUTPUTPERKS, &CSrEditView::OnHelpTestoutputperks)
ON_BN_CLICKED(IDC_ACTIVECHECK, &CSrEditView::OnBnClickedActivecheck)
ON_EN_CHANGE(IDC_FILTERTEXT, &CSrEditView::OnEnChangeFiltertext)
ON_WM_TIMER()
ON_WM_CLOSE()
ON_COMMAND(ID_EDIT_USELOCALSTRINGS, &CSrEditView::OnEditUselocalstrings)
ON_UPDATE_COMMAND_UI(ID_EDIT_USELOCALSTRINGS, &CSrEditView::OnUpdateEditUselocalstrings)
ON_COMMAND(ID_EDIT_SETMODAUTHOR, &CSrEditView::OnEditSetmodauthor)
ON_COMMAND(ID_EDIT_SETMODDESCRIPTION, &CSrEditView::OnEditSetmoddescription)
ON_COMMAND(ID_MENU_VIEWSUMMARY, &CSrEditView::OnMenuViewsummary)
ON_UPDATE_COMMAND_UI(ID_MENU_EDITRECORD, &CSrEditView::OnUpdateMenuEditrecord)
ON_WM_INITMENUPOPUP()
ON_COMMAND(ID_VIEW_ACTIVEONLY, &CSrEditView::OnViewActiveonly)
ON_UPDATE_COMMAND_UI(ID_VIEW_ACTIVEONLY, &CSrEditView::OnUpdateViewActiveonly)
ON_COMMAND(ID_MENU_CHANGEMODINDEX, &CSrEditView::OnMenuChangemodindex)
ON_UPDATE_COMMAND_UI(ID_MENU_CHANGEMODINDEX, &CSrEditView::OnUpdateMenuEditrecord)
ON_COMMAND(ID_MENU_CHANGEFORMID, &CSrEditView::OnMenuChangeformid)
ON_UPDATE_COMMAND_UI(ID_MENU_CHANGEFORMID, &CSrEditView::OnUpdateMenuEditrecord)
ON_COMMAND(ID_MENU_ASSIGNNEWFORMID, &CSrEditView::OnMenuAssignnewformid)
ON_UPDATE_COMMAND_UI(ID_MENU_ASSIGNNEWFORMID, &CSrEditView::OnUpdateMenuEditrecord)
END_MESSAGE_MAP()
/*===========================================================================
* End of Class CSrEditView Message Map
*=========================================================================*/
/*===========================================================================
*
* Begin Class Diagnostics
*
*=========================================================================*/
#ifdef _DEBUG
void CSrEditView::AssertValid() const { CFormView::AssertValid(); }
void CSrEditView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); }
CSrEditDoc* CSrEditView::GetDocument() { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSrEditDoc))); return (CSrEditDoc*)m_pDocument; }
#endif
/*===========================================================================
* End of Class Diagnostics
*=========================================================================*/
/*===========================================================================
*
* Function - int l_RenamePromptFunc (EditInfo, UserData);
*
* Used to prompt when renaming a record.
*
*=========================================================================*/
int l_RenamePromptFunc (sreditrecinfo_t& EditInfo, long UserData) {
CSrEditDlgHandler* pDlgHandler = (CSrEditDlgHandler *) UserData;
if (pDlgHandler == NULL) return (0);
return pDlgHandler->PromptRenameCopy(EditInfo);
}
/*===========================================================================
* End of Function l_RenamePromptFunc()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Constructor
*
*=========================================================================*/
CSrEditView::CSrEditView() : CFormView(CSrEditView::IDD)
{
m_IsInitialized = false;
m_pCurrentFilter = NULL;
m_UpdateFilterCounts = false;
m_hFilterUpdateThreadID = 0;
m_hFilterUpdateThread = 0;
m_ThreadCloseEvent = 0;
}
/*===========================================================================
* End of Class CSrEditView Constructor
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Destructor
*
*=========================================================================*/
CSrEditView::~CSrEditView()
{
SetEvent(m_ThreadCloseEvent);
DWORD Result = WaitForSingleObject(m_hFilterUpdateThread, 10000);
if (Result != WAIT_OBJECT_0) TerminateThread(m_hFilterUpdateThread, 0x8888);
Sleep(50);
DWORD ExitCode = 0;
BOOL bResult = GetExitCodeThread(m_hFilterUpdateThread, &ExitCode);
SystemLog.Printf("Exit FilterUpdateThread: Result = 0x%08X, ExitCode(%d) = 0x%08X", Result, bResult, ExitCode);
CloseHandle(m_ThreadCloseEvent);
CloseHandle(m_hFilterUpdateThread);
}
/*===========================================================================
* End of Class CSrEditView Destructor
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Method - void DoDataExchange (pDX);
*
*=========================================================================*/
void CSrEditView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
DDX_Control(pDX, IDC_VEDGE, m_VertEdge);
DDX_Control(pDX, IDC_RECORDLIST, m_RecordList);
DDX_Control(pDX, IDC_RECORDTREE, m_RecordTree);
DDX_Control(pDX, IDC_FILTERTEXT, m_FilterText);
DDX_Control(pDX, IDC_ACTIVECHECK, m_ActiveCheck);
}
/*===========================================================================
* End of Class Method CSrEditView::DoDataExchange()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnContextMenu (pWnd, Point);
*
*=========================================================================*/
void CSrEditView::OnContextMenu(CWnd* pWnd, CPoint Point) {
CMenu Menu;
CMenu* pSubMenu;
int Result;
if (pWnd->GetDlgCtrlID() == IDC_RECORDTREE) {
Result = Menu.LoadMenu(IDR_RECORDTREE_MENU);
if (!Result) return;
pSubMenu = Menu.GetSubMenu(0);
if (pSubMenu == NULL) return;
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, Point.x, Point.y, this, NULL);
}
else if (pWnd->GetDlgCtrlID() == IDC_RECORDLIST) {
Result = Menu.LoadMenu(IDR_RECORDLIST_MENU);
if (!Result) return;
pSubMenu = Menu.GetSubMenu(0);
if (pSubMenu == NULL) return;
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, Point.x, Point.y, this, NULL);
}
}
/*===========================================================================
* End of Class Event CSrEditView::OnContextMenu()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnFileExportCsvexportexteriorplants ();
*
*=========================================================================*/
void CSrEditView::OnFileExportCsvexportexteriorplants() {
srexportinfo_t ExportInfo = g_ExportCsvPlants;
CString Buffer;
/* Prompt user for output filename */
Buffer.Format(_T("Select CSV File to Export Exterior Plant Locations..."));
ExportInfo.GroupFormID = 0;
OnCsvExport(ExportInfo, Buffer);
}
/*===========================================================================
* End of Class Event CSrEditView::OnFileExportCsvexportexteriorplants()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnFileExportCsvexteriorlocations ();
*
*=========================================================================*/
void CSrEditView::OnFileExportCsvexteriorlocations() {
srexportinfo_t ExportInfo = g_ExportCsvExtLocations;
CString Buffer;
Buffer.Format(_T("Select CSV File to Export Exterior Locations..."));
ExportInfo.GroupFormID = 0;
OnCsvExport(ExportInfo, Buffer);
}
/*===========================================================================
* End of Class Event CSrEditView::OnFileExportCsvexteriorlocations()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnFileExportCsvExtMapMarkers ();
*
*=========================================================================*/
void CSrEditView::OnFileExportCsvExtMapMarkers() {
srexportinfo_t ExportInfo = g_ExportCsvMapMarkers;
CString Buffer;
Buffer.Format(_T("Select CSV File to Export Exterior Map Markers..."));
ExportInfo.GroupFormID = 0;
OnCsvExport(ExportInfo, Buffer);
}
/*===========================================================================
* End of Class Event CSrEditView::OnFileExportCsvExtMapMarkers()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - bool OnCsvExport (ExportInfo, pDialogTitle);
*
*=========================================================================*/
bool CSrEditView::OnCsvExport (srexportinfo_t& ExportInfo, const TCHAR* pDialogTitle) {
CFileDialog OpenDlg(FALSE, SREDIT_CSV_EXT, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, SREDIT_CSV_FILTER, this);
int Result;
/* Prompt user for output filename */
if (pDialogTitle != NULL) OpenDlg.m_ofn.lpstrTitle = pDialogTitle;
Result = OpenDlg.DoModal();
if (Result != IDOK) return (true);
Result = SrCsvExport(OpenDlg.GetPathName(), GetDocument()->GetActiveFile(), ExportInfo);
if (Result != 0) {
SrEditShowError(_T("CSV Error"), _T("Error exporting records to the CSV file '%s'!"), OpenDlg.GetPathName());
}
return (Result != 0);
}
/*===========================================================================
* End of Class Event CSrEditView::OnCsvExport()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnFileExportcsvSelecteditems ();
*
*=========================================================================*/
void CSrEditView::OnFileExportcsvSelecteditems() {
CFileDialog OpenDlg(FALSE, SREDIT_CSV_EXT, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, SREDIT_CSV_FILTER, this);
POSITION ItemPos;
CSrRecord* pRecord;
CSrRecord* pFirstRecord;
srcsvinfo_t CsvInfo;
CCsvFile CsvFile;
CString Buffer;
int ListIndex;
int Result;
/* Ignore if no records to export */
ItemPos = m_RecordList.GetFirstSelectedItemPosition();
if (ItemPos == NULL) return;
/* Prompt user for output filename */
Buffer.Format(_T("Select CSV File to Export %d Records..."), m_RecordList.GetSelectedCount());
OpenDlg.m_ofn.lpstrTitle = Buffer;
Result = OpenDlg.DoModal();
if (Result != IDOK) return;
CsvInfo.pCsvFile = &CsvFile;
/* Output all selected records in the current list */
while (ItemPos != NULL) {
ListIndex = m_RecordList.GetNextSelectedItem(ItemPos);
pRecord = m_RecordList.GetRecord(ListIndex);
if (pRecord == NULL) continue;
/* Initialize the CSV file on the first record */
if (CsvFile.GetNumRows() == 0) {
pFirstRecord = pRecord;
Result = PrepareSrCsvExport(CsvInfo, pRecord->GetFieldMap());
if (!Result) return;
}
/* Ensure all records are the same type */
if (pFirstRecord->GetRecordType() != pRecord->GetRecordType()) continue;
pRecord->ExportCsv(CsvInfo);
}
Result = CsvFile.Save(OpenDlg.GetPathName());
if (!Result) {
SrEditShowError(_T("CSV Error"), _T("Error saving the CSV file '%s'!"), OpenDlg.GetPathName());
}
}
/*===========================================================================
* End of Class Event CSrEditView::OnFileExportcsvSelecteditems()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnRecordtreeExporttocsv ();
*
*=========================================================================*/
void CSrEditView::OnRecordtreeExporttocsv() {
CFileDialog OpenDlg(FALSE, SREDIT_CSV_EXT, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, SREDIT_CSV_FILTER, this);
CSrRecord* pRecord;
CSrRecord* pFirstRecord;
srcsvinfo_t CsvInfo;
CCsvFile CsvFile;
CString Buffer;
int ListIndex;
int Result;
/* Ignore if no filter currently in use or no records to export */
if (m_pCurrentFilter == NULL) return;
if (m_RecordList.GetItemCount() <= 0) return;
/* Prompt user for output filename */
Buffer.Format(_T("Select CSV File to Export %d Records..."), m_RecordList.GetItemCount());
OpenDlg.m_ofn.lpstrTitle = Buffer;
Result = OpenDlg.DoModal();
if (Result != IDOK) return;
CsvInfo.pCsvFile = &CsvFile;
/* Output all records in the current list */
for (ListIndex = 0; ListIndex < m_RecordList.GetItemCount(); ++ListIndex) {
pRecord = m_RecordList.GetRecord(ListIndex);
if (pRecord == NULL) continue;
/* Initialize the CSV file on the first record */
if (CsvFile.GetNumRows() == 0) {
pFirstRecord = pRecord;
Result = PrepareSrCsvExport(CsvInfo, pRecord->GetFieldMap());
if (!Result) return;
}
/* Ensure all records are the same type */
if (pFirstRecord->GetRecordType() != pRecord->GetRecordType()) continue;
pRecord->ExportCsv(CsvInfo);
}
Result = CsvFile.Save(OpenDlg.GetPathName());
if (!Result) {
SrEditShowError(_T("Error saving the CSV file '%s'!"), OpenDlg.GetPathName());
}
}
/*===========================================================================
* End of Class Event CSrEditView::OnRecordtreeExporttocsv()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnFileImportCsv ();
*
*=========================================================================*/
void CSrEditView::OnFileImportCsv() {
CFileDialog OpenDlg(TRUE, SREDIT_CSV_EXT, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, SREDIT_CSV_FILTER, this);
CString Buffer;
CCsvFile CsvFile;
dword NewRecords;
int Result;
OpenDlg.m_ofn.lpstrTitle = _T("Select CSV File to Import...");
Result = OpenDlg.DoModal();
if (Result != IDOK) return;
Result = CsvFile.Load(OpenDlg.GetPathName());
if (!Result) {
SrEditShowError(_T("Failed to load the file '%s'!"), OpenDlg.GetPathName());
return;
}
Buffer.Format(_T("Loaded %d rows from csv file"), CsvFile.GetNumRows());
MessageBox(Buffer);
Result = GetDocument()->GetRecordHandler().ImportCsv(NewRecords, CsvFile);
if (NewRecords > 0) GetDocument()->SetModifiedFlag(TRUE);
if (!Result) SrEditShowError(_T("Error importing CSV file!"));
}
/*===========================================================================
* End of Class Event CSrEditView::OnFileImportCsv()
*=========================================================================*/
DWORD WINAPI l_ThreadFilterUpdate(LPVOID lpParameter)
{
CSrEditView* pView = (CSrEditView *) lpParameter;
if (pView == NULL) return 1;
pView->ThreadUpdateFilterProc();
//ExitThread(0x1234);
return 0x4321;
}
/*===========================================================================
*
* Class CSrEditView Event - void OnInitialUpdate ();
*
*=========================================================================*/
void CSrEditView::OnInitialUpdate() {
/* Call the base class method first */
CFormView::OnInitialUpdate();
m_ThreadCloseEvent = CreateEvent(NULL, TRUE, FALSE, TEXT("SkyEditThreadClose"));
m_hFilterUpdateThread = CreateThread(NULL, 0, l_ThreadFilterUpdate, this, 0, &m_hFilterUpdateThreadID);
m_DlgHandler.SetDocument(GetDocument());
GetDocument()->GetRecordHandler().GetEventHandler().AddListener(this);
GetDocument()->GetRecordHandler().GetEventHandler().AddListener(&m_DlgHandler);
/* Setup the tree control */
m_RecordTree.Initialize(CSrRecordTreeCtrl::GetOptions().FullFilterFile);
/* Setup the list control */
m_RecordList.SetListName("MainList");
m_RecordList.DefaultSettings();
//m_RecordList.SetupList(SR_NAME_ARMO);
m_RecordList.SetOwner(this);
ResizeParentToFit();
m_RecordList.SetAutoResizeOffset();
m_RecordList.SetAutoResize(true);
m_IsInitialized = true;
/* Disable the view scroll bars */
SetScrollSizes(MM_TEXT, CSize(0, 0) );
//GetParentFrame()->RecalcLayout();
//ResizeParentToFit();
UpdateContents();
}
/*===========================================================================
* End of Class Event CSrEditView::OnInitialUpdate()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnEditFindbinarydata ();
*
*=========================================================================*/
void CSrEditView::OnEditFindbinarydata() {
CSrProgressDlg* pProgressDlg;
CSrCallback SrEditFindCallback;
CSrFindBinaryDlg FindDlg;
CString Buffer;
const TCHAR* pParse;
dword Index;
srfinddata_t FindData;
dword Count;
int Result;
srtimer_t Timer;
double DeltaTime;
byte* pNewData = NULL;
Result = FindDlg.DoModal();
if (Result != IDOK) return;
/* Initialize the find data */
FindData.Flags = SR_FIND_OUTPUTLOG /*| SR_FIND_ALLHEADERS*/;
FindData.DataSize = _tcslen(FindDlg.GetBinaryData())/2;
if (FindData.DataSize == 0) return;
pNewData = new byte[FindData.DataSize + 4];
FindData.pData = pNewData;
/* Parse the binary data text */
Index = 0;
pParse = FindDlg.GetBinaryData();
while (Index < FindData.DataSize*2) {
pNewData[Index/2] = ConvertFromHexByte(pParse + Index);
Index += 2;
}
Buffer.Empty();
for (Index = 0; Index < FindData.DataSize; ++Index) {
Buffer += ConvertByteToHexChar(FindData.pData[Index]);
}
SystemLog.Printf("Searching for binary data '%s' (%.*s)...", Buffer, FindData.DataSize, FindData.pData);
pProgressDlg = ShowSrProgressDlg(_T("Find Data"), _T("Finding binary data..."));
SrEditFindCallback.SetCallbackInterval(1);
SrEditFindCallback.SetFunction(SrEditDefaultProgressCallback);
SrEditFindCallback.SetUserPtr((void *) pProgressDlg);
SrEditFindCallback.Reset();
SrEditFindCallback.ForceCallback(0);
SrStartTimer(Timer);
/* Perform the find */
Count = GetDocument()->Search(FindData, &SrEditFindCallback);
DeltaTime = SrEndTimer(Timer);
SystemLog.Printf("Found %u matches in %u files, %u groups, %u records, and %u subrecords in %f seconds!", Count,
FindData.FileCount, FindData.GroupCount, FindData.RecordCount, FindData.SubrecordCount, DeltaTime);
DestroySrProgressDlg(pProgressDlg);
/* Cleanup the find data */
delete[] pNewData;
}
/*===========================================================================
* End of Class Event CSrEditView::OnEditFindbinarydata()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnHelpTestfindformid ();
*
*=========================================================================*/
void CSrEditView::OnHelpTestfindformid() {
CSrProgressDlg* pProgressDlg;
CString Buffer;
CSrRecord* pRecord;
srfinddata_t FindData;
CSrCallback SrEditFindCallback;
dword Count = 0;
dword TotalCount;
dword LimitCount = 200;
dword Index;
srrectype_t ExcludeNames[] = { SR_NAME_LAND, SR_NAME_NULL }; //SR_NAME_PGRD
byte* pNewData = NULL;
CSrGroup* pGroup = GetDocument()->GetTopGroup()->GetTypeGroup(SR_NAME_ARMO);
if (pGroup == NULL) return;
TotalCount = pGroup->GetNumRecords();
TotalCount = LimitCount;
pProgressDlg = ShowSrProgressDlg(_T("Find FormID"), _T("Finding formid..."));
SrEditFindCallback.SetCallbackInterval(1);
SrEditFindCallback.SetFunction(SrEditDefaultProgressCallback);
SrEditFindCallback.SetUserPtr((void *) pProgressDlg);
SrEditFindCallback.SetTotalRecords(TotalCount);
SrEditFindCallback.Reset();
/* Initialize the find data */
FindData.Flags = SR_FIND_OUTPUTLOG /*| SR_FIND_ALLHEADERS*/;
FindData.DataSize = 4;
pNewData = new byte[8];
FindData.pData = pNewData;
FindData.pExcludeRecords = &ExcludeNames[0];
Index = 0;
pRecord = SrCastClassNull(CSrRecord, pGroup->GetRecord(Index));
while (pRecord) {
Buffer.Format("Finding formId 0x%08X... (%4.4s)", pRecord->GetFormID(), pRecord->GetRecordType().Name);
SystemLog.Printf(Buffer);
pProgressDlg->SetLabel(Buffer);
pProgressDlg->SetProgress((float)Count*100.0f / (float) TotalCount);
++Count;
++Index;
if (Count > LimitCount) break;
*(dword *)(pNewData) = pRecord->GetFormID();
GetDocument()->GetActiveFile().Find(FindData, &SrEditFindCallback);
pRecord = SrCastClassNull(CSrRecord, pGroup->GetRecord(Index));
}
DestroySrProgressDlg(pProgressDlg);
/* Cleanup the find data */
delete[] pNewData;
}
/*===========================================================================
* End of Class Event CSrEditView::OnHelpTestfindformid()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnRecordtreeReload ();
*
*=========================================================================*/
void CSrEditView::OnRecordtreeReload() {
m_RecordTree.LoadFilters(CSrRecordTreeCtrl::GetOptions().FullFilterFile);
}
/*===========================================================================
* End of Class Event CSrEditView::OnRecordtreeReload()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnSize (nType, CX, CY);
*
*=========================================================================*/
void CSrEditView::OnSize (UINT nType, int CX, int CY)
{
CFormView::OnSize(nType, CX, CY);
if (m_IsInitialized)
{
m_RecordList.SetWindowPos(NULL, 0, 0, CX - 191, CY, SWP_NOMOVE | SWP_NOZORDER);
m_RecordTree.SetWindowPos(NULL, 0, 0, 188, CY - 48, SWP_NOMOVE | SWP_NOZORDER);
m_VertEdge.SetWindowPos(NULL, 0, 0, 3, CY+2, SWP_NOMOVE | SWP_NOZORDER);
}
}
/*===========================================================================
* End of Class Event CSrEditView::OnSize()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnSelchangedRecordtree (pNMHDR, pResult);
*
*=========================================================================*/
void CSrEditView::OnSelchangedRecordtree (NMHDR* pNMHDR, LRESULT* pResult) {
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
CSrRecordFilter* pFilter;
DWORD Value;
*pResult = 0;
Value = m_RecordTree.GetItemData(pNMTreeView->itemNew.hItem);
if (Value == 0) return;
pFilter = (CSrRecordFilter *) Value;
if (pFilter == m_pCurrentFilter) return;
if (pFilter->IsFlagEmpty() || pFilter->GetRecordType() == SR_NAME_NULL) pFilter = NULL;
m_pCurrentFilter = pFilter;
m_RecordList.SetupList(m_pCurrentFilter);
m_RecordList.AddAllRecords(GetDocument()->GetTopGroup());
}
/*===========================================================================
* End of Class Event CSrEditView::OnSelchangedRecordtree()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnUpdate (pSender, lHint, pHint);
*
*=========================================================================*/
void CSrEditView::OnUpdate (CView* pSender, LPARAM lHint, CObject* pHint) {
srrecupdateinfo_t* pUpdateInfo = (srrecupdateinfo_t *) pHint;
switch (lHint) {
case SREDIT_DOC_HINT_UPDATEALL:
UpdateContents();
break;
case SREDIT_DOC_HINT_UPDATERECORD:
m_RecordList.UpdateRecord(pUpdateInfo->pNewRecord, pUpdateInfo->pOldRecord);
m_RecordTree.UpdateFilterCounts(GetDocument()->GetTopGroup());
break;
case SREDIT_DOC_HINT_ADDRECORD:
m_RecordList.AddRecord(pUpdateInfo->pNewRecord);
m_RecordTree.IncludeInCounts(pUpdateInfo->pNewRecord);
break;
case SREDIT_DOC_HINT_GETDATA:
/* TODO */
break;
case SREDIT_DOC_HINT_CLEARFILTERS: {
break; }
case SREDIT_DOC_HINT_UPDATEFILTERS: {
break; }
default:
CView::OnUpdate(pSender, lHint, pHint);
break;
}
}
/*===========================================================================
* End of Class Event CSrEditView::OnUpdate()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnViewFilestructure ();
*
*=========================================================================*/
void CSrEditView::OnViewFilestructure() {
CSrFileTreeDlg TreeDlg;
TreeDlg.SetTopGroup(GetDocument()->GetTopGroup());
TreeDlg.DoModal();
}
/*===========================================================================
* End of Class Event CSrEditView::OnViewFilestructure()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Method - BOOL PreCreateWindow (cs);
*
*=========================================================================*/
BOOL CSrEditView::PreCreateWindow (CREATESTRUCT& cs) {
return CFormView::PreCreateWindow(cs);
}
/*===========================================================================
* End of Class Method CSrEditView::PreCreateWindow()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditView Event - void OnHelpTestfieldlookup ();
*
1096769 Records
09:17:59 (24609) - Iteration Time = 0.013028 secs
09:17:59 (24718) - Iteration Time with Class Cast = 0.095499 secs
09:17:59 (25234) - Find WEIGHT Field = 0.522570 secs
09:18:00 (25781) - Get WEIGHT String = 0.551424 secs
09:18:00 (26234) - Find EDITORID Field = 0.452844 secs
09:18:01 (26750) - Get EDITORID String = 0.511969 secs
09:18:01 (26984) - Find WEIGHT Field1 = 0.232224 secs
09:18:01 (27218) - Find EDITORID Field1 = 0.228567 secs
09:18:01 (27468) - Get WEIGHT String1 = 0.251833 secs
09:18:02 (27718) - Get EDITORID String1 = 0.255710 secs
09:18:05 (30984) - Iteration Time = 0.013076 secs
09:18:05 (31078) - Iteration Time with Class Cast = 0.095586 secs
09:18:06 (31593) - Find WEIGHT Field = 0.508603 secs
09:18:06 (32015) - Get WEIGHT String = 0.425909 secs
09:18:06 (32453) - Find EDITORID Field = 0.439205 secs
09:18:07 (32859) - Get EDITORID String = 0.393132 secs
09:18:07 (33031) - Find WEIGHT Field1 = 0.173945 secs
09:18:07 (33187) - Find EDITORID Field1 = 0.166808 secs
09:18:07 (33375) - Get WEIGHT String1 = 0.181755 secs
09:18:08 (33609) - Get EDITORID String1 = 0.233427 secs
1023759 Records using GetFirst/GetNext...
11:36:29 (26968) - Iteration Time = 0.102827 secs
11:36:29 (27093) - Iteration Time with Class Cast = 0.139105 secs
11:36:29 (27312) - Find WEIGHT Field = 0.217886 secs
11:36:30 (27562) - Get WEIGHT String = 0.247051 secs
11:36:30 (27781) - Find EDITORID Field = 0.212212 secs
11:36:30 (28078) - Get EDITORID String = 0.292917 secs
11:36:30 (28218) - Find WEIGHT Field1 = 0.140716 secs
11:36:30 (28359) - Find EDITORID Field1 = 0.140012 secs
11:36:30 (28500) - Get WEIGHT String1 = 0.141654 secs
11:36:31 (28640) - Get EDITORID String1 = 0.139036 secs
11:36:31 (28640) - Record Count = 1023759
Using Switch Compare
10:03:11 (30968) - Compare WEIGHT Field = 0.173250 secs
10:03:11 (31140) - Compare EDITORID Field = 0.175900 secs
Using Field Map Compare
01:06:38 (72687) - Compare WEIGHT Field = 0.239074 secs
01:06:39 (72984) - Compare EDITORID Field = 0.303329 secs
*=========================================================================*/
void CSrEditView::OnHelpTestfieldlookup() {
/*
srtimer_t Timer;
CSrRecordHandler* pHandler = &(GetDocument()->GetRecordHandler());
//CSrEspFile* pFile = &(GetDocument()->GetEspFile());
CSrBaseRecord* pBaseRecord;
const srrecfield_t* pField;
CSString Buffer;
CSrRecord* pRecord;
//CSrWeapRecord TestRecord;
SRMAPPOS RecordPos;
dword Count = 0;
TestRecord.InitializeNew();
TestRecord.SetEditorID("testeditorid01");
SrStartTimer(Timer);
pBaseRecord = pHandler->GetFirstRecord(RecordPos);
while (pBaseRecord != NULL) {
++Count;
pBaseRecord = pHandler->GetNextRecord(RecordPos);
}
SrEndTimer(Timer, "Iteration Time");
SrStartTimer(Timer);
pBaseRecord = pHandler->GetFirstRecord(RecordPos);
while (pBaseRecord != NULL) {
pRecord = SrCastClass(CSrRecord, pBaseRecord);
if (pRecord) {
}
pBaseRecord = pHandler->GetNextRecord(RecordPos);
}
SrEndTimer(Timer, "Iteration Time with Class Cast");
SrStartTimer(Timer);
pBaseRecord = pHandler->GetFirstRecord(RecordPos);
while (pBaseRecord != NULL) {
pRecord = SrCastClass(CSrRecord, pBaseRecord);
if (pRecord) {
pField = pRecord->FindField(SR_FIELD_WEIGHT);
}
pBaseRecord = pHandler->GetNextRecord(RecordPos);
}
SrEndTimer(Timer, "Find WEIGHT Field");
SrStartTimer(Timer);
pBaseRecord = pHandler->GetFirstRecord(RecordPos);
while (pBaseRecord != NULL) {
pRecord = SrCastClass(CSrRecord, pBaseRecord);
if (pRecord) {
pRecord->GetField(Buffer, SR_FIELD_WEIGHT);
}
pBaseRecord = pHandler->GetNextRecord(RecordPos);
}
SrEndTimer(Timer, "Get WEIGHT String");
SrStartTimer(Timer);
pBaseRecord = pHandler->GetFirstRecord(RecordPos);
while (pBaseRecord != NULL) {
pRecord = SrCastClass(CSrRecord, pBaseRecord);
if (pRecord) {
pField = pRecord->FindField(SR_FIELD_EDITORID);
}
pBaseRecord = pHandler->GetNextRecord(RecordPos);
}
SrEndTimer(Timer, "Find EDITORID Field");
SrStartTimer(Timer);
pBaseRecord = pHandler->GetFirstRecord(RecordPos);
while (pBaseRecord != NULL) {
pRecord = SrCastClass(CSrRecord, pBaseRecord);
if (pRecord) {
pRecord->GetField(Buffer, SR_FIELD_EDITORID);
}
pBaseRecord = pHandler->GetNextRecord(RecordPos);
}
SrEndTimer(Timer, "Get EDITORID String");
SrStartTimer(Timer);
pBaseRecord = pHandler->GetFirstRecord(RecordPos);
while (pBaseRecord != NULL) {
pRecord = SrCastClass(CSrRecord, pBaseRecord);
if (pRecord) {
//pField = pRecord->GetField1(SR_FIELD_WEIGHT);
}
pBaseRecord = pHandler->GetNextRecord(RecordPos);
}
SrEndTimer(Timer, "Find WEIGHT Field1");
SrStartTimer(Timer);
pBaseRecord = pHandler->GetFirstRecord(RecordPos);
while (pBaseRecord != NULL) {
pRecord = SrCastClass(CSrRecord, pBaseRecord);
if (pRecord) {
//pField = pRecord->GetField1(SR_FIELD_EDITORID);
}
pBaseRecord = pHandler->GetNextRecord(RecordPos);
}
SrEndTimer(Timer, "Find EDITORID Field1");
SrStartTimer(Timer);
pBaseRecord = pHandler->GetFirstRecord(RecordPos);