1 |
|
unit Tool_BinEdit; |
2 |
– |
|
2 |
|
interface |
4 |
– |
|
3 |
|
uses |
4 |
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
5 |
< |
Dialogs, Wrapgrid, StdCtrls, Grids, StrUtils, MPHexEditor, ExtCtrls, Clipbrd, |
6 |
< |
Data, Code_Functions, Code_DataStructures, Code_Exporters, Code_OniDataClass, |
7 |
< |
Menus, Math, VirtualTrees, VTHeaderPopup; |
5 |
> |
Dialogs, Tool_Template, StdCtrls, ExtCtrls, VirtualTrees, Grids, Wrapgrid, |
6 |
> |
MPHexEditor, VTHeaderPopup, Menus, StrUtils, Clipbrd, |
7 |
> |
Data, Code_OniDataClass, Code_Functions, Code_DataStructures, Code_Exporters; |
8 |
|
|
9 |
|
type |
10 |
< |
TForm_BinEdit = class(TForm) |
11 |
< |
Splitter1: TSplitter; |
14 |
< |
panel_data: TPanel; |
15 |
< |
hex: TMPHexEditor; |
10 |
> |
TForm_BinEdit = class(TForm_ToolTemplate) |
11 |
> |
hex: TMPHexEditor; |
12 |
|
Splitter2: TSplitter; |
17 |
– |
panel_files: TPanel; |
18 |
– |
list: TListBox; |
19 |
– |
panel_extension: TPanel; |
20 |
– |
lbl_filter: TLabel; |
21 |
– |
combo_extension: TComboBox; |
22 |
– |
Bevel1: TBevel; |
23 |
– |
panel_imexport: TPanel; |
24 |
– |
btn_export: TButton; |
25 |
– |
btn_import: TButton; |
26 |
– |
opend: TOpenDialog; |
27 |
– |
saved: TSaveDialog; |
13 |
|
value_viewer: TWrapGrid; |
14 |
+ |
VST: TVirtualStringTree; |
15 |
|
Splitter3: TSplitter; |
16 |
|
value_viewer_context: TPopupMenu; |
17 |
|
value_viewer_context_copy: TMenuItem; |
32 |
– |
value_viewer_context_copyashex: TMenuItem; |
18 |
|
value_viewer_context_copyasdec: TMenuItem; |
19 |
|
value_viewer_context_copyasfloat: TMenuItem; |
20 |
|
value_viewer_context_copyasbitset: TMenuItem; |
21 |
|
value_viewer_context_copyasstring: TMenuItem; |
22 |
< |
check_zerobyte: TCheckBox; |
38 |
< |
edit_filtername: TEdit; |
39 |
< |
check_filtername: TCheckBox; |
40 |
< |
VST: TVirtualStringTree; |
22 |
> |
value_viewer_context_copyashex: TMenuItem; |
23 |
|
VTHPopup: TVTHeaderPopupMenu; |
24 |
+ |
procedure FormCreate(Sender: TObject); |
25 |
+ |
procedure NewFile(fileinfo: TFileInfo); |
26 |
+ |
|
27 |
+ |
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
28 |
+ |
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
29 |
+ |
|
30 |
+ |
procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
31 |
+ |
procedure hexSelectionChanged(Sender: TObject); |
32 |
+ |
procedure hexChange(Sender: TObject); |
33 |
+ |
|
34 |
+ |
procedure LoadDat(_fileid: LongWord); |
35 |
+ |
function Save: Boolean; |
36 |
+ |
function GetValue(datatype: Word; offset: LongWord): String; |
37 |
+ |
procedure SetNewValue(datatype: Word; offset: LongWord; Value: String); |
38 |
+ |
|
39 |
+ |
procedure WriteStructureInfos; |
40 |
+ |
procedure ClearStructViewer; |
41 |
+ |
procedure VSTDblClick(Sender: TObject); |
42 |
|
procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; |
43 |
|
Column: TColumnIndex); |
44 |
– |
procedure VSTDblClick(Sender: TObject); |
44 |
|
procedure VTHPopupColumnChange(const Sender: TBaseVirtualTree; |
45 |
|
const Column: TColumnIndex; Visible: Boolean); |
46 |
|
procedure VSTHeaderDragged(Sender: TVTHeader; Column: TColumnIndex; |
47 |
|
OldPosition: Integer); |
48 |
|
procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; |
49 |
|
Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); |
51 |
– |
procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
52 |
– |
procedure LoadDat(_fileid: LongWord); |
53 |
– |
procedure LoadFileNames; |
54 |
– |
procedure check_filternameClick(Sender: TObject); |
55 |
– |
procedure check_zerobyteClick(Sender: TObject); |
56 |
– |
procedure combo_extensionClick(Sender: TObject); |
57 |
– |
procedure panel_extensionResize(Sender: TObject); |
58 |
– |
procedure listClick(Sender: TObject); |
59 |
– |
procedure Recreatelist; |
50 |
|
|
51 |
< |
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
51 |
> |
procedure ClearValues; |
52 |
> |
procedure WriteValues; |
53 |
|
procedure value_viewerDblClick(Sender: TObject); |
54 |
|
procedure value_viewer_context_copyClick(Sender: TObject); |
55 |
|
procedure value_viewerMouseDown(Sender: TObject; Button: TMouseButton; |
56 |
|
Shift: TShiftState; X, Y: Integer); |
57 |
|
procedure value_viewer_contextPopup(Sender: TObject); |
67 |
– |
procedure btn_importClick(Sender: TObject); |
68 |
– |
procedure btn_exportClick(Sender: TObject); |
69 |
– |
procedure panel_imexportResize(Sender: TObject); |
70 |
– |
function Save: Boolean; |
71 |
– |
procedure FormClose(Sender: TObject; var Action: TCloseAction); |
72 |
– |
function GetValue(datatype: Word; offset: LongWord): String; |
73 |
– |
procedure WriteStructureInfos; //(structinfoid:Integer); |
74 |
– |
procedure hexSelectionChanged(Sender: TObject); |
75 |
– |
procedure hexChange(Sender: TObject); |
76 |
– |
procedure FormResize(Sender: TObject); |
77 |
– |
procedure ClearStructViewer; |
78 |
– |
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
79 |
– |
procedure FormCreate(Sender: TObject); |
80 |
– |
procedure ClearValues; |
81 |
– |
procedure WriteValues; |
82 |
– |
procedure SetNewValue(datatype: Word; offset: LongWord; Value: String); |
83 |
– |
procedure listMouseDown(Sender: TObject; Button: TMouseButton; |
84 |
– |
Shift: TShiftState; X, Y: Integer); |
58 |
|
private |
59 |
|
fileid: LongWord; |
60 |
|
public |
65 |
|
|
66 |
|
implementation |
67 |
|
|
68 |
+ |
uses Helper_ValueEdit, Main, Tool_RawEdit; |
69 |
|
{$R *.dfm} |
70 |
|
|
97 |
– |
uses Main, Helper_ValueEdit, Tool_Rawedit; |
98 |
– |
|
71 |
|
type |
72 |
|
PNodeData = ^TNodeData; |
73 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
+ |
procedure TForm_BinEdit.FormCreate(Sender: TObject); |
85 |
+ |
begin |
86 |
+ |
inherited; |
87 |
+ |
Self.OnNewFileSelected := NewFile; |
88 |
+ |
|
89 |
+ |
Self.Caption := ''; |
90 |
+ |
fileid := 0; |
91 |
+ |
VST.NodeDataSize := SizeOf(TNodeData); |
92 |
+ |
value_viewer.ColCount := 2; |
93 |
+ |
value_viewer.RowCount := 8; |
94 |
+ |
value_viewer.FixedRows := 1; |
95 |
+ |
value_viewer.Cells[0, 0] := 'Type'; |
96 |
+ |
value_viewer.Cells[1, 0] := 'Value'; |
97 |
+ |
value_viewer.Cells[0, 1] := '1 byte, unsigned'; |
98 |
+ |
value_viewer.Cells[0, 2] := '2 bytes, unsigned'; |
99 |
+ |
value_viewer.Cells[0, 3] := '4 bytes, unsigned'; |
100 |
+ |
value_viewer.Cells[0, 4] := 'Bitset'; |
101 |
+ |
value_viewer.Cells[0, 5] := 'Float'; |
102 |
+ |
value_viewer.Cells[0, 6] := 'String'; |
103 |
+ |
value_viewer.Cells[0, 7] := 'Selected length'; |
104 |
+ |
// value_viewer.ColWidths[0] := 100; |
105 |
+ |
// value_viewer.ColWidths[1] := value_viewer.Width - 150; |
106 |
+ |
// hex.Height := content.Height - 215; |
107 |
+ |
// |
108 |
+ |
value_viewer.Font.Charset := AppSettings.CharSet; |
109 |
+ |
VST.Font.Charset := AppSettings.CharSet; |
110 |
+ |
hex.Translation := tkAsIs; |
111 |
+ |
hex.Font.Charset := AppSettings.CharSet; |
112 |
+ |
// |
113 |
+ |
end; |
114 |
+ |
|
115 |
+ |
procedure TForm_BinEdit.NewFile(fileinfo: TFileInfo); |
116 |
+ |
begin |
117 |
+ |
LoadDat(fileinfo.ID); |
118 |
+ |
end; |
119 |
+ |
|
120 |
+ |
|
121 |
+ |
|
122 |
|
|
123 |
|
function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; |
124 |
|
ARecord: TNodeData): PVirtualNode; |
136 |
|
|
137 |
|
procedure TForm_BinEdit.LoadDat(_fileid: LongWord); |
138 |
|
var |
129 |
– |
i: LongWord; |
139 |
|
mem: TMemoryStream; |
140 |
|
Data: Tdata; |
141 |
|
begin |
143 |
|
begin |
144 |
|
if not Save then |
145 |
|
begin |
146 |
< |
for i := 0 to list.Count - 1 do |
147 |
< |
begin |
139 |
< |
if OniDataConnection.ExtractFileID(list.Items.Strings[i]) = fileid then |
140 |
< |
begin |
141 |
< |
list.ItemIndex := i; |
142 |
< |
Exit; |
143 |
< |
end; |
144 |
< |
end; |
146 |
> |
Self.SelectFileID(fileid); |
147 |
> |
Exit; |
148 |
|
end; |
149 |
|
end; |
150 |
|
fileid := _fileid; |
151 |
< |
for i := 0 to list.Count - 1 do |
152 |
< |
if OniDataConnection.ExtractFileID(list.Items.Strings[i]) = fileid then |
153 |
< |
begin |
151 |
< |
list.ItemIndex := i; |
152 |
< |
Break; |
153 |
< |
end; |
151 |
> |
if OniDataConnection.ExtractFileID( |
152 |
> |
filelist.Items.Strings[filelist.ItemIndex]) <> fileid then |
153 |
> |
Self.SelectFileID(fileid); |
154 |
|
Self.ClearStructViewer; |
155 |
|
Data := OniDataConnection.LoadDatFile(fileid); |
156 |
|
if Length(Data) > 0 then |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
– |
procedure TForm_BinEdit.Recreatelist; |
176 |
– |
var |
177 |
– |
i: LongWord; |
178 |
– |
exts: TStringArray; |
179 |
– |
begin |
180 |
– |
combo_extension.Items.Clear; |
181 |
– |
combo_extension.Items.Add('_All files_ (' + IntToStr( |
182 |
– |
OniDataConnection.GetFilesCount) + ')'); |
183 |
– |
exts := OniDataConnection.GetExtensionsList; |
184 |
– |
for i := 0 to High(exts) do |
185 |
– |
combo_extension.Items.Add(exts[i]); |
186 |
– |
combo_extension.ItemIndex := 0; |
187 |
– |
combo_extensionClick(Self); |
188 |
– |
end; |
189 |
– |
|
190 |
– |
|
191 |
– |
|
192 |
– |
|
193 |
– |
procedure TForm_BinEdit.LoadFileNames; |
194 |
– |
var |
195 |
– |
Extension: String[4]; |
196 |
– |
no_zero_bytes: Boolean; |
197 |
– |
pattern: String; |
198 |
– |
files: TStringArray; |
199 |
– |
i: LongWord; |
200 |
– |
begin |
201 |
– |
Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4); |
202 |
– |
no_zero_bytes := not check_zerobyte.Checked; |
203 |
– |
pattern := ''; |
204 |
– |
if check_filtername.Checked then |
205 |
– |
pattern := edit_filtername.Text; |
206 |
– |
if Extension = '_All' then |
207 |
– |
Extension := ''; |
208 |
– |
|
209 |
– |
files := OniDataConnection.GetFilesList(extension, pattern, no_zero_bytes); |
210 |
– |
list.Items.Clear; |
211 |
– |
if Length(files) > 0 then |
212 |
– |
for i := 0 to High(files) do |
213 |
– |
list.Items.Add(files[i]); |
214 |
– |
end; |
215 |
– |
|
216 |
– |
|
217 |
– |
|
218 |
– |
|
219 |
– |
procedure TForm_BinEdit.panel_extensionResize(Sender: TObject); |
220 |
– |
begin |
221 |
– |
combo_extension.Width := panel_extension.Width - 5; |
222 |
– |
edit_filtername.Width := panel_extension.Width - 5; |
223 |
– |
end; |
224 |
– |
|
225 |
– |
|
226 |
– |
|
227 |
– |
|
228 |
– |
procedure TForm_BinEdit.combo_extensionClick(Sender: TObject); |
229 |
– |
begin |
230 |
– |
LoadFileNames; |
231 |
– |
end; |
232 |
– |
|
233 |
– |
|
234 |
– |
|
235 |
– |
|
236 |
– |
procedure TForm_BinEdit.check_zerobyteClick(Sender: TObject); |
237 |
– |
begin |
238 |
– |
LoadFileNames; |
239 |
– |
end; |
240 |
– |
|
241 |
– |
|
242 |
– |
|
243 |
– |
|
244 |
– |
procedure TForm_BinEdit.check_filternameClick(Sender: TObject); |
245 |
– |
begin |
246 |
– |
edit_filtername.Enabled := not check_filtername.Checked; |
247 |
– |
LoadFileNames; |
248 |
– |
end; |
249 |
– |
|
250 |
– |
|
251 |
– |
|
252 |
– |
|
253 |
– |
procedure TForm_BinEdit.listClick(Sender: TObject); |
254 |
– |
begin |
255 |
– |
LoadDat(OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex])); |
256 |
– |
end; |
257 |
– |
|
258 |
– |
|
259 |
– |
|
260 |
– |
|
261 |
– |
procedure TForm_BinEdit.listMouseDown(Sender: TObject; Button: TMouseButton; |
262 |
– |
Shift: TShiftState; X, Y: Integer); |
263 |
– |
var |
264 |
– |
pt: TPoint; |
265 |
– |
begin |
266 |
– |
pt.X := x; |
267 |
– |
pt.Y := y; |
268 |
– |
list.ItemIndex := list.ItemAtPos(pt, true); |
269 |
– |
if list.ItemIndex > -1 then |
270 |
– |
Self.listClick(Self); |
271 |
– |
end; |
272 |
– |
|
175 |
|
function IntToBin(Value: Byte): String; |
176 |
|
var |
177 |
|
i: Byte; |
489 |
|
|
490 |
|
|
491 |
|
|
590 |
– |
procedure TForm_BinEdit.FormCreate(Sender: TObject); |
591 |
– |
begin |
592 |
– |
Self.Caption := ''; |
593 |
– |
fileid := 0; |
594 |
– |
VST.NodeDataSize := SizeOf(TNodeData); |
595 |
– |
value_viewer.ColCount := 2; |
596 |
– |
value_viewer.RowCount := 8; |
597 |
– |
value_viewer.FixedRows := 1; |
598 |
– |
value_viewer.Cells[0, 0] := 'Type'; |
599 |
– |
value_viewer.Cells[1, 0] := 'Value'; |
600 |
– |
value_viewer.Cells[0, 1] := '1 byte, unsigned'; |
601 |
– |
value_viewer.Cells[0, 2] := '2 bytes, unsigned'; |
602 |
– |
value_viewer.Cells[0, 3] := '4 bytes, unsigned'; |
603 |
– |
value_viewer.Cells[0, 4] := 'Bitset'; |
604 |
– |
value_viewer.Cells[0, 5] := 'Float'; |
605 |
– |
value_viewer.Cells[0, 6] := 'String'; |
606 |
– |
value_viewer.Cells[0, 7] := 'Selected length'; |
607 |
– |
value_viewer.ColWidths[0] := 100; |
608 |
– |
value_viewer.ColWidths[1] := value_viewer.Width - 150; |
609 |
– |
hex.Height := panel_data.Height - 215; |
610 |
– |
// |
611 |
– |
value_viewer.Font.Charset := AppSettings.CharSet; |
612 |
– |
VST.Font.Charset := AppSettings.CharSet; |
613 |
– |
hex.Translation := tkAsIs; |
614 |
– |
hex.Font.Charset := AppSettings.CharSet; |
615 |
– |
// |
616 |
– |
end; |
617 |
– |
|
618 |
– |
|
619 |
– |
|
620 |
– |
|
492 |
|
function TForm_BinEdit.Save: Boolean; |
493 |
|
var |
494 |
|
mem: TMemoryStream; |
544 |
|
|
545 |
|
|
546 |
|
|
676 |
– |
procedure TForm_BinEdit.FormResize(Sender: TObject); |
677 |
– |
begin |
678 |
– |
if Self.Width >= 650 then |
679 |
– |
begin |
680 |
– |
end |
681 |
– |
else |
682 |
– |
Self.Width := 650; |
683 |
– |
if Self.Height >= 450 then |
684 |
– |
begin |
685 |
– |
end |
686 |
– |
else |
687 |
– |
Self.Height := 450; |
688 |
– |
end; |
689 |
– |
|
690 |
– |
|
547 |
|
|
548 |
|
|
549 |
|
procedure TForm_BinEdit.hexChange(Sender: TObject); |
622 |
|
|
623 |
|
|
624 |
|
|
769 |
– |
procedure TForm_BinEdit.FormClose(Sender: TObject; var Action: TCloseAction); |
770 |
– |
begin |
771 |
– |
Action := caFree; |
772 |
– |
end; |
773 |
– |
|
774 |
– |
|
775 |
– |
|
776 |
– |
|
777 |
– |
procedure TForm_BinEdit.panel_imexportResize(Sender: TObject); |
778 |
– |
begin |
779 |
– |
btn_import.Width := panel_imexport.Width - 8; |
780 |
– |
btn_export.Width := panel_imexport.Width - 8; |
781 |
– |
end; |
782 |
– |
|
783 |
– |
|
784 |
– |
|
785 |
– |
|
786 |
– |
procedure TForm_BinEdit.btn_exportClick(Sender: TObject); |
787 |
– |
begin |
788 |
– |
saved.Filter := 'Files of matching extension (*.' + OniDataConnection.GetFileInfo( |
789 |
– |
fileid).Extension + ')|*.' + OniDataConnection.GetFileInfo(fileid).Extension + |
790 |
– |
'|All files|*.*'; |
791 |
– |
saved.DefaultExt := OniDataConnection.GetFileInfo(fileid).Extension; |
792 |
– |
if saved.Execute then |
793 |
– |
begin |
794 |
– |
ExportDatFile(fileid, saved.FileName); |
795 |
– |
end; |
796 |
– |
end; |
797 |
– |
|
798 |
– |
|
799 |
– |
|
800 |
– |
|
801 |
– |
procedure TForm_BinEdit.btn_importClick(Sender: TObject); |
802 |
– |
var |
803 |
– |
fs: TFileStream; |
804 |
– |
begin |
805 |
– |
opend.Filter := 'Files of matching extension (*.' + OniDataConnection.GetFileInfo( |
806 |
– |
fileid).Extension + ')|*.' + OniDataConnection.GetFileInfo(fileid).Extension + |
807 |
– |
'|All files|*.*'; |
808 |
– |
if opend.Execute then |
809 |
– |
begin |
810 |
– |
fs := TFileStream.Create(opend.FileName, fmOpenRead); |
811 |
– |
if fs.Size <> hex.DataSize then |
812 |
– |
begin |
813 |
– |
ShowMessage('Can''t import ' + ExtractFilename(opend.FileName) + |
814 |
– |
', file has to have same size as file in .dat.' + CrLf + |
815 |
– |
'Size of file in .dat: ' + FormatFileSize(hex.datasize) + CrLf + |
816 |
– |
'Size of chosen file: ' + FormatFileSize(fs.Size)); |
817 |
– |
end |
818 |
– |
else |
819 |
– |
begin |
820 |
– |
hex.LoadFromStream(fs); |
821 |
– |
hex.Modified := True; |
822 |
– |
end; |
823 |
– |
fs.Free; |
824 |
– |
end; |
825 |
– |
end; |
826 |
– |
|
827 |
– |
|
828 |
– |
|
829 |
– |
|
625 |
|
procedure TForm_BinEdit.value_viewer_contextPopup(Sender: TObject); |
626 |
|
var |
627 |
|
i: Byte; |
758 |
|
if nodedata.DataType = 11 then |
759 |
|
begin |
760 |
|
if OniDataConnection.GetRawInfo(fileid, nodedata.offset).raw_size > 0 then |
761 |
< |
begin |
967 |
< |
if Form_Main.open_child('rawedit') then |
968 |
< |
begin |
969 |
< |
TForm_RawEdit(Form_Main.ActiveMDIChild).LoadRaw( |
970 |
< |
OniDataConnection.GetRawInfo(fileid, nodedata.offset)); |
971 |
< |
end; |
972 |
< |
end; |
761 |
> |
Form_Main.open_child('rawedit', fileid); |
762 |
|
end; |
763 |
|
if nodedata.DataType = 12 then |
764 |
|
begin |
767 |
|
(StrToInt(nodedata.Value) <> fileid) then |
768 |
|
begin |
769 |
|
if OniDataConnection.GetFileInfo(StrToInt(nodedata.Value)).Size > 0 then |
770 |
< |
begin |
982 |
< |
if Form_Main.open_child('binedit') then |
983 |
< |
begin |
984 |
< |
TForm_BinEdit(Form_Main.ActiveMDIChild).LoadDat(StrToInt(nodedata.Value)); |
985 |
< |
end; |
986 |
< |
end |
770 |
> |
Form_Main.open_child('binedit', StrToInt(nodedata.Value)) |
771 |
|
else |
988 |
– |
begin |
772 |
|
ShowMessage('Linked filed is a zero-byte-file'); |
990 |
– |
end; |
773 |
|
end; |
774 |
|
end; |
775 |
|
if (nodedata.DataType >= 100) and (nodedata.DataType <= 300) then |
776 |
|
begin |
777 |
< |
if Form_Main.open_child('binedit') then |
777 |
> |
if Form_Main.open_child('binedit', -1) then |
778 |
|
begin |
779 |
|
TForm_BinEdit(Form_Main.ActiveMDIChild).edit_filtername.Text := nodedata.Value; |
780 |
|
TForm_BinEdit(Form_Main.ActiveMDIChild).check_filtername.Checked := True; |
977 |
|
end; |
978 |
|
|
979 |
|
|
980 |
+ |
begin |
981 |
+ |
AddToolListEntry('binedit', 'Binary .dat-Editor', ''); |
982 |
|
end. |