-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfrmMain.pas
2323 lines (1957 loc) · 70.4 KB
/
frmMain.pas
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
{
******************************************************
DoubleFine Explorer
By Bennyboy
Http://quickandeasysoftware.net
******************************************************
}
{
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
}
{
TODO
Iron Brigade + UI.fsb in The Cave - still some sounds not working - different codec?
Looks like FSB says mp3/wav but actually another codec
Filter by actual file extension no rather than type? Eg where type is blob but there's
different extensions within that like lua, csv etc
Use generic types for files rather than file extensions eg ImageFileTypes
}
unit frmMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, ImgList, Buttons, ExtCtrls, IniFiles, System.UITypes,
System.ImageList,
JvBaseDlg, JvBrowseFolder, JvExStdCtrls, JvRichEdit, JvEdit, JvExControls,
JvTracker, JvExExtCtrls, JvExtComponent, JvSplit, JvAnimatedImage, JvGIFCtrl,
GR32_Image, pngimage, gr32, VirtualTrees,
AdvGlowButton,
JCLSysInfo, JCLStrings, JCLShell, JCLFileUtils, bass,
uDFExplorer_Const, uDFExplorer_Base, uDFExplorer_Types, uDFExplorer_Funcs;
type
TformMain = class(TForm)
OpenDialog1: TOpenDialog;
panelButtons: TPanel;
btnAbout: TAdvGlowButton;
btnFilterView: TAdvGlowButton;
btnSaveAllFiles: TAdvGlowButton;
btnSaveFile: TAdvGlowButton;
btnOpen: TAdvGlowButton;
editFind: TJvEdit;
panelPreviewContainer: TPanel;
PanelPreviewAudio: TPanel;
lblTime: TLabel;
TrackBarAudio: TJvTracker;
panelPreviewImage: TPanel;
imagePreview: TImage32;
panelPreviewText: TPanel;
memoPreview: TMemo;
panelBlank: TPanel;
Image1: TImage;
Tree: TVirtualStringTree;
panelBottom: TPanel;
memoLog: TJvRichEdit;
SaveDialog1: TSaveDialog;
dlgBrowseForSaveFolder: TJvBrowseForFolderDialog;
PopupFileTypes: TPopupMenu;
popupOpen: TPopupMenu;
MenuItemOpenFolder: TMenuItem;
N2: TMenuItem;
MenuItemOpenCave: TMenuItem;
popupSave: TPopupMenu;
menuItemDumpFile: TMenuItem;
menuItemDumpImage: TMenuItem;
menuItemDumpDDSImage: TMenuItem;
menuItemDumpText: TMenuItem;
menuItemDumpAudio: TMenuItem;
popupSaveAll: TPopupMenu;
menuItemSaveAllRaw: TMenuItem;
menuItemSaveAllImages: TMenuItem;
menuItemSaveAllDDSImages: TMenuItem;
menuItemSaveAllText: TMenuItem;
menuItemSaveAllAudio: TMenuItem;
JvxSplitter1: TJvxSplitter;
ImageList1: TImageList;
panelProgress: TPanel;
Image2: TImage;
JvGIFAnimator1: TJvGIFAnimator;
Timer1: TTimer;
btnSendToHex: TAdvGlowButton;
menuItemSaveAllVisibleRaw: TMenuItem;
MenuItemOpenIronBrigade: TMenuItem;
panelAudioButtons: TPanel;
btnPlay: TSpeedButton;
btnPause: TSpeedButton;
btnStop: TSpeedButton;
MenuItemOpenBrutalLegend: TMenuItem;
MenuItemOpenBrokenAge: TMenuItem;
menuItemSaveAllLua: TMenuItem;
menuItemDumpLua: TMenuItem;
MenuItemOpenCostumeQuest2: TMenuItem;
MenuItemOpenPsychonauts: TMenuItem;
MenuItemOpenGrimRemastered: TMenuItem;
FileSaveDialogFolder: TFileOpenDialog;
MenuItemOpenMassiveChalice: TMenuItem;
MenuItemOpenDOTT: TMenuItem;
MenuItemOpenHeadlander: TMenuItem;
MenuItemOpenFullThrottle: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure editFindChange(Sender: TObject);
procedure memoLogURLClick(Sender: TObject; const URLText: string;
Button: TMouseButton);
procedure OpenPopupMenuHandler(Sender: TObject);
procedure TreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
procedure TreeChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure menuItemDumpFileClick(Sender: TObject);
procedure btnSaveFileClick(Sender: TObject);
procedure menuItemDumpImageClick(Sender: TObject);
procedure menuItemDumpDDSImageClick(Sender: TObject);
procedure menuItemDumpTextClick(Sender: TObject);
procedure menuItemSaveAllRawClick(Sender: TObject);
procedure btnSaveAllFilesClick(Sender: TObject);
procedure menuItemSaveAllImagesClick(Sender: TObject);
procedure btnAboutClick(Sender: TObject);
procedure menuItemSaveAllDDSImagesClick(Sender: TObject);
procedure menuItemSaveAllTextClick(Sender: TObject);
procedure btnPauseClick(Sender: TObject);
procedure btnPlayClick(Sender: TObject);
procedure btnStopClick(Sender: TObject);
procedure TrackBarAudioChangedValue(Sender: TObject; NewValue: Integer);
procedure Timer1Timer(Sender: TObject);
procedure TreeDblClick(Sender: TObject);
procedure menuItemDumpAudioClick(Sender: TObject);
procedure menuItemSaveAllAudioClick(Sender: TObject);
procedure btnSendToHexClick(Sender: TObject);
procedure menuItemSaveAllVisibleRawClick(Sender: TObject);
procedure menuItemSaveAllLuaClick(Sender: TObject);
procedure menuItemDumpLuaClick(Sender: TObject);
procedure TreeGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean;
var ImageIndex: TImageIndex);
private
fExplorer: TDFExplorerBase;
fAudioStream: TMemoryStream;
fAudioHandle: HSTREAM;
fTotalTime: string;
fTrackBarChanging: boolean;
fHexEditorPath: string;
fFilesToCleanup: TStringList;
fLuaDecExe: string;
function IsViewFilteredByCategory: boolean;
function GetCommandLineFilePath: string;
function CaptureConsoleOutput(const ACommand, AParameters: String): ansistring;
function DecompileLuaToString(FileNo: cardinal): string;
function SaveFolderDialog(DialogTitle: string = 'Choose a folder'): string;
function BundleContainsOneOfFileType(FileType: TFileType): boolean;
procedure OnDoneLoading(Count: integer);
procedure DoLog(Text: string);
procedure FreeResources;
procedure StopAndFreeAudio;
procedure ShowProgress(Running: boolean);
procedure EnableDisableButtonsGlobal(Value: boolean);
procedure EnableDisableButtons_TreeDependant;
procedure AddFiletypePopupItems;
procedure FilterNodesByFileExt(FileExt: string);
procedure FilterNodesByFileExtArray(Extensions: array of string);
procedure FileTypePopupMenuHandler(Sender: TObject);
procedure OpenFile;
procedure UpdateSaveAllMenu;
procedure OnDebug(DebugText: string);
procedure CheckIniForHexEditor;
public
{ Public declarations }
end;
var
formMain: TformMain;
MyPopUpItems: array of TMenuItem;
const
arrSavedGameTypes: array[0..171] of string =(
'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',
'1001', '1002', '1003', '1005', '1007', '1010', '1012', '1016',
'1017', '1018', '1020', '1021', '1023', '1025', '1026', '1027',
'1028', '1029', '1032', '1034', '1036', '1037', '1042', '1043',
'1044', '1045', '1046', '1047', '1048', '1049', '1050', '1051',
'1052', '1053', '1054', '1055', '1056', '1059', '1060', '1061',
'1062', '1064', '1065', '1066', '1067', '1068', '1070', '1073',
'1076', '1082', '1083', '1090', '1091', '1094', '1095', '1096',
'1097', '1098', '1099', '1100', '1107', '1115', '1116', '1123',
'1130', '1131', '1141', '1142', '1144', '1171', '1174', '1190',
'1191');
implementation
uses frmAbout;
{$R *.dfm}
procedure TformMain.FormCreate(Sender: TObject);
var
FileToOpen: string;
ResStream: TResourceStream;
begin
formMain.Caption := strAppName + ' ' + strAppVersion;
EditFind.Font.Size:=20;
dlgBrowseforSavefolder.RootDirectory:=fdDesktopDirectory;
dlgBrowseforSavefolder.RootDirectoryPath:=GetDesktopDirectoryFolder;
FileSaveDialogFolder.DefaultFolder := GetDesktopDirectoryFolder;
SaveDialog1.InitialDir:=GetDesktopDirectoryFolder;
JvxSplitter1.TopLeftLimit:=Tree.Constraints.MinWidth;
lblTime.Font.Size := lblTime.Font.Size + 4;
MemoLog.Clear;
DoLog(strAppName + ' ' + strAppVersion);
DoLog(strAppURL);
{$IFDEF DebugMode}
DoLog('Debug mode ON');
{$ENDIF}
// check the correct BASS dll was loaded
if (HIWORD(BASS_GetVersion) <> BASSVERSION) then
begin
MessageBox(0, PChar(strIncorrectBASSVersion), nil, MB_ICONERROR);
Halt;
end;
// Initialize audio - default device, 44100hz, stereo, 16 bits
if not BASS_Init(-1, 44100, 0, Handle, nil) then
MessageBox(0, PChar(strErrorInitializingAudio), nil, MB_ICONERROR);
//Look for ini file and path to hex editor
CheckIniForHexEditor;
if fHexEditorPath = '' then
begin
btnSendToHex.Visible := false;
editFind.Left := 412;
editFind.Width := 450;
end;
//Check command line switch - may need to open a passed file (hack for fsb files)
FileToOpen := GetCommandLineFilePath;
if FileToOpen <> '' then
begin
OpenDialog1.FileName := FileToOpen;
OpenFile;
//Add file to list so it can be cleaned up later if possible
if fFilesToCleanup = nil then
fFilesToCleanUp := TStringList.Create;
fFilesToCleanUp.Add(FileToOpen);
end;
//Extract luadec for later use
fLuaDecExe := IncludeTrailingPathDelimiter(Getwindowstempfolder) + 'luadec.exe';
ResStream := TResourceStream.Create(hInstance, 'luadec', RT_RCDATA);
try
try
if FileExists(fLuaDecExe) then //Want it to make a new file not overwrite existing one - could be 2 instances open eg with fsb files
fLuaDecExe := FindUnusedFileName(fLuaDecExe, '.exe');
ResStream.SaveToFile(fLuaDecExe);
except on E: EFCreateError do //If it tries to overwrite and cant this gets raised
begin
fLuaDecExe := FindUnusedFileName(fLuaDecExe, '.exe');
ResStream.SaveToFile(fLuaDecExe);
end;
end;
finally
ResStream.Free;
end;
end;
procedure TformMain.FormDestroy(Sender: TObject);
begin
FreeResources;
if fFilesToCleanup <> nil then //might still be open if not all files could be deleted in FreeResources()
fFilesToCleanup.Free;
//Delete luadec exe we extracted when program started
RemoveReadOnlyFileAttribute(fLuaDecExe); //Occasionally possible to become read only on some systems if the file thats copied like the exe is already read only
DeleteFile(fLuaDecExe);
BASS_Free;
end;
procedure TformMain.OpenFile;
begin
FreeResources;
try
fExplorer:=TDFExplorerBase.Create(OpenDialog1.FileName, OnDebug);
try
EnableDisableButtonsGlobal(false);
memoLog.Clear;
imagePreview.Bitmap.Clear;
Tree.Clear;
fExplorer.OnDoneLoading:=OnDoneLoading;
fExplorer.OnDebug:=OnDebug;
Tree.Header.AutoFitColumns(true);
PanelBlank.BringToFront;
fExplorer.Initialise;
UpdateSaveAllMenu;
DoLog('Opened file: ' + ExtractFileName( OpenDialog1.FileName ) );
finally
EnableDisableButtonsGlobal(true);
end;
except on E: EInvalidFile do
begin
DoLog(E.Message);
FreeResources;
EnableDisableButtonsGlobal(true);
end;
end;
end;
procedure TformMain.FreeResources;
var
i: integer;
begin
editFind.Text:='';
tree.Clear;
StopAndFreeAudio;
//In case invalid files are opened twice in succession
if fExplorer <> nil then
FreeAndNil(FExplorer);
//Try and delete any temp files sent to hex editor
if fFilesToCleanup <> nil then
begin
for i := fFilesToCleanup.Count - 1 downto 0 do
begin
RemoveReadOnlyFileAttribute(fFilesToCleanup[i]); //Occasionally possible to become read only on some systems if the file thats copied like the exe is already read only
if DeleteFile(fFilesToCleanup[i]) then fFilesToCleanup.Delete(i);
end;
{if theres still files to be deleted - keep them on the list - FreeResources is called
every time a ttarch is opened so could free it later}
if fFilesToCleanup.Count = 0 then
FreeAndNil(fFilesToCleanup);
end;
if MyPopUpItems <> nil then
begin
for i:=low(mypopupitems) to high(mypopupitems) do
mypopupitems[i].Free;
MyPopUpItems:=nil;
end;
end;
function TformMain.GetCommandLineFilePath: string;
var
intTemp: integer;
tempParam: string;
begin
//First find what number param the switch is
intTemp:=FindParamIndex(strCmdLineOpenAndDelete);
if (intTemp <> -1) and (ParamCount >= intTemp + 1) then
begin
tempParam:=ParamStr(intTemp + 1); //Paramstr automatically parses out speech marks
tempParam:=Trim(TempParam); //Remove trailing spaces
result:=tempParam;
end
else
result:='';
end;
{****************** Custom Events ******************}
procedure TformMain.DoLog(Text: string);
begin
memoLog.Lines.Add(Text);
end;
procedure TformMain.OnDoneLoading(Count: integer);
begin
Tree.RootNodeCount := Count;
AddFileTypePopupItems;
end;
procedure TformMain.OnDebug(DebugText: string);
begin
memoLog.Lines.Add(DebugText);
end;
function TformMain.SaveFolderDialog(DialogTitle: string = 'Choose a folder'): string;
begin
result := '';
if Win32MajorVersion >= 6 then //Vista and above
begin
FileSaveDialogFolder.Title := DialogTitle;
if FileSaveDialogFolder.Execute then
result := FileSaveDialogFolder.FileName;
end
else
begin
dlgBrowseForSaveFolder.Title := DialogTitle;
if dlgBrowseForSaveFolder.Execute then
result := dlgBrowseForSaveFolder.Directory;
end;
end;
procedure TformMain.ShowProgress(Running: boolean);
begin
case Running of
True:
begin
jvgifanimator1.Animate := true;
panelProgress.Visible:=true;
panelProgress.BringToFront;
end;
False:
begin
JvGifAnimator1.Animate := false;
panelProgress.Visible:=false;
end;
end;
end;
{****************** Form update stuff Stuff ******************}
procedure TformMain.editFindChange(Sender: TObject);
var
i, FoundPos: integer;
TempNode: pVirtualNode;
begin
//sometimes it still has focus when view is filtered by category
if (editFind.Focused = false) then exit;
if EditFind.Text = '' then
begin
{If view is filtered and someone clicks in the search box and out again without typing
anything , we dont want the view to change to show all nodes}
if IsViewFilteredByCategory = false then
FilterNodesByFileExt('');
exit;
end;
//Remove tick from all items
for I := 0 to PopupFileTypes.Items.Count -1 do
begin
PopupFileTypes.Items[i].Checked:=false;
end;
tree.BeginUpdate;
//Make them all visible again
FilterNodesByFileExt('');
TempNode:=Tree.GetFirst;
while (tempNode <> nil) do
begin
FoundPos:=pos(uppercase(EditFind.Text), uppercase(fExplorer.FileName[TempNode.index]));
if FoundPos > 0 then
begin
tree.IsVisible[TempNode]:=true;
end
else
tree.IsVisible[TempNode]:=false;
TempNode:=Tree.GetNext(TempNode);
end;
tree.EndUpdate;
//Show hide the save all visible menu
menuItemSaveAllVisibleRaw.Visible := Tree.VisibleCount > 0;
end;
procedure TformMain.EnableDisableButtonsGlobal(Value: boolean);
begin
btnOpen.Enabled:=Value;
btnSaveFile.Enabled:=Value;
btnSaveAllFiles.Enabled:=Value;
tree.Enabled:=Value;
btnFilterView.Enabled:=Value;
btnAbout.Enabled:=Value;
editFind.Enabled:=Value;
btnSendToHex.Enabled:=Value;
btnPlay.Enabled:=Value;
btnPause.Enabled:=Value;
btnStop.Enabled:=Value;
TrackBarAudio.Enabled:=Value;
if Value then EnableDisableButtons_TreeDependant;
end;
procedure TformMain.EnableDisableButtons_TreeDependant;
var
NodeIsSelected: boolean;
begin
if Tree.RootNodeCount > 0 then
btnSaveAllFiles.Enabled:=true
else
btnSaveAllFiles.Enabled:=false;
NodeIsSelected := Tree.SelectedCount > 0;
btnSaveFile.Enabled:=NodeIsSelected;
btnSendToHex.Enabled:=NodeIsSelected;
menuItemSaveAllVisibleRaw.Visible := Tree.VisibleCount > 0;
if NodeIsSelected then
begin
menuItemDumpImage.Visible :=
(fExplorer.FileType[Tree.focusednode.Index] = ft_GenericImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_DDSImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_HeaderlessDDSImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_HeaderlessPsychoDDSImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_HeaderlessDOTTDDSImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_DOTTFontImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_DOTTXMLCostumeWithImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_FTHeaderlessCHNKImage);
menuItemDumpDDSImage.Visible :=
(fExplorer.FileType[Tree.focusednode.Index] = ft_DDSImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_HeaderlessDDSImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_HeaderlessPsychoDDSImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_HeaderlessDOTTDDSImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_DOTTXMLCostumeWithImage) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_FTHeaderlessCHNKImage);
menuItemDumpText.Visible :=
(fExplorer.FileType[Tree.focusednode.Index] = ft_Text) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_DelimitedText) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_CSVText) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_Lua);
menuItemDumpAudio.Visible :=
(fExplorer.FileType[Tree.focusednode.Index] = ft_Audio) or
(fExplorer.FileType[Tree.focusednode.Index] = ft_IMCAudio);
menuItemDumpLua.Visible :=
fExplorer.FileType[Tree.focusednode.Index] = ft_Lua;
end;
end;
procedure TformMain.memoLogURLClick(Sender: TObject; const URLText: string;
Button: TMouseButton);
begin
shellexec(0, 'open', URLText,'', '', SW_SHOWNORMAL);
end;
procedure TformMain.UpdateSaveAllMenu;
var
i: integer;
begin
{Parse through all files and enable the appropriate menu if it finds
corresponding file type}
if Tree.RootNodeCount = 0 then exit;
menuItemSaveAllImages.Visible:=false;
menuItemSaveAllText.Visible:=false;
menuItemSaveAllDDSImages.Visible:=false;
menuItemSaveAllAudio.Visible:=false;
menuItemSaveAllLua.Visible:=false;
for i:=0 to tree.RootNodeCount -1 do
begin
if (fExplorer.FileType[i] = ft_GenericImage) or
(fExplorer.FileType[i] = ft_DOTTFontImage) or
(fExplorer.FileType[i] = ft_DDSImage) or
(fExplorer.FileType[i] = ft_HeaderlessDDSImage) or
(fExplorer.FileType[i] = ft_HeaderlessPsychoDDSImage) or
(fExplorer.FileType[i] = ft_HeaderlessDOTTDDSImage) or
(fExplorer.FileType[i] = ft_DOTTXMLCostumeWithImage) or
(fExplorer.FileType[i] = ft_FTHeaderlessCHNKImage) then
begin
menuItemSaveAllImages.Visible:=true;
end;
if (fExplorer.FileType[i] = ft_DDSImage) or
(fExplorer.FileType[i] = ft_HeaderlessDDSImage) or
(fExplorer.FileType[i] = ft_HeaderlessPsychoDDSImage) or
(fExplorer.FileType[i] = ft_HeaderlessDOTTDDSImage) or
(fExplorer.FileType[i] = ft_DOTTXMLCostumeWithImage) or
(fExplorer.FileType[i] = ft_FTHeaderlessCHNKImage) then
begin
menuItemSaveAllImages.Visible:=true;
menuItemSaveAllDDSImages.Visible:=true;
end;
if (fExplorer.FileType[i] = ft_Text) or
(fExplorer.FileType[i] = ft_DelimitedText) or
(fExplorer.FileType[i] = ft_CSVText) then
begin
menuItemSaveAllText.Visible:=true;
end;
if (fExplorer.FileType[i] = ft_Audio) or
(fExplorer.FileType[i] = ft_IMCAudio) then
begin
menuItemSaveAllAudio.Visible:=true;
end;
if fExplorer.FileType[i] = ft_Lua then
menuItemSaveAllLua.Visible := true;
end;
end;
function TformMain.BundleContainsOneOfFileType(FileType: TFileType): boolean;
var
i: integer;
begin
result := false;
if Tree.RootNodeCount = 0 then exit;
for i:=0 to Tree.RootNodeCount -1 do
begin
if fExplorer.FileType[i] = FileType then
begin
result := true;
exit;
end;
end;
end;
{****************** Tree Stuff ******************}
procedure TformMain.TreeChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
var
ext: string;
TempStrings: TStringList;
begin
EnableDisableButtons_TreeDependant;
if Tree.RootNodeCount=0 then exit;
if Tree.SelectedCount=0 then exit;
panelBlank.BringToFront;
//Clear resources here just to save memory ie not leaving a big image hanging around
imagePreview.Bitmap.Clear;
memoPreview.Clear;
ext:=Uppercase(extractfileext(fExplorer.FileName[Tree.focusednode.Index]));
//Other images
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_GenericImage then
begin
panelPreviewImage.BringToFront;
fExplorer.DrawImageGeneric(Tree.focusednode.Index, imagePreview.Bitmap);
end;
//Text types
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_Text then
begin
panelPreviewText.BringToFront;
memoPreview.Clear;
fExplorer.ReadText(Tree.focusednode.Index, memoPreview.Lines);
end;
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_CSVText then
begin
panelPreviewText.BringToFront;
memoPreview.Clear;
fExplorer.ReadCSVText(Tree.focusednode.Index, memoPreview.Lines);
end;
if (fExplorer.FileType[Tree.FocusedNode.Index] = ft_DelimitedText) then
begin
panelPreviewText.BringToFront;
memoPreview.Clear;
TempStrings := TStringList.Create;
try
fExplorer.ReadDelimitedText(Tree.focusednode.Index, TempStrings);
memoPreview.Text := TempStrings.Text; //This is much faster than assign
finally
TempStrings.Free;
end;
end;
//DDS Images
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_DDSImage then
begin
panelPreviewImage.BringToFront;
fExplorer.DrawImageDDS(Tree.focusednode.Index, imagePreview.Bitmap);
end;
//Headerless DDS images
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_HeaderlessDDSImage then
begin
panelPreviewImage.BringToFront;
fExplorer.DrawImageDDS(Tree.focusednode.Index, imagePreview.Bitmap, DDS_HEADERLESS);
end;
//Headerless Psychonauts DDS images
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_HeaderlessPsychoDDSImage then
begin
panelPreviewImage.BringToFront;
fExplorer.DrawImageDDS(Tree.focusednode.Index, imagePreview.Bitmap,
DDS_HEADERLESS_PSYCHONAUTS);
end;
//Headerless DOTT DDS images
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_HeaderlessDOTTDDSImage then
begin
panelPreviewImage.BringToFront;
fExplorer.DrawImageDDS(Tree.focusednode.Index, imagePreview.Bitmap,
DDS_HEADERLESS_DOTT);
end;
//DOTT Font images
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_DOTTFontImage then
begin
panelPreviewImage.BringToFront;
fExplorer.DrawImageDOTTFont(Tree.focusednode.Index, imagePreview.Bitmap);
end;
//DOTT XML Costume images
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_DOTTXMLCostumeWithImage then
begin
panelPreviewImage.BringToFront;
fExplorer.DrawImageDDS(Tree.focusednode.Index, imagePreview.Bitmap,
DDS_HEADERLESS_DOTT_COSTUME);
end;
//FT CHNK images
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_FTHeaderlessCHNKImage then
begin
panelPreviewImage.BringToFront;
fExplorer.DrawImageDDS(Tree.focusednode.Index, imagePreview.Bitmap,
DDS_HEADERLESS_FT_CHNK);
end;
//Audio types
if (fExplorer.FileType[Tree.FocusedNode.Index] = ft_Audio) or
(fExplorer.FileType[Tree.FocusedNode.Index] = ft_FSBFile) or
(fExplorer.FileType[Tree.FocusedNode.Index] = ft_IMCAudio) then
begin
panelPreviewAudio.BringToFront;
end;
//Compiled LUA
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_LUA then
begin
panelPreviewText.BringToFront;
memoPreview.Clear;
memoPreview.Lines.BeginUpdate;
EnableDisableButtonsGlobal(false);
try
memoPreview.Text :=( DecompileLuaToString(Tree.FocusedNode.Index) );
finally
EnableDisableButtonsGlobal(true);
memoPreview.Lines.EndUpdate;
formMain.FocusControl(Tree); //Disabling the controls takes the focus from this -
//so when restored couldnt use keyboard
end;
end;
end;
procedure TformMain.TreeDblClick(Sender: TObject);
var
NewName: string;
begin
//Audio types
if fExplorer.FileType[Tree.focusednode.Index] = ft_Audio then
begin
panelPreviewAudio.BringToFront;
StopAndFreeAudio;
btnPlay.Click;
end;
//Broken Age hack - dump the fsb and reopen
if fExplorer.FileType[Tree.FocusedNode.Index] = ft_FSBFile then
begin
EnableDisableButtonsGlobal(false);
try
try
fExplorer.SaveFile(
Tree.focusednode.Index,
IncludeTrailingPathDelimiter(Getwindowstempfolder),
ExtractFileName(SanitiseFileName(fExplorer.FileName[Tree.focusednode.Index])),
false);
ShellExec(
0,
'open',
ExtractFilePath(application.ExeName) + ExtractFileName(application.ExeName),
strCmdLineOpenAndDelete + ' "' +
IncludeTrailingPathDelimiter( GetWindowsTempFolder) +
ExtractFileName(SanitiseFileName(fExplorer.FileName[Tree.focusednode.Index])) +
'"',
ExtractFilePath(Application.ExeName),
SW_SHOWNORMAL);
except on E: EFCreateError do
begin //get new name if its already there and open
NewName := FindUnusedFileName(
IncludeTrailingPathDelimiter( GetWindowsTempFolder ) +
ExtractFileName(SanitiseFileName(fExplorer.FileName[Tree.focusednode.Index])),
ExtractFileExt(fExplorer.FileName[Tree.focusednode.Index]),
'-copy');
DoLog(strErrHexFileExists + NewName);
fExplorer.SaveFile(
Tree.focusednode.Index,
IncludeTrailingPathDelimiter(Getwindowstempfolder),
ExtractFileName(NewName),
false);
ShellExec(
0,
'open',
ExtractFilePath(application.ExeName) + ExtractFileName(application.ExeName),
strCmdLineOpenAndDelete + ' "' +
IncludeTrailingPathDelimiter( GetWindowsTempFolder) +
ExtractFileName(NewName) +'"',
ExtractFilePath(Application.ExeName),
SW_SHOWNORMAL);
end;
end;
finally
EnableDisableButtonsGlobal(true);
end;
end;
//Grim Remastered IMC audio
if fExplorer.FileType[Tree.focusednode.Index] = ft_IMCAudio then
begin
panelPreviewAudio.BringToFront;
StopAndFreeAudio;
btnPlay.Click;
end;
end;
procedure TformMain.TreeGetImageIndex(Sender: TBaseVirtualTree;
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
var Ghosted: Boolean; var ImageIndex: TImageIndex);
var
FileType: TFileType;
begin
if column <> 0 then exit;
if (Kind = ikOverlay) or (Kind = ikState) then exit;
FileType := fExplorer.FileType[node.Index];
case FileType of
ft_GenericImage: ImageIndex:= 8;
ft_DDSImage: ImageIndex:= 8;
ft_HeaderlessDDSImage: ImageIndex:= 8;
ft_HeaderlessPsychoDDSImage: ImageIndex:= 8;
ft_HeaderlessDOTTDDSImage: ImageIndex:= 8;
ft_DOTTXMLCostumeWithImage: ImageIndex:=8;
ft_DOTTFontImage: ImageIndex:= 8;
ft_FTHeaderlessCHNKImage: ImageIndex:= 8;
ft_Text: ImageIndex:= 9;
ft_DelimitedText: ImageIndex:= 14;
ft_CSVText: ImageIndex:= 14;
ft_Audio: ImageIndex:= 12;
ft_FSBFile: ImageIndex:= 12;
ft_IMCAudio: ImageIndex:= 12;
ft_LUA: ImageIndex:= 15;
ft_Other: ImageIndex:= 5;
ft_Unknown: ImageIndex:= 5;
else
ImageIndex:=5;
end;
end;
procedure TformMain.TreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
begin
case Column of
0: Celltext := fExplorer.FileName[node.index];
1: Celltext := fExplorer.FileExtension[node.Index];
2: Celltext := inttostr(fExplorer.FileSize[node.index] );
3: Celltext := inttostr (fExplorer.FileOffset[node.index] );
end;
end;
{****************** Category Filtering Stuff ******************}
function TformMain.IsViewFilteredByCategory: boolean;
var
i: integer;
begin
result:=false;
for I := 0 to PopupFileTypes.Items.Count -1 do
begin
if PopupFileTypes.Items[i].Checked then
result:=true;
end;
end;
procedure TformMain.AddFiletypePopupItems;
var
FileTypes: TStringList;
tempStr: string;
tempFileType: TFileType;
i: integer;
begin
Filetypes:=tstringlist.Create;
try
for i:=0 to tree.RootNodeCount -1 do
begin
tempStr:= fExplorer.FileExtension[i];
if (FileTypes.IndexOf(tempStr)=-1) and (tempStr > '' ) then
begin
if StrIndex(tempStr, arrSavedGameTypes) > -1 then //Its a saved game filetype
begin
if FileTypes.IndexOf(strViewSavedGameFiles) = -1 then //If doesnt already exist
FileTypes.Add(strViewSavedGameFiles) //Add the saved games menu item
end
else //Just add the file extension
FileTypes.Add(tempStr);
end;
end;
FileTypes.Sort;
SetLength(MyPopupItems, Filetypes.Count + 2); //+2 for 'all files' and line break
for i:=low(mypopupitems) to high(mypopupitems) -2 do
begin
MyPopUpItems[i]:=TMenuItem.Create(Self);
MyPopUpItems[i].Caption:=FileTypes[i];
MyPopUpItems[i].tag:=i + 2;
PopupFileTypes.Items.add(MyPopupItems[i]);
MyPopUpItems[i].OnClick:=FileTypePopupMenuHandler;
//icons
tempFileType := GetFileTypeFromFileExtension( FileTypes[i] );
case tempFileType of
ft_GenericImage: MyPopupItems[i].ImageIndex:=8;
ft_DDSImage: MyPopupItems[i].ImageIndex:=8;
ft_HeaderlessDDSImage: MyPopupItems[i].ImageIndex:=8;
ft_HeaderlessPsychoDDSImage: MyPopupItems[i].ImageIndex:=8;
ft_HeaderlessDOTTDDSImage: MyPopupItems[i].ImageIndex:=8;
ft_DOTTXMLCostumeWithImage: MyPopupItems[i].ImageIndex:=8;
ft_DOTTFontImage: MyPopupItems[i].ImageIndex:=8;
ft_FTHeaderlessCHNKImage: MyPopUpItems[i].ImageIndex:=8;