source: oup/current/Tools/RawEdit.pas@ 294

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