source: oup/releases/0.33a/Tools/RawEdit.pas@ 526

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