Changeset 45 for oup/current/Tool_RawEdit.pas
- Timestamp:
- Dec 23, 2006, 1:03:50 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/Tool_RawEdit.pas
r43 r45 1 1 unit Tool_RawEdit; 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;5 Dialogs, Tool_Template, StdCtrls, ExtCtrls, Menus, Grids, Wrapgrid, 6 MPHexEditor, Clipbrd, StrUtils, 7 Data, Code_Functions, Code_DataStructures, Code_Exporters, Code_OniDataClass; 10 8 11 9 type 12 TForm_RawEdit = class(TForm) 13 Splitter1: TSplitter; 14 panel_data: TPanel; 15 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; 16 18 Splitter2: TSplitter; 17 19 value_viewer: TWrapGrid; 18 20 value_viewer_context: TPopupMenu; 19 21 value_viewer_context_copy: TMenuItem; 20 value_viewer_context_copyashex: TMenuItem;21 22 value_viewer_context_copyasdec: TMenuItem; 22 23 value_viewer_context_copyasfloat: TMenuItem; 23 24 value_viewer_context_copyasbitset: TMenuItem; 24 25 value_viewer_context_copyasstring: TMenuItem; 25 panel_files: TPanel;26 value_viewer_context_copyashex: TMenuItem; 26 27 opend: TOpenDialog; 27 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);42 29 procedure list_offsetClick(Sender: TObject); 30 procedure NewFile(fileinfo: TFileInfo); 43 31 procedure LoadRaw(raw_info: TRawInfo); 44 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;50 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); 51 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 52 48 procedure value_viewerDblClick(Sender: TObject); 53 49 procedure value_viewer_context_copyClick(Sender: TObject); … … 55 51 Shift: TShiftState; X, Y: Integer); 56 52 procedure value_viewer_contextPopup(Sender: TObject); 57 procedure btn_importClick(Sender: TObject); 58 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); 63 55 procedure hexSelectionChanged(Sender: TObject); 64 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);74 57 private 75 58 fileid: LongWord; … … 83 66 84 67 implementation 85 86 68 {$R *.dfm} 87 88 69 uses Main, Helper_ValueEdit; 89 70 90 91 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; 92 94 93 95 procedure TForm_RawEdit.LoadRaw(raw_info: TRawInfo); … … 95 97 i: LongWord; 96 98 Data: Tdata; 97 mem: TMemoryStream;98 99 begin 99 100 if hex.Modified then … … 106 107 if list_offset.Count = 0 then 107 108 begin 108 for i := 0 to list.Count - 1 do109 begin 110 if OniDataConnection.ExtractFileID( list.Items.Strings[i]) = raw_info.src_id then111 begin 112 list.ItemIndex := i;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; 113 114 listClick(Self); 114 115 Break; … … 150 151 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; 214 215 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; 153 290 154 291 155 procedure TForm_RawEdit.list_offsetClick(Sender: TObject); … … 500 364 501 365 procedure TForm_RawEdit.FormCreate(Sender: TObject); 502 begin 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 503 384 Self.Caption := ''; 504 385 fileid := 0; … … 516 397 value_viewer.Cells[0, 7] := 'Selected length'; 517 398 value_viewer.ColWidths[0] := 100; 518 hex.Height := panel_data.Height - 190;519 Self.panel_dataResize(Self);520 399 // 521 400 value_viewer.Font.Charset := AppSettings.CharSet; … … 574 453 575 454 576 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); 594 456 begin 595 457 value_viewer.ColWidths[1] := value_viewer.Width - value_viewer.ColWidths[0] - 28; … … 674 536 675 537 676 procedure TForm_RawEdit.FormClose(Sender: TObject; var Action: TCloseAction);677 begin678 Action := caFree;679 end;680 681 682 683 684 procedure TForm_RawEdit.panel_imexportResize(Sender: TObject);685 begin686 btn_import.Width := panel_imexport.Width - 8;687 btn_export.Width := panel_imexport.Width - 8;688 end;689 690 691 692 538 693 539 procedure TForm_RawEdit.btn_exportClick(Sender: TObject); … … 966 812 end; 967 813 814 begin 815 AddToolListEntry('rawedit', 'Binary .raw-Editor', ''); 968 816 end.
Note:
See TracChangeset
for help on using the changeset viewer.