Ignore:
Timestamp:
Dec 23, 2006, 1:03:50 AM (18 years ago)
Author:
alloc
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • oup/current/Tool_RawEdit.pas

    r43 r45  
    11unit Tool_RawEdit;
    2 
    32interface
    4 
    53uses
    64  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;
    108
    119type
    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;
    1618    Splitter2: TSplitter;
    1719    value_viewer: TWrapGrid;
    1820    value_viewer_context: TPopupMenu;
    1921    value_viewer_context_copy: TMenuItem;
    20     value_viewer_context_copyashex: TMenuItem;
    2122    value_viewer_context_copyasdec: TMenuItem;
    2223    value_viewer_context_copyasfloat: TMenuItem;
    2324    value_viewer_context_copyasbitset: TMenuItem;
    2425    value_viewer_context_copyasstring: TMenuItem;
    25     panel_files: TPanel;
     26    value_viewer_context_copyashex: TMenuItem;
    2627    opend: TOpenDialog;
    2728    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);
    4229    procedure list_offsetClick(Sender: TObject);
     30    procedure NewFile(fileinfo: TFileInfo);
    4331    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);
    5139    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
    5248    procedure value_viewerDblClick(Sender: TObject);
    5349    procedure value_viewer_context_copyClick(Sender: TObject);
     
    5551      Shift: TShiftState; X, Y: Integer);
    5652    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);
    6355    procedure hexSelectionChanged(Sender: TObject);
    6456    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);
    7457  private
    7558    fileid:     LongWord;
     
    8366
    8467implementation
    85 
    8668{$R *.dfm}
    87 
    8869uses Main, Helper_ValueEdit;
    8970
    90 
    91 
     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;
    9294
    9395procedure TForm_RawEdit.LoadRaw(raw_info: TRawInfo);
     
    9597  i:    LongWord;
    9698  Data: Tdata;
    97   mem:  TMemoryStream;
    9899begin
    99100  if hex.Modified then
     
    106107  if list_offset.Count = 0 then
    107108  begin
    108     for i := 0 to list.Count - 1 do
    109     begin
    110       if OniDataConnection.ExtractFileID(list.Items.Strings[i]) = raw_info.src_id then
    111       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;
    113114        listClick(Self);
    114115        Break;
     
    150151
    151152
    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
    290154
    291155procedure TForm_RawEdit.list_offsetClick(Sender: TObject);
     
    500364
    501365procedure TForm_RawEdit.FormCreate(Sender: TObject);
    502 begin
     366var
     367  i:     LongWord;
     368  exts: String;
     369begin
     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
    503384  Self.Caption := '';
    504385  fileid     := 0;
     
    516397  value_viewer.Cells[0, 7] := 'Selected length';
    517398  value_viewer.ColWidths[0] := 100;
    518   hex.Height := panel_data.Height - 190;
    519   Self.panel_dataResize(Self);
    520399  //
    521400  value_viewer.Font.Charset := AppSettings.CharSet;
     
    574453
    575454
    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);
     455procedure TForm_RawEdit.panel_contentResize(Sender: TObject);
    594456begin
    595457  value_viewer.ColWidths[1] := value_viewer.Width - value_viewer.ColWidths[0] - 28;
     
    674536
    675537
    676 procedure TForm_RawEdit.FormClose(Sender: TObject; var Action: TCloseAction);
    677 begin
    678   Action := caFree;
    679 end;
    680 
    681 
    682 
    683 
    684 procedure TForm_RawEdit.panel_imexportResize(Sender: TObject);
    685 begin
    686   btn_import.Width := panel_imexport.Width - 8;
    687   btn_export.Width := panel_imexport.Width - 8;
    688 end;
    689 
    690 
    691 
    692538
    693539procedure TForm_RawEdit.btn_exportClick(Sender: TObject);
     
    966812end;
    967813
     814begin
     815  AddToolListEntry('rawedit', 'Binary .raw-Editor', '');
    968816end.
Note: See TracChangeset for help on using the changeset viewer.