Changeset 45 for oup/current/Tool_BinEdit.pas
- Timestamp:
- Dec 23, 2006, 1:03:50 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/Tool_BinEdit.pas
r43 r45 1 1 unit Tool_BinEdit; 2 3 2 interface 4 5 3 uses 6 4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 Dialogs, Wrapgrid, StdCtrls, Grids, StrUtils, MPHexEditor, ExtCtrls, Clipbrd,8 Data, Code_Functions, Code_DataStructures, Code_Exporters, Code_OniDataClass,9 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; 10 8 11 9 type 12 TForm_BinEdit = class(TForm) 13 Splitter1: TSplitter; 14 panel_data: TPanel; 15 hex: TMPHexEditor; 10 TForm_BinEdit = class(TForm_ToolTemplate) 11 hex: TMPHexEditor; 16 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;28 13 value_viewer: TWrapGrid; 14 VST: TVirtualStringTree; 29 15 Splitter3: TSplitter; 30 16 value_viewer_context: TPopupMenu; 31 17 value_viewer_context_copy: TMenuItem; 32 value_viewer_context_copyashex: TMenuItem;33 18 value_viewer_context_copyasdec: TMenuItem; 34 19 value_viewer_context_copyasfloat: TMenuItem; 35 20 value_viewer_context_copyasbitset: TMenuItem; 36 21 value_viewer_context_copyasstring: TMenuItem; 37 check_zerobyte: TCheckBox; 38 edit_filtername: TEdit; 39 check_filtername: TCheckBox; 40 VST: TVirtualStringTree; 22 value_viewer_context_copyashex: TMenuItem; 41 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 42 procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; 43 43 Column: TColumnIndex); 44 procedure VSTDblClick(Sender: TObject);45 44 procedure VTHPopupColumnChange(const Sender: TBaseVirtualTree; 46 45 const Column: TColumnIndex; Visible: Boolean); … … 49 48 procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; 50 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; 60 61 procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); 50 51 procedure ClearValues; 52 procedure WriteValues; 62 53 procedure value_viewerDblClick(Sender: TObject); 63 54 procedure value_viewer_context_copyClick(Sender: TObject); … … 65 56 Shift: TShiftState; X, Y: Integer); 66 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);85 58 private 86 59 fileid: LongWord; … … 93 66 implementation 94 67 68 uses Helper_ValueEdit, Main, Tool_RawEdit; 95 69 {$R *.dfm} 96 97 uses Main, Helper_ValueEdit, Tool_Rawedit;98 70 99 71 type … … 110 82 111 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 112 122 113 123 function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; … … 127 137 procedure TForm_BinEdit.LoadDat(_fileid: LongWord); 128 138 var 129 i: LongWord;130 139 mem: TMemoryStream; 131 140 Data: Tdata; … … 135 144 if not Save then 136 145 begin 137 for i := 0 to list.Count - 1 do 138 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; 145 148 end; 146 149 end; 147 150 fileid := _fileid; 148 for i := 0 to list.Count - 1 do 149 if OniDataConnection.ExtractFileID(list.Items.Strings[i]) = fileid then 150 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 154 Self.ClearStructViewer; 155 155 Data := OniDataConnection.LoadDatFile(fileid); … … 172 172 173 173 174 175 procedure TForm_BinEdit.Recreatelist;176 var177 i: LongWord;178 exts: TStringArray;179 begin180 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) do185 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 var195 Extension: String[4];196 no_zero_bytes: Boolean;197 pattern: String;198 files: TStringArray;199 i: LongWord;200 begin201 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 then205 pattern := edit_filtername.Text;206 if Extension = '_All' then207 Extension := '';208 209 files := OniDataConnection.GetFilesList(extension, pattern, no_zero_bytes);210 list.Items.Clear;211 if Length(files) > 0 then212 for i := 0 to High(files) do213 list.Items.Add(files[i]);214 end;215 216 217 218 219 procedure TForm_BinEdit.panel_extensionResize(Sender: TObject);220 begin221 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 begin230 LoadFileNames;231 end;232 233 234 235 236 procedure TForm_BinEdit.check_zerobyteClick(Sender: TObject);237 begin238 LoadFileNames;239 end;240 241 242 243 244 procedure TForm_BinEdit.check_filternameClick(Sender: TObject);245 begin246 edit_filtername.Enabled := not check_filtername.Checked;247 LoadFileNames;248 end;249 250 251 252 253 procedure TForm_BinEdit.listClick(Sender: TObject);254 begin255 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 var264 pt: TPoint;265 begin266 pt.X := x;267 pt.Y := y;268 list.ItemIndex := list.ItemAtPos(pt, true);269 if list.ItemIndex > -1 then270 Self.listClick(Self);271 end;272 174 273 175 function IntToBin(Value: Byte): String; … … 588 490 589 491 590 procedure TForm_BinEdit.FormCreate(Sender: TObject);591 begin592 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 621 492 function TForm_BinEdit.Save: Boolean; 622 493 var … … 672 543 673 544 674 675 676 procedure TForm_BinEdit.FormResize(Sender: TObject);677 begin678 if Self.Width >= 650 then679 begin680 end681 else682 Self.Width := 650;683 if Self.Height >= 450 then684 begin685 end686 else687 Self.Height := 450;688 end;689 545 690 546 … … 767 623 768 624 769 procedure TForm_BinEdit.FormClose(Sender: TObject; var Action: TCloseAction);770 begin771 Action := caFree;772 end;773 774 775 776 777 procedure TForm_BinEdit.panel_imexportResize(Sender: TObject);778 begin779 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 begin788 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 then793 begin794 ExportDatFile(fileid, saved.FileName);795 end;796 end;797 798 799 800 801 procedure TForm_BinEdit.btn_importClick(Sender: TObject);802 var803 fs: TFileStream;804 begin805 opend.Filter := 'Files of matching extension (*.' + OniDataConnection.GetFileInfo(806 fileid).Extension + ')|*.' + OniDataConnection.GetFileInfo(fileid).Extension +807 '|All files|*.*';808 if opend.Execute then809 begin810 fs := TFileStream.Create(opend.FileName, fmOpenRead);811 if fs.Size <> hex.DataSize then812 begin813 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 end818 else819 begin820 hex.LoadFromStream(fs);821 hex.Modified := True;822 end;823 fs.Free;824 end;825 end;826 827 828 829 830 625 procedure TForm_BinEdit.value_viewer_contextPopup(Sender: TObject); 831 626 var … … 964 759 begin 965 760 if OniDataConnection.GetRawInfo(fileid, nodedata.offset).raw_size > 0 then 966 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); 973 762 end; 974 763 if nodedata.DataType = 12 then … … 979 768 begin 980 769 if OniDataConnection.GetFileInfo(StrToInt(nodedata.Value)).Size > 0 then 981 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)) 987 771 else 988 begin989 772 ShowMessage('Linked filed is a zero-byte-file'); 990 end;991 773 end; 992 774 end; 993 775 if (nodedata.DataType >= 100) and (nodedata.DataType <= 300) then 994 776 begin 995 if Form_Main.open_child('binedit' ) then777 if Form_Main.open_child('binedit', -1) then 996 778 begin 997 779 TForm_BinEdit(Form_Main.ActiveMDIChild).edit_filtername.Text := nodedata.Value; … … 1196 978 1197 979 980 begin 981 AddToolListEntry('binedit', 'Binary .dat-Editor', ''); 1198 982 end.
Note:
See TracChangeset
for help on using the changeset viewer.