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

Diff Legend

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