forked from uesp/skyedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sredit.cpp
1674 lines (1313 loc) · 50.5 KB
/
sredit.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: Sredit.CPP
* Author: Dave Humphrey ([email protected])
* Created On: 26 November 2011
*
* Defines the class behaviors for the application.
*
*=========================================================================*/
/* Include Files */
#include "stdafx.h"
#include "sredit.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "sreditDoc.h"
#include "sreditView.h"
#include "srloaddlg.h"
#include "stdarg.h"
#include "aboutdlg.h"
#include "shlwapi.h"
#include "dialogs/SrScriptView.h"
#include "ChildFrmScript.h"
#include "ChildFrmFix.h"
#include "common/srbackup.h"
/*===========================================================================
*
* Begin Local Definitions
*
*=========================================================================*/
/* Debug definitions */
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/* Main application object */
CSrEditApp theApp;
/* Global clipboard objects */
CSrConditionArray g_GlobClipConditions;
CSrVmadScriptArray g_GlobClipScripts;
/*===========================================================================
* End of Local Definitions
*=========================================================================*/
/*===========================================================================
*
* Begin CSrEditApp Message Map
*
*=========================================================================*/
BEGIN_MESSAGE_MAP(CSrEditApp, CWinAppEx)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
END_MESSAGE_MAP()
/*===========================================================================
* End of CSrEditApp Message Map
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Constructor
*
*=========================================================================*/
CSrEditApp::CSrEditApp()
{
m_pCurrentLoadInfo = NULL;
m_pCurrentProgressDlg = NULL;
m_pCurrentLoadCallback = NULL;
m_NewFileIndex = 1;
m_InitResourceHandler = false;
m_pMainFrame = NULL;
m_LoadAllScripts = false;
m_EditScriptExternalByDefault = false;
}
/*===========================================================================
* End of Class CSrEditApp Constructor
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Destructor
*
*=========================================================================*/
CSrEditApp::~CSrEditApp()
{
}
/*===========================================================================
* End of Class CSrEditApp Destructor
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - BOOL InitInstance ();
*
*=========================================================================*/
BOOL CSrEditApp::InitInstance() {
TCHAR Buffer[_MAX_PATH + 8];
CSString PathBuffer;
bool Result;
SystemLog.Open("skyedit.log");
AfxEnableControlContainer();
AfxInitRichEdit2();
InitContextMenuManager();
#ifdef _AFXDLL
Enable3dControls();
#else
Enable3dControlsStatic();
#endif
/* Register custom window classes */
WNDCLASSEX ClassInfo;
ClassInfo.cbSize = sizeof(ClassInfo);
ClassInfo.style = 0;
ClassInfo.lpfnWndProc = DefWindowProc;
ClassInfo.cbClsExtra = 0;
ClassInfo.cbWndExtra = 0;
ClassInfo.hInstance = m_hInstance;
ClassInfo.hIcon = NULL;
ClassInfo.hCursor = NULL;
ClassInfo.hbrBackground = NULL;
ClassInfo.hIconSm = NULL;
ClassInfo.lpszMenuName = NULL;
ClassInfo.lpszClassName = "PreviewImageClass";
RegisterClassEx(&ClassInfo);
/* Initialize the image library */
ilInit();
iluInit();
ilutInit();
/* Load the standard display filters file */
GetCurrentDirectory(_MAX_PATH, Buffer);
m_AppPath = Buffer;
TerminatePathString(m_AppPath);
/* Change the registry key under which our settings are stored. */
SetRegistryKey(_T("UESP"));
/* Load standard INI file options (including MRU) */
LoadStdProfileSettings();
/* Register document templates */
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(IDR_SREDITTYPE,
RUNTIME_CLASS(CSrEditDoc),
RUNTIME_CLASS(CChildFrame), /* Custom MDI child frame */
RUNTIME_CLASS(CSrEditView));
AddDocTemplate(pDocTemplate);
/* Create main MDI Frame window */
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE;
m_pMainWnd = pMainFrame;
m_pMainFrame = pMainFrame;
/* Load the default config file */
LoadOptions(SREDIT_OPTIONS_FILE);
/* Change to the data file path */ /*
Result = GetSrInstallPath(PathBuffer);
if (Result) {
PathBuffer += "data\\";
SetCurrentDirectory(PathBuffer);
} //*/
/* Parse command line for standard shell commands, DDE, file open */
CCommandLineInfo cmdInfo;
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
ParseCommandLine(cmdInfo);
/* Dispatch commands specified on the command line */
if (!ProcessShellCommand(cmdInfo)) return FALSE;
/* The main window has been initialized, so show and update it. */
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
/* Resource handler and view initialization */
m_pCurrentProgressDlg = ShowSrProgressDlg("Resources", "Initializing Resource Information...");
m_pCurrentProgressDlg->SetAllowCancel(false);
m_pCurrentProgressDlg->Update(0);
InitResourceHandler();
DestroySrProgressDlg(m_pCurrentProgressDlg);
m_pCurrentProgressDlg = NULL;
//OpenResourceView();
LoadAllScripts();
/* Display the about box initially if required */
m_ConfigFile.GetBoolean(Result, "DisplayAboutOnLoad", true);
if (Result) OnAppAbout();
return TRUE;
}
/*===========================================================================
* End of Class Method CSrEditApp::InitInstance()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - int ExitInstance ();
*
*=========================================================================*/
int CSrEditApp::ExitInstance()
{
extern long g_StringAllocations;
SystemLog.Printf("Total String Allocations = %ld", g_StringAllocations);
CSrMultiRecordHandler::m_SkyrimMaster.Destroy();
m_ResourceHandler.Destroy();
m_BsaFiles.Destroy();
return CWinAppEx::ExitInstance();
}
/*===========================================================================
* End of Class Method CSrEditApp::ExitInstance()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Event - void OnAppAbout ();
*
* Application command to run the about dialog.
*
*=========================================================================*/
void CSrEditApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/*===========================================================================
* End of Class Event CSrEditApp::OnAppAbout()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Event - void OnFileOpen (void);
*
*=========================================================================*/
void CSrEditApp::OnFileOpen (void)
{
CSrProgressDlg* pProgressDlg;
CSrCallback LoadCallback;
CDocument* pDocument;
CSrLoadDlg LoadDlg;
srfileloadinfo_t* pLoadInfo;
CString Buffer;
bool NotActive;
int Result;
/* Prompt the user to select the files */
Result = LoadDlg.DoModal();
if (Result != IDOK) return;
pLoadInfo = &LoadDlg.GetLoadInfo();
/* Initialize the progress dialog */
pProgressDlg = ShowSrProgressDlg(_T("Loading Plugin"), _T("Loading..."));
//pProgressDlg->SetCancelMsg(_T("Are you sure you wish to abort loading this plugin?"));
LoadCallback.SetCallbackInterval(10000);
LoadCallback.SetFunction(SrEditDefaultProgressCallback);
LoadCallback.SetUserPtr((void *) pProgressDlg);
LoadCallback.Reset();
Buffer = pLoadInfo->m_ActiveFilename;
NotActive = Buffer.IsEmpty() != 0;
if (NotActive) Buffer.Format(_T("noname%u"), m_NewFileIndex++);
/* Load the file */
m_pCurrentLoadInfo = pLoadInfo;
m_pCurrentProgressDlg = pProgressDlg;
m_pCurrentLoadCallback = &LoadCallback;
pDocument = OpenDocumentFile(Buffer);
m_pCurrentLoadInfo = NULL;
m_pCurrentProgressDlg = NULL;
m_pCurrentLoadCallback = NULL;
DestroySrProgressDlg(pProgressDlg);
if (pDocument == NULL) SrEditShowLastError(_T("Failed to load the requested plugin(s)!"));
}
/*===========================================================================
* End of Class Event CSrEditApp::OnFileOpen()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Event - void OnFileNew (void);
*
*=========================================================================*/
void CSrEditApp::OnFileNew (void)
{
CSrProgressDlg* pProgressDlg;
CSrCallback LoadCallback;
CDocument* pDocument;
CSrLoadDlg LoadDlg;
srfileloadinfo_t* pLoadInfo;
CString Buffer;
int Result;
/* Prompt the user to select the files */
Result = LoadDlg.DoModalNew();
if (Result != IDOK) return;
pLoadInfo = &LoadDlg.GetLoadInfo();
/* Initialize the progress dialog */
pProgressDlg = ShowSrProgressDlg("Loading Plugins for New File", "Loading...");
LoadCallback.SetCallbackInterval(10000);
LoadCallback.SetFunction(SrEditDefaultProgressCallback);
LoadCallback.SetUserPtr((void *) pProgressDlg);
LoadCallback.Reset();
Buffer.Format("noname%u", m_NewFileIndex++);
/* Load the file */
m_pCurrentLoadInfo = pLoadInfo;
m_pCurrentProgressDlg = pProgressDlg;
m_pCurrentLoadCallback = &LoadCallback;
pDocument = OpenDocumentFile(Buffer);
if (pDocument == NULL) return;
pDocument->SetModifiedFlag(TRUE);
m_pCurrentLoadInfo = NULL;
m_pCurrentProgressDlg = NULL;
m_pCurrentLoadCallback = NULL;
DestroySrProgressDlg(pProgressDlg);
if (pDocument == NULL) SrEditShowLastError("Failed to create a new plugin file!");
}
/*===========================================================================
* End of Class Event CSrEditApp::OnFileNew()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - CDocument* OpenDocumentFile (lpszFileName);
*
*=========================================================================*/
CDocument* CSrEditApp::OpenDocumentFile (LPCTSTR lpszFileName)
{
return CWinAppEx::OpenDocumentFile(lpszFileName, FALSE);
}
/*===========================================================================
* End of Class Method CSrEditApp::OpenDocumentFile()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - bool LoadOptions (pFilename);
*
*=========================================================================*/
bool CSrEditApp::LoadOptions (const TCHAR* pFilename)
{
bool Result;
Result = m_ConfigFile.Load(pFilename);
if (!Result) return (false);
/* Update all settings */
UpdateOptions(false);
return (true);
}
/*===========================================================================
* End of Class Method CSrEditApp::LoadOptions()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - bool SaveOptions (pFilename);
*
*=========================================================================*/
bool CSrEditApp::SaveOptions (const TCHAR* pFilename)
{
bool Result;
/* Update all settings */
UpdateOptions(false);
Result = m_ConfigFile.Save(pFilename);
if (!Result) return (false);
return (true);
}
/*===========================================================================
* End of Class Method CSrEditApp::SaveOptions()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - void UpdateOptions (SetConfigFile);
*
* If Set is true the configfile values are updated from the option
* data.
*
*=========================================================================*/
void CSrEditApp::UpdateOptions (const bool Set)
{
/* Record list options */
m_ConfigFile.UpdateBoolean(Set, "RecordListEnableColors", CSrRecordListCtrl::GetOptions().EnableColors);
m_ConfigFile.UpdateBoolean(Set, "RecordListSaveState", CSrRecordListCtrl::GetOptions().SaveState);
m_ConfigFile.UpdateBoolean(Set, "RecordListEnableActiveColor", CSrRecordListCtrl::GetOptions().ActiveColor.Enable);
m_ConfigFile.UpdateBoolean(Set, "RecordListEnableDeletedColor", CSrRecordListCtrl::GetOptions().DeletedColor.Enable);
m_ConfigFile.UpdateBoolean(Set, "RecordListEnableIgnoredColor", CSrRecordListCtrl::GetOptions().IgnoredColor.Enable);
m_ConfigFile.UpdateBoolean(Set, "RecordListEnableDangerousColor", CSrRecordListCtrl::GetOptions().DangerousColor.Enable);
m_ConfigFile.UpdateBoolean(Set, "RecordListEnableQuestColor", CSrRecordListCtrl::GetOptions().QuestColor.Enable);
m_ConfigFile.UpdateInteger(Set, "RecordListActiveColorOrder", CSrRecordListCtrl::GetOptions().ActiveColor.Order);
m_ConfigFile.UpdateInteger(Set, "RecordListDeletedColorOrder", CSrRecordListCtrl::GetOptions().DeletedColor.Order);
m_ConfigFile.UpdateInteger(Set, "RecordListIgnoredColorOrder", CSrRecordListCtrl::GetOptions().IgnoredColor.Order);
m_ConfigFile.UpdateInteger(Set, "RecordListDangerousColorOrder", CSrRecordListCtrl::GetOptions().DangerousColor.Order);
m_ConfigFile.UpdateInteger(Set, "RecordListQuestColorOrder", CSrRecordListCtrl::GetOptions().QuestColor.Order);
m_ConfigFile.UpdateDword(Set, "RecordListActiveColor", CSrRecordListCtrl::GetOptions().ActiveColor.Color);
m_ConfigFile.UpdateDword(Set, "RecordListDeletedColor", CSrRecordListCtrl::GetOptions().DeletedColor.Color);
m_ConfigFile.UpdateDword(Set, "RecordListIgnoredColor", CSrRecordListCtrl::GetOptions().IgnoredColor.Color);
m_ConfigFile.UpdateDword(Set, "RecordListDangerousColor", CSrRecordListCtrl::GetOptions().DangerousColor.Color);
m_ConfigFile.UpdateDword(Set, "RecordListQuestColor", CSrRecordListCtrl::GetOptions().QuestColor.Color);
/* Record tree options */
m_ConfigFile.UpdateBoolean(Set, "RecordTreeEnableCounts", CSrRecordTreeCtrl::GetOptions().EnableCounts);
m_ConfigFile.UpdateString (Set, "RecordTreeFilterFile", CSrRecordTreeCtrl::GetOptions().FilterFile);
/* Undo options */
m_ConfigFile.UpdateBoolean(Set, "EnableUndo", CSrMultiRecordHandler::GetOptions().Undo.EnableUndo);
m_ConfigFile.UpdateDword (Set, "UndoLimit", CSrMultiRecordHandler::GetOptions().Undo.UndoLimit);
/* Backup options */
m_ConfigFile.UpdateBoolean(Set, "EnableBackup", g_SrBackupOptions.EnableBackup);
m_ConfigFile.UpdateBoolean(Set, "EnableBackupOnSave", g_SrBackupOptions.EnableBackupOnSave);
m_ConfigFile.UpdateInteger(Set, "MaximumBackupSize", g_SrBackupOptions.MaxBackupSizeMB);
m_ConfigFile.UpdateInteger(Set, "MaximumBackupCount", g_SrBackupOptions.MaxBackupCount);
m_ConfigFile.UpdateString (Set, "BackupPath", g_SrBackupOptions.BackupPath);
m_ConfigFile.UpdateBoolean(Set, "EnableAutoBackup", g_SrBackupOptions.EnableAutoBackup);
m_ConfigFile.UpdateInteger(Set, "AutoBackupTime", g_SrBackupOptions.AutoBackupTime);
/* Performance settings */
m_ConfigFile.UpdateBoolean(Set, "EnableCaching", CSrMultiRecordHandler::GetOptions().EnableCaching);
/* Dialog options */
m_ConfigFile.UpdateBoolean(Set, "EnableWebHelp", CSrEditDlgHandler::GetOptions().EnableWebHelp);
m_ConfigFile.UpdateBoolean(Set, "UseUESPWikiHelp", CSrEditDlgHandler::GetOptions().UseUESPWikiHelp);
m_ConfigFile.UpdateString(Set, "CSWikiPrefix", CSrEditDlgHandler::GetOptions().CSWikiPrefix);
m_ConfigFile.UpdateString(Set, "UESPWikiPrefix", CSrEditDlgHandler::GetOptions().UESPWikiPrefix);
m_ConfigFile.UpdateString(Set, "DefaultCSPage", CSrEditDlgHandler::GetOptions().DefaultCSPage);
m_ConfigFile.UpdateString(Set, "DefaultUESPPage", CSrEditDlgHandler::GetOptions().DefaultUESPPage);
m_ConfigFile.UpdateString (Set, "SkyrimInstallPath", g_SrManualInstallPath);
g_SrManualInstallPath.Trim();
/* Language/string file options */
m_ConfigFile.UpdateString(Set, "StringFileLanguage", g_SrLanguage);
/* File/path options */
CSString Value;
int Position;
if (!Set)
{
bool Result = m_ConfigFile.FindFirst(Value, "ExtraLoadPath", Position);
CSrLoadDlg::s_ExtraFilePaths.RemoveAll();
while (Result)
{
CSrLoadDlg::s_ExtraFilePaths.Add(Value.c_str());
Result = m_ConfigFile.FindNext(Value, "ExtraLoadPath", Position);
}
}
/* Script options */
m_ConfigFile.UpdateBoolean(Set, "EditScriptExternalByDefault", m_EditScriptExternalByDefault);
m_ConfigFile.UpdateString (Set, "ScriptCompilerCmdOptions", CSrScriptView::s_ScriptOptions.CompilerCmdOptions);
m_ConfigFile.UpdateString (Set, "ScriptFontName", CSrScriptView::s_ScriptOptions.FontName);
m_ConfigFile.UpdateInteger(Set, "ScriptFontSize", CSrScriptView::s_ScriptOptions.FontSize);
m_ConfigFile.UpdateInteger(Set, "ScriptTabSize", CSrScriptView::s_ScriptOptions.TabSize);
//m_ConfigFile.UpdateDword (Set, "ScriptForeColor[]", CSrScptView::m_Options.DefaultForeColor);
//m_ConfigFile.UpdateDword (Set, "ScriptBackColor[]", CSrScptView::m_Options.DefaultBackColor);
//UpdateScriptErrorOptions(Set);
/* Force a redraw */
if (!Set)
{
ResolveOptionPaths();
CWnd* pWnd = AfxGetMainWnd();
if (pWnd != NULL) pWnd->RedrawWindow();
}
}
/*===========================================================================
* End of Class Method CSrEditApp::UpdateOptions()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - void UpdateScriptColorOptions (Compiler, Set);
*
*=========================================================================*/
/*
void CSrEditApp::UpdateScriptColorOptions (CCustomCompiler& Compiler, const bool Set) {
CTokenTypeArray* pTokens = &Compiler.GetTokenTypes();
CSString Buffer;
CTokenType* pToken;
dword Index;
bool Result;
for (Index = 0; Index < pTokens->GetNumRecords(); ++Index) {
pToken = pTokens->GetRecord(Index);
Buffer.Format("ScriptForeColor[%s]", pToken->GetName());
Result = m_ConfigFile.UpdateDword(Set, Buffer, pToken->GetForeColorRef());
if (!Result && Set) pToken->GetForeColorRef() = CSrScptView::m_Options.DefaultForeColor;
Buffer.Format("ScriptBackColor[%s]", pToken->GetName());
Result = m_ConfigFile.UpdateDword(Set, Buffer, pToken->GetBackColorRef());
if (!Result && Set) pToken->GetBackColorRef() = CSrScptView::m_Options.DefaultBackColor;
}
} */
/*===========================================================================
* End of Class Method CSrEditApp::UpdateScriptColorOptions()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - void UpdateScriptErrorOptions (Set);
*
*=========================================================================*/
/*
void CSrEditApp::UpdateScriptErrorOptions (const bool Set) {
CString Buffer;
dword Index;
for (Index = 0; g_ObScriptErrorDefs[Index].pName != NULL; ++Index) {
Buffer.Format("ScriptError[%s]", g_ObScriptErrorDefs[Index].pName);
m_ConfigFile.UpdateInteger(Set, Buffer, g_ObScriptErrorDefs[Index].Level);
}
}*/
/*===========================================================================
* End of Class Method CSrEditApp::UpdateScriptErrorOptions()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - void ResolveOptionPaths (void);
*
*=========================================================================*/
void CSrEditApp::ResolveOptionPaths (void) {
char Buffer[_MAX_PATH + 8];
dword Result;
bool HasPath = false;
if (g_SrBackupOptions.BackupPath[0] != '\\' &&
g_SrBackupOptions.BackupPath[1] != ':') {
Result = GetSrInstallPath(g_SrBackupOptions.FullBackupPath);
if (Result) {
g_SrBackupOptions.FullBackupPath += "data\\";
g_SrBackupOptions.FullBackupPath += g_SrBackupOptions.BackupPath;
TerminatePathString(g_SrBackupOptions.FullBackupPath);
HasPath = true;
}
}
if (!HasPath) {
Result = GetFullPathName(g_SrBackupOptions.BackupPath, _MAX_PATH, Buffer, NULL);
if (Result)
g_SrBackupOptions.FullBackupPath = Buffer;
else
g_SrBackupOptions.FullBackupPath = g_SrBackupOptions.BackupPath;
}
/* Create the fulll display filter path */
CSrRecordTreeCtrl::GetOptions().FullFilterFile = m_AppPath;
CSrRecordTreeCtrl::GetOptions().FullFilterFile += CSrRecordTreeCtrl::GetOptions().FilterFile;
SystemLog.Printf("Full backup path: %s", g_SrBackupOptions.BackupPath.c_str());
}
/*===========================================================================
* End of Class Method CSrEditApp::ResolveOptionPaths()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Event - bool OpenWebHelp (pPage);
*
*=========================================================================*/
bool CSrEditApp::OpenWebHelp (const char* pPage)
{
CSString Buffer;
/* Ignore if web help is disabled */
if (!CSrEditDlgHandler::GetOptions().EnableWebHelp) return (false);
if (CSrEditDlgHandler::GetOptions().UseUESPWikiHelp) {
Buffer = CSrEditDlgHandler::GetOptions().UESPWikiPrefix;
if (pPage == NULL) pPage = CSrEditDlgHandler::GetOptions().DefaultUESPPage;
}
else {
Buffer = CSrEditDlgHandler::GetOptions().CSWikiPrefix;
if (pPage == NULL) pPage = CSrEditDlgHandler::GetOptions().DefaultCSPage;
}
if (pPage != NULL) Buffer += pPage;
OpenWebPage(Buffer);
return (true);
}
bool CSrEditApp::OpenWebHelp (const char* pUESPPage, const char* pCSPage)
{
CSString Buffer;
if (!CSrEditDlgHandler::GetOptions().EnableWebHelp) return (false);
if (CSrEditDlgHandler::GetOptions().UseUESPWikiHelp)
{
Buffer = CSrEditDlgHandler::GetOptions().UESPWikiPrefix;
if (pUESPPage == NULL) pUESPPage = CSrEditDlgHandler::GetOptions().DefaultUESPPage;
if (pUESPPage != NULL) Buffer += pUESPPage;
}
else
{
Buffer = CSrEditDlgHandler::GetOptions().CSWikiPrefix;
if (pCSPage == NULL) pCSPage = CSrEditDlgHandler::GetOptions().DefaultCSPage;
if (pCSPage != NULL) Buffer += pCSPage;
}
OpenWebPage(Buffer);
return true;
}
/*===========================================================================
* End of Class Event CSrEditApp::OpenWebHelp()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - CFrameWnd* FindResourceView (void);
*
*=========================================================================*/
CFrameWnd* CSrEditApp::FindResourceView (void) {
CWnd* pWnd;
CWnd* pWnd1;
HWND hWnd;
hWnd = GetWindow(m_pMainFrame->m_hWndMDIClient, GW_CHILD);
while (hWnd != NULL) {
pWnd = CWnd::FromHandle(hWnd);
if (pWnd != NULL) {
pWnd1 = pWnd->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
if (pWnd1 != NULL && pWnd1->IsKindOf(RUNTIME_CLASS(CSrResourceView))) {
if (pWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd))) return (CFrameWnd *) pWnd;
}
}
hWnd = GetWindow(hWnd, GW_HWNDNEXT);
}
return (NULL);
}
/*===========================================================================
* End of Class Method CSrEditApp::FindResourceView()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - void OpenResourceView (pResource);
*
*=========================================================================*/
void CSrEditApp::OpenResourceView (const char* pResource) {
CSrResourceView* pView;
pView = OpenResourceView();
if (pView == NULL) return;
pView->SelectResource(pResource);
}
/*===========================================================================
* End of Class Method CSrEditApp::OpenResourceView()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - CSrResourceView* CreateResourceView (void);
*
*=========================================================================*/
CSrResourceView* CSrEditApp::CreateResourceView (void)
{
CSrResourceView* pView;
CCreateContext Context;
CFrameWnd* pFrame;
CWnd* pWnd;
if (m_pCurrentProgressDlg == NULL)
{
m_pCurrentProgressDlg = ShowSrProgressDlg("Resource Viewer", "Initializing Resources...");
m_pCurrentProgressDlg->Update(50);
}
/* Initialize the context structure */
Context.m_pCurrentDoc = NULL;
Context.m_pCurrentFrame = NULL;
Context.m_pNewDocTemplate = NULL;
Context.m_pLastView = NULL;
Context.m_pNewViewClass = RUNTIME_CLASS(CSrResourceView);
/* Create the dialog parent frame */
pFrame = (CFrameWnd *) RUNTIME_CLASS(CChildFrame)->CreateObject();
ASSERT_KINDOF(CFrameWnd, pFrame);
/* Create new form view from resource */
pFrame->LoadFrame(IDD_RESOURCE_VIEW, WS_OVERLAPPEDWINDOW, m_pMainWnd, &Context);
pFrame->SetIcon(LoadIcon(MAKEINTRESOURCE(IDR_RESOURCE_VIEW)), false);
/* Attempt to initialize the new view */
pWnd = pFrame->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
if (pWnd != NULL && pWnd->IsKindOf(RUNTIME_CLASS(CSrResourceView)))
{
pView = (CSrResourceView *) pWnd;
pView->SetResourceHandler(&m_ResourceHandler);
pView->SetBsaFileArray(&m_BsaFiles);
}
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(75);
pFrame->InitialUpdateFrame(NULL, TRUE);
pFrame->ActivateFrame(SW_SHOWNORMAL);
pFrame->SetWindowText("Resource Viewer");
return (pView);
}
/*===========================================================================
* End of Class Method CSrEditApp::CreateResourceView()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - CSrResourceView* OpenResourceView (void);
*
*=========================================================================*/
CSrResourceView* CSrEditApp::OpenResourceView (void)
{
CSrResourceView* pView = NULL;
CFrameWnd* pFrame;
CWnd* pWnd;
/* Force the initialization of the resource handler if required */
if (!m_InitResourceHandler)
{
m_pCurrentProgressDlg = ShowSrProgressDlg("Resource Viewer", "Initializing Resources...");
m_pCurrentProgressDlg->SetAllowCancel(false);
m_pCurrentProgressDlg->Update(0);
InitResourceHandler();
}
/* Find an already open view */
pFrame = FindResourceView();
if (pFrame != NULL)
{
pFrame->ActivateFrame(SW_RESTORE);
pWnd = pFrame->GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
if (pWnd != NULL && pWnd->IsKindOf(RUNTIME_CLASS(CSrResourceView))) pView = (CSrResourceView *) pWnd;
}
else
{
pView = CreateResourceView();
}
if (m_pCurrentProgressDlg)
{
DestroySrProgressDlg(m_pCurrentProgressDlg);
m_pCurrentProgressDlg = NULL;
}
return (pView);
}
/*===========================================================================
* End of Class Method CSrEditApp::OpenResourceView()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - bool InitResourceHandler (void);
*
*=========================================================================*/
bool CSrEditApp::InitResourceHandler (void) {
CSString Buffer;
CSString Buffer1;
CSString Filename;
srtimer_t Timer;
bool Result;
/* Clear any current content */
m_BsaFiles.Destroy();
m_ResourceHandler.Destroy();
m_InitResourceHandler = false;
/* Get the current Oblivion path */
Result = GetSrInstallPath(Buffer);
if (!Result) return AddSrGeneralError("Failed to find the Skyrim install path!");
Buffer += "data\\";
m_ResourceHandler.SetBasePath(Buffer);
/* Add files in the data file path */
SrStartTimer(Timer);
m_ResourceHandler.AddPathContents(Buffer, false);
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(10);
SrEndTimer(Timer, "Added resources under 'data\\' path contents in");
/* Add known BSA files for now */
Filename = Buffer + "Skyrim - Animations.bsa";
AddBsaFile(Filename);
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(20);
Filename = Buffer + "Skyrim - Interface.bsa";
AddBsaFile(Filename);
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(30);
Filename = Buffer + "Skyrim - Misc.bsa";
AddBsaFile(Filename);
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(35);
Filename = Buffer + "Skyrim - Meshes.bsa";
AddBsaFile(Filename);
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(40);
Filename = Buffer + "Skyrim - Sounds.bsa";
AddBsaFile(Filename);
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(45);
Filename = Buffer + "Skyrim - Shaders.bsa";
AddBsaFile(Filename);
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(50);
Filename = Buffer + "Skyrim - Textures.bsa";
AddBsaFile(Filename);
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(60);
Filename = Buffer + "Skyrim - Voices.bsa";
AddBsaFile(Filename);
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(70);
Filename = Buffer + "Skyrim - VoicesExtra.bsa";
AddBsaFile(Filename);
if (m_pCurrentProgressDlg) m_pCurrentProgressDlg->Update(80);
SrEndTimer(Timer, "Added all resource contents in");
m_InitResourceHandler = true;
return (true);
}
/*===========================================================================
* End of Class Method CSrEditApp::InitResourceHandler()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - bool AddBsaFile (pFilename);
*
*=========================================================================*/
bool CSrEditApp::AddBsaFile (const char* pFilename) {
CSrBsaFile* pBsaFile;
bool Result;
srtimer_t Timer;
pBsaFile = new CSrBsaFile;
m_BsaFiles.Add(pBsaFile);
SrStartTimer(Timer);
Result = pBsaFile->Load(pFilename);
SrEndTimer(Timer, "Loaded BSA file in ");
if (!Result) {
m_BsaFiles.Delete(pBsaFile);
return (false);
}
SrStartTimer(Timer);
m_ResourceHandler.AddBsaFile(pBsaFile);
SrEndTimer(Timer, "Added BSA records in ");
return (true);
}
/*===========================================================================
* End of Class Method CSrEditApp::AddBsaFile()
*=========================================================================*/
/*===========================================================================
*
* Class CSrEditApp Method - void ResetListState (void);
*
*=========================================================================*/
void CSrEditApp::ResetListState (void) {
CString Section;
dword Result;
Result = MessageBox(NULL, "This action will delete the state and restore all lists in SkyEdit to their default settings.\r\nAre you sure you wish to proceed?", "Reset List State", MB_YESNO | MB_ICONQUESTION);
if (Result != IDYES) return;
/* The registry section to delete */
Section.Format("%s%s\\", SREDIT_REGISTRY_BASE, SRRL_REGKEY_ROOT);
Result = SHDeleteKey(HKEY_CURRENT_USER, Section);
if (Result != ERROR_SUCCESS) {
AddSrWindowsError("Failed to delete the registry section '%s' and all its sub-keys!", Section);
}
}
/*===========================================================================
* End of Class Method CSrEditApp::ResetListState()
*=========================================================================*/
/*===========================================================================
*
* Function - CSrEditApp& GetSrEditApp (void);
*
*=========================================================================*/
CSrEditApp& GetSrEditApp (void) {
return theApp;
}
CSrConfigFile& GetSrEditConfigFile (void) {
return theApp.GetConfigFile();
}
/*===========================================================================
* End of Function GetSrEditApp()
*=========================================================================*/
/*===========================================================================
*
* Function - bool SrEditShowError (Flags, pTitle, pString, ...);
*
* Displays a modal error dialog showing error message. Returns false.
*
*=========================================================================*/
bool SrEditShowError (const dword Flags, const TCHAR* pTitle, const TCHAR* pString, ...) {
CSrErrorDlg ErrorDlg;