ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Tools/RawEdit.pas
(Generate patch)

Comparing:
oup/rewrite/Tools/RawEdit.pas (file contents), Revision 104 by alloc, Tue Feb 20 22:03:11 2007 UTC vs.
oup/current/Tools/RawEdit.pas (file contents), Revision 175 by alloc, Wed May 2 15:16:58 2007 UTC

# Line 38 | Line 38 | type
38      procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
39      procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
40  
41 <    function GetValue(datatype: Word; offset: LongWord): String;
41 >    function GetValue(datatype: Word; offset: Integer): String;
42      procedure ClearValues;
43      procedure WriteValues;
44 <    procedure SetNewValue(datatype: Word; offset: LongWord; Value: String);
44 >    procedure SetNewValue(datatype: Word; offset: Integer; Value: String);
45  
46      procedure value_viewerDblClick(Sender: TObject);
47      procedure value_viewer_context_copyClick(Sender: TObject);
# Line 53 | Line 53 | type
53      procedure hexSelectionChanged(Sender: TObject);
54      procedure hexChange(Sender: TObject);
55    private
56 <    ConID, fileid, datoffset: Integer;
56 >    fileid, datoffset: Integer;
57    public
58    end;
59  
# Line 62 | Line 62 | var
62  
63   implementation
64   {$R *.dfm}
65 < uses Main, ValueEdit;
65 > uses Main, ValueEdit, RawList;
66  
67   procedure TForm_RawEdit.NewFile(fileinfo: TFileInfo);
68   var
# Line 100 | Line 100 | end;
100  
101   procedure TForm_RawEdit.LoadRaw(raw_info: TRawDataInfo);
102   var
103 <  i:    LongWord;
103 >  i:    Integer;
104    mem: TMemoryStream;
105   begin
106    if hex.Modified then
# Line 114 | Line 114 | begin
114    begin
115      for i := 0 to filelist.Count - 1 do
116      begin
117 <      if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[i]) = RawInfo.SrcID then
117 >      if ConManager.Connection[ConnectionID].ExtractFileIDOfName(filelist.Items.Strings[i]) = Raw_Info.SrcID then
118        begin
119          filelist.ItemIndex := i;
120          listClick(Self);
# Line 131 | Line 131 | begin
131      end;
132    end;
133    mem := nil;
134 <  ConManager.Connection[ConID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, mem);
134 >  ConManager.Connection[ConnectionID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, TStream(mem));
135    hex.LoadFromStream(mem);
136    ClearValues;
137    hexSelectionChanged(Self);
# Line 145 | Line 145 | end;
145   procedure TForm_RawEdit.list_offsetClick(Sender: TObject);
146   begin
147    ClearValues;
148 <  dat_offset := StrToInt('$' + MidStr(
148 >  datoffset := StrToInt('$' + MidStr(
149      list_offset.Items.Strings[list_offset.ItemIndex], 3, 8));
150 <  LoadRaw(Connection.GetRawInfo(fileid, dat_offset));
150 >  LoadRaw(ConManager.Connection[ConnectionID].GetRawInfo(fileid, datoffset));
151   end;
152  
153  
154  
155  
156 < function IntToBin(Value: Byte): String;
156 > function TForm_RawEdit.GetValue(datatype: Word; offset: Integer): String;
157   var
158 <  i: Byte;
159 < begin
160 <  Result := '';
161 <  for i := 7 downto 0 do
162 <  begin
163 <    Result := Result + IntToStr((Value shr i) and $01);
164 <  end;
165 < end;
166 <
167 <
168 <
169 <
170 < function TForm_RawEdit.GetValue(datatype: Word; offset: LongWord): String;
171 < var
172 <  Data: Tdata;
158 >  Data: TByteData;
159    i:    Word;
160    floatformat: TFormatSettings;
161   begin
# Line 230 | Line 216 | var
216    i: Byte;
217   begin
218    for i := 1 to value_viewer.RowCount - 1 do
233  begin
219      value_viewer.Cells[1, i] := '';
235  end;
220   end;
221  
222  
# Line 241 | Line 225 | end;
225   procedure TForm_RawEdit.WriteValues;
226   var
227    i, j:  Integer;
228 <  Data:  Tdata;
228 >  Data:  TByteData;
229    str:   String;
230 <  Value: LongWord;
230 >  Value: Integer;
231    floatformat: TFormatSettings;
232   begin
233    floatformat.DecimalSeparator := '.';
# Line 326 | Line 310 | begin
310        str := '';
311        if hex.SelCount = 0 then
312        begin
313 <        while (hex.Data[hex.SelStart + j] > 0) and ((hex.SelStart + j) < hex.DataSize) do
313 >        while (hex.SelStart + j) < hex.DataSize do
314          begin
315 +          if hex.Data[hex.SelStart + j] = 0 then
316 +            Break;
317            if hex.Data[hex.selstart + j] >= 32 then
318              str := str + Char(hex.Data[hex.SelStart + j])
319            else
# Line 355 | Line 341 | end;
341  
342   procedure TForm_RawEdit.FormCreate(Sender: TObject);
343   var
344 <  i:     LongWord;
344 >  i:     Integer;
345    exts: String;
346   begin
347    inherited;
348    Self.OnNewFileSelected := Self.NewFile;
349  
350    exts := '';
351 <  if Length(RawListHandlers) > 0 then
351 >  if Length(RawLists.RawListHandlers) > 0 then
352    begin
353 <    for i := 0 to High(RawListHandlers) do
353 >    for i := 0 to High(RawLists.RawListHandlers) do
354        if Length(exts) > 0 then
355 <        exts := exts + ',' + RawListHandlers[i].Ext
355 >        exts := exts + ',' + RawLists.RawListHandlers[i].Ext
356        else
357 <        exts := RawListHandlers[i].Ext;
357 >        exts := RawLists.RawListHandlers[i].Ext;
358    end;
359    Self.AllowedExts := exts;
360  
# Line 403 | Line 389 | end;
389   function TForm_RawEdit.Save: Boolean;
390   var
391    mem:  TMemoryStream;
392 <  Data: Tdata;
407 <  i:    LongWord;
392 >  i:    Integer;
393   begin
394    case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' +
395 <      Connection.GetFileInfo(fileid).FileName + '?'), PChar('Data changed...'),
395 >      ConManager.Connection[ConnectionID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'),
396        MB_YESNOCANCEL) of
397      idYes:
398      begin
399        mem := TMemoryStream.Create;
400        hex.SaveToStream(mem);
401        mem.Seek(0, soFromBeginning);
402 <      SetLength(Data, mem.Size);
418 <      mem.Read(Data[0], mem.Size);
402 >      ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, mem);
403        mem.Free;
420      Connection.UpdateRawFile(fileid_opened, dat_offset_opened,
421        Length(Data), @Data[0]);
404        hex.Modified := False;
405        for i := 0 to hex.Datasize - 1 do
406          hex.ByteChanged[i] := False;
# Line 427 | Line 409 | begin
409      idNo:
410        Result := True;
411      idCancel:
430    begin
412        Result := False;
432    end;
413    end;
414   end;
415  
# Line 439 | Line 419 | end;
419   procedure TForm_RawEdit.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
420   begin
421    if hex.Modified then
442  begin
422      if not Save then
423        CanClose := False;
445  end;
424   end;
425  
426  
# Line 528 | Line 506 | procedure TForm_RawEdit.btn_exportClick(
506   var
507    fs: TFileStream;
508   begin
509 <  saved.Filter     := 'Files of matching extension (*.' + Connection.GetFileInfo(
510 <    fileid).Extension + ')|*.' + Connection.GetFileInfo(fileid).Extension +
509 >  saved.Filter     := 'Files of matching extension (*.' +
510 >    ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' +
511 >    ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension +
512      '|All files|*.*';
513 <  saved.DefaultExt := Connection.GetFileInfo(fileid).Extension;
513 >  saved.DefaultExt := ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension;
514    if saved.Execute then
515    begin
516      fs := TFileStream.Create(saved.FileName, fmCreate);
# Line 547 | Line 526 | procedure TForm_RawEdit.btn_importClick(
526   var
527   //  Data: Tdata;
528    fs:   TFileStream;
529 +  i: Integer;
530 +  rawinfo: TRawDataInfo;
531   begin
532 <  opend.Filter := 'Files of matching extension (*.' + Connection.GetFileInfo(
533 <    fileid).Extension + ')|*.' + Connection.GetFileInfo(fileid).Extension +
532 >  opend.Filter := 'Files of matching extension (*.' +
533 >    ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' +
534 >    ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension +
535      '|All files|*.*';
536    if opend.Execute then
537    begin
538      fs := TFileStream.Create(opend.FileName, fmOpenRead);
539      if fs.Size <> hex.DataSize then
540      begin
541 <      ShowMessage('Can''t import ' + ExtractFilename(opend.FileName) +
542 <        ', file has to have same size as file in .dat.' + CrLf +
543 <        'Size of file in .dat: ' + FormatFileSize(hex.datasize) + CrLf +
544 <        'Size of chosen file: ' + FormatFileSize(fs.Size));
545 <    end
546 <    else
547 <    begin
548 <      hex.LoadFromStream(fs);
549 <      hex.Modified := True;
550 <    end;
541 >      if (not (CR_ResizeRaw in ConManager.Connection[ConnectionID].ChangeRights)) and (not (CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights)) then
542 >      begin
543 >        ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) +
544 >            ', file has to have same size as file in .raw with this backend.' + CrLf +
545 >            'Size of file in .raw: ' + FormatFileSize(hex.DataSize) + CrLf +
546 >            'Size of chosen file: ' + FormatFileSize(fs.Size));
547 >        Exit;
548 >      end else begin
549 >        if MessageBox(Self.Handle,
550 >              PChar('File has different size from the file in the .raw.' + CrLf +
551 >                    'Size of file in .dat: ' + FormatFileSize(hex.DataSize) + CrLf +
552 >                    'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf +
553 >                    'Replace anyway?' + CrLf +
554 >                    'WARNING: This only replaces the raw-data. It doesn''t' + CrLf +
555 >                    'do the according changes in the .dat. Oni probably' + CrLf +
556 >                    'won''t be able to use the data correctly!'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then
557 >        begin
558 >          Exit;
559 >        end;
560 >      end;
561 >      rawinfo := ConManager.Connection[ConnectionID].GetRawInfo(fileid, datoffset);
562 >      if CR_ResizeRaw in ConManager.Connection[ConnectionID].ChangeRights then
563 >        ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, fs)
564 >      else if CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights then
565 >        i := ConManager.Connection[ConnectionID].AppendRawFile(rawinfo.LocSep, fs);
566 >        ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, datoffset, 4, @i);
567 >    end else begin
568 >      ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, fs);
569 >    end;
570 >    fs.Seek(0, soFromBeginning);
571 >    hex.LoadFromStream(fs);
572 >    hex.Modified := False;
573 >    for i := 0 to hex.Datasize - 1 do
574 >      hex.ByteChanged[i] := False;
575      fs.Free;
576    end;
577   end;
# Line 629 | Line 635 | procedure TForm_RawEdit.value_viewer_con
635   var
636   //  i:     Byte;
637    Name:  String;
638 <  Value: LongWord;
638 >  Value: Integer;
639   begin
640    Name := TMenuItem(Sender).Name;
641    if Pos('asstring', Name) > 0 then
# Line 688 | Line 694 | end;
694  
695  
696  
697 < procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String);
697 > procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: Integer; Value: String);
698   var
699 <  Data: Tdata;
699 >  Data: TByteData;
700    value_int: LongWord;
701    value_float: Single;
702    i: Word;
# Line 755 | Line 761 | end;
761  
762   procedure TForm_RawEdit.value_viewerDblClick(Sender: TObject);
763   var
764 <  offset:     LongWord;
764 >  offset:     Integer;
765    datatype:   Word;
766    objectname: String;
767    Value:      String;

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)