--- oup/rewrite/Tools/RawEdit.pas 2007/02/20 22:03:11 104 +++ oup/rewrite/Tools/RawEdit.pas 2007/02/21 00:29:27 105 @@ -62,7 +62,7 @@ var implementation {$R *.dfm} -uses Main, ValueEdit; +uses Main, ValueEdit, RawList; procedure TForm_RawEdit.NewFile(fileinfo: TFileInfo); var @@ -114,7 +114,7 @@ begin begin for i := 0 to filelist.Count - 1 do begin - if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[i]) = RawInfo.SrcID then + if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[i]) = Raw_Info.SrcID then begin filelist.ItemIndex := i; listClick(Self); @@ -131,7 +131,7 @@ begin end; end; mem := nil; - ConManager.Connection[ConID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, mem); + ConManager.Connection[ConID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, TStream(mem)); hex.LoadFromStream(mem); ClearValues; hexSelectionChanged(Self); @@ -145,23 +145,9 @@ end; procedure TForm_RawEdit.list_offsetClick(Sender: TObject); 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; - - - - -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; + LoadRaw(ConManager.Connection[ConID].GetRawInfo(fileid, datoffset)); end; @@ -169,7 +155,7 @@ end; function TForm_RawEdit.GetValue(datatype: Word; offset: LongWord): String; var - Data: Tdata; + Data: TByteData; i: Word; floatformat: TFormatSettings; begin @@ -230,9 +216,7 @@ var i: Byte; begin for i := 1 to value_viewer.RowCount - 1 do - begin value_viewer.Cells[1, i] := ''; - end; end; @@ -241,7 +225,7 @@ end; procedure TForm_RawEdit.WriteValues; var i, j: Integer; - Data: Tdata; + Data: TByteData; str: String; Value: LongWord; floatformat: TFormatSettings; @@ -362,13 +346,13 @@ begin 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 +387,18 @@ end; function TForm_RawEdit.Save: Boolean; var mem: TMemoryStream; - Data: Tdata; i: LongWord; begin case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' + - Connection.GetFileInfo(fileid).FileName + '?'), PChar('Data changed...'), + ConManager.Connection[ConID].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[ConID].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 +407,7 @@ begin idNo: Result := True; idCancel: - begin Result := False; - end; end; end; @@ -439,10 +417,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 +504,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[ConID].GetFileInfo(fileid).Extension + ')|*.' + + ConManager.Connection[ConID].GetFileInfo(fileid).Extension + '|All files|*.*'; - saved.DefaultExt := Connection.GetFileInfo(fileid).Extension; + saved.DefaultExt := ConManager.Connection[ConID].GetFileInfo(fileid).Extension; if saved.Execute then begin fs := TFileStream.Create(saved.FileName, fmCreate); @@ -547,25 +524,53 @@ procedure TForm_RawEdit.btn_importClick( var // Data: Tdata; fs: TFileStream; + data: TByteData; + 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[ConID].GetFileInfo(fileid).Extension + ')|*.' + + ConManager.Connection[ConID].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[ConID].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[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); + end else begin + ConManager.Connection[ConID].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; @@ -690,7 +695,7 @@ end; procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String); var - Data: Tdata; + Data: TByteData; value_int: LongWord; value_float: Single; i: Word;