1 | unit RawEdit;
|
---|
2 | interface
|
---|
3 | uses
|
---|
4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
5 | Dialogs, Template, StdCtrls, ExtCtrls, Menus, Grids, Wrapgrid,
|
---|
6 | MPHexEditor, Clipbrd, StrUtils, TypeDefs,
|
---|
7 | Data, Functions, DatStructureLoader, ConnectionManager, Buttons;
|
---|
8 |
|
---|
9 | type
|
---|
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;
|
---|
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 | value_viewer_context_copyashex: TMenuItem;
|
---|
27 | opend: TOpenDialog;
|
---|
28 | saved: TSaveDialog;
|
---|
29 | procedure list_offsetClick(Sender: TObject);
|
---|
30 | procedure NewFile(fileinfo: TFileInfo);
|
---|
31 | procedure LoadRaw(raw_info: TRawDataInfo);
|
---|
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 | function GetValue(datatype: Word; offset: LongWord): String;
|
---|
42 | procedure ClearValues;
|
---|
43 | procedure WriteValues;
|
---|
44 | procedure SetNewValue(datatype: Word; offset: LongWord; Value: String);
|
---|
45 |
|
---|
46 | procedure value_viewerDblClick(Sender: TObject);
|
---|
47 | procedure value_viewer_context_copyClick(Sender: TObject);
|
---|
48 | procedure value_viewerMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
49 | Shift: TShiftState; X, Y: Integer);
|
---|
50 | procedure value_viewer_contextPopup(Sender: TObject);
|
---|
51 |
|
---|
52 | procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
53 | procedure hexSelectionChanged(Sender: TObject);
|
---|
54 | procedure hexChange(Sender: TObject);
|
---|
55 | private
|
---|
56 | ConID, fileid, datoffset: Integer;
|
---|
57 | public
|
---|
58 | end;
|
---|
59 |
|
---|
60 | var
|
---|
61 | Form_RawEdit: TForm_RawEdit;
|
---|
62 |
|
---|
63 | implementation
|
---|
64 | {$R *.dfm}
|
---|
65 | uses Main, ValueEdit, RawList;
|
---|
66 |
|
---|
67 | procedure TForm_RawEdit.NewFile(fileinfo: TFileInfo);
|
---|
68 | var
|
---|
69 | offsets: TRawDataList;
|
---|
70 | i: Integer;
|
---|
71 | begin
|
---|
72 | if fileinfo.ID >= 0 then
|
---|
73 | begin
|
---|
74 | if hex.Modified then
|
---|
75 | if not Save then
|
---|
76 | Exit;
|
---|
77 | ClearValues;
|
---|
78 | hex.DataSize := 0;
|
---|
79 | fileid := fileinfo.ID;
|
---|
80 | list_offset.Enabled := False;
|
---|
81 | if fileinfo.size > 0 then
|
---|
82 | begin
|
---|
83 | offsets := ConManager.Connection[ConnectionID].GetRawList(fileid);
|
---|
84 | list_offset.Items.Clear;
|
---|
85 | if Length(offsets) > 0 then
|
---|
86 | for i := 0 to High(offsets) do
|
---|
87 | list_offset.Items.Add('0x' + IntToHex(offsets[i].SrcOffset, 8) +
|
---|
88 | ', ' + IntToStr(offsets[i].RawSize) + ' Bytes');
|
---|
89 | list_offset.Enabled := True;
|
---|
90 | end;
|
---|
91 | end
|
---|
92 | else
|
---|
93 | begin
|
---|
94 | ClearValues;
|
---|
95 | hex.DataSize := 0;
|
---|
96 | fileid := -1;
|
---|
97 | list_offset.Items.Clear;
|
---|
98 | end;
|
---|
99 | end;
|
---|
100 |
|
---|
101 | procedure TForm_RawEdit.LoadRaw(raw_info: TRawDataInfo);
|
---|
102 | var
|
---|
103 | i: LongWord;
|
---|
104 | mem: TMemoryStream;
|
---|
105 | begin
|
---|
106 | if hex.Modified then
|
---|
107 | begin
|
---|
108 | if not Save then
|
---|
109 | begin
|
---|
110 | Exit;
|
---|
111 | end;
|
---|
112 | end;
|
---|
113 | if list_offset.Count = 0 then
|
---|
114 | begin
|
---|
115 | for i := 0 to filelist.Count - 1 do
|
---|
116 | begin
|
---|
117 | if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[i]) = Raw_Info.SrcID then
|
---|
118 | begin
|
---|
119 | filelist.ItemIndex := i;
|
---|
120 | listClick(Self);
|
---|
121 | Break;
|
---|
122 | end;
|
---|
123 | end;
|
---|
124 | for i := 0 to list_offset.Count - 1 do
|
---|
125 | begin
|
---|
126 | if MidStr(list_offset.Items.Strings[i], 3, 8) = IntToHex(raw_info.SrcOffset, 8) then
|
---|
127 | begin
|
---|
128 | list_offset.ItemIndex := i;
|
---|
129 | Break;
|
---|
130 | end;
|
---|
131 | end;
|
---|
132 | end;
|
---|
133 | mem := nil;
|
---|
134 | ConManager.Connection[ConID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, TStream(mem));
|
---|
135 | hex.LoadFromStream(mem);
|
---|
136 | ClearValues;
|
---|
137 | hexSelectionChanged(Self);
|
---|
138 | end;
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 |
|
---|
145 | procedure TForm_RawEdit.list_offsetClick(Sender: TObject);
|
---|
146 | begin
|
---|
147 | ClearValues;
|
---|
148 | datoffset := StrToInt('$' + MidStr(
|
---|
149 | list_offset.Items.Strings[list_offset.ItemIndex], 3, 8));
|
---|
150 | LoadRaw(ConManager.Connection[ConID].GetRawInfo(fileid, datoffset));
|
---|
151 | end;
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 |
|
---|
156 | function TForm_RawEdit.GetValue(datatype: Word; offset: LongWord): String;
|
---|
157 | var
|
---|
158 | Data: TByteData;
|
---|
159 | i: Word;
|
---|
160 | floatformat: TFormatSettings;
|
---|
161 | begin
|
---|
162 | floatformat.DecimalSeparator := '.';
|
---|
163 | case datatype of
|
---|
164 | 1:
|
---|
165 | Result := IntToStr(hex.Data[offset]);
|
---|
166 | 2:
|
---|
167 | Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256);
|
---|
168 | 3:
|
---|
169 | Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256 + hex.Data[offset + 2] * 256 * 256);
|
---|
170 | 4:
|
---|
171 | Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256 + hex.Data[offset + 2] *
|
---|
172 | 256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256);
|
---|
173 | 5:
|
---|
174 | Result := '0x' + IntToHex(hex.Data[offset], 2);
|
---|
175 | 6:
|
---|
176 | Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256, 4);
|
---|
177 | 7:
|
---|
178 | Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 +
|
---|
179 | hex.Data[offset + 2] * 256 * 256, 6);
|
---|
180 | 8:
|
---|
181 | Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 +
|
---|
182 | hex.Data[offset + 2] * 256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256, 8);
|
---|
183 | 9:
|
---|
184 | begin
|
---|
185 | SetLength(Data, 4);
|
---|
186 | Data[0] := hex.Data[offset];
|
---|
187 | Data[1] := hex.Data[offset + 1];
|
---|
188 | Data[2] := hex.Data[offset + 2];
|
---|
189 | Data[3] := hex.Data[offset + 3];
|
---|
190 | Result := FloatToStr(Decode_Float(Data), floatformat);
|
---|
191 | end;
|
---|
192 | 10:
|
---|
193 | Result := IntToBin(hex.Data[offset]);
|
---|
194 | 11:
|
---|
195 | Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 +
|
---|
196 | hex.Data[offset + 2] * 256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256, 8);
|
---|
197 | 10000..65535:
|
---|
198 | begin
|
---|
199 | Result := '';
|
---|
200 | for i := 1 to datatype - 10000 do
|
---|
201 | begin
|
---|
202 | if hex.Data[offset + i - 1] >= 32 then
|
---|
203 | Result := Result + Chr(hex.Data[offset + i - 1])
|
---|
204 | else
|
---|
205 | Result := Result + '.';
|
---|
206 | end;
|
---|
207 | end;
|
---|
208 | end;
|
---|
209 | end;
|
---|
210 |
|
---|
211 |
|
---|
212 |
|
---|
213 |
|
---|
214 | procedure TForm_RawEdit.ClearValues;
|
---|
215 | var
|
---|
216 | i: Byte;
|
---|
217 | begin
|
---|
218 | for i := 1 to value_viewer.RowCount - 1 do
|
---|
219 | value_viewer.Cells[1, i] := '';
|
---|
220 | end;
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 |
|
---|
225 | procedure TForm_RawEdit.WriteValues;
|
---|
226 | var
|
---|
227 | i, j: Integer;
|
---|
228 | Data: TByteData;
|
---|
229 | str: String;
|
---|
230 | Value: LongWord;
|
---|
231 | floatformat: TFormatSettings;
|
---|
232 | begin
|
---|
233 | floatformat.DecimalSeparator := '.';
|
---|
234 | for i := 1 to value_viewer.RowCount - 1 do
|
---|
235 | begin
|
---|
236 | if value_viewer.Cells[0, i] = '1 byte, unsigned' then
|
---|
237 | begin
|
---|
238 | if ((hex.SelCount = 1) or (hex.SelCount = 0)) and not
|
---|
239 | ((hex.SelStart + 1) > hex.DataSize) then
|
---|
240 | begin
|
---|
241 | Value := hex.Data[hex.SelStart];
|
---|
242 | value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 2);
|
---|
243 | end
|
---|
244 | else
|
---|
245 | value_viewer.Cells[1, i] := '';
|
---|
246 | end;
|
---|
247 | if value_viewer.Cells[0, i] = '2 bytes, unsigned' then
|
---|
248 | begin
|
---|
249 | if ((hex.SelCount = 2) or (hex.SelCount = 0)) and not
|
---|
250 | ((hex.SelStart + 2) > hex.DataSize) then
|
---|
251 | begin
|
---|
252 | Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256;
|
---|
253 | value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 4);
|
---|
254 | end
|
---|
255 | else
|
---|
256 | value_viewer.Cells[1, i] := '';
|
---|
257 | end;
|
---|
258 | if value_viewer.Cells[0, i] = '4 bytes, unsigned' then
|
---|
259 | begin
|
---|
260 | if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
|
---|
261 | ((hex.SelStart + 4) > hex.DataSize) then
|
---|
262 | begin
|
---|
263 | Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256 +
|
---|
264 | hex.Data[hex.SelStart + 2] * 256 * 256 + hex.Data[hex.SelStart + 3] * 256 * 256 * 256;
|
---|
265 | value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 8);
|
---|
266 | end
|
---|
267 | else
|
---|
268 | value_viewer.Cells[1, i] := '';
|
---|
269 | end;
|
---|
270 | if value_viewer.Cells[0, i] = 'Bitset' then
|
---|
271 | begin
|
---|
272 | if (hex.SelCount <= 8) then
|
---|
273 | begin
|
---|
274 | if hex.SelCount = 0 then
|
---|
275 | begin
|
---|
276 | SetLength(Data, 1);
|
---|
277 | Data[0] := hex.Data[hex.SelStart];
|
---|
278 | end
|
---|
279 | else
|
---|
280 | begin
|
---|
281 | SetLength(Data, hex.SelCount);
|
---|
282 | for j := 0 to hex.SelCount - 1 do
|
---|
283 | Data[j] := hex.Data[hex.SelStart + j];
|
---|
284 | end;
|
---|
285 | value_viewer.Cells[1, i] := DataToBin(Data);
|
---|
286 | end
|
---|
287 | else
|
---|
288 | value_viewer.Cells[1, i] := '';
|
---|
289 | end;
|
---|
290 | if value_viewer.Cells[0, i] = 'Float' then
|
---|
291 | begin
|
---|
292 | if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
|
---|
293 | ((hex.SelStart + 4) > hex.DataSize) then
|
---|
294 | begin
|
---|
295 | SetLength(Data, 4);
|
---|
296 | for j := 0 to 3 do
|
---|
297 | Data[j] := hex.Data[hex.SelStart + j];
|
---|
298 | value_viewer.Cells[1, i] := FloatToStr(Decode_Float(Data), floatformat);
|
---|
299 | end
|
---|
300 | else
|
---|
301 | value_viewer.Cells[1, i] := '';
|
---|
302 | end;
|
---|
303 | if value_viewer.Cells[0, i] = 'Selected length' then
|
---|
304 | begin
|
---|
305 | value_viewer.Cells[1, i] := IntToStr(hex.SelCount) + ' bytes';
|
---|
306 | end;
|
---|
307 | if value_viewer.Cells[0, i] = 'String' then
|
---|
308 | begin
|
---|
309 | j := 0;
|
---|
310 | str := '';
|
---|
311 | if hex.SelCount = 0 then
|
---|
312 | begin
|
---|
313 | while (hex.Data[hex.SelStart + j] > 0) and ((hex.SelStart + j) < hex.DataSize) do
|
---|
314 | begin
|
---|
315 | if hex.Data[hex.selstart + j] >= 32 then
|
---|
316 | str := str + Char(hex.Data[hex.SelStart + j])
|
---|
317 | else
|
---|
318 | str := str + '.';
|
---|
319 | Inc(j);
|
---|
320 | end;
|
---|
321 | end
|
---|
322 | else
|
---|
323 | begin
|
---|
324 | for j := 0 to hex.SelCount - 1 do
|
---|
325 | if hex.Data[hex.selstart + j] >= 32 then
|
---|
326 | str := str + Char(hex.Data[hex.SelStart + j])
|
---|
327 | else if hex.Data[hex.selstart + j] > 0 then
|
---|
328 | str := str + '.'
|
---|
329 | else
|
---|
330 | Break;
|
---|
331 | end;
|
---|
332 | value_viewer.Cells[1, i] := str;
|
---|
333 | end;
|
---|
334 | end;
|
---|
335 | end;
|
---|
336 |
|
---|
337 |
|
---|
338 |
|
---|
339 |
|
---|
340 | procedure TForm_RawEdit.FormCreate(Sender: TObject);
|
---|
341 | var
|
---|
342 | i: LongWord;
|
---|
343 | exts: String;
|
---|
344 | begin
|
---|
345 | inherited;
|
---|
346 | Self.OnNewFileSelected := Self.NewFile;
|
---|
347 |
|
---|
348 | exts := '';
|
---|
349 | if Length(RawLists.RawListHandlers) > 0 then
|
---|
350 | begin
|
---|
351 | for i := 0 to High(RawLists.RawListHandlers) do
|
---|
352 | if Length(exts) > 0 then
|
---|
353 | exts := exts + ',' + RawLists.RawListHandlers[i].Ext
|
---|
354 | else
|
---|
355 | exts := RawLists.RawListHandlers[i].Ext;
|
---|
356 | end;
|
---|
357 | Self.AllowedExts := exts;
|
---|
358 |
|
---|
359 | Self.Caption := '';
|
---|
360 | fileid := -1;
|
---|
361 |
|
---|
362 | {
|
---|
363 | value_viewer.ColCount := 2;
|
---|
364 | value_viewer.RowCount := 8;
|
---|
365 | }
|
---|
366 | value_viewer.FixedRows := 1;
|
---|
367 | value_viewer.FixedCols := 1;
|
---|
368 | value_viewer.Cells[0, 0] := 'Type';
|
---|
369 | value_viewer.Cells[1, 0] := 'Value';
|
---|
370 | value_viewer.Cells[0, 1] := '1 byte, unsigned';
|
---|
371 | value_viewer.Cells[0, 2] := '2 bytes, unsigned';
|
---|
372 | value_viewer.Cells[0, 3] := '4 bytes, unsigned';
|
---|
373 | value_viewer.Cells[0, 4] := 'Bitset';
|
---|
374 | value_viewer.Cells[0, 5] := 'Float';
|
---|
375 | value_viewer.Cells[0, 6] := 'String';
|
---|
376 | value_viewer.Cells[0, 7] := 'Selected length';
|
---|
377 | value_viewer.ColWidths[0] := 125;
|
---|
378 | value_viewer.ColWidths[1] := 1000;
|
---|
379 | //
|
---|
380 | value_viewer.Font.Charset := AppSettings.CharSet;
|
---|
381 | //
|
---|
382 | end;
|
---|
383 |
|
---|
384 |
|
---|
385 |
|
---|
386 |
|
---|
387 | function TForm_RawEdit.Save: Boolean;
|
---|
388 | var
|
---|
389 | mem: TMemoryStream;
|
---|
390 | i: LongWord;
|
---|
391 | begin
|
---|
392 | case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' +
|
---|
393 | ConManager.Connection[ConID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'),
|
---|
394 | MB_YESNOCANCEL) of
|
---|
395 | idYes:
|
---|
396 | begin
|
---|
397 | mem := TMemoryStream.Create;
|
---|
398 | hex.SaveToStream(mem);
|
---|
399 | mem.Seek(0, soFromBeginning);
|
---|
400 | ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, mem);
|
---|
401 | mem.Free;
|
---|
402 | hex.Modified := False;
|
---|
403 | for i := 0 to hex.Datasize - 1 do
|
---|
404 | hex.ByteChanged[i] := False;
|
---|
405 | Result := True;
|
---|
406 | end;
|
---|
407 | idNo:
|
---|
408 | Result := True;
|
---|
409 | idCancel:
|
---|
410 | Result := False;
|
---|
411 | end;
|
---|
412 | end;
|
---|
413 |
|
---|
414 |
|
---|
415 |
|
---|
416 |
|
---|
417 | procedure TForm_RawEdit.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
---|
418 | begin
|
---|
419 | if hex.Modified then
|
---|
420 | if not Save then
|
---|
421 | CanClose := False;
|
---|
422 | end;
|
---|
423 |
|
---|
424 |
|
---|
425 |
|
---|
426 |
|
---|
427 | procedure TForm_RawEdit.hexChange(Sender: TObject);
|
---|
428 | begin
|
---|
429 | ClearValues;
|
---|
430 | if hex.DataSize > 0 then
|
---|
431 | begin
|
---|
432 | { WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension));
|
---|
433 | WriteValues;
|
---|
434 | } end;
|
---|
435 | end;
|
---|
436 |
|
---|
437 |
|
---|
438 |
|
---|
439 |
|
---|
440 | procedure TForm_RawEdit.hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
441 | //var
|
---|
442 | // temps: String;
|
---|
443 | begin
|
---|
444 | if (Shift = [ssCtrl]) and (Key = Ord('C')) then
|
---|
445 | begin
|
---|
446 | if hex.SelCount > 0 then
|
---|
447 | begin
|
---|
448 | if hex.InCharField then
|
---|
449 | Clipboard.AsText := hex.SelectionAsText
|
---|
450 | else
|
---|
451 | Clipboard.AsText := hex.SelectionAsHex;
|
---|
452 | end;
|
---|
453 | end;
|
---|
454 | if (Shift = [ssCtrl]) and (Key = Ord('V')) then
|
---|
455 | begin
|
---|
456 | { temps:=Clipboard.AsText;
|
---|
457 | IF hex.SelStart+Length(temps)>hex.DataSize THEN
|
---|
458 | SetLength(temps, hex.DataSize-hex.SelStart);
|
---|
459 | hex.Sel
|
---|
460 | hex.SelCount:=Length(temps);
|
---|
461 | hex.ReplaceSelection(temps,Length(temps));
|
---|
462 | } end;
|
---|
463 | end;
|
---|
464 |
|
---|
465 |
|
---|
466 |
|
---|
467 |
|
---|
468 | procedure TForm_RawEdit.hexSelectionChanged(Sender: TObject);
|
---|
469 | //var
|
---|
470 | // selstart: Integer;
|
---|
471 | // i, j: Word;
|
---|
472 | begin
|
---|
473 | { FOR i:=1 TO structs.RowCount-1 DO BEGIN
|
---|
474 | FOR j:=0 TO structs.ColCount-1 DO BEGIN
|
---|
475 | structs.CellColors[j,i]:=clWhite;
|
---|
476 | structs.CellFontColors[j,i]:=clBlack;
|
---|
477 | END;
|
---|
478 | END;
|
---|
479 | } if hex.DataSize > 0 then
|
---|
480 | begin
|
---|
481 | { selstart:=hex.SelStart;
|
---|
482 | IF GetStructureInfoId(GetFileInfo(fileid).Extension)>=0 THEN BEGIN
|
---|
483 | WITH structure_infos[GetStructureInfoId(GetFileInfo(fileid).Extension)] DO BEGIN
|
---|
484 | FOR i:=0 TO High(entries) DO BEGIN
|
---|
485 | IF ((selstart-entries[i].offset)<GetTypeDataLength(entries[i].datatype)) AND ((selstart-entries[i].offset)>=0) THEN BEGIN
|
---|
486 | FOR j:=0 TO structs.ColCount-1 DO BEGIN
|
---|
487 | structs.CellColors[j,i+1]:=clBlue;
|
---|
488 | structs.CellFontColors[j,i+1]:=clWhite;
|
---|
489 | END;
|
---|
490 | structs.Row:=i+1;
|
---|
491 | END;
|
---|
492 | END;
|
---|
493 | END;
|
---|
494 | END;
|
---|
495 | } WriteValues;
|
---|
496 | end;
|
---|
497 | end;
|
---|
498 |
|
---|
499 |
|
---|
500 |
|
---|
501 |
|
---|
502 |
|
---|
503 | procedure TForm_RawEdit.btn_exportClick(Sender: TObject);
|
---|
504 | var
|
---|
505 | fs: TFileStream;
|
---|
506 | begin
|
---|
507 | saved.Filter := 'Files of matching extension (*.' +
|
---|
508 | ConManager.Connection[ConID].GetFileInfo(fileid).Extension + ')|*.' +
|
---|
509 | ConManager.Connection[ConID].GetFileInfo(fileid).Extension +
|
---|
510 | '|All files|*.*';
|
---|
511 | saved.DefaultExt := ConManager.Connection[ConID].GetFileInfo(fileid).Extension;
|
---|
512 | if saved.Execute then
|
---|
513 | begin
|
---|
514 | fs := TFileStream.Create(saved.FileName, fmCreate);
|
---|
515 | hex.SaveToStream(fs);
|
---|
516 | fs.Free;
|
---|
517 | end;
|
---|
518 | end;
|
---|
519 |
|
---|
520 |
|
---|
521 |
|
---|
522 |
|
---|
523 | procedure TForm_RawEdit.btn_importClick(Sender: TObject);
|
---|
524 | var
|
---|
525 | // Data: Tdata;
|
---|
526 | fs: TFileStream;
|
---|
527 | data: TByteData;
|
---|
528 | i: Integer;
|
---|
529 | rawinfo: TRawDataInfo;
|
---|
530 | begin
|
---|
531 | opend.Filter := 'Files of matching extension (*.' +
|
---|
532 | ConManager.Connection[ConID].GetFileInfo(fileid).Extension + ')|*.' +
|
---|
533 | ConManager.Connection[ConID].GetFileInfo(fileid).Extension +
|
---|
534 | '|All files|*.*';
|
---|
535 | if opend.Execute then
|
---|
536 | begin
|
---|
537 | fs := TFileStream.Create(opend.FileName, fmOpenRead);
|
---|
538 | if fs.Size <> hex.DataSize then
|
---|
539 | begin
|
---|
540 | if (not (CR_ResizeRaw in ConManager.Connection[ConID].ChangeRights)) and (not (CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights)) then
|
---|
541 | begin
|
---|
542 | ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) +
|
---|
543 | ', file has to have same size as file in .raw with this backend.' + CrLf +
|
---|
544 | 'Size of file in .raw: ' + FormatFileSize(hex.DataSize) + CrLf +
|
---|
545 | 'Size of chosen file: ' + FormatFileSize(fs.Size));
|
---|
546 | Exit;
|
---|
547 | end else begin
|
---|
548 | if MessageBox(Self.Handle,
|
---|
549 | PChar('File has different size from the file in the .raw.' + CrLf +
|
---|
550 | 'Size of file in .dat: ' + FormatFileSize(hex.DataSize) + CrLf +
|
---|
551 | 'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf +
|
---|
552 | 'Replace anyway?' + CrLf +
|
---|
553 | 'WARNING: This only replaces the raw-data. It doesn''t' + CrLf +
|
---|
554 | 'do the according changes in the .dat. Oni probably' + CrLf +
|
---|
555 | 'won''t be able to use the data correctly!'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then
|
---|
556 | begin
|
---|
557 | Exit;
|
---|
558 | end;
|
---|
559 | end;
|
---|
560 | rawinfo := ConManager.Connection[ConID].GetRawInfo(fileid, datoffset);
|
---|
561 | if CR_ResizeRaw in ConManager.Connection[ConID].ChangeRights then
|
---|
562 | ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, fs)
|
---|
563 | else if CR_AppendRaw in ConManager.Connection[ConID].ChangeRights then
|
---|
564 | i := ConManager.Connection[ConID].AppendRawFile(rawinfo.LocSep, fs);
|
---|
565 | ConManager.Connection[ConID].UpdateDatFilePart(fileid, datoffset, 4, @i);
|
---|
566 | end else begin
|
---|
567 | ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, fs);
|
---|
568 | end;
|
---|
569 | fs.Seek(0, soFromBeginning);
|
---|
570 | hex.LoadFromStream(fs);
|
---|
571 | hex.Modified := False;
|
---|
572 | for i := 0 to hex.Datasize - 1 do
|
---|
573 | hex.ByteChanged[i] := False;
|
---|
574 | fs.Free;
|
---|
575 | end;
|
---|
576 | end;
|
---|
577 |
|
---|
578 |
|
---|
579 |
|
---|
580 |
|
---|
581 | procedure TForm_RawEdit.value_viewer_contextPopup(Sender: TObject);
|
---|
582 | var
|
---|
583 | i: Byte;
|
---|
584 | begin
|
---|
585 | for i := 0 to value_viewer_context.Items.Count - 1 do
|
---|
586 | value_viewer_context.Items.Items[i].Visible := False;
|
---|
587 | with value_viewer do
|
---|
588 | begin
|
---|
589 | if (Col = 1) and (Row > 0) and (Length(Cells[Col, Row]) > 0) then
|
---|
590 | begin
|
---|
591 | if Pos(' byte', Cells[0, Row]) = 2 then
|
---|
592 | begin
|
---|
593 | value_viewer_context.Items.Find('Copy to &clipboard').Visible := True;
|
---|
594 | value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible := True;
|
---|
595 | value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible := True;
|
---|
596 | end;
|
---|
597 | if Pos('Float', Cells[0, Row]) = 1 then
|
---|
598 | value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible := True;
|
---|
599 | if Pos('Bitset', Cells[0, Row]) = 1 then
|
---|
600 | value_viewer_context.Items.Find(
|
---|
601 | 'Copy to clipboard (as &bitset)').Visible := True;
|
---|
602 | if Pos('String', Cells[0, Row]) = 1 then
|
---|
603 | value_viewer_context.Items.Find(
|
---|
604 | 'Copy to clipboard (as &string)').Visible := True;
|
---|
605 | if Pos('Selected length', Cells[0, Row]) = 1 then
|
---|
606 | value_viewer_context.Items.Find('Copy to &clipboard').Visible := True;
|
---|
607 | end;
|
---|
608 | end;
|
---|
609 | end;
|
---|
610 |
|
---|
611 |
|
---|
612 |
|
---|
613 |
|
---|
614 | procedure TForm_RawEdit.value_viewerMouseDown(Sender: TObject; Button: TMouseButton;
|
---|
615 | Shift: TShiftState; X, Y: Integer);
|
---|
616 | var
|
---|
617 | ACol, ARow: Integer;
|
---|
618 | begin
|
---|
619 | if Button = mbRight then
|
---|
620 | begin
|
---|
621 | value_viewer.MouseToCell(x, y, ACol, ARow);
|
---|
622 | if ARow > 0 then
|
---|
623 | begin
|
---|
624 | value_viewer.Col := ACol;
|
---|
625 | value_viewer.Row := ARow;
|
---|
626 | end;
|
---|
627 | end;
|
---|
628 | end;
|
---|
629 |
|
---|
630 |
|
---|
631 |
|
---|
632 |
|
---|
633 | procedure TForm_RawEdit.value_viewer_context_copyClick(Sender: TObject);
|
---|
634 | var
|
---|
635 | // i: Byte;
|
---|
636 | Name: String;
|
---|
637 | Value: LongWord;
|
---|
638 | begin
|
---|
639 | Name := TMenuItem(Sender).Name;
|
---|
640 | if Pos('asstring', Name) > 0 then
|
---|
641 | begin
|
---|
642 | Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
|
---|
643 | end
|
---|
644 | else if Pos('asfloat', Name) > 0 then
|
---|
645 | begin
|
---|
646 | Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
|
---|
647 | end
|
---|
648 | else if Pos('asbitset', Name) > 0 then
|
---|
649 | begin
|
---|
650 | Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
|
---|
651 | end
|
---|
652 | else if (Pos('ashex', Name) > 0) or (Pos('asdec', Name) > 0) then
|
---|
653 | begin
|
---|
654 | if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
|
---|
655 | begin
|
---|
656 | if ((hex.SelCount = 1) or (hex.SelCount = 0)) and not
|
---|
657 | ((hex.SelStart + 1) > hex.DataSize) then
|
---|
658 | Value := hex.Data[hex.SelStart];
|
---|
659 | end;
|
---|
660 | if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
|
---|
661 | begin
|
---|
662 | if ((hex.SelCount = 2) or (hex.SelCount = 0)) and not
|
---|
663 | ((hex.SelStart + 2) > hex.DataSize) then
|
---|
664 | Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256;
|
---|
665 | end;
|
---|
666 | if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
|
---|
667 | begin
|
---|
668 | if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
|
---|
669 | ((hex.SelStart + 4) > hex.DataSize) then
|
---|
670 | Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256 +
|
---|
671 | hex.Data[hex.SelStart + 2] * 256 * 256 + hex.Data[hex.SelStart + 3] * 256 * 256 * 256;
|
---|
672 | end;
|
---|
673 | if Pos('asdec', Name) > 0 then
|
---|
674 | begin
|
---|
675 | Clipboard.AsText := IntToStr(Value);
|
---|
676 | end
|
---|
677 | else
|
---|
678 | begin
|
---|
679 | if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
|
---|
680 | Clipboard.AsText := '0x' + IntToHex(Value, 2);
|
---|
681 | if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
|
---|
682 | Clipboard.AsText := '0x' + IntToHex(Value, 4);
|
---|
683 | if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
|
---|
684 | Clipboard.AsText := '0x' + IntToHex(Value, 8);
|
---|
685 | end;
|
---|
686 | end
|
---|
687 | else
|
---|
688 | begin
|
---|
689 | Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
|
---|
690 | end;
|
---|
691 | end;
|
---|
692 |
|
---|
693 |
|
---|
694 |
|
---|
695 |
|
---|
696 | procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String);
|
---|
697 | var
|
---|
698 | Data: TByteData;
|
---|
699 | value_int: LongWord;
|
---|
700 | value_float: Single;
|
---|
701 | i: Word;
|
---|
702 | begin
|
---|
703 | case datatype of
|
---|
704 | 1..4:
|
---|
705 | begin
|
---|
706 | value_int := StrToInt(Value);
|
---|
707 | SetLength(Data, datatype);
|
---|
708 | for i := 0 to datatype - 1 do
|
---|
709 | begin
|
---|
710 | Data[i] := value_int mod 256;
|
---|
711 | value_int := value_int div 256;
|
---|
712 | end;
|
---|
713 | end;
|
---|
714 | 5..8:
|
---|
715 | begin
|
---|
716 | value_int := StrToInt('$' + Value);
|
---|
717 | SetLength(Data, datatype - 4);
|
---|
718 | for i := 0 to datatype - 5 do
|
---|
719 | begin
|
---|
720 | Data[i] := value_int mod 256;
|
---|
721 | value_int := value_int div 256;
|
---|
722 | end;
|
---|
723 | end;
|
---|
724 | 9:
|
---|
725 | begin
|
---|
726 | value_float := StrToFloat(Value);
|
---|
727 | Data := Encode_Float(value_float);
|
---|
728 | end;
|
---|
729 | 10:
|
---|
730 | begin
|
---|
731 | value_int := BinToInt(Value);
|
---|
732 | SetLength(Data, 1);
|
---|
733 | Data[0] := value_int;
|
---|
734 | end;
|
---|
735 | 10000..65535:
|
---|
736 | begin
|
---|
737 | SetLength(Data, datatype - 10000);
|
---|
738 | for i := 1 to datatype - 10000 do
|
---|
739 | begin
|
---|
740 | if i <= Length(Value) then
|
---|
741 | Data[i - 1] := Ord(Value[i])
|
---|
742 | else
|
---|
743 | Data[i - 1] := 0;
|
---|
744 | end;
|
---|
745 | end;
|
---|
746 | end;
|
---|
747 | for i := 0 to High(Data) do
|
---|
748 | begin
|
---|
749 | if hex.Data[offset + i] <> Data[i] then
|
---|
750 | hex.ByteChanged[offset + i] := True;
|
---|
751 | hex.Data[offset + i] := Data[i];
|
---|
752 | end;
|
---|
753 | hex.Modified := True;
|
---|
754 | hexChange(Self);
|
---|
755 | hex.Repaint;
|
---|
756 | end;
|
---|
757 |
|
---|
758 |
|
---|
759 |
|
---|
760 |
|
---|
761 | procedure TForm_RawEdit.value_viewerDblClick(Sender: TObject);
|
---|
762 | var
|
---|
763 | offset: LongWord;
|
---|
764 | datatype: Word;
|
---|
765 | objectname: String;
|
---|
766 | Value: String;
|
---|
767 | begin
|
---|
768 | if (value_viewer.Col = 1) and (Length(value_viewer.Cells[1, value_viewer.Row]) > 0) then
|
---|
769 | begin
|
---|
770 | offset := hex.SelStart;
|
---|
771 | if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
|
---|
772 | datatype := 1;
|
---|
773 | if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
|
---|
774 | datatype := 2;
|
---|
775 | if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
|
---|
776 | datatype := 4;
|
---|
777 | if value_viewer.Cells[0, value_viewer.Row] = 'Bitset' then
|
---|
778 | datatype := 10;
|
---|
779 | if value_viewer.Cells[0, value_viewer.Row] = 'Float' then
|
---|
780 | datatype := 9;
|
---|
781 | if value_viewer.Cells[0, value_viewer.Row] = 'Selected length' then
|
---|
782 | Exit;
|
---|
783 | if value_viewer.Cells[0, value_viewer.Row] = 'String' then
|
---|
784 | begin
|
---|
785 | if hex.SelCount > 0 then
|
---|
786 | datatype := 10000 + hex.SelCount
|
---|
787 | else
|
---|
788 | datatype := 10000 + Length(value_viewer.Cells[1, value_viewer.Row]);
|
---|
789 | end;
|
---|
790 | objectname := '';
|
---|
791 | Value := GetValue(datatype, offset);
|
---|
792 | Form_ValueEdit.MakeVarInput(objectname, offset, datatype, Value, Self);
|
---|
793 | end;
|
---|
794 | end;
|
---|
795 |
|
---|
796 |
|
---|
797 |
|
---|
798 |
|
---|
799 | procedure TForm_RawEdit.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
800 | begin
|
---|
801 | if (Shift = [ssCtrl]) and (Key = 83) then
|
---|
802 | if hex.Modified then
|
---|
803 | if not Save then
|
---|
804 | Exit;
|
---|
805 | end;
|
---|
806 |
|
---|
807 | begin
|
---|
808 | AddToolListEntry('rawedit', 'Binary .raw-Editor', '');
|
---|
809 | end.
|
---|