--- oup/rewrite/Tools/RawEdit.pas 2007/02/20 22:03:11 104 +++ oup/current/Tools/RawEdit.pas 2007/05/17 15:08:29 180 @@ -38,10 +38,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,7 +53,7 @@ type procedure hexSelectionChanged(Sender: TObject); procedure hexChange(Sender: TObject); private - ConID, fileid, datoffset: Integer; + fileid, datoffset: Integer; public end; @@ -62,7 +62,7 @@ var implementation {$R *.dfm} -uses Main, ValueEdit; +uses Main, ValueEdit, RawList; procedure TForm_RawEdit.NewFile(fileinfo: TFileInfo); var @@ -100,8 +100,7 @@ end; procedure TForm_RawEdit.LoadRaw(raw_info: TRawDataInfo); var - i: LongWord; - mem: TMemoryStream; + i: Integer; begin if hex.Modified then begin @@ -110,31 +109,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]) = RawInfo.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, mem); - hex.LoadFromStream(mem); - ClearValues; - hexSelectionChanged(Self); end; @@ -143,33 +135,28 @@ end; procedure TForm_RawEdit.list_offsetClick(Sender: TObject); +var + mem: TMemoryStream; + rawinfo: TRawDataInfo; begin - ClearValues; - dat_offset := StrToInt('$' + MidStr( + datoffset := StrToInt('$' + MidStr( list_offset.Items.Strings[list_offset.ItemIndex], 3, 8)); - LoadRaw(Connection.GetRawInfo(fileid, dat_offset)); -end; - + rawinfo := ConManager.Connection[ConnectionID].GetRawInfo(fileid, datoffset); - -function IntToBin(Value: Byte): String; -var - i: Byte; -begin - Result := ''; - for i := 7 downto 0 do - begin - Result := Result + IntToStr((Value shr i) and $01); - end; + mem := nil; + ConManager.Connection[ConnectionID].LoadRawFile(rawinfo.SrcID, rawinfo.SrcOffset, TStream(mem)); + hex.LoadFromStream(mem); + ClearValues; + hexSelectionChanged(Self); end; -function TForm_RawEdit.GetValue(datatype: Word; offset: LongWord): String; +function TForm_RawEdit.GetValue(datatype: Word; offset: Integer): String; var - Data: Tdata; + Data: TByteData; i: Word; floatformat: TFormatSettings; begin @@ -230,9 +217,7 @@ var i: Byte; begin for i := 1 to value_viewer.RowCount - 1 do - begin value_viewer.Cells[1, i] := ''; - end; end; @@ -241,9 +226,9 @@ end; procedure TForm_RawEdit.WriteValues; var i, j: Integer; - Data: Tdata; + Data: TByteData; str: String; - Value: LongWord; + Value: Integer; floatformat: TFormatSettings; begin floatformat.DecimalSeparator := '.'; @@ -326,8 +311,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 @@ -355,20 +342,20 @@ end; procedure TForm_RawEdit.FormCreate(Sender: TObject); var - i: LongWord; + i: Integer; exts: String; begin inherited; Self.OnNewFileSelected := Self.NewFile; exts := ''; - if Length(RawListHandlers) > 0 then + if Length(RawLists.RawListHandlers) > 0 then begin - for i := 0 to High(RawListHandlers) do + for i := 0 to High(RawLists.RawListHandlers) do if Length(exts) > 0 then - exts := exts + ',' + RawListHandlers[i].Ext + exts := exts + ',' + RawLists.RawListHandlers[i].Ext else - exts := RawListHandlers[i].Ext; + exts := RawLists.RawListHandlers[i].Ext; end; Self.AllowedExts := exts; @@ -403,22 +390,18 @@ end; function TForm_RawEdit.Save: Boolean; var mem: TMemoryStream; - Data: Tdata; - i: LongWord; + i: Integer; begin case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' + - Connection.GetFileInfo(fileid).FileName + '?'), 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); - SetLength(Data, mem.Size); - mem.Read(Data[0], mem.Size); + ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, mem); mem.Free; - Connection.UpdateRawFile(fileid_opened, dat_offset_opened, - Length(Data), @Data[0]); hex.Modified := False; for i := 0 to hex.Datasize - 1 do hex.ByteChanged[i] := False; @@ -427,9 +410,7 @@ begin idNo: Result := True; idCancel: - begin Result := False; - end; end; end; @@ -439,10 +420,8 @@ end; procedure TForm_RawEdit.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin if hex.Modified then - begin if not Save then CanClose := False; - end; end; @@ -528,10 +507,11 @@ procedure TForm_RawEdit.btn_exportClick( var fs: TFileStream; begin - saved.Filter := 'Files of matching extension (*.' + Connection.GetFileInfo( - fileid).Extension + ')|*.' + Connection.GetFileInfo(fileid).Extension + + saved.Filter := 'Files of matching extension (*.' + + ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' + + ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + '|All files|*.*'; - saved.DefaultExt := Connection.GetFileInfo(fileid).Extension; + saved.DefaultExt := ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension; if saved.Execute then begin fs := TFileStream.Create(saved.FileName, fmCreate); @@ -547,25 +527,55 @@ procedure TForm_RawEdit.btn_importClick( var // Data: Tdata; fs: TFileStream; + i: Integer; + rawinfo: TRawDataInfo; begin - opend.Filter := 'Files of matching extension (*.' + Connection.GetFileInfo( - fileid).Extension + ')|*.' + Connection.GetFileInfo(fileid).Extension + + opend.Filter := 'Files of matching 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 - ShowMessage('Can''t import ' + ExtractFilename(opend.FileName) + - ', file has to have same size as file in .dat.' + CrLf + - 'Size of file in .dat: ' + FormatFileSize(hex.datasize) + CrLf + - 'Size of chosen file: ' + FormatFileSize(fs.Size)); - end - else - begin - hex.LoadFromStream(fs); - hex.Modified := True; - end; + 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 + + 'Size of file in .raw: ' + FormatFileSize(hex.DataSize) + CrLf + + 'Size of chosen file: ' + FormatFileSize(fs.Size)); + Exit; + end else begin + if MessageBox(Self.Handle, + PChar('File has different size from the file in the .raw.' + CrLf + + 'Size of file in .dat: ' + FormatFileSize(hex.DataSize) + CrLf + + 'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf + + 'Replace anyway?' + CrLf + + 'WARNING: This only replaces the raw-data. It doesn''t' + CrLf + + 'do the according changes in the .dat. Oni probably' + CrLf + + 'won''t be able to use the data correctly!'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then + begin + Exit; + end; + end; + 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[ConnectionID].UpdateRawFile(fileid, datoffset, fs); + end; + fs.Seek(0, soFromBeginning); + hex.LoadFromStream(fs); + hex.Modified := False; + for i := 0 to hex.Datasize - 1 do + hex.ByteChanged[i] := False; fs.Free; end; end; @@ -629,7 +639,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 @@ -688,9 +698,9 @@ end; -procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String); +procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: Integer; Value: String); var - Data: Tdata; + Data: TByteData; value_int: LongWord; value_float: Single; i: Word; @@ -755,7 +765,7 @@ end; procedure TForm_RawEdit.value_viewerDblClick(Sender: TObject); var - offset: LongWord; + offset: Integer; datatype: Word; objectname: String; Value: String;