1 |
|
unit Tool_RawEdit; |
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; |
5 |
> |
Dialogs, Tool_Template, StdCtrls, ExtCtrls, Menus, Grids, Wrapgrid, |
6 |
> |
MPHexEditor, Clipbrd, StrUtils, |
7 |
> |
Data, Code_Functions, Code_DataStructures, Code_Exporters, Code_OniDataClass; |
8 |
|
|
9 |
|
type |
10 |
< |
TForm_RawEdit = class(TForm) |
11 |
< |
Splitter1: TSplitter; |
12 |
< |
panel_data: TPanel; |
13 |
< |
hex: TMPHexEditor; |
10 |
> |
TForm_RawEdit = class(TForm_ToolTemplate) |
11 |
> |
Splitter4: TSplitter; |
12 |
> |
panel_imexport: TPanel; |
13 |
> |
btn_export: TButton; |
14 |
> |
btn_import: TButton; |
15 |
> |
GroupBox1: TGroupBox; |
16 |
> |
list_offset: TListBox; |
17 |
> |
hex: TMPHexEditor; |
18 |
|
Splitter2: TSplitter; |
19 |
|
value_viewer: TWrapGrid; |
20 |
|
value_viewer_context: TPopupMenu; |
21 |
|
value_viewer_context_copy: TMenuItem; |
20 |
– |
value_viewer_context_copyashex: TMenuItem; |
22 |
|
value_viewer_context_copyasdec: TMenuItem; |
23 |
|
value_viewer_context_copyasfloat: TMenuItem; |
24 |
|
value_viewer_context_copyasbitset: TMenuItem; |
25 |
|
value_viewer_context_copyasstring: TMenuItem; |
26 |
< |
panel_files: TPanel; |
26 |
> |
value_viewer_context_copyashex: TMenuItem; |
27 |
|
opend: TOpenDialog; |
28 |
|
saved: TSaveDialog; |
28 |
– |
panel_imexport: TPanel; |
29 |
– |
btn_export: TButton; |
30 |
– |
btn_import: TButton; |
31 |
– |
group_file: TGroupBox; |
32 |
– |
list: TListBox; |
33 |
– |
panel_extension: TPanel; |
34 |
– |
lbl_filter: TLabel; |
35 |
– |
combo_extension: TComboBox; |
36 |
– |
edit_filtername: TEdit; |
37 |
– |
check_filtername: TCheckBox; |
38 |
– |
GroupBox1: TGroupBox; |
39 |
– |
list_offset: TListBox; |
40 |
– |
Splitter4: TSplitter; |
41 |
– |
procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
29 |
|
procedure list_offsetClick(Sender: TObject); |
30 |
+ |
procedure NewFile(fileinfo: TFileInfo); |
31 |
|
procedure LoadRaw(raw_info: TRawInfo); |
32 |
< |
procedure LoadFileNames; |
45 |
< |
procedure check_filternameClick(Sender: TObject); |
46 |
< |
procedure combo_extensionClick(Sender: TObject); |
47 |
< |
procedure panel_extensionResize(Sender: TObject); |
48 |
< |
procedure listClick(Sender: TObject); |
49 |
< |
procedure Recreatelist; |
32 |
> |
function Save: Boolean; |
33 |
|
|
34 |
+ |
procedure btn_importClick(Sender: TObject); |
35 |
+ |
procedure btn_exportClick(Sender: TObject); |
36 |
+ |
|
37 |
+ |
procedure FormCreate(Sender: TObject); |
38 |
+ |
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
39 |
|
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
40 |
+ |
|
41 |
+ |
procedure panel_contentResize(Sender: TObject); |
42 |
+ |
|
43 |
+ |
function GetValue(datatype: Word; offset: LongWord): String; |
44 |
+ |
procedure ClearValues; |
45 |
+ |
procedure WriteValues; |
46 |
+ |
procedure SetNewValue(datatype: Word; offset: LongWord; Value: String); |
47 |
+ |
|
48 |
|
procedure value_viewerDblClick(Sender: TObject); |
49 |
|
procedure value_viewer_context_copyClick(Sender: TObject); |
50 |
|
procedure value_viewerMouseDown(Sender: TObject; Button: TMouseButton; |
51 |
|
Shift: TShiftState; X, Y: Integer); |
52 |
|
procedure value_viewer_contextPopup(Sender: TObject); |
53 |
< |
procedure btn_importClick(Sender: TObject); |
54 |
< |
procedure btn_exportClick(Sender: TObject); |
59 |
< |
procedure panel_imexportResize(Sender: TObject); |
60 |
< |
function Save: Boolean; |
61 |
< |
procedure FormClose(Sender: TObject; var Action: TCloseAction); |
62 |
< |
function GetValue(datatype: Word; offset: LongWord): String; |
53 |
> |
|
54 |
> |
procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); |
55 |
|
procedure hexSelectionChanged(Sender: TObject); |
56 |
|
procedure hexChange(Sender: TObject); |
65 |
– |
procedure panel_dataResize(Sender: TObject); |
66 |
– |
procedure FormResize(Sender: TObject); |
67 |
– |
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
68 |
– |
procedure FormCreate(Sender: TObject); |
69 |
– |
procedure ClearValues; |
70 |
– |
procedure WriteValues; |
71 |
– |
procedure SetNewValue(datatype: Word; offset: LongWord; Value: String); |
72 |
– |
procedure listMouseDown(Sender: TObject; Button: TMouseButton; |
73 |
– |
Shift: TShiftState; X, Y: Integer); |
57 |
|
private |
58 |
|
fileid: LongWord; |
59 |
|
dat_offset: LongWord; |
65 |
|
Form_RawEdit: TForm_RawEdit; |
66 |
|
|
67 |
|
implementation |
85 |
– |
|
68 |
|
{$R *.dfm} |
87 |
– |
|
69 |
|
uses Main, Helper_ValueEdit; |
70 |
|
|
71 |
< |
|
72 |
< |
|
71 |
> |
procedure TForm_RawEdit.NewFile(fileinfo: TFileInfo); |
72 |
> |
var |
73 |
> |
offsets: TRawList; |
74 |
> |
i: Integer; |
75 |
> |
begin |
76 |
> |
if hex.Modified then |
77 |
> |
if not Save then |
78 |
> |
Exit; |
79 |
> |
ClearValues; |
80 |
> |
hex.DataSize := 0; |
81 |
> |
fileid := fileinfo.ID; |
82 |
> |
list_offset.Enabled := False; |
83 |
> |
if fileinfo.size > 0 then |
84 |
> |
begin |
85 |
> |
offsets := OniDataConnection.GetRawList(fileid); |
86 |
> |
list_offset.Items.Clear; |
87 |
> |
if Length(offsets) > 0 then |
88 |
> |
for i := 0 to High(offsets) do |
89 |
> |
list_offset.Items.Add('0x' + IntToHex(offsets[i].src_offset, 8) + |
90 |
> |
', ' + IntToStr(offsets[i].raw_size) + ' bytes'); |
91 |
> |
list_offset.Enabled := True; |
92 |
> |
end; |
93 |
> |
end; |
94 |
|
|
95 |
|
procedure TForm_RawEdit.LoadRaw(raw_info: TRawInfo); |
96 |
|
var |
97 |
|
i: LongWord; |
98 |
|
Data: Tdata; |
97 |
– |
mem: TMemoryStream; |
99 |
|
begin |
100 |
|
if hex.Modified then |
101 |
|
begin |
106 |
|
end; |
107 |
|
if list_offset.Count = 0 then |
108 |
|
begin |
109 |
< |
for i := 0 to list.Count - 1 do |
109 |
> |
for i := 0 to filelist.Count - 1 do |
110 |
|
begin |
111 |
< |
if OniDataConnection.ExtractFileID(list.Items.Strings[i]) = raw_info.src_id then |
111 |
> |
if OniDataConnection.ExtractFileID(filelist.Items.Strings[i]) = raw_info.src_id then |
112 |
|
begin |
113 |
< |
list.ItemIndex := i; |
113 |
> |
filelist.ItemIndex := i; |
114 |
|
listClick(Self); |
115 |
|
Break; |
116 |
|
end; |
150 |
|
|
151 |
|
|
152 |
|
|
152 |
– |
procedure TForm_RawEdit.Recreatelist; |
153 |
– |
var |
154 |
– |
i: LongWord; |
155 |
– |
exts: TStringArray; |
156 |
– |
Count: LongWord; |
157 |
– |
begin |
158 |
– |
combo_extension.Items.Clear; |
159 |
– |
combo_extension.Items.Add('_All files_ ('{+IntToStr(dat_header.Files)} + ')'); |
160 |
– |
exts := OniDataConnection.GetExtensionsList; |
161 |
– |
for i := 0 to High(RawListHandlers) do |
162 |
– |
begin |
163 |
– |
Count := Length(OniDataConnection.GetFilesList(RawListHandlers[i].Ext, '', True)); |
164 |
– |
combo_extension.Items.Add(RawListHandlers[i].ext + ' (' + IntToStr(Count) + ')'); |
165 |
– |
end; |
166 |
– |
// FOR i:=0 TO High(exts) DO |
167 |
– |
// combo_extension.Items.Add(exts[i]); |
168 |
– |
combo_extension.ItemIndex := 0; |
169 |
– |
combo_extensionClick(Self); |
170 |
– |
end; |
171 |
– |
|
172 |
– |
|
173 |
– |
|
174 |
– |
|
175 |
– |
procedure TForm_RawEdit.LoadFileNames; |
176 |
– |
var |
177 |
– |
Extension: String; |
178 |
– |
no_zero_bytes: Boolean; |
179 |
– |
pattern: String; |
180 |
– |
files: TStringArray; |
181 |
– |
i: LongWord; |
182 |
– |
begin |
183 |
– |
Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4); |
184 |
– |
pattern := ''; |
185 |
– |
if check_filtername.Checked then |
186 |
– |
pattern := edit_filtername.Text; |
187 |
– |
if Extension = '_All' then |
188 |
– |
begin |
189 |
– |
Extension := ''; |
190 |
– |
for i := 0 to High(RawListHandlers) do |
191 |
– |
begin |
192 |
– |
if Length(Extension) > 0 then |
193 |
– |
Extension := Extension + ','; |
194 |
– |
Extension := Extension + RawListHandlers[i].Ext; |
195 |
– |
end; |
196 |
– |
end; |
197 |
– |
|
198 |
– |
files := OniDataConnection.GetFilesList(extension, pattern, True); |
199 |
– |
list.Items.Clear; |
200 |
– |
if Length(files) > 0 then |
201 |
– |
for i := 0 to High(files) do |
202 |
– |
list.Items.Add(files[i]); |
203 |
– |
list_offset.Items.Clear; |
204 |
– |
end; |
205 |
– |
|
206 |
– |
|
207 |
– |
|
208 |
– |
|
209 |
– |
procedure TForm_RawEdit.panel_extensionResize(Sender: TObject); |
210 |
– |
begin |
211 |
– |
combo_extension.Width := panel_extension.Width - 5; |
212 |
– |
edit_filtername.Width := panel_extension.Width - 5; |
213 |
– |
end; |
153 |
|
|
154 |
|
|
216 |
– |
|
217 |
– |
|
218 |
– |
procedure TForm_RawEdit.combo_extensionClick(Sender: TObject); |
219 |
– |
begin |
220 |
– |
LoadFileNames; |
221 |
– |
end; |
222 |
– |
|
223 |
– |
|
224 |
– |
|
225 |
– |
|
226 |
– |
procedure TForm_RawEdit.check_filternameClick(Sender: TObject); |
227 |
– |
begin |
228 |
– |
edit_filtername.Enabled := not check_filtername.Checked; |
229 |
– |
LoadFileNames; |
230 |
– |
end; |
231 |
– |
|
232 |
– |
|
233 |
– |
|
234 |
– |
|
235 |
– |
procedure TForm_RawEdit.listClick(Sender: TObject); |
236 |
– |
var |
237 |
– |
mem: TMemoryStream; |
238 |
– |
Data: Tdata; |
239 |
– |
i: LongWord; |
240 |
– |
offsets: TRawList; |
241 |
– |
begin |
242 |
– |
if hex.Modified then |
243 |
– |
begin |
244 |
– |
if not Save then |
245 |
– |
begin |
246 |
– |
Exit; |
247 |
– |
end; |
248 |
– |
end; |
249 |
– |
ClearValues; |
250 |
– |
hex.DataSize := 0; |
251 |
– |
fileid := OniDataConnection.ExtractFileID(list.Items.Strings[list.ItemIndex]); |
252 |
– |
list_offset.Enabled := True; |
253 |
– |
if OniDataConnection.GetFileInfo(fileid).size > 0 then |
254 |
– |
begin |
255 |
– |
offsets := OniDataConnection.GetRawList(fileid); |
256 |
– |
list_offset.Items.Clear; |
257 |
– |
if Length(offsets) > 0 then |
258 |
– |
begin |
259 |
– |
for i := 0 to High(offsets) do |
260 |
– |
begin |
261 |
– |
list_offset.Items.Add('0x' + IntToHex(offsets[i].src_offset, 8) + |
262 |
– |
', ' + IntToStr(offsets[i].raw_size) + ' bytes'); |
263 |
– |
end; |
264 |
– |
end |
265 |
– |
else |
266 |
– |
begin |
267 |
– |
list_offset.Enabled := False; |
268 |
– |
end; |
269 |
– |
end |
270 |
– |
else |
271 |
– |
begin |
272 |
– |
list_offset.Enabled := False; |
273 |
– |
end; |
274 |
– |
end; |
275 |
– |
|
276 |
– |
|
277 |
– |
|
278 |
– |
|
279 |
– |
procedure TForm_RawEdit.listMouseDown(Sender: TObject; Button: TMouseButton; |
280 |
– |
Shift: TShiftState; X, Y: Integer); |
281 |
– |
var |
282 |
– |
pt: TPoint; |
283 |
– |
begin |
284 |
– |
pt.X := x; |
285 |
– |
pt.Y := y; |
286 |
– |
list.ItemIndex := list.ItemAtPos(pt, true); |
287 |
– |
if list.ItemIndex > -1 then |
288 |
– |
Self.listClick(Self); |
289 |
– |
end; |
290 |
– |
|
155 |
|
procedure TForm_RawEdit.list_offsetClick(Sender: TObject); |
156 |
|
var |
157 |
|
i: LongWord; |
363 |
|
|
364 |
|
|
365 |
|
procedure TForm_RawEdit.FormCreate(Sender: TObject); |
366 |
+ |
var |
367 |
+ |
i: LongWord; |
368 |
+ |
exts: String; |
369 |
|
begin |
370 |
+ |
inherited; |
371 |
+ |
Self.OnNewFileSelected := Self.NewFile; |
372 |
+ |
|
373 |
+ |
exts := ''; |
374 |
+ |
if Length(RawListHandlers) > 0 then |
375 |
+ |
begin |
376 |
+ |
for i := 0 to High(RawListHandlers) do |
377 |
+ |
if Length(exts) > 0 then |
378 |
+ |
exts := exts + ',' + RawListHandlers[i].Ext |
379 |
+ |
else |
380 |
+ |
exts := RawListHandlers[i].Ext; |
381 |
+ |
end; |
382 |
+ |
Self.AllowedExts := exts; |
383 |
+ |
|
384 |
|
Self.Caption := ''; |
385 |
|
fileid := 0; |
386 |
|
value_viewer.ColCount := 2; |
396 |
|
value_viewer.Cells[0, 6] := 'String'; |
397 |
|
value_viewer.Cells[0, 7] := 'Selected length'; |
398 |
|
value_viewer.ColWidths[0] := 100; |
518 |
– |
hex.Height := panel_data.Height - 190; |
519 |
– |
Self.panel_dataResize(Self); |
399 |
|
// |
400 |
|
value_viewer.Font.Charset := AppSettings.CharSet; |
401 |
|
// |
452 |
|
|
453 |
|
|
454 |
|
|
455 |
< |
procedure TForm_RawEdit.FormResize(Sender: TObject); |
577 |
< |
begin |
578 |
< |
if Self.Width >= 650 then |
579 |
< |
begin |
580 |
< |
end |
581 |
< |
else |
582 |
< |
Self.Width := 650; |
583 |
< |
if Self.Height >= 450 then |
584 |
< |
begin |
585 |
< |
end |
586 |
< |
else |
587 |
< |
Self.Height := 450; |
588 |
< |
end; |
589 |
< |
|
590 |
< |
|
591 |
< |
|
592 |
< |
|
593 |
< |
procedure TForm_RawEdit.panel_dataResize(Sender: TObject); |
455 |
> |
procedure TForm_RawEdit.panel_contentResize(Sender: TObject); |
456 |
|
begin |
457 |
|
value_viewer.ColWidths[1] := value_viewer.Width - value_viewer.ColWidths[0] - 28; |
458 |
|
end; |
535 |
|
|
536 |
|
|
537 |
|
|
676 |
– |
procedure TForm_RawEdit.FormClose(Sender: TObject; var Action: TCloseAction); |
677 |
– |
begin |
678 |
– |
Action := caFree; |
679 |
– |
end; |
680 |
– |
|
681 |
– |
|
682 |
– |
|
683 |
– |
|
684 |
– |
procedure TForm_RawEdit.panel_imexportResize(Sender: TObject); |
685 |
– |
begin |
686 |
– |
btn_import.Width := panel_imexport.Width - 8; |
687 |
– |
btn_export.Width := panel_imexport.Width - 8; |
688 |
– |
end; |
689 |
– |
|
690 |
– |
|
691 |
– |
|
538 |
|
|
539 |
|
procedure TForm_RawEdit.btn_exportClick(Sender: TObject); |
540 |
|
var |
811 |
|
Exit; |
812 |
|
end; |
813 |
|
|
814 |
+ |
begin |
815 |
+ |
AddToolListEntry('rawedit', 'Binary .raw-Editor', ''); |
816 |
|
end. |