-
Notifications
You must be signed in to change notification settings - Fork 0
/
LBAPackEd1.pas
1664 lines (1555 loc) · 49 KB
/
LBAPackEd1.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
//******************************************************************************
// LBA Package Editor - editing hqr, ile, obl, vox packages from
// Little Big Adventure 1 & 2
//
// LBAPackEd1 unit.
// This is the main unit. Contains all main window events.
//
// Copyright (C) Zink
// e-mail: [email protected]
// See the GNU General Public License (License.txt) for details.
//******************************************************************************
unit LBAPackEd1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, ComCtrls, Buttons, ExtCtrls, ImgList, IniFiles,
ShellApi, Menus, ActnList, StdActns, ToolWin, TLHelp32, StrUtils, Hint;
type
TForm1 = class(TForm)
FileList: TStringGrid;
dOpenPack: TOpenDialog;
Status1: TStatusBar;
dSavePack: TSaveDialog;
dSaveProject: TSaveDialog;
dOpenProject: TOpenDialog;
Panel1: TPanel;
InLabel: TLabel;
OutLabel: TLabel;
bChangeIn: TButton;
bChangeOut: TButton;
dOpenReplace: TOpenDialog;
Panel2: TPanel;
Shape1: TShape;
Label1: TLabel;
Label11: TLabel;
Label2: TLabel;
Label3: TLabel;
dSaveEntry: TSaveDialog;
InfAll: TStaticText;
InfReal: TStaticText;
InfHidden: TStaticText;
InfRep: TStaticText;
InfBlank: TStaticText;
ToolBar1: TToolBar;
tbLoadInput: TToolButton;
tbOpenProject: TToolButton;
tbSaveProject: TToolButton;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
tbDispAll: TToolButton;
tbDispRH: TToolButton;
ToolButton3: TToolButton;
tbSettings: TToolButton;
ToolButton5: TToolButton;
tbReplace: TToolButton;
tbClear: TToolButton;
tbClearAll: TToolButton;
ToolButton6: TToolButton;
tbExtract: TToolButton;
ToolButton8: TToolButton;
tbChangeOut: TToolButton;
ToolButton9: TToolButton;
tbBuild: TToolButton;
ToolButton7: TToolButton;
Images: TImageList;
Timer1: TTimer;
Label5: TLabel;
ToolButton10: TToolButton;
tbUnloadPack: TToolButton;
lb_filedesc: TLabel;
Label6: TLabel;
ToolButton11: TToolButton;
Edit1: TEdit;
bSame: TBitBtn;
ThdTimer: TTimer;
Label4: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
EntriesMenu: TPopupMenu;
DisabledMenu: TPopupMenu;
MultiMenu: TPopupMenu;
mThisEntry: TMenuItem;
mOpen: TMenuItem;
mOpenCommon: TMenuItem;
N1: TMenuItem;
mReplace: TMenuItem;
mReplaceTemp: TMenuItem;
N2: TMenuItem;
mClearRepl: TMenuItem;
mClearAll: TMenuItem;
N3: TMenuItem;
mExtract: TMenuItem;
mExtractTemp: TMenuItem;
mExtractPart: TMenuItem;
hisentryisblank2: TMenuItem;
N6: TMenuItem;
Youcandonothingwithblankentries1: TMenuItem;
Morethanoneentryselected1: TMenuItem;
N7: TMenuItem;
Replaceselectedentrieswith2: TMenuItem;
Replaceselentrieswiththeonesfromtemp4: TMenuItem;
N8: TMenuItem;
Clearreplacementsforselectedentries2: TMenuItem;
ClearreplacementsforALLentries3: TMenuItem;
N10: TMenuItem;
Extractselectedentries2: TMenuItem;
Extractselectedentriestotempdirectory4: TMenuItem;
Partialextract3: TMenuItem;
ActionList: TActionList;
aOffset: TAction;
aRlSize: TAction;
aCpSize: TAction;
aComp: TAction;
aType: TAction;
aExt: TAction;
aInfo: TAction;
aRepl: TAction;
aRemember: TAction;
aOpen: TAction;
aOpenCommon: TAction;
aReplace: TAction;
aReplaceTemp: TAction;
aClear: TAction;
aClearAll: TAction;
aSelectOut: TAction;
aBuild: TAction;
aExtractTemp: TAction;
aExtract: TAction;
aExtractPart: TAction;
aOpenPack: TAction;
aReload: TAction;
aUnloadPack: TAction;
aOpenProject: TAction;
aSaveProject: TAction;
aRecent: TAction;
aExit: TAction;
aAbout: TAction;
aShowHints: TAction;
aConfigTools: TAction;
aBlank: TAction;
aCompact: TAction;
aSettings: TAction;
mMain: TMainMenu;
File1: TMenuItem;
View1: TMenuItem;
Columns1: TMenuItem;
Commands1: TMenuItem;
mTools: TMenuItem;
Help1: TMenuItem;
Loadpackagefile1: TMenuItem;
Reloadpackage1: TMenuItem;
Unloadpackage1: TMenuItem;
N4: TMenuItem;
Openproject1: TMenuItem;
N5: TMenuItem;
N9: TMenuItem;
N11: TMenuItem;
Displayblankentries1: TMenuItem;
Compactblankentries1: TMenuItem;
N12: TMenuItem;
Settings1: TMenuItem;
mOffset: TMenuItem;
mRlSize: TMenuItem;
mCpSize: TMenuItem;
mComp: TMenuItem;
mType: TMenuItem;
mExt: TMenuItem;
mInfo: TMenuItem;
mRepl: TMenuItem;
N13: TMenuItem;
Rememberthesesettings1: TMenuItem;
Openselectedentrywith1: TMenuItem;
Openwith1: TMenuItem;
Clearopenedindicatorforselectedentry1: TMenuItem;
N14: TMenuItem;
Replaceselectedentrieswith1: TMenuItem;
Replaceselentrieswiththeonesfromtemp1: TMenuItem;
N15: TMenuItem;
Clearreplacementsforselectedentries1: TMenuItem;
ClearreplacementsforALLentries1: TMenuItem;
N16: TMenuItem;
Specifyoutputfile1: TMenuItem;
Buildoutputfile1: TMenuItem;
N17: TMenuItem;
Extractselectedentries1: TMenuItem;
Partialextract1: TMenuItem;
Extractselectedentriestotempdirectory1: TMenuItem;
Configuretools1: TMenuItem;
About1: TMenuItem;
Showhints1: TMenuItem;
N20: TMenuItem;
mRecent: TMenuItem;
N18: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FileListSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure FileListDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure WMDropFiles (hDrop : THandle; hWindow : HWnd);
procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
procedure AppException(Sender: TObject; E: Exception);
procedure aBlankExecute(Sender: TObject);
procedure FileListDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure aChangeOutExecute(Sender: TObject);
procedure aBuildExecute(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure aLoadInputExecute(Sender: TObject);
procedure FileListMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure aReplaceExecute(Sender: TObject);
procedure aClearExecute(Sender: TObject);
procedure aSaveProjectExecute(Sender: TObject);
procedure aOpenProjectExecute(Sender: TObject);
procedure aClearAllExecute(Sender: TObject);
procedure aSettingsExecute(Sender: TObject);
procedure FileListDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure FileListEndDrag(Sender, Target: TObject; X, Y: Integer);
procedure FileListStartDrag(Sender: TObject;
var DragObject: TDragObject);
procedure FileListKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormResize(Sender: TObject);
procedure aExtractExecute(Sender: TObject);
procedure aExtractPartExecute(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FileListMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FileListMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure aUnloadPackExecute(Sender: TObject);
procedure aAboutExecute(Sender: TObject);
procedure FileListDblClick(Sender: TObject);
procedure ColumnsMenuClick(Sender: TObject);
procedure aReloadExecute(Sender: TObject);
procedure aOpenRecent(Sender: TObject);
procedure Edit1Exit(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure EmptyActionExecute(Sender: TObject);
procedure aExitExecute(Sender: TObject);
procedure aConfigureExecute(Sender: TObject);
procedure ToolExecute(Sender: TObject);
procedure aOpenExecute(Sender: TObject);
procedure bSameClick(Sender: TObject);
procedure ThdTimerTimer(Sender: TObject);
procedure aExtractTempExecute(Sender: TObject);
procedure aReplaceTempExecute(Sender: TObject);
procedure aClearOpenedExecute(Sender: TObject);
// procedure dOpenPackFilePreview(Sender: TObject; const Filename: string; Canvas: TCanvas;
// const Rect: TRect; Progress: TProgressEvent; var Handled: Boolean);
private
{ Private declarations }
public
Procedure AppShowHint(var HintStr: String; var CanShow: Boolean;
var HintInfo: THintInfo);
end;
const VNum = '0.11';
var
Form1: TForm1;
DirPath: String;
OutSpec: Boolean = false;
Modified: Boolean = False;
//hThread: THandle;
LastOsDir: String;
LastReDir: String;
LastIoDir: String;
HintParam: Integer;
DragRow: Integer;
DragStarted: Boolean = False;
ClickedRow: Integer;
DragType: (dtNone, dtEntry, dtRepl);
DragPoint: TPoint;
DraggingUp: Boolean;
SelectedRows: array of Boolean;
SelectCount: Integer = 0;
NoSelect: Boolean = False;
DoubleClick: Boolean = False;
SMSelected, SMEntries: ShortString;
//function MsgThread(p: pointer): Integer;
function FindRow(index: Integer):Integer;
Procedure EnableMenus(Enable: Boolean);
procedure EnableIfNeeded(ARow: Integer);
procedure SetReplacement(ARow: Integer; Path: String);
procedure DopasujRozmiar;
implementation
uses ProgBar, files, Math, Settings, DePack, ExtractDlg, About, Info,
Tools, Dialog;
{$R *.dfm}
Procedure EnableMenus(Enable: Boolean);
begin
Form1.aSaveProject.Enabled:=Enable;
Form1.aReplace.Enabled:=Enable;
Form1.aClear.Enabled:=Enable;
Form1.aClearAll.Enabled:=Enable;
Form1.aSelectOut.Enabled:=Enable;
Form1.bSame.Enabled:=Enable;
Form1.aOpen.Enabled:=Enable;
Form1.aOpenCommon.Enabled:=Enable;
Form1.aExtract.Enabled:=Enable;
Form1.aExtractPart.Enabled:=Enable;
Form1.aBuild.Enabled:=Enable;
Form1.aUnloadPack.Enabled:=Enable;
Form1.aReload.Enabled:=Enable;
Form1.aExtractTemp.Enabled:=Enable;
Form1.aReplaceTemp.Enabled:=Enable;
end;
Procedure DisableAll;
var a: Integer;
begin
//Form1.mMain.Enabled:=False;
for a:=0 to Form1.ActionList.ActionCount-1 do
(Form1.ActionList.Actions[a] as TAction).Enabled:=False;
end;
Procedure EnableAll;
var a: Integer;
begin
//Form1.mMain.Enabled:=True;
for a:=0 to Form1.ActionList.ActionCount-1 do
(Form1.ActionList.Actions[a] as TAction).Enabled:=True;
end;
procedure SetSingleMulti(Multi, OpenAllowed: Boolean);
begin
If Multi then begin
SMSelected:='selected';
SMEntries:='entries';
Form1.mThisEntry.ImageIndex:=-1;
Form1.mThisEntry.Caption:='More than one entry selected';
Form1.mOpen.Visible:=OpenAllowed;
Form1.mReplaceTemp.Caption:='Replace sel. entries with the ones from temp';
end
else begin
SMSelected:='this';
SMEntries:='entry';
Form1.mOpen.Visible:=True;
Form1.mReplaceTemp.Caption:='Replace this entry with the one from temp';
end;
Form1.mReplace.Caption:=Format('Replace %s %s with...',[SMSelected,SMEntries]);
Form1.mClearRepl.Caption:=Format('Clear replacement for %s %s',[SMSelected,SMEntries]);
Form1.mExtract.Caption:=Format('Extract %s %s...',[SMSelected,SMEntries]);
Form1.mExtractTemp.Caption:=Format('Extract %s %s to temp directory',[SMSelected,SMEntries]);
end;
function CheckSameEditors: Boolean; //Checks if all the selected entries have the same editor
var a, First, Index: Integer;
begin
First:=-1;
Result:=True;
For a:=1 to Form1.FileList.RowCount-1 do
If SelectedRows[a] then begin
Index:=Entries[DispMap[a]].ExtIndex;
If Index=2 then Continue;
If First=-1 then begin First:=Index; Continue; end;
If not (AnsiSameText(ToolPaths[Index],ToolPaths[First]) and
((AnsiSameText(ToolParams[Index],ToolParams[First]) and ToolUseMenu[Index] and ToolUseMenu[First])
or not (ToolUseMenu[Index] or ToolUseMenu[First]))) then begin
Result:=False;
Exit;
end;
end;
end;
function GetFirstSelected: Integer;
var a, LastFirst: Integer;
begin
Result:=0;
for a:=1 to Form1.FileList.RowCount-1 do
If SelectedRows[a] then begin
LastFirst:=a;
If Entries[DispMap[a]].ExtIndex=2 then Continue;
Result:=a;
Exit;
end;
If Result=0 then Result:=LastFirst;
end;
procedure SetEditor(Image: Integer; CaptionPopup, CaptionMain: String);
begin
Form1.aOpen.Caption:=CaptionMain;
Form1.mOpen.Caption:=CaptionPopup;
Form1.aOpen.ImageIndex:=Image;
Form1.aOpen.Enabled:=Image>-1;
Form1.mOpen.Enabled:=Image>-1;
end;
procedure EnableOpenWith;
begin
Form1.aOpenCommon.ImageIndex:=Form1.mTools.Items[0].ImageIndex;
Form1.aOpenCommon.Caption:=Format('Open selected %s with %s',[SMEntries,ToolNames[0]]);
Form1.mOpenCommon.Caption:=Format('Open %s %s with %s',[SMSelected,SMEntries,ToolNames[0]]);
Form1.aOpenCommon.Enabled:=True;
end;
Procedure DisableReplace(FType: Integer);
begin
Form1.aReplace.Enabled:=False;
Form1.aClear.Enabled:=False;
Form1.aExtract.Enabled:=False;
Form1.aOpen.Enabled:=False;
Form1.aOpenCommon.Enabled:=False;
{for a:=1 to Length(SelectedRows)-1 do
If SelectedRows[a] then begin
Form1.aReplace.Enabled:=True;
Form1.aClear.Enabled:=True;
Form1.aExtract.Enabled:=True;
Break;
end; }
If FType=-2 then
Form1.DisabledMenu.Items.Items[0].Caption:='This entry is blank'
else
Form1.DisabledMenu.Items.Items[0].Caption:='This entry is repeated';
SetEditor(-1,'No editor/viewer associated','No editor/viewer associated');
Form1.FileList.PopupMenu:=Form1.DisabledMenu;
Form1.Status1.Panels[1].Text:='';
end;
Procedure EnableReplace(ext: Byte);
var buff: String;
a, b: Integer;
begin
With Form1 do begin
aReplace.Enabled:=True;
aClear.Enabled:=True;
aExtract.Enabled:=True;
aOpen.Enabled:=True;
aOpenCommon.Enabled:=SelectCount=1;
{If SelectCount<>1 then begin
FileList.PopupMenu:=MultiMenu;
SetEditor(-1,'','More than one entry selected');
end
else} begin
FileList.PopupMenu:=EntriesMenu;
SetSingleMulti(SelectCount>1,CheckSameEditors);
If SelectCount=1 then begin
buff:=GetDescription(ext);
mThisEntry.ImageIndex:=19;
If UnknownPack then
mThisEntry.Caption:='Current package file is not known'
else begin
If buff='unknown file' then
mThisEntry.Caption:='This entry is not known yet'
else begin
mThisEntry.Caption:='This entry is known as '+buff+' (.'+Extensions[ext]+')';
mThisEntry.ImageIndex:=ext+19;
end;
end;
end;
EnableOpenWith;
If SelectCount>1 then ext:=Entries[DispMap[GetFirstSelected]].ExtIndex;
If ToolEnabled[ext] and (ext<>0) then
SetEditor(mTools.Items[ext].ImageIndex,
Format('Open %s %s with %s',[SMSelected,SMEntries,ToolNames[ext]]),
Format('Open selected %s with %s',[SMEntries,ToolNames[ext]]))
else
SetEditor(-1,'No editor/viewer associated','No editor/viewer associated');
If FileList.Dragging then
Status1.Panels[1].Text:=''
else
Status1.Panels[1].Text:='Press <Enter> or <F2> to begin manual replacement editing';
end;
end;
end;
procedure CheckModified;
begin
If Modified then
case MessageBox(Form1.handle,'Current set of replacements or input/output file path has been changed. Do you want to save it as project file?','LBA Package Editor',MB_ICONQUESTION+MB_YESNOCANCEL) of
ID_YES: begin
Form1.aSaveProjectExecute(Form1);
if Modified then Abort;
end;
ID_CANCEL: Abort;
end;
end;
Function IsAnyReplaced: Boolean;
var a: Integer;
begin
Result:=True;
for a:=0 to FCount-1 do
If Entries[a].Replace<>'' then Exit;
Result:=False;
end;
Procedure TForm1.AppShowHint(var HintStr: String; var CanShow: Boolean;
var HintInfo: THintInfo);
var ARow, ACol: Integer;
p: TPoint;
s: String;
begin
If HintInfo.HintControl is TLabel then begin
HintInfo.HintWindowClass:=THintLabel;
HintInfo.HintPos.X:=HintInfo.HintControl.ClientOrigin.X-3;
HintInfo.HintPos.Y:=HintInfo.HintControl.ClientOrigin.Y-1;
end
else if HintInfo.HintControl = FileList then begin
p:=FileList.ScreenToClient(Mouse.CursorPos);
FileList.MouseToCell(p.X,p.Y,ACol,ARow);
CanShow:=False;
If (FileList.ColCount>=ACol) and (FileList.RowCount>=ARow) then begin
s:=FileList.Cells[ACol,ARow];
If (s<>'') and ((ACol=7) or (ACol=8))
and ((FileList.Canvas.TextWidth(s)>FileList.ColWidths[ACol]-2)
or ((ACol=8) and (s<>Entries[DispMap[ARow]].Replace) and (s[1]<>'>'))) then begin
HintInfo.HintWindowClass:=THintList;
If ACol=8 then begin
HintStr:=Entries[DispMap[ARow]].Replace;
HintParam:=-1;
end
else begin
HintStr:=s;
HintParam:=Entries[DispMap[ARow]].ExtIndex;
end;
HintInfo.HintData:=@HintParam;
p:=FileList.ClientToScreen(FileList.CellRect(ACol,ARow).TopLeft);
HintInfo.HintPos.X:=p.X-1;
HintInfo.HintPos.Y:=p.Y-1;
HintInfo.ReshowTimeout:=100;
CanShow:=True;
end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
//var ThreadId: Cardinal;
begin
CreateToolMenu;
Form1.Label7.Caption:='Version: '+VNum;
With FileList do begin
Cells[0,0]:='Nr';
Cells[1,0]:='Offset';
Cells[2,0]:='Orig. size';
Cells[3,0]:='Packed size';
Cells[4,0]:='C';
Cells[5,0]:='Type';
Cells[6,0]:='Ext';
Cells[7,0]:='Info';
Cells[8,0]:=' will be replaced with';
end;
dSaveEntry.Filter:='Unknown file (*.lun)|*.lun|LBA image (*.lim)|*.lim|Palette file (*.pal)|*.pal|LBA text file (*.lbt)|*.lbt|LBA sprite (*.lsp)|*.lsp|LBA Raw sprite (*.lsr)|*.lsr|LBA 1 3D model (*.lm1)|*.lm1|LBA 2 3D model (*.lm2)|*.lm2|'+
'LBA font file (*.lfn)|*.lfn|Riff wave file (*.wav)|*.wav|Creative voice file (*.voc)|*.voc|Smacker movie (*.smk)|*.smk|XMidi file (*.xmi)|*.xmi|LBA animation (*.anm)|*.anm|Graphics image (*.gif)|*.gif|LBA shape file (*.lsh)|*.lsh|'+
'LBA 1 scene (*.ls1)|*.ls1|LBA 2 scene (*.ls2)|*.ls2|LBA brick file (*.brk)|*.brk|LBA 1 layouts library (*.bl1)|*.bl1|LBA 2 layouts library (*.bl2)|*.bl2|LBA 1 grid file (*.gr1)|*.gr1|LBA 2 grid file (*.gr2)|*.gr2|ZSoft paintbrush (*.pcx)|*.pcx|'+
'LBA 2 grid fragment (*.grf)|*.grf';
Application.OnMessage:=AppMessage;
Application.OnException:=AppException;
Application.OnShowHint:=AppShowHint;
//dOpenPack.Options:=dOpenPack.Options+[ofPreview,ofAutoPreview];
//dOpenPack.OnFilePreview:=dOpenPackFilePreview;
DragAcceptFiles(Form1.Handle,True);
//hThread:=BeginThread(nil,0,@MsgThread,nil,0,ThreadId);
//SetThreadPriority(hThread,THREAD_PRIORITY_LOWEST);
dOpenReplace.FilterIndex:=1;
//Application.OnHint:=AppHint;
end;
procedure SetReplacement(ARow: Integer; Path: String);
begin
If not (InLoaded and Displayed) then Exit;
If IsBlank(DispMap[ARow]) then begin
MessageBox(Form1.Handle,'Blank entries cannot be replaced!','LBA Package Editor',MB_ICONERROR+MB_OK);
Exit;
end;
Entries[DispMap[ARow]].Replace:= Path;
If Copy(Path,1,1)='>' then
Form1.FileList.Cells[8,ARow]:='>'+Form1.FileList.Cells[0,FindRow(StrToInt(Copy(Path,2,Length(Path)-1)))]
else
Form1.FileList.Cells[8,ARow]:=MinPath(Path);
Modified:=True;
end;
function FindRow(index: Integer):Integer;
var a: Integer;
begin
for a:=1 to Length(DispMap)-1 do
If DispMap[a]=index then begin
Result:=a;
Exit;
end;
Result:=0;
end;
Procedure Unselect(ARow: Integer);
var a: Integer;
cr: TRect;
begin
With Form1.FileList do begin
Canvas.Brush.Color:=clWindow;
For a:=0 to 8 do begin
cr:=CellRect(a,ARow);
Canvas.FillRect(cr);
Canvas.TextOut(cr.Left+2,cr.Top+2,Cells[a,ARow]);
end;
end;
end;
function IsNormalSelected: Boolean;
var a: Integer;
begin
Result:=False;
With Form1.FileList do
for a:=0 to Length(SelectedRows)-1 do
If SelectedRows[a] and
(IsNorm(DispMap[a]) or IsHidden(DispMap[a]) or IsRep(DispMap[a])) then begin
Result:=True;
Exit;
end;
end;
function SelectedRow: Integer;
var a: Integer;
begin
for a:=1 to Length(SelectedRows)-1 do
If SelectedRows[a] then begin
Result:=a;
Exit;
end;
Result:=-1;
end;
procedure EnableIfNeeded(ARow: Integer);
begin
If InLoaded and Displayed then begin
If IsNormalSelected then EnableReplace(Entries[DispMap[ARow]].ExtIndex)
else DisableReplace(Entries[DispMap[ARow]].FType);
end;
end;
procedure SelectCell(ACol, ARow: Integer; NoKeys: Boolean = False);
var a, c: Integer;
Shift: TShiftState;
begin
If not Displayed then Exit;
If NoSelect then Exit;
If NoKeys then Shift:=[] else Shift:=KeyboardStateToShiftState;
With Form1.FileList do begin
{If not Form1.Filelist.Dragging then} begin
If (ssCtrl in Shift) then begin
If SelectedRows[ARow] then begin
SelectedRows[ARow]:=False;
Dec(SelectCount);
If ARow=Selection.Top then
Unselect(ARow);
end
else begin
SelectedRows[ARow]:=True;
Inc(SelectCount);
end;
end
else if (ssShift in Shift) then begin
for a:=Min(ARow,Selection.Top) to Max(ARow,Selection.Top) do
If not SelectedRows[a] then begin
SelectedRows[a]:=True;
Inc(SelectCount);
end;
Repaint;
end
else begin
SetLength(SelectedRows,0);
SetLength(SelectedRows,RowCount);
SelectedRows[ARow]:=True;
If (SelectCount<>1) and not Dragging then Repaint;
SelectCount:=1;
end;
Form1.Label5.Caption:='Selected: '+IntToStr(SelectCount);
end;
For a:=1 to RowCount-1 do
If Cells[0,a][1]='+' then
Cells[0,a]:=Copy(Cells[0,a],2,Length(Cells[0,a])-1);
If (Cells[5,ARow]='Normal') then
for a:=0 to FCount-1 do
If Entries[a].FType=DispMap[ARow] then begin
c:=FindRow(a);
If c>0 then
Cells[0,c]:='+'+Cells[0,c];
end;
EnableIfNeeded(ARow);
end;
end;
procedure TForm1.FileListSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
SelectCell(ACol,ARow);
end;
function BottomRow: Integer;
begin
Result:=(Form1.FileList.Height div Form1.FileList.DefaultRowHeight)+Form1.Filelist.TopRow-3;
end;
procedure TForm1.FileListDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var ARow, ACol: Integer;
cr: TRect;
begin
If DragStarted then
FileList.MouseToCell(x,y,ACol,DragRow);
DragStarted:=False;
Accept:=False;
If not (InLoaded and Displayed) then Exit;
If SelectCount<>1 then Exit;
FileList.MouseToCell(x,y,ACol,ARow);
If ARow=0 then begin
DraggingUp:=True;
Timer1.Enabled:=True;
end
else if ARow>=BottomRow then begin
DraggingUp:=False;
Timer1.Enabled:=True;
end else Timer1.Enabled:=False;
If ARow>0 then begin
FileList.Selection:=TGridRect(Rect(0,ARow,8,ARow));
SelectCell(0,ARow);
If (DragRow=0) or (DragRow=ARow) then Exit;
If Source=FileList then begin
If (ARow<>DragRow) and (FileList.TopRow<=DragRow) and (BottomRow>=DragRow) then begin
FileList.Canvas.Brush.Color:=clMoneyGreen;
Case DragType of
dtEntry: For ACol:=0 to 7 do begin
cr:=FileList.CellRect(ACol,DragRow);
FileList.Canvas.FillRect(cr);
FileList.Canvas.TextOut(cr.Left+2,cr.Top+2,FileList.Cells[ACol,DragRow]);
end;
dtRepl: begin
cr:=FileList.CellRect(8,DragRow);
FileList.Canvas.FillRect(cr);
FileList.Canvas.TextOut(cr.Left+2,cr.Top+2,FileList.Cells[8,DragRow]);
end;
end;
end;
If IsBlank(DispMap[DragRow]) or IsBlank(DispMap[ARow]) then Exit;
If (DragType=dtEntry) and (IsHidden(DispMap[DragRow]) or IsHidden(DispMap[ARow])) then Exit;
Accept:=True;
end;
end;
end;
procedure TForm1.FileListStartDrag(Sender: TObject; var DragObject: TDragObject);
begin
DragStarted:=True;
If DragType=dtRepl then Form1.Status1.Panels[1].Text:='Press <Alt> to move with copy';
end;
procedure TForm1.FileListDragDrop(Sender, Source: TObject; X, Y: Integer);
var ShiftState: TShiftState;
ACol, ARow: Integer;
Old: String;
begin
FileList.MouseToCell(x,y,ACol,ARow);
ShiftState:=KeyboardStateToShiftState;
If DragType=dtRepl then begin
Old:=Entries[DispMap[ARow]].Replace;
SetReplacement(ARow,Entries[DispMap[DragRow]].Replace);
If not (ssAlt in ShiftState) then
If Old<>'' then
SetReplacement(DragRow,Old)
else
SetReplacement(DragRow,'');
end
else
SetReplacement(ARow,'>'+IntToStr(DispMap[DragRow]));
end;
procedure TForm1.FileListEndDrag(Sender, Target: TObject; X, Y: Integer);
begin
Timer1.Enabled:=False;
FileList.Repaint;
DragPoint:=FileList.ClientToScreen(DragPoint);
If (DragPoint.x=x) and (DragPoint.y=y) then
FileList.PopupMenu.Popup(x,y);
end;
function Instances: Integer; //returns number of running instatces of this prog
var FSnapshotHandle: THandle; //...actually number of running progs with the same file name
FProcessEntry32:TProcessEntry32;
Licznik: Integer; //counter
begin
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
Licznik:=0;
If Process32First(FSnapshotHandle,FProcessEntry32) then
repeat
If AnsiSameText(FProcessEntry32.szExeFile,ExtractFileName(Application.ExeName)) then Inc(Licznik);
until not Process32Next(FSnapshotHandle,FProcessEntry32);
CloseHandle(FSnapshotHandle);
Result:=Licznik;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var sr: TSearchRec;
begin
CheckModified;
DragAcceptFiles(FileList.Handle, False);
DragAcceptFiles(Form1.Handle,False);
SaveSettings;
If fSettings.cbDelTemp.Checked and DirectoryExists(TempDir) and (Instances<=1) then begin
If FindFirst(TempDir+'\*.*',faAnyFile,sr)=0 then
repeat
If (sr.Name<>'.') and (sr.Name<>'..') then DeleteFile(TempDir+'\'+sr.Name);
until FindNext(sr)<>0;
FindClose(sr);
RemoveDir(TempDir+'\');
end;
end;
//obs³uga Drag & Drop
procedure TForm1.WMDropFiles (hDrop : THandle; hWindow : HWnd);
var
TotalNumberOfFiles, nFileLength, ACol, ARow: Integer;
pszFileName: PChar;
DropPoint: TPoint;
begin
//liczba zrzuconych plików
TotalNumberOfFiles:=DragQueryFile(hDrop,$FFFFFFFF,nil,0);
If TotalNumberOfFiles=1 then begin
nFileLength:=DragQueryFile(hDrop,0,Nil,0)+1;
GetMem(pszFileName,nFileLength);
DragQueryFile(hDrop,0,pszFileName,nFileLength);
DragQueryPoint(hDrop,DropPoint);
//pszFileName - nazwa upuszczonego pliku
//tutaj robimy co z nazw¹ pliku
If FindControl(hWindow).Name='FileList' then begin
FileList.MouseToCell(DropPoint.x,DropPoint.y,ACol,ARow);
if ARow>0 then
SetReplacement(ARow, pszFileName)
else
Beep;
end
else begin
try //¿eby wykona³o siê FreeMem je¿eli bêdzie b³¹d
CheckModified;
UnloadPack;
OpenParam(pszFileName);
except
end;
end;
FreeMem(pszFileName,nFileLength);
end
else
MessageBox(handle,'You can''t replace one entry with more than one file.','LBA Package Editor',MB_ICONERROR+MB_OK);
DragFinish(hDrop);
end; //sprawdzamy co zosta³o przeci¹gniête i obs³ugujemy to
procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
case Msg.Message of
WM_DROPFILES: WMDropFiles(Msg.wParam, Msg.hWnd);
end;
end;
procedure TForm1.AppException(Sender: TObject; E: Exception);
begin
If ProgBarForm.Visible then ProgBarForm.Close;
if fSettings.Visible then fSettings.Close;
if fExtract.Visible then fExtract.Close;
Screen.Cursor:=crArrow;
MessageBox(handle,PChar('LBA Package Editor have risen an exception called: "'+E.Message+'" and may be unstable. Please save all changes and restart the program as soon as possible.'),'LBA Package Editor',MB_ICONWARNING+MB_OK);
end;
//following function was for highlighting rows during dragging files from explorer,
//but I didn't magage it to work well
{function MsgThread(p: pointer): Integer;
var pt, old_pt, fl_pt, form_pt: TPoint;
ARow, ACol: Integer;
flCanSelect: Boolean;
MouseBtn: Word;
begin
With Form1 do begin
repeat
FileDragging:=True;
Sleep(10);
pt:=Mouse.CursorPos;
form_pt:=ClientToScreen(pt);
fl_pt:=FileList.ScreenToClient(pt);
//Form1.Label1.Caption:=IntToStr(pt.x)+' '+IntToStr(pt.y);
SetCaption('InLabel',IntToStr(MouseBtn));
If FileDragging and ((old_pt.x<>pt.x) or (old_pt.y<>pt.y)) and
(fl_pt.x>=0) and (fl_pt.y>=0) and
(fl_pt.x<=FileList.Width) and (fl_pt.y<=FileList.Height) //and
then begin
Form1.FileList.MouseToCell(fl_pt.x,fl_pt.y,ACol,ARow);
if ARow>0 then begin
//mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN, pt.x, pt.y, 0, 0);
//mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, pt.x, pt.y, 0, 0);
Form1.FileList.Selection:=TGridRect(Rect(0,ARow,8,ARow));
Form1.FileListSelectCell(nil,0,ARow,flCanSelect);
end;
end;
old_pt:=pt;
until 0=1;
end;
end;}
procedure TForm1.aBlankExecute(Sender: TObject);
begin
DisplayStruct;
end;
procedure TForm1.FileListDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var a: Integer;
NumRect: TRect;
begin
If ARow=0 then Exit;
if SelectedRows[ARow] then begin
FileList.Canvas.Brush.Color:=clSkyBlue;
FileList.Canvas.Font.Color:=clBlack;
FileList.Canvas.FillRect(Rect);
FileList.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,Filelist.Cells[ACol,ARow]);
end
else if ARow=FileList.Selection.Top then begin
FileList.Canvas.Brush.Color:=clWindow;
FileList.Canvas.Font.Color:=clBlack;
FileList.Canvas.FillRect(Rect);
FileList.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,Filelist.Cells[ACol,ARow]);
end;
Case ACol of
5:begin
If IsNorm(DispMap[ARow]) then begin
FileList.Canvas.Font.Color:=clGreen;
FileList.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,'Normal');
end
else if IsHidden(DispMap[ARow]) then begin
FileList.Canvas.Font.Color:=clOlive;
FileList.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,'Hidden');
end
else if IsBlank(DispMap[ARow]) then begin
FileList.Canvas.Font.Color:=clMaroon;
NumRect:=Classes.Rect(FileList.CellRect(0,ARow).Left,Rect.Top,FileList.CellRect(8,Arow).Right,Rect.Bottom);
FileList.Canvas.TextRect(NumRect,NumRect.Left+2,NumRect.Top+2,FileList.Cells[0,ARow]);
NumRect.Left:=NumRect.Left+FileList.Canvas.TextWidth(FileList.Cells[0,ARow])+2;
NumRect.Right:=FileList.CellRect(5,ARow).Right;
If FileList.Cells[5,ARow]='Blank' then
FileList.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,'Blank')
else
FileList.Canvas.TextRect(NumRect,NumRect.Right-2-FileList.Canvas.TextWidth(FileList.Cells[5,ARow]),NumRect.Top+2,FileList.Cells[5,ARow]);
end
else begin
FileList.Canvas.Font.Color:=clBlue;
FileList.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,Filelist.Cells[5,ARow]);
end;
end;
0:If Copy(FileList.Cells[0,ARow],1,1)='+' then begin
FileList.Canvas.Brush.Color:=clSkyBlue;
FileList.Canvas.Font.Color:=clBlack;
//FileList.Canvas.FillRect(Rect);
FileList.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,Filelist.Cells[0,ARow]);
end;
7:if not IsBlank(DispMap[ARow]) then begin
a:=Entries[DispMap[ARow]].ExtIndex;
If a>0 then begin
FileList.Canvas.Font.Color:=inf_colour[a];
FileList.Canvas.TextRect(Rect,Rect.Left+2,Rect.Top+2,FileList.Cells[ACol,ARow]);
end;
end;
end;
end;
procedure TForm1.aChangeOutExecute(Sender: TObject);
var ext: String;
begin
ext:=LowerCase(ExtractFileExt(InLabel.Caption));
dSavePack.FilterIndex:=1;
If ext='.ile' then dSavePack.FilterIndex:=2;
If ext='.obl' then dSavePack.FilterIndex:=3;
If ext='.vox' then dSavePack.FilterIndex:=4;
dSavePack.InitialDir:=LastIODir;