--- oup/current/Tools/RawEdit.pas 2007/02/21 03:12:33 109 +++ oup/current/Tools/RawEdit.pas 2007/06/18 14:23:58 223 @@ -1,22 +1,25 @@ unit RawEdit; + interface + uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, - Dialogs, Template, StdCtrls, ExtCtrls, Menus, Grids, Wrapgrid, - MPHexEditor, Clipbrd, StrUtils, TypeDefs, - Data, Functions, DatStructureLoader, ConnectionManager, Buttons; + Dialogs, _TemplateFileList, Menus, StdCtrls, ExtCtrls, Buttons, ComCtrls, + TypeDefs, Grids, Wrapgrid, MPHexEditor; type - TForm_RawEdit = class(TForm_ToolTemplate) - Splitter4: TSplitter; + TForm_RawEdit = class(TForm_TemplateFileList) panel_imexport: TPanel; btn_export: TButton; btn_import: TButton; GroupBox1: TGroupBox; list_offset: TListBox; + Splitter4: TSplitter; + opend: TOpenDialog; + saved: TSaveDialog; hex: TMPHexEditor; - Splitter2: TSplitter; value_viewer: TWrapGrid; + Splitter2: TSplitter; value_viewer_context: TPopupMenu; value_viewer_context_copy: TMenuItem; value_viewer_context_copyasdec: TMenuItem; @@ -24,8 +27,6 @@ type value_viewer_context_copyasbitset: TMenuItem; value_viewer_context_copyasstring: TMenuItem; value_viewer_context_copyashex: TMenuItem; - opend: TOpenDialog; - saved: TSaveDialog; procedure list_offsetClick(Sender: TObject); procedure NewFile(fileinfo: TFileInfo); procedure LoadRaw(raw_info: TRawDataInfo); @@ -38,10 +39,10 @@ type procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); - function GetValue(datatype: Word; offset: LongWord): String; + function GetValue(datatype: Word; offset: Integer): String; procedure ClearValues; procedure WriteValues; - procedure SetNewValue(datatype: Word; offset: LongWord; Value: String); + procedure SetNewValue(datatype: Word; offset: Integer; Value: String); procedure value_viewerDblClick(Sender: TObject); procedure value_viewer_context_copyClick(Sender: TObject); @@ -53,16 +54,16 @@ type procedure hexSelectionChanged(Sender: TObject); procedure hexChange(Sender: TObject); private - ConID, fileid, datoffset: Integer; + fileid, datoffset: Integer; public end; -var - Form_RawEdit: TForm_RawEdit; implementation {$R *.dfm} -uses Main, ValueEdit, RawList; +uses + _TemplateFile, ValueEdit, ConnectionManager, StrUtils, Functions, RawList, + Data, Clipbrd; procedure TForm_RawEdit.NewFile(fileinfo: TFileInfo); var @@ -100,8 +101,7 @@ end; procedure TForm_RawEdit.LoadRaw(raw_info: TRawDataInfo); var - i: LongWord; - mem: TMemoryStream; + i: Integer; begin if hex.Modified then begin @@ -110,31 +110,24 @@ begin Exit; end; end; - if list_offset.Count = 0 then + for i := 0 to filelist.Count - 1 do begin - for i := 0 to filelist.Count - 1 do + if ConManager.Connection[ConnectionID].ExtractFileIDOfName(filelist.Items.Strings[i]) = Raw_Info.SrcID then begin - if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[i]) = Raw_Info.SrcID then - begin - filelist.ItemIndex := i; - listClick(Self); - Break; - end; + filelist.ItemIndex := i; + listClick(Self); + Break; end; - for i := 0 to list_offset.Count - 1 do + end; + for i := 0 to list_offset.Count - 1 do + begin + if MidStr(list_offset.Items.Strings[i], 3, 8) = IntToHex(raw_info.SrcOffset, 8) then begin - if MidStr(list_offset.Items.Strings[i], 3, 8) = IntToHex(raw_info.SrcOffset, 8) then - begin - list_offset.ItemIndex := i; - Break; - end; + list_offset.ItemIndex := i; + list_offsetClick(Self); + Break; end; end; - mem := nil; - ConManager.Connection[ConID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, TStream(mem)); - hex.LoadFromStream(mem); - ClearValues; - hexSelectionChanged(Self); end; @@ -143,17 +136,34 @@ end; procedure TForm_RawEdit.list_offsetClick(Sender: TObject); +var + mem: TMemoryStream; + rawinfo: TRawDataInfo; begin - ClearValues; datoffset := StrToInt('$' + MidStr( list_offset.Items.Strings[list_offset.ItemIndex], 3, 8)); - LoadRaw(ConManager.Connection[ConID].GetRawInfo(fileid, datoffset)); + + rawinfo := ConManager.Connection[ConnectionID].GetRawInfo(fileid, datoffset); + + if rawinfo.RawSize > 0 then + begin + mem := nil; + ConManager.Connection[ConnectionID].LoadRawFile(rawinfo.SrcID, rawinfo.SrcOffset, TStream(mem)); + hex.LoadFromStream(mem); + ClearValues; + hexSelectionChanged(Self); + end + else + begin + hex.DataSize := 0; + ClearValues; + end; end; -function TForm_RawEdit.GetValue(datatype: Word; offset: LongWord): String; +function TForm_RawEdit.GetValue(datatype: Word; offset: Integer): String; var Data: TByteData; i: Word; @@ -227,7 +237,7 @@ var i, j: Integer; Data: TByteData; str: String; - Value: LongWord; + Value: Integer; floatformat: TFormatSettings; begin floatformat.DecimalSeparator := '.'; @@ -310,8 +320,10 @@ begin str := ''; if hex.SelCount = 0 then begin - while (hex.Data[hex.SelStart + j] > 0) and ((hex.SelStart + j) < hex.DataSize) do + while (hex.SelStart + j) < hex.DataSize do begin + if hex.Data[hex.SelStart + j] = 0 then + Break; if hex.Data[hex.selstart + j] >= 32 then str := str + Char(hex.Data[hex.SelStart + j]) else @@ -339,7 +351,7 @@ end; procedure TForm_RawEdit.FormCreate(Sender: TObject); var - i: LongWord; + i: Integer; exts: String; begin inherited; @@ -387,17 +399,17 @@ end; function TForm_RawEdit.Save: Boolean; var mem: TMemoryStream; - i: LongWord; + i: Integer; begin case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' + - ConManager.Connection[ConID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'), + ConManager.Connection[ConnectionID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'), MB_YESNOCANCEL) of idYes: begin mem := TMemoryStream.Create; hex.SaveToStream(mem); mem.Seek(0, soFromBeginning); - ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, mem); + ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, mem); mem.Free; hex.Modified := False; for i := 0 to hex.Datasize - 1 do @@ -505,10 +517,10 @@ var fs: TFileStream; begin saved.Filter := 'Files of matching extension (*.' + - ConManager.Connection[ConID].GetFileInfo(fileid).Extension + ')|*.' + - ConManager.Connection[ConID].GetFileInfo(fileid).Extension + + ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' + + ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + '|All files|*.*'; - saved.DefaultExt := ConManager.Connection[ConID].GetFileInfo(fileid).Extension; + saved.DefaultExt := ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension; if saved.Execute then begin fs := TFileStream.Create(saved.FileName, fmCreate); @@ -524,20 +536,22 @@ procedure TForm_RawEdit.btn_importClick( var // Data: Tdata; fs: TFileStream; - data: TByteData; i: Integer; rawinfo: TRawDataInfo; begin opend.Filter := 'Files of matching extension (*.' + - ConManager.Connection[ConID].GetFileInfo(fileid).Extension + ')|*.' + - ConManager.Connection[ConID].GetFileInfo(fileid).Extension + + ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' + + ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + '|All files|*.*'; if opend.Execute then begin fs := TFileStream.Create(opend.FileName, fmOpenRead); if fs.Size <> hex.DataSize then begin - if (not (CR_ResizeRaw in ConManager.Connection[ConID].ChangeRights)) and (not (CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights)) then + if + (not (CR_ResizeRaw in ConManager.Connection[ConnectionID].ChangeRights)) + and (not (CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights)) + then begin ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) + ', file has to have same size as file in .raw with this backend.' + CrLf + @@ -557,14 +571,14 @@ begin Exit; end; end; - rawinfo := ConManager.Connection[ConID].GetRawInfo(fileid, datoffset); - if CR_ResizeRaw in ConManager.Connection[ConID].ChangeRights then - ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, fs) - else if CR_AppendRaw in ConManager.Connection[ConID].ChangeRights then - i := ConManager.Connection[ConID].AppendRawFile(rawinfo.LocSep, fs); - ConManager.Connection[ConID].UpdateDatFilePart(fileid, datoffset, 4, @i); + rawinfo := ConManager.Connection[ConnectionID].GetRawInfo(fileid, datoffset); + if CR_ResizeRaw in ConManager.Connection[ConnectionID].ChangeRights then + ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, fs) + else if CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights then + i := ConManager.Connection[ConnectionID].AppendRawFile(rawinfo.LocSep, fs); + ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, datoffset, 4, @i); end else begin - ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, fs); + ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, fs); end; fs.Seek(0, soFromBeginning); hex.LoadFromStream(fs); @@ -634,7 +648,7 @@ procedure TForm_RawEdit.value_viewer_con var // i: Byte; Name: String; - Value: LongWord; + Value: Integer; begin Name := TMenuItem(Sender).Name; if Pos('asstring', Name) > 0 then @@ -693,7 +707,7 @@ end; -procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String); +procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: Integer; Value: String); var Data: TByteData; value_int: LongWord; @@ -760,7 +774,7 @@ end; procedure TForm_RawEdit.value_viewerDblClick(Sender: TObject); var - offset: LongWord; + offset: Integer; datatype: Word; objectname: String; Value: String; @@ -806,4 +820,6 @@ end; begin AddToolListEntry('rawedit', 'Binary .raw-Editor', ''); -end. \ No newline at end of file +end. + +