Changeset 97 for oup/rewrite/Tools


Ignore:
Timestamp:
Jan 23, 2007, 12:05:45 AM (18 years ago)
Author:
alloc
Message:
 
Location:
oup/rewrite/Tools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • oup/rewrite/Tools/BinEdit.pas

    r93 r97  
    140140var
    141141  mem:  TMemoryStream;
    142   Data: Tdata;
     142  Data: TByteData;
    143143begin
    144144  if con <> nil then
     
    397397procedure TForm_BinEdit.WriteValues;
    398398var
    399   i, j:  Byte;
     399  i, j:  Integer;
    400400  Data:  Tdata;
    401401  str:   String;
  • oup/rewrite/Tools/Preview.pas

    r94 r97  
    44  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    55  Dialogs, StdCtrls, Template, ExtCtrls, Math, StrUtils,
    6   ConnectionManager, {OniImgClass,} Data, TypeDefs, Menus, Buttons;
     6  ConnectionManager, OniImgClass, Data, TypeDefs, Menus, Buttons;
    77
    88type
     
    8484procedure TForm_Preview.LoadImage(fileid, index: Integer);
    8585var
    86   Data:      TByteArray;
     86  Data:      TByteData;
    8787  memstream: TMemoryStream;
    8888  OniImage:  TOniImage;
     
    9090begin
    9191  OniImage := TOniImage.Create;
    92   OniImage.Load(Connection, fileid);
    93   Data := OniImage.GetAsBMP;
     92  OniImage.Load(ConnectionID, fileid);
     93  OniImage.GetAsBMP(Data);
    9494  OniImage.Free;
    9595
     
    147147  i:    Byte;
    148148begin
    149   Connection.LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
    150   Connection.LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
     149  ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
     150  ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
    151151  SetBitmapCount(linkcount);
    152152  for i := 0 to linkcount - 1 do
    153153  begin
    154     Connection.LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
     154    ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
    155155    link := link div 256;
    156156    if link = 0 then
     
    190190  else
    191191    actualimg := High(bitmaps);
    192   Self.Caption := 'Preview ' + Connection.GetFileInfo(_fileid).FileName +
     192  Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
    193193    ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
    194194  DrawImage(actualimg);
     
    202202  else
    203203    actualimg := 0;
    204   Self.Caption := 'Preview ' + Connection.GetFileInfo(_fileid).FileName +
     204  Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
    205205    ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
    206206  DrawImage(actualimg);
  • oup/rewrite/Tools/RawEdit.pas

    r93 r97  
    44  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    55  Dialogs, Template, StdCtrls, ExtCtrls, Menus, Grids, Wrapgrid,
    6   MPHexEditor, Clipbrd, StrUtils,
    7   Data, Functions, DataStructures, Exporters, OniDataClass, Buttons;
     6  MPHexEditor, Clipbrd, StrUtils, TypeDefs,
     7  Data, Functions, DatStructureLoader, ConnectionManager, Buttons;
    88
    99type
     
    2929    procedure list_offsetClick(Sender: TObject);
    3030    procedure NewFile(fileinfo: TFileInfo);
    31     procedure LoadRaw(raw_info: TRawInfo);
     31    procedure LoadRaw(raw_info: TRawDataInfo);
    3232    function Save: Boolean;
    3333
     
    259259procedure TForm_RawEdit.WriteValues;
    260260var
    261   i, j:  Byte;
     261  i, j:  Integer;
    262262  Data:  Tdata;
    263263  str:   String;
  • oup/rewrite/Tools/Template.dfm

    r93 r97  
    1919  OnActivate = FormActivate
    2020  OnClose = FormClose
    21   OnCreate = FormCreate
    2221  OnResize = FormResize
    2322  PixelsPerInch = 96
  • oup/rewrite/Tools/Template.pas

    r93 r97  
    66  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    77  Dialogs, ExtCtrls, StdCtrls, StrUtils,
    8   ConnectionManager, {Functions,} Data, TypeDefs, Menus, Buttons;
     8  Data, TypeDefs, Menus, Buttons;
    99
    1010type
    1111  TNewFileSelectedEvent = procedure(FileInfo: TFileInfo) of object;
    1212  TNewConnectionEvent = procedure(Connection: Integer) of object;
     13  TCheckCloseableEvent = function: Boolean of object;
    1314
    1415  TForm_ToolTemplate = class(TForm)
     
    4041    combo_connection: TComboBox;
    4142    Bevel1: TBevel;
    42     procedure RecreateList;
    43     procedure UpdateList;
    4443    procedure RecreateExtList;
     44    procedure UpdateConList;
    4545    procedure LoadFileNames;
    46     procedure SelectFileName(connection: Integer; FileName: String);
    47     procedure SelectFileID(connection: Integer; FileID: Integer);
     46    procedure SelectFileName(ConnectionID: Integer; FileName: String);
     47    procedure SelectFileID(ConnectionID, FileID: Integer);
     48    procedure SelectConnection(ConnectionID: Integer);
    4849    procedure check_filternameClick(Sender: TObject);
    4950    procedure check_zerobyteClick(Sender: TObject);
     
    5455
    5556    procedure FormResize(Sender: TObject);
    56     procedure FormCreate(Sender: TObject);
    5757    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    5858    procedure popup_importClick(Sender: TObject);
     
    6767    FOnNewFileSelected: TNewFileSelectedEvent;
    6868    FOnNewConnection: TNewConnectionEvent;
     69    FOnCheckCloseable: TCheckCloseableEvent;
    6970    FAllowedExts: String;
    7071    FAllowMultiSelect: Boolean;
    7172    FSelectedFile: TFileInfo;
    72     FConnection: Integer;
     73    FConnectionID: Integer;
    7374    procedure SetAllowedExts(exts: String);
    7475    procedure SetMultiSelect(allow: Boolean);
     76    function GetToolCloseable: Boolean;
    7577  public
    7678    constructor Create(AOwner: TComponent); override;
     
    7981    property OnNewFileSelected: TNewFileSelectedEvent read FOnNewFileSelected write FOnNewFileSelected;
    8082    property OnNewConnection: TNewConnectionEvent read FOnNewConnection write FOnNewConnection;
     83    property OnCheckCloseable: TCheckCloseableEvent read FOnCheckCloseable write FOnCheckCloseable;
    8184    property AllowedExts: String read FAllowedExts write SetAllowedExts;
    8285    property AllowMultiSelect: Boolean read FAllowMultiSelect write SetMultiSelect;
    8386    property SelectedFile: TFileInfo read FSelectedFile;
    84     property Connection: Integer read FConnection;
     87    property ConnectionID: Integer read FConnectionID;
     88    property Closeable: Boolean read GetToolCloseable;
    8589  end;
    8690
     
    9195implementation
    9296{$R *.dfm}
    93 uses Main, Exporters;
    94 
    95 
    96 procedure TForm_ToolTemplate.UpdateList;
     97uses Main, ConnectionManager, Exporters, Functions;
     98
     99
     100procedure TForm_ToolTemplate.UpdateConList;
    97101var
    98102  i: Integer;
    99103  fn, datatype, boxstring: String;
    100104  level: Integer;
    101   oldcon: String;
    102 begin
    103   oldcon := combo_connection.Items.Strings[combo_connection.ItemIndex];
     105begin
    104106  combo_connection.ItemIndex := -1;
    105107  combo_connection.Items.Clear;
    106   if Length(DataConnections) > 0 then
    107   begin
    108     for i := 0 to High(DataConnections) do
     108  if ConManager.Count > 0 then
     109  begin
     110    for i := 0 to ConManager.Count - 1 do
    109111    begin
    110       level := DataConnections[i].LevelInfo.LevelNumber;
    111       fn := ExtractFileName(DataConnections[i].FileName);
    112       if DataConnections[i].Backend = ODB_Dat then
     112      level := ConManager.ConnectionByIndex[i].LevelNumber;
     113      fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
     114      if ConManager.ConnectionByIndex[i].Backend = DB_ONI then
    113115        datatype := 'ONI-.dat: '
    114       else if DataConnections[i].Backend = ODB_ADB then
     116      else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then
    115117        datatype := 'OUP-DB: '
    116118      else
     
    118120      boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
    119121      combo_connection.Items.Add(boxstring);
    120       if oldcon = boxstring then
     122      if ConManager.ConnectionByIndex[i].ConnectionID = FConnectionID then
    121123        combo_connection.ItemIndex := combo_connection.Items.Count - 1;
    122124    end;
     
    129131  else
    130132  begin
    131     FConnection := nil;
     133    FConnectionID := 0;
    132134    filelist.Items.Clear;
    133135    combo_extension.Items.Clear;
    134136    combo_connectionChange(Self);
    135     FSelectedFile := GetEmptyFileInfo;
     137    FSelectedFile.ID := -1;
    136138    if Assigned(FOnNewFileSelected) then
    137139      FOnNewFileSelected(FSelectedFile);
     
    139141end;
    140142
    141 procedure TForm_ToolTemplate.RecreateList;
    142 var
    143   i: Integer;
    144   fn, datatype: String;
    145   level: Integer;
    146 begin
    147   combo_connection.Items.Clear;
    148   if Length(DataConnections) > 0 then
    149   begin
    150     for i := 0 to High(DataConnections) do
    151     begin
    152       level := DataConnections[i].LevelInfo.LevelNumber;
    153       fn := ExtractFileName(DataConnections[i].FileName);
    154       if DataConnections[i].Backend = ODB_Dat then
    155         datatype := 'ONI-.dat: '
    156       else if DataConnections[i].Backend = ODB_ADB then
    157         datatype := 'OUP-DB: '
    158       else
    159         datatype := 'Unknown: ';
    160       combo_connection.Items.Add(datatype + fn + ' (Level: ' + IntToStr(level) + ')');
    161     end;
    162     FConnection := DataConnections[0];
    163     combo_connection.ItemIndex := 0;
    164     combo_connectionChange(Self);
    165   end
    166   else
    167   begin
    168     FConnection := nil;
    169     filelist.Items.Clear;
    170     combo_extension.Items.Clear;
    171     combo_connectionChange(Self);
    172   end;
    173 end;
    174 
    175143procedure TForm_ToolTemplate.RecreateExtList;
    176144var
    177   i:    LongWord;
    178   exts: TStringArray;
     145  i:    Integer;
     146  exts: TStrings;
    179147begin
    180148  combo_extension.Items.Clear;
    181   if FConnection <> nil then
     149  if FConnectionID > -1 then
    182150  begin
    183151    combo_extension.Items.Add('_All files_ (' +
    184       IntToStr(FConnection.GetFilesCount) + ')');
    185     exts := FConnection.GetExtensionsList;
    186     for i := 0 to High(exts) do
     152      IntToStr(ConManager.Connection[FConnectionID].GetFileCount) + ')');
     153    exts := ConManager.Connection[FConnectionID].GetExtensionsList(EF_ExtCount);
     154    for i := 0 to exts.Count - 1 do
    187155      if Length(FAllowedExts) > 0 then
    188156      begin
    189         if Pos(MidStr(exts[i],1,4), FAllowedExts) > 0 then
    190         begin
    191           combo_extension.Items.Add(exts[i]);
    192         end;
    193       end else
    194         combo_extension.Items.Add(exts[i]);
     157        if Pos(MidStr(exts.Strings[i],1,4), FAllowedExts) > 0 then
     158          combo_extension.Items.Add(exts.Strings[i]);
     159      end
     160      else
     161        combo_extension.Items.Add(exts.Strings[i]);
    195162    combo_extension.ItemIndex := 0;
    196163    combo_extensionClick(Self);
     164    exts.Free;
    197165  end;
    198166end;
     
    206174  no_zero_bytes: Boolean;
    207175  pattern: String;
    208   files: TStringArray;
    209   i: LongWord;
    210 begin
    211   if FConnection <> nil then
     176  files: TStrings;
     177  i: Integer;
     178begin
     179  if FConnectionID > -1 then
    212180  begin
    213181    Extension := MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex], 1, 4);
     
    222190        Extension := '';
    223191
    224     files := FConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
     192    files := ConManager.Connection[FConnectionID].GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
    225193
    226194    filelist.Visible := False;
    227195    filelist.Items.Clear;
    228     if Length(files) > 0 then
    229       for i := 0 to High(files) do
    230         filelist.Items.Add(files[i]);
     196    if files.Count > 0 then
     197      filelist.Items.AddStrings(files);
    231198    filelist.Visible := True;
    232199  end;
     
    239206  ext: String;
    240207begin
    241   id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
     208  id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
    242209  ext := RightStr(filelist.Items.Strings[filelist.ItemIndex], 4);
    243210  exportd.Filter := 'Files of matching extension (*.' + ext + ')|*.' + ext + '|All files|*.*';
    244211  exportd.DefaultExt := ext;
    245212  if exportd.Execute then
    246     ExportDatFile(FConnection, id, exportd.FileName);
     213    ExportDatFile(FConnectionID, id, exportd.FileName);
    247214end;
    248215
     
    252219  finfo: TFileInfo;
    253220  fs: TFileStream;
    254   data: TData;
    255 begin
    256   id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
    257   finfo := FConnection.GetFileInfo(id);
     221begin
     222  id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
     223  finfo := ConManager.Connection[FConnectionID].GetFileInfo(id);
    258224
    259225  importd.Filter := 'Files of matching extension (*.' + finfo.Extension + ')|*.' +
     
    268234        'Size of chosen file: ' + FormatFileSize(fs.Size))
    269235    else begin
    270       SetLength(data, fs.Size);
    271       fs.Read(data[0], fs.Size);
    272       FConnection.UpdateDatFile(id, data);
     236      ConManager.Connection[FConnectionID].UpdateDatFile(id, fs);
    273237      Self.listClick(Self);
    274238    end;
     
    283247begin
    284248  sender_name := TComponent(Sender).Name;
    285   id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
     249  id := ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[filelist.ItemIndex]);
    286250  context := MidStr(sender_name, Pos('_', sender_name) + 1, Length(sender_name) - Pos('_', sender_name));
    287   Form_Main.open_child(context, FConnection, id);
     251  Form_Main.open_child(context, FConnectionID, id);
    288252end;
    289253
     
    295259begin
    296260  if combo_connection.ItemIndex >= 0 then
    297   begin
    298     name := combo_connection.Items.Strings[combo_connection.ItemIndex];
    299     nstart := Pos(' ', name) + 1;
    300     nend := Pos('(', name) - 1;
    301     name := MidStr(name, nstart, nend - nstart);
    302 
    303     for i := 0 to High(DataConnections) do
    304     begin
    305       if ExtractFileName(DataConnections[i].FileName) = name then
    306       begin
    307         FConnection := DataConnections[i];
    308         Break;
    309       end;
    310     end;
    311     if i = Length(DataConnections) then
    312       FConnection := nil;
    313 
    314     RecreateExtList;
    315     if Assigned(FOnNewConnection) then
    316       FOnNewConnection(FConnection);
    317   end;
     261    FConnectionID := combo_connection.ItemIndex
     262  else
     263    FConnectionID := -1;
     264  RecreateExtList;
     265  if Assigned(FOnNewConnection) then
     266    FOnNewConnection(FConnectionID);
    318267end;
    319268
     
    330279begin
    331280  inherited;
    332   RecreateList;
    333   FSelectedFile := GetEmptyFileInfo;
     281  Self.Width  := 260;
     282  Self.Height := 300;
     283  FAllowedExts := '';
     284  FAllowMultiSelect := False;
     285  FOnNewFileSelected := nil;
     286  FOnNewConnection := nil;
     287  FOnCheckCloseable := nil;
     288  FConnectionID := -1;
     289  FSelectedFile.ID := -1;
     290  UpdateConList;
    334291  if Length(ToolList) > 0 then
    335292  begin
     
    368325begin
    369326  if btn_sort_id_asc.Down then
    370     FSortBy := stIDAsc
     327    FSortBy := ST_IDAsc
    371328  else if btn_sort_id_desc.Down then
    372     FSortBy := stIDDesc
     329    FSortBy := ST_IDDesc
    373330  else if btn_sort_name_asc.Down then
    374     FSortBy := stNameAsc
     331    FSortBy := ST_NameAsc
    375332  else if btn_sort_name_desc.Down then
    376     FSortBy := stNameDesc
     333    FSortBy := ST_NameDesc
    377334  else if btn_sort_ext_asc.Down then
    378     FSortBy := stExtAsc
     335    FSortBy := ST_ExtAsc
    379336  else if btn_sort_ext_desc.Down then
    380     FSortBy := stExtDesc;
     337    FSortBy := ST_ExtDesc;
    381338  LoadFileNames;
    382339end;
     
    394351  if filelist.ItemIndex > -1 then
    395352  begin
    396     fileid := FConnection.ExtractFileID(
     353    fileid := ConManager.Connection[FConnectionID].ExtractFileIDOfName(
    397354          filelist.Items.Strings[filelist.ItemIndex]);
    398     FSelectedFile := FConnection.GetFileInfo(fileid);
     355    FSelectedFile := ConManager.Connection[FConnectionID].GetFileInfo(fileid);
    399356    if Assigned(FOnNewFileSelected) then
    400357      FOnNewFileSelected(FSelectedFile);
     
    415372
    416373
    417 procedure TForm_ToolTemplate.SelectFileID(connection: TOniData; id: Integer);
    418 var
    419   i: Integer;
    420   name: String;
    421   nstart, nend: Integer;
    422 begin
    423   for i := 0 to combo_connection.Items.Count - 1 do
    424   begin
    425     name := combo_connection.Items.Strings[i];
    426     nstart := Pos(' ', name) + 1;
    427     nend := Pos('(', name) - 1;
    428     name := MidStr(name, nstart, nend - nstart);
    429 
    430     if ExtractFileName(connection.FileName) = name then
    431     begin
    432       combo_connection.ItemIndex := i;
    433       combo_connectionChange(Self);
    434     end;
    435   end;
     374procedure TForm_ToolTemplate.SelectConnection(ConnectionID: Integer);
     375begin
     376  if FConnectionID <> ConnectionID then
     377  begin
     378    combo_connection.ItemIndex := ConManager.ConnectionIndexByID[ConnectionID];
     379    combo_connectionChange(Self);
     380  end;
     381end;
     382
     383procedure TForm_ToolTemplate.SelectFileID(ConnectionID, FileID: Integer);
     384var
     385  i: Integer;
     386begin
     387  if FConnectionID <> ConnectionID then
     388    SelectConnection(ConnectionID);
    436389
    437390  filelist.ItemIndex := -1;
    438391  if filelist.Items.Count > 0 then
    439392    for i := 0 to filelist.Items.Count - 1 do
    440       if FConnection.ExtractFileID(filelist.Items.Strings[i]) = id then
     393      if ConManager.Connection[FConnectionID].ExtractFileIDOfName(filelist.Items.Strings[i]) = FileID then
    441394      begin
    442395        filelist.ItemIndex := i;
     
    446399end;
    447400
    448 procedure TForm_ToolTemplate.SelectFileName(connection: TOniData; filename: String);
    449 var
    450   i: Integer;
    451   name: String;
    452   nstart, nend: Integer;
    453 begin
    454   for i := 0 to combo_connection.Items.Count - 1 do
    455   begin
    456     name := combo_connection.Items.Strings[i];
    457     nstart := Pos(' ', name) + 1;
    458     nend := Pos('(', name) - 1;
    459     name := MidStr(name, nstart, nend - nstart);
    460 
    461     if ExtractFileName(connection.FileName) = name then
    462     begin
    463       combo_connection.ItemIndex := i;
    464       combo_connectionChange(Self);
    465     end;
    466   end;
     401procedure TForm_ToolTemplate.SelectFileName(ConnectionID: Integer; filename: String);
     402var
     403  i: Integer;
     404begin
     405  if FConnectionID <> ConnectionID then
     406    SelectConnection(ConnectionID);
    467407
    468408  filelist.ItemIndex := -1;
     
    519459
    520460
    521 procedure TForm_ToolTemplate.FormCreate(Sender: TObject);
    522 begin
    523   Self.Width  := 260;
    524   Self.Height := 300;
    525   FOnNewFileSelected := nil;
    526   FOnNewConnection := nil;
    527   FAllowedExts := '';
    528   FAllowMultiSelect := False;
     461function TForm_ToolTemplate.GetToolCloseable: Boolean;
     462begin
     463  if Assigned(FOnCheckCloseable) then
     464    Result := FOnCheckCloseable
     465  else
     466    Result := True;
    529467end;
    530468
  • oup/rewrite/Tools/TxmpReplace.pas

    r93 r97  
    44  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    55  Dialogs, Template, StdCtrls, ExtCtrls,
    6   Functions, Data, OniImgClass, Menus, Buttons;
     6  Functions, Data, OniImgClass, Menus, Buttons, TypeDefs;
    77
    88type
     
    4141implementation
    4242{$R *.dfm}
    43 uses Main, OniDataClass;
     43uses Main, ConnectionManager;
    4444
    4545
     
    4747procedure TForm_TxmpReplace.SelectFile(fileinfo: TFileInfo);
    4848var
    49   Data: Tdata;
     49  Data: TByteData;
    5050  mem:  TMemoryStream;
    5151  fadingbyte, depthbyte, storebyte: Byte;
Note: See TracChangeset for help on using the changeset viewer.