Changeset 86 for oup/current


Ignore:
Timestamp:
Jan 14, 2007, 9:19:08 PM (18 years ago)
Author:
alloc
Message:
 
Location:
oup/current
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • oup/current/Code/Exporters.pas

    r74 r86  
    33interface
    44
    5 uses Classes, Dialogs, StrUtils, SysUtils, Math, Data, OniImgClass;
    6 
    7 procedure ExportDatFile(fileid: LongWord; filename: String);
    8 procedure ExportRawFiles(fileid: LongWord; filename: String);
    9 procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
    10 function ExportConverted(fileid: LongWord; filename: String): Integer;
    11 
    12 function ExportSNDD(fileid: LongWord; filename: String): Integer;
    13 function ExportTRAC(fileid: LongWord; filename: String): Integer;
    14 function ExportTXAN(fileid: LongWord; filename: String): Integer;
    15 function ExportImage(fileid: LongWord; filename: String): Integer;
     5uses Classes, Dialogs, StrUtils, SysUtils, Math, Data, OniImgClass, OniDataClass;
     6
     7type
     8  TExportHandlers = record
     9    Ext:     String[4];
     10    needed:  Boolean;
     11    Handler: function(connection: TOniData; fileid: LongWord; filename: String): Integer;
     12  end;
     13
     14procedure ExportDatFile(connection: TOniData; fileid: LongWord; filename: String);
     15procedure ExportRawFiles(connection: TOniData; fileid: LongWord; filename: String);
     16procedure ExportRawFile(connection: TOniData; fileid: LongWord; dat_offset: LongWord; filename: String);
     17function ExportConverted(connection: TOniData; fileid: LongWord; filename: String): Integer;
     18
     19function ExportSNDD(connection: TOniData; fileid: LongWord; filename: String): Integer;
     20function ExportTRAC(connection: TOniData; fileid: LongWord; filename: String): Integer;
     21function ExportTXAN(connection: TOniData; fileid: LongWord; filename: String): Integer;
     22function ExportImage(connection: TOniData; fileid: LongWord; filename: String): Integer;
    1623
    1724var
     
    3037implementation
    3138
    32 uses Functions, DataStructures, OniDataClass;
    33 
    34 
    35 
    36 procedure ExportDatFile(fileid: LongWord; filename: String);
     39uses Functions, DataStructures;
     40
     41
     42
     43procedure ExportDatFile(connection: TOniData; fileid: LongWord; filename: String);
    3744var
    3845  filestream: TFileStream;
    3946  Data: Tdata;
    4047begin
    41   Data := OniDataConnection.LoadDatFile(fileid);
     48  Data := connection.LoadDatFile(fileid);
    4249  if FileExists(filename) then
    4350  begin
     
    5461
    5562
    56 procedure ExportRawFiles(fileid: LongWord; filename: String);
     63procedure ExportRawFiles(connection: TOniData; fileid: LongWord; filename: String);
    5764var
    5865  i: Integer;
    5966  rawlist: TRawList;
    6067begin
    61   rawlist := OniDataConnection.GetRawList(fileid);
     68  rawlist := connection.GetRawList(fileid);
    6269  if Length(rawlist) > 0 then
    6370    for i := 0 to High(rawlist) do
    64       ExportRawFile(fileid, rawlist[i].src_offset, filename);
    65 end;
    66 
    67 procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
     71      ExportRawFile(connection, fileid, rawlist[i].src_offset, filename);
     72end;
     73
     74procedure ExportRawFile(connection: TOniData; fileid: LongWord; dat_offset: LongWord; filename: String);
    6875var
    6976  filestream: TFileStream;
    7077  Data: Tdata;
    7178begin
    72   SetLength(Data, OniDataConnection.GetRawInfo(fileid, dat_offset).raw_size);
    73   OniDataConnection.LoadRawFile(fileid, dat_offset, @Data[0]);
     79  SetLength(Data, connection.GetRawInfo(fileid, dat_offset).raw_size);
     80  connection.LoadRawFile(fileid, dat_offset, @Data[0]);
    7481  if FileExists(filename + '.raw0x' + IntToHex(dat_offset, 8)) then
    7582  begin
     
    8693end;
    8794
    88 function ExportConverted(fileid: LongWord; filename: String): Integer;
     95function ExportConverted(connection: TOniData; fileid: LongWord; filename: String): Integer;
    8996var
    9097  i: Integer;
    9198  fileinfo: TFileInfo;
    9299begin
    93   fileinfo := OniDataConnection.GetFileInfo(fileid);
     100  fileinfo := connection.GetFileInfo(fileid);
    94101  if Length(ExportHandlers) > 0 then
    95102    for i := 0 to High(ExportHandlers) do
    96103      if ExportHandlers[i].Ext = fileinfo.Extension then
    97         ExportHandlers[i].Handler(fileid, filename);
     104        ExportHandlers[i].Handler(connection, fileid, filename);
    98105end;
    99106
     
    142149begin
    143150  Result := export_noerror;
    144   OniDataConnection.LoadDatFilePart(fileid, 0, SizeOf(DatData), @DatData);
     151  connection.LoadDatFilePart(fileid, 0, SizeOf(DatData), @DatData);
    145152  with DatData do
    146153  begin
     
    154161    WAVE_DataLen := RAWSize;
    155162    SetLength(Data, RAWSize);
    156     OniDataConnection.LoadRawFile(fileid, $44, Data);
     163    connection.LoadRawFile(fileid, $44, Data);
    157164
    158165    //Now start packing this into a neat wave...
     
    192199  Result := export_noerror;
    193200
    194   OniDataConnection.LoadDatFilePart(fileid, $18, SizeOf(link), @link);
     201  connection.LoadDatFilePart(fileid, $18, SizeOf(link), @link);
    195202  link := link div 256;
    196203
    197   OniDataConnection.LoadDatFilePart(fileid, $1E, SizeOf(linkcount), @linkcount);
     204  connection.LoadDatFilePart(fileid, $1E, SizeOf(linkcount), @linkcount);
    198205  for i := 1 to linkcount do
    199206  begin
    200     OniDataConnection.LoadDatFilePart(fileid, $20 + (i - 1) * 12 + 8, SizeOf(link), @link);
     207    connection.LoadDatFilePart(fileid, $20 + (i - 1) * 12 + 8, SizeOf(link), @link);
    201208    link := link div 256;
    202209  end;
     
    215222  Result := export_noerror;
    216223
    217   OniDataConnection.LoadDatFilePart(fileid, $14, SizeOf(loop_speed), @loop_speed);
    218   OniDataConnection.LoadDatFilePart(fileid, $16, SizeOf(unknown), @unknown);
    219 
    220   OniDataConnection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
     224  connection.LoadDatFilePart(fileid, $14, SizeOf(loop_speed), @loop_speed);
     225  connection.LoadDatFilePart(fileid, $16, SizeOf(unknown), @unknown);
     226
     227  connection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
    221228  for i := 0 to linkcount - 1 do
    222229  begin
    223     OniDataConnection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
     230    connection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
    224231    link := link div 256;
    225232    if link = 0 then
     
    240247
    241248  img := TOniImage.Create;
    242   img.Load(fileid);
     249  img.Load(connection, fileid);
    243250  data := img.GetAsBMP;
    244251  img.Free;
  • oup/current/Code/Functions.pas

    r75 r86  
    2121function DecodeHexString(hex: String): Tdata;
    2222function GetWinFileName(Name: String): String;
    23 function GetExtractPath: String;
     23//function GetExtractPath: String;
    2424
    2525function Explode(_string: String; delimiter: Char): TStringArray;
     
    352352
    353353
    354 
     354{
    355355function GetExtractPath: String;
    356356begin
    357   Result := ExtractFilePath(OniDataConnection.FileName) + '\extracted_' +
    358     ExtractFileName(OniDataConnection.Filename);
    359 end;
    360 
     357  Result := ExtractFilePath(DataConnections[i].FileName) + '\extracted_' +
     358    ExtractFileName(DataConnections[i].Filename);
     359end;
     360}
    361361
    362362end.
  • oup/current/Code/OniDataClass.pas

    r56 r86  
    136136  end;
    137137
     138  TOniDataEmpty = class(TOniData)
     139  private
     140  protected
     141  public
     142    constructor Create(OLDBFilename: String; var Result: Boolean); override;
     143    procedure Close; override;
     144{
     145    procedure UpdateListCache;
     146    //      function GetDatLinks(srcid:LongWord):TDatLinks;
     147    function GetFileInfo(fileid: LongWord): TFileInfo; override;
     148    function GetFilesList(ext: String; pattern: String;
     149      NoEmptyFiles: Boolean; sort: TSortType): TStringArray; override;
     150    function GetFilesCount: LongWord; override;
     151    function GetExtensionsList: TStringArray; override;
     152    function GetExtendedExtensionsList: TExtensionsMap; override;
     153    function GetNamedFilesMap: TNamedFilesMap;
     154
     155    function LoadDatFile(fileid: LongWord): Tdata; override;
     156    procedure UpdateDatFile(fileid: LongWord; Data: Tdata); override;
     157    procedure LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
     158    procedure UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
     159
     160    function GetRawList(fileid: LongWord): TRawList; override;
     161    procedure LoadRawFile(fileid, dat_offset: LongWord; target: Pointer); override;
     162    procedure UpdateRawFile(fileid, dat_offset: LongWord; size: LongWord;
     163      target: Pointer); override;
     164    procedure LoadRawFilePart(fileid, dat_offset: LongWord;
     165      offset, size: LongWord; target: Pointer); override;
     166    procedure UpdateRawFilePart(fileid, dat_offset: LongWord;
     167      offset, size: LongWord; target: Pointer); override;
     168}  published
     169  end;
    138170
    139171const
     
    143175
    144176var
     177//  OniDataConnection: TOniData;
     178  DataConnections: array of TOniData;
    145179  OniDataConnection: TOniData;
    146180
    147 function CreateDataConnection(filename: String; backend: Integer): Boolean;
    148 procedure CloseDataConnection;
     181function CreateDataConnection(filename: String; backend: Integer): TOniData;
     182procedure CloseDataConnection(connection: TOniData);
     183
    149184
    150185
     
    13721407
    13731408
    1374 function CreateDataConnection(filename: String; backend: Integer): Boolean;
     1409function CreateDataConnection(filename: String; backend: Integer): TOniData;
    13751410var
    13761411  answer: Boolean;
    1377 begin
    1378   if Assigned(OniDataConnection) then
    1379   begin
    1380     OniDataConnection.Close;
    1381     OniDataConnection.Free;
    1382     OniDataConnection := nil;
    1383   end;
     1412  i: Integer;
     1413begin
     1414  if Length(DataConnections) > 0 then
     1415  begin
     1416    for i := 0 to High(DataConnections) do
     1417    begin
     1418      if ExtractFileName(DataConnections[i].FFileName) = ExtractFileName(filename) then
     1419      begin
     1420        if DataConnections[i].FFileName <> filename then
     1421        begin
     1422          Result := nil;
     1423          ShowMessage('You can not open two files with the same name at a time.');
     1424        end
     1425        else
     1426          Result := DataConnections[i];
     1427        Exit;
     1428      end;
     1429    end;
     1430  end;
     1431
     1432  if not FileExists(filename) then
     1433  begin
     1434    ShowMessage('File "' + filename + '" does not exist!');
     1435    Result := nil;
     1436    Exit;
     1437  end;
     1438
     1439  SetLength(DataConnections, Length(DataConnections) + 1);
     1440  i := High(DataConnections);
    13841441  case backend of
    13851442    ODB_Dat:
    1386       OniDataConnection := TOniDataDat.Create(filename, answer);
     1443      DataConnections[i] := TOniDataDat.Create(filename, answer);
    13871444    ODB_ADB:
    1388       OniDataConnection := TOniDataADB.Create(filename, answer);
     1445      DataConnections[i] := TOniDataADB.Create(filename, answer);
    13891446    else
    13901447      ShowMessage('Unknown Backend');
    1391       Result := False;
     1448      Result := nil;
    13921449      Exit;
    13931450  end;
     
    13951452  if answer then
    13961453  begin
    1397     //      ShowMessage('file loaded');
    1398     //      ShowMessage('Files: '+IntToStr(OniDataConnection.GetFilesCount));
    1399     Result := True;
     1454    Result := DataConnections[i];
     1455//    Result := True;
    14001456  end
    14011457  else
    14021458  begin
    14031459    ShowMessage('File not loaded');
    1404     OniDataConnection.Close;
    1405     OniDataConnection.Free;
    1406     Result := False;
    1407   end;
    1408 end;
    1409 
    1410 
    1411 
    1412 
    1413 procedure CloseDataConnection;
    1414 begin
    1415   if Assigned(OniDataConnection) then
    1416   begin
    1417     OniDataConnection.Close;
    1418     OniDataConnection := nil;
    1419   end;
     1460    DataConnections[i].Close;
     1461    DataConnections[i].Free;
     1462    DataConnections[i] := nil;
     1463    SetLength(DataConnections, Length(DataConnections) - 1);
     1464    Result := nil;
     1465  end;
     1466end;
     1467
     1468
     1469
     1470
     1471procedure CloseDataConnection(connection: TOniData);
     1472var
     1473  i: Integer;
     1474  found: Boolean;
     1475begin
     1476  if Assigned(connection) then
     1477  begin
     1478    found := False;
     1479    for i := 0 to High(DataConnections) do
     1480    begin
     1481      if not found then
     1482      begin
     1483        if DataConnections[i] = connection then
     1484        begin
     1485          DataConnections[i].Close;
     1486          DataConnections[i].Free;
     1487          DataConnections[i] := nil;
     1488          found := True;
     1489        end;
     1490      end
     1491      else
     1492      begin
     1493        DataConnections[i - 1] := DataConnections[i];
     1494      end;
     1495    end;
     1496    if found then
     1497      SetLength(DataConnections, Length(DataConnections) - 1);
     1498  end;
     1499end;
     1500
     1501
     1502
     1503
     1504constructor TOniDataEmpty.Create(OLDBFilename: String; var Result: Boolean);
     1505var
     1506  i, j:  Byte;
     1507  temps: String;
     1508begin
     1509  ShowMessage('OLD');
     1510end;
     1511
     1512procedure TOniDataEmpty.Close;
     1513begin
     1514  ShowMessage('OLD');
    14201515end;
    14211516
  • oup/current/Code/OniImgClass.pas

    r46 r86  
    3333
    3434    constructor Create;
    35     function Load(fileid: LongWord): Boolean;
    36     function LoadFromPSpc(fileid: LongWord): Boolean;
    37     function LoadFromTXMP(fileid: LongWord): Boolean;
    38     function LoadFromTXMB(fileid: LongWord): Boolean;
     35    function Load(connection: TOniData; fileid: Cardinal): Boolean;
     36    function LoadFromPSpc(connection: TOniData; fileid: LongWord): Boolean;
     37    function LoadFromTXMP(connection: TOniData; fileid: LongWord): Boolean;
     38    function LoadFromTXMB(connection: TOniData; fileid: LongWord): Boolean;
    3939    function GetImageDataSize(fading: Boolean): LongWord;
    4040
     
    303303
    304304
    305 function TOniImage.Load(fileid: LongWord): Boolean;
     305function TOniImage.Load(connection: TOniData; fileid: Cardinal): Boolean;
    306306var
    307307  FileInfo: TFileInfo;
    308308  ext:      String;
    309309begin
    310   FileInfo := OniDataConnection.GetFileInfo(fileid);
     310  FileInfo := connection.GetFileInfo(fileid);
    311311  if FileInfo.Extension = 'PSpc' then
    312     Result := LoadFromPSpc(fileid)
     312    Result := LoadFromPSpc(connection, fileid)
    313313  else if FileInfo.Extension = 'TXMB' then
    314     Result := LoadFromTXMB(fileid)
     314    Result := LoadFromTXMB(connection, fileid)
    315315  else if FileInfo.Extension = 'TXMP' then
    316     Result := LoadFromTXMP(fileid)
     316    Result := LoadFromTXMP(connection, fileid)
    317317  else
    318318    Result := False;
     
    322322
    323323
    324 function TOniImage.LoadFromPSpc(fileid: LongWord): Boolean;
     324function TOniImage.LoadFromPSpc(connection: TOniData; fileid: LongWord): Boolean;
    325325type
    326326  TPoint = packed record
     
    357357  col, row: Byte;
    358358begin
    359   OniDataConnection.LoadDatFilePart(fileid, $08, SizeOf(PSpc), @PSpc);
     359  connection.LoadDatFilePart(fileid, $08, SizeOf(PSpc), @PSpc);
    360360  PSpc.TXMP := PSpc.TXMP div 256;
    361361  if PSpc.TXMP = 0 then
     
    365365  end;
    366366  txmpimg := TOniImage.Create;
    367   txmpimg.LoadFromTXMP(PSpc.TXMP);
     367  txmpimg.LoadFromTXMP(connection, PSpc.TXMP);
    368368  txmpimg.DecodeImage;
    369369  txmpimg.WriteToBMP('C:\file.bmp');
     
    464464
    465465
    466 function TOniImage.LoadFromTXMP(fileid: LongWord): Boolean;
     466function TOniImage.LoadFromTXMP(connection: TOniData; fileid: LongWord): Boolean;
    467467var
    468468  img_addr: LongWord;
    469469begin
    470470  Result := True;
    471   OniDataConnection.LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth);
    472   OniDataConnection.LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight);
    473   OniDataConnection.LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType),
     471  connection.LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth);
     472  connection.LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight);
     473  connection.LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType),
    474474    @Self.FStoreType);
    475   if not OniDataConnection.OSisMac then
    476     OniDataConnection.LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr)
     475  if not connection.OSisMac then
     476    connection.LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr)
    477477  else
    478     OniDataConnection.LoadDatFilePart(fileid, $A0, SizeOf(img_addr), @img_addr);
     478    connection.LoadDatFilePart(fileid, $A0, SizeOf(img_addr), @img_addr);
    479479
    480480  case Self.FStoreType of
     
    499499  end;
    500500
    501   if not OniDataConnection.OSisMac then
    502     OniDataConnection.LoadRawFile(fileid, $9C, @Self.FData[0])
     501  if not connection.OSisMac then
     502    connection.LoadRawFile(fileid, $9C, @Self.FData[0])
    503503  else
    504     OniDataConnection.LoadRawFile(fileid, $A0, @Self.FData[0]);
     504    connection.LoadRawFile(fileid, $A0, @Self.FData[0]);
    505505
    506506  Self.FDataType := [DT_OniReverted, DT_Oni];
     
    510510
    511511
    512 function TOniImage.LoadFromTXMB(fileid: LongWord): Boolean;
     512function TOniImage.LoadFromTXMB(connection: TOniData; fileid: LongWord): Boolean;
    513513var
    514514  i, x, y, x2, y2, pixelid, imgid: LongWord;
     
    519519  x_start, y_start: LongWord;
    520520begin
    521   OniDataConnection.LoadDatFilePart(fileid, $10, SizeOf(Self.FWidth), @Self.FWidth);
    522   OniDataConnection.LoadDatFilePart(fileid, $12, SizeOf(Self.FHeight), @Self.FHeight);
    523   OniDataConnection.LoadDatFilePart(fileid, $18, SizeOf(cols), @cols);
    524   OniDataConnection.LoadDatFilePart(fileid, $1A, SizeOf(rows), @rows);
    525   OniDataConnection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
     521  connection.LoadDatFilePart(fileid, $10, SizeOf(Self.FWidth), @Self.FWidth);
     522  connection.LoadDatFilePart(fileid, $12, SizeOf(Self.FHeight), @Self.FHeight);
     523  connection.LoadDatFilePart(fileid, $18, SizeOf(cols), @cols);
     524  connection.LoadDatFilePart(fileid, $1A, SizeOf(rows), @rows);
     525  connection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
    526526  SetLength(images_decoded, linkcount);
    527527  for i := 0 to linkcount - 1 do
    528528  begin
    529     OniDataConnection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
     529    connection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
    530530    link := link div 256;
    531531    images_decoded[i] := TOniImage.Create;
    532     images_decoded[i].LoadFromTXMP(link);
     532    images_decoded[i].LoadFromTXMP(connection, link);
    533533    images_decoded[i].DecodeImage;
    534534    images_decoded[i].RevertImage;
  • oup/current/Data.pas

    r79 r86  
    6868  end;
    6969
    70   TExportHandlers = record
    71     Ext:     String[4];
    72     needed:  Boolean;
    73     Handler: function(fileid: LongWord; filename: String): Integer;
    74   end;
    75 
    7670  TStringArray = array of String;
    7771  TExtList     = array of record
  • oup/current/Helper_LevelDB.pas

    r85 r86  
    7979  levelid:  LongWord;
    8080  timeformat: TFormatSettings;
     81
     82  conIndex: Integer;
     83  connection: TOniData;
    8184const
    8285  steps: Byte = 3;
     
    105108  timeformat.TimeSeparator := ':';
    106109
    107   if not CreateDataConnection(Source, ODB_ADB) then
     110  if CreateDataConnection(Source, ODB_ADB) = nil then
    108111  begin
    109112    ShowMessage('Could not connect to .oldb-file');
     
    208211                ((Data[$88] and $01) > 0) then
    209212              begin
    210                 OniImage.LoadFromTXMP(i);
     213                OniImage.LoadFromTXMP(Connection, i);
    211214                OniImage.GetMipMappedImage(rawdata);
    212215                rawlist[j].raw_size := OniImage.GetImageDataSize(True);
     
    310313  converting := False;
    311314
    312   CloseDataConnection;
     315  CloseDataConnection(DataConnections[conIndex]);
    313316end;
    314317
     
    345348  fileinfo: TFileInfo;
    346349  timeformat: TFormatSettings;
     350
     351  conIndex: Integer;
    347352const
    348353  steps: Byte = 4;
     
    362367
    363368begin
    364   if not CreateDataConnection(Source, ODB_Dat) then
     369  if CreateDataConnection(Source, ODB_Dat) = nil then
    365370  begin
    366371    ShowMessage('Could not connect to .dat-file');
     
    564569  database.Free;
    565570
    566   CloseDataConnection;
     571  CloseDataConnection(DataConnections[conIndex]);
    567572end;
    568573
  • oup/current/Main.dfm

    r83 r86  
    913913    Top = 176
    914914    Bitmap = {
    915       494C010102000400040010001000FFFFFFFFFF00FFFFFFFFFFFFFFFF424D3600
     915      494C010102000400040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
    916916      0000000000003600000028000000400000001000000001002000000000000010
    917917      0000000000000000000000000000000000000000000000000000000000000000
     
    10491049      8001800100000000800180010000000080018001000000008001800100000000
    10501050      8001800100000000800180010000000080018001000000008001800100000000
    1051       C003C00300000000FFFFFFFF00000000}
     1051      C003C00300000000FFFFFFFF0000000000000000000000000000000000000000
     1052      000000000000}
    10521053  end
    10531054end
  • oup/current/Main.pas

    r84 r86  
    7575    tb_opendb: TTBItem;
    7676    Images_Close: TImageList;
     77    procedure UpdateConLists;
    7778    procedure LoadFile(typedb: Boolean);
    7879    function TryCloseAll: Boolean;
     
    154155  else if MidStr(ParamStr(1), 1, 4) = 'oldb' then
    155156  begin
    156     if not CreateDataConnection(ParamStr(2), ODB_ADB) then
     157    if CreateDataConnection(ParamStr(2), ODB_ADB) = nil then
    157158      ShowMessage('Error while loading the file:' + CrLf + ParamStr(
    158159        2) + CrLf + 'Perhaps not an OniUnPacker-LevelDatabase-file?');
     
    160161  else if MidStr(ParamStr(1), 1, 3) = 'dat' then
    161162  begin
    162     if not CreateDataConnection(ParamStr(2), ODB_Dat) then
     163    if CreateDataConnection(ParamStr(2), ODB_Dat) = nil then
    163164      ShowMessage('Error while loading the file:' + CrLf + ParamStr(
    164165        2) + CrLf + 'Perhaps not an Oni-.dat-file?');
     
    263264  pt.Y := Y;
    264265  tabIndex := MDITab.GetTabAtPos(pt);
    265   if (Button = mbRight) and (tabIndex >= 0) then
    266     MDITab.MDIChildren[tabIndex].Close;
     266
     267//  if (Button = mbRight) and (tabIndex >= 0) then
     268//    MDITab.MDIChildren[tabIndex].Close;
    267269
    268270  if (Button = mbLeft) and (tabIndex >= 0) then
     
    309311procedure TForm_Main.UpdateStatBar;
    310312begin
    311   if Assigned(OniDataConnection) then
    312   begin
    313     Self.Caption      := 'Oni Un/Packer ' + version + ' (' + ExtractFileName(
    314       OniDataConnection.FileName) + ')';
     313  if Length(DataConnections) > 0 then
     314  begin
     315    Self.Caption      := 'Oni Un/Packer ' + version;
    315316    ActivateTools(True);
    316     statbar.Panels.Items[1].Text := 'Files: ' + IntToStr(OniDataConnection.GetFilesCount);
    317     statbar.Panels.Items[2].Text :=
    318       'Extensions: ' + IntToStr(Length(OniDataConnection.GetExtensionsList));
    319     case OniDataConnection.Backend of
    320       ODB_Dat:
    321         begin
    322           statbar.Panels.Items[0].Text := '.dat loaded: ' + OniDataConnection.FileName;
    323         end;
    324       ODB_ADB:
    325         begin
    326           statbar.Panels.Items[0].Text := 'OLDB loaded: ' + OniDataConnection.FileName;
    327         end;
    328     else
    329       Self.Caption      := 'Oni Un/Packer ' + version;
    330       statbar.Panels.Items[0].Text := 'Nothing loaded';
    331       statbar.Panels.Items[1].Text := 'Files: -';
    332       statbar.Panels.Items[2].Text := 'Extensions: -';
    333       ActivateTools(False);
    334     end;
     317    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections));
    335318  end
    336319  else
     
    380363
    381364
     365procedure TForm_Main.UpdateConLists;
     366var
     367  i: Integer;
     368begin
     369  for i := 0 to MDITab.MDIChildCount - 1 do
     370    if MDITab.MDIChildren[i] is TForm_ToolTemplate then
     371      TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateList;
     372end;
     373
    382374
    383375procedure TForm_Main.LoadFile(typedb: Boolean);
     
    385377  ext: String;
    386378begin
    387   if TryCloseAll then
    388   begin
    389     CloseDataConnection;
    390     opend.InitialDir := AppSettings.DatPath;
    391     opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
    392     if typedb then
    393       opend.FilterIndex := 3
    394     else
    395       opend.FilterIndex := 2;
    396     if opend.Execute then
     379  opend.InitialDir := AppSettings.DatPath;
     380  opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
     381  if typedb then
     382    opend.FilterIndex := 3
     383  else
     384    opend.FilterIndex := 2;
     385  if opend.Execute then
     386  begin
     387    ext := ExtractFileExt(opend.FileName);
     388    if ext = '.dat' then
    397389    begin
    398       ext := ExtractFileExt(opend.FileName);
    399       if ext = '.dat' then
    400       begin
    401         if not CreateDataConnection(opend.FileName, ODB_Dat) then
    402           ShowMessage('Error while loading the file:' + CrLf + opend.FileName +
    403             CrLf + 'Perhaps not an Oni-.dat-file?');
    404       end else if ext = '.oldb' then
    405       begin
    406         if not CreateDataConnection(opend.FileName, ODB_ADB) then
    407           ShowMessage('Error while loading the file:' + CrLf + opend.FileName +
    408             CrLf + 'Perhaps not an OniUnPacker-LevelDatabase-file?');
    409       end else
    410         ShowMessage('Incompatible file');
    411       AppSettings.DatPath := ExtractFilepath(opend.FileName);
    412     end;
     390      if CreateDataConnection(opend.FileName, ODB_Dat) <> nil then
     391        UpdateConLists;
     392    end else if ext = '.oldb' then
     393    begin
     394      if CreateDataConnection(opend.FileName, ODB_ADB) <> nil then
     395        UpdateConLists;
     396    end else
     397      ShowMessage('Incompatible file');
     398    AppSettings.DatPath := ExtractFilepath(opend.FileName);
    413399  end;
    414400  UpdateStatBar;
     
    451437procedure TForm_Main.menu_createdbClick(Sender: TObject);
    452438begin
    453   if Assigned(OniDataConnection) then
     439{  if Assigned(OniDataConnection) then
    454440    if MessageBox(Self.Handle, PChar('You have currently opened a level-file. ' +
    455441          'Do you want to close it to continue?'), PChar('Close file?'),
     
    470456    if saved.Execute then
    471457      Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
    472 end;
     458}end;
    473459
    474460
     
    477463procedure TForm_Main.menu_createlvlClick(Sender: TObject);
    478464begin
    479   if Assigned(OniDataConnection) then
     465{  if Assigned(OniDataConnection) then
    480466    if MessageBox(Self.Handle, PChar('You have currently opened a level-file. ' +
    481467          'Do you want to close it to continue?'), PChar('Close file?'),
     
    496482    if saved.Execute then
    497483      Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
    498 end;
     484}end;
    499485
    500486 {#################################}
  • oup/current/Tools/Extractor.dfm

    r74 r86  
    22  Caption = 'Extractor'
    33  ClientHeight = 491
    4   ExplicitWidth = 500
    54  ExplicitHeight = 518
    65  PixelsPerInch = 96
     
    2221    inherited filelist: TListBox
    2322      Width = 333
    24       Height = 362
     23      Height = 338
     24      ExplicitTop = 153
    2525      ExplicitWidth = 333
    26       ExplicitHeight = 362
     26      ExplicitHeight = 338
    2727    end
    2828    inherited panel_extension: TPanel
  • oup/current/Tools/Extractor.pas

    r74 r86  
    108108      filename := GetWinFilename(filelist.Items.Strings[i]);
    109109      if check_dat.Checked then
    110         ExportDatFile(fileid, path + filename);
     110        ExportDatFile(Connection, fileid, path + filename);
    111111      if check_raw.Checked then
    112         ExportRawFiles(fileid, path + filename);
     112        ExportRawFiles(Connection, fileid, path + filename);
    113113      if check_convert.Checked then
    114         ExportConverted(fileid, path + filename);
     114        ExportConverted(Connection, fileid, path + filename);
    115115      Inc(done);
    116116    end;
  • oup/current/Tools/Preview.pas

    r46 r86  
    8080begin
    8181  OniImage := TOniImage.Create;
    82   OniImage.Load(fileid);
     82  OniImage.Load(Connection, fileid);
    8383  Data := OniImage.GetAsBMP;
    8484  OniImage.Free;
     
    137137  i:    Byte;
    138138begin
    139   OniDataConnection.LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
    140   OniDataConnection.LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
     139  Connection.LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
     140  Connection.LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
    141141  SetBitmapCount(linkcount);
    142142  for i := 0 to linkcount - 1 do
    143143  begin
    144     OniDataConnection.LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
     144    Connection.LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
    145145    link := link div 256;
    146146    if link = 0 then
     
    180180  else
    181181    actualimg := High(bitmaps);
    182   Self.Caption := 'Preview ' + OniDataConnection.GetFileInfo(_fileid).FileName +
     182  Self.Caption := 'Preview ' + Connection.GetFileInfo(_fileid).FileName +
    183183    ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
    184184  DrawImage(actualimg);
     
    192192  else
    193193    actualimg := 0;
    194   Self.Caption := 'Preview ' + OniDataConnection.GetFileInfo(_fileid).FileName +
     194  Self.Caption := 'Preview ' + Connection.GetFileInfo(_fileid).FileName +
    195195    ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
    196196  DrawImage(actualimg);
  • oup/current/Tools/Template.dfm

    r58 r86  
    4343    object filelist: TListBox
    4444      Left = 0
    45       Top = 129
     45      Top = 153
    4646      Width = 200
    47       Height = 294
     47      Height = 270
    4848      Align = alClient
    4949      ItemHeight = 13
     
    5252      OnClick = listClick
    5353      OnMouseDown = listMouseDown
     54      ExplicitTop = 129
     55      ExplicitHeight = 294
    5456    end
    5557    object panel_extension: TPanel
     
    5759      Top = 0
    5860      Width = 200
    59       Height = 129
     61      Height = 153
    6062      Align = alTop
    6163      BevelOuter = bvNone
     
    6365      DesignSize = (
    6466        200
    65         129)
     67        153)
    6668      object Label2: TLabel
    6769        Left = 100
    68         Top = 105
     70        Top = 129
    6971        Width = 17
    7072        Height = 18
     
    8082      object Label1: TLabel
    8183        Left = 47
    82         Top = 105
     84        Top = 129
    8385        Width = 17
    8486        Height = 18
     
    9496      object label_ext: TLabel
    9597        Left = 2
    96         Top = 62
     98        Top = 86
    9799        Width = 100
    98100        Height = 17
     
    103105      object btn_sort_id_asc: TSpeedButton
    104106        Left = 3
    105         Top = 101
     107        Top = 125
    106108        Width = 20
    107109        Height = 22
     
    124126      object btn_sort_id_desc: TSpeedButton
    125127        Left = 23
    126         Top = 101
     128        Top = 125
    127129        Width = 20
    128130        Height = 22
     
    144146      object btn_sort_name_asc: TSpeedButton
    145147        Left = 58
    146         Top = 101
     148        Top = 125
    147149        Width = 20
    148150        Height = 22
     
    164166      object btn_sort_name_desc: TSpeedButton
    165167        Left = 78
    166         Top = 101
     168        Top = 125
    167169        Width = 20
    168170        Height = 22
     
    184186      object btn_sort_ext_asc: TSpeedButton
    185187        Left = 108
    186         Top = 101
     188        Top = 125
    187189        Width = 20
    188190        Height = 22
     
    204206      object btn_sort_ext_desc: TSpeedButton
    205207        Left = 128
    206         Top = 101
     208        Top = 125
    207209        Width = 20
    208210        Height = 22
     
    222224        OnClick = btn_sortClick
    223225      end
     226      object Label3: TLabel
     227        Left = 3
     228        Top = 6
     229        Width = 61
     230        Height = 13
     231        Caption = 'Connection: '
     232      end
     233      object Bevel1: TBevel
     234        Left = 0
     235        Top = 25
     236        Width = 199
     237        Height = 3
     238        Anchors = [akLeft, akTop, akRight]
     239        Style = bsRaised
     240      end
    224241      object combo_extension: TComboBox
    225242        Left = 2
    226         Top = 76
    227         Width = 192
     243        Top = 100
     244        Width = 196
    228245        Height = 21
    229246        Style = csDropDownList
     
    243260      object check_zerobyte: TCheckBox
    244261        Left = 2
    245         Top = 44
     262        Top = 68
    246263        Width = 130
    247264        Height = 13
     
    252269      object edit_filtername: TEdit
    253270        Left = 2
    254         Top = 20
    255         Width = 192
     271        Top = 44
     272        Width = 196
    256273        Height = 18
    257274        Anchors = [akLeft, akTop, akRight]
     
    261278      object check_filtername: TCheckBox
    262279        Left = 2
    263         Top = 5
     280        Top = 29
    264281        Width = 130
    265282        Height = 15
     
    267284        TabOrder = 0
    268285        OnClick = check_filternameClick
     286      end
     287      object combo_connection: TComboBox
     288        Left = 64
     289        Top = 3
     290        Width = 134
     291        Height = 21
     292        Style = csDropDownList
     293        Anchors = [akLeft, akTop, akRight]
     294        ItemHeight = 13
     295        TabOrder = 4
     296        OnChange = combo_connectionChange
    269297      end
    270298    end
  • oup/current/Tools/Template.pas

    r83 r86  
    1010type
    1111  TNewFileSelectedEvent = procedure(fileinfo: TFileInfo) of object;
     12  TNewConnectionEvent = procedure(connection: TOniData) of object;
    1213
    1314  TForm_ToolTemplate = class(TForm)
     
    3637    Label1: TLabel;
    3738    Label2: TLabel;
     39    Label3: TLabel;
     40    combo_connection: TComboBox;
     41    Bevel1: TBevel;
    3842    procedure RecreateList;
     43    procedure UpdateList;
     44    procedure RecreateExtList;
    3945    procedure LoadFileNames;
    4046    procedure SelectFileName(filename: String);
     
    5662    procedure btn_sortClick(Sender: TObject);
    5763    procedure FormActivate(Sender: TObject);
     64    procedure combo_connectionChange(Sender: TObject);
    5865  private
    5966    FSortBy: TSortType;
    6067    FOnNewFileSelected: TNewFileSelectedEvent;
     68    FOnNewConnection: TNewConnectionEvent;
    6169    FAllowedExts: String;
    6270    FAllowMultiSelect: Boolean;
    6371    FSelectedFile: TFileInfo;
     72    FConnection: TOniData;
    6473    procedure SetAllowedExts(exts: String);
    6574    procedure SetMultiSelect(allow: Boolean);
     
    6978  published
    7079    property OnNewFileSelected: TNewFileSelectedEvent read FOnNewFileSelected write FOnNewFileSelected;
     80    property OnNewConnection: TNewConnectionEvent read FOnNewConnection write FOnNewConnection;
    7181    property AllowedExts: String read FAllowedExts write SetAllowedExts;
    7282    property AllowMultiSelect: Boolean read FAllowMultiSelect write SetMultiSelect;
    7383    property SelectedFile: TFileInfo read FSelectedFile;
     84    property Connection: TOniData read FConnection;
    7485  end;
    7586
     
    8394
    8495
     96procedure TForm_ToolTemplate.UpdateList;
     97var
     98  i: Integer;
     99  fn, datatype, boxstring: String;
     100  level: Integer;
     101  oldcon: String;
     102begin
     103  oldcon := combo_connection.Items.Strings[combo_connection.ItemIndex];
     104  combo_connection.Items.Clear;
     105  for i := 0 to High(DataConnections) do
     106  begin
     107    level := DataConnections[i].LevelInfo.LevelNumber;
     108    fn := ExtractFileName(DataConnections[i].FileName);
     109    if DataConnections[i].Backend = ODB_Dat then
     110      datatype := 'ONI-.dat: '
     111    else if DataConnections[i].Backend = ODB_ADB then
     112      datatype := 'OUP-DB: '
     113    else
     114      datatype := 'Unknown: ';
     115    boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
     116    combo_connection.Items.Add(boxstring);
     117    if oldcon = boxstring then
     118      combo_connection.ItemIndex := combo_connection.Items.Count - 1;
     119  end;
     120end;
     121
    85122procedure TForm_ToolTemplate.RecreateList;
     123var
     124  i: Integer;
     125  fn, datatype: String;
     126  level: Integer;
     127begin
     128  combo_connection.Items.Clear;
     129  for i := 0 to High(DataConnections) do
     130  begin
     131    level := DataConnections[i].LevelInfo.LevelNumber;
     132    fn := ExtractFileName(DataConnections[i].FileName);
     133    if DataConnections[i].Backend = ODB_Dat then
     134      datatype := 'ONI-.dat: '
     135    else if DataConnections[i].Backend = ODB_ADB then
     136      datatype := 'OUP-DB: '
     137    else
     138      datatype := 'Unknown: ';
     139    combo_connection.Items.Add(datatype + fn + ' (Level: ' + IntToStr(level) + ')');
     140  end;
     141  FConnection := DataConnections[0];
     142  combo_connection.ItemIndex := 0;
     143  combo_connectionChange(Self);
     144end;
     145
     146procedure TForm_ToolTemplate.RecreateExtList;
    86147var
    87148  i:    LongWord;
     
    90151  combo_extension.Items.Clear;
    91152  combo_extension.Items.Add('_All files_ (' +
    92     IntToStr(OniDataConnection.GetFilesCount) + ')');
    93   exts := OniDataConnection.GetExtensionsList;
     153    IntToStr(FConnection.GetFilesCount) + ')');
     154  exts := FConnection.GetExtensionsList;
    94155  for i := 0 to High(exts) do
    95156    if Length(FAllowedExts) > 0 then
     
    127188      Extension := '';
    128189
    129   files := OniDataConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
     190  files := FConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
    130191
    131192  filelist.Visible := False;
     
    143204  ext: String;
    144205begin
    145   id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
     206  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
    146207  ext := RightStr(filelist.Items.Strings[filelist.ItemIndex], 4);
    147208  exportd.Filter := 'Files of matching extension (*.' + ext + ')|*.' + ext + '|All files|*.*';
    148209  exportd.DefaultExt := ext;
    149210  if exportd.Execute then
    150     ExportDatFile(id, exportd.FileName);
     211    ExportDatFile(FConnection, id, exportd.FileName);
    151212end;
    152213
     
    158219  data: TData;
    159220begin
    160   id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
    161   finfo := OniDataConnection.GetFileInfo(id);
     221  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
     222  finfo := FConnection.GetFileInfo(id);
    162223
    163224  importd.Filter := 'Files of matching extension (*.' + finfo.Extension + ')|*.' +
     
    174235      SetLength(data, fs.Size);
    175236      fs.Read(data[0], fs.Size);
    176       OniDataConnection.UpdateDatFile(id, data);
     237      FConnection.UpdateDatFile(id, data);
    177238      Self.listClick(Self);
    178239    end;
     
    187248begin
    188249  sender_name := TComponent(Sender).Name;
    189   id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
     250  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
    190251  context := MidStr(sender_name, Pos('_', sender_name) + 1, Length(sender_name) - Pos('_', sender_name));
    191252  Form_Main.open_child(context, id);
    192253end;
    193254
     255procedure TForm_ToolTemplate.combo_connectionChange(Sender: TObject);
     256var
     257  name: String;
     258  nstart, nend: Integer;
     259  i: Integer;
     260begin
     261  if combo_connection.ItemIndex >= 0 then
     262  begin
     263    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
     264    nstart := Pos(' ', name) + 1;
     265    nend := Pos('(', name) - 1;
     266    name := MidStr(name, nstart, nend - nstart);
     267
     268    for i := 0 to High(DataConnections) do
     269    begin
     270      if ExtractFileName(DataConnections[i].FileName) = name then
     271      begin
     272        FConnection := DataConnections[i];
     273        Break;
     274      end;
     275    end;
     276    if i = Length(DataConnections) then
     277      FConnection := nil;
     278
     279    RecreateExtList;
     280    if Assigned(FOnNewConnection) then
     281      FOnNewConnection(FConnection);
     282  end;
     283end;
     284
    194285procedure TForm_ToolTemplate.combo_extensionClick(Sender: TObject);
    195286begin
     
    205296  inherited;
    206297  RecreateList;
     298  FConnection := nil;
    207299  FSelectedFile.ID := -1;
    208300  FSelectedFile.FileName := '';
     
    270362  if filelist.ItemIndex > -1 then
    271363  begin
    272     fileid := OniDataConnection.ExtractFileID(
     364    fileid := FConnection.ExtractFileID(
    273365          filelist.Items.Strings[filelist.ItemIndex]);
    274     FSelectedFile := OniDataConnection.GetFileInfo(fileid);
     366    FSelectedFile := FConnection.GetFileInfo(fileid);
    275367    if Assigned(FOnNewFileSelected) then
    276368      FOnNewFileSelected(FSelectedFile);
     
    298390  if filelist.Items.Count > 0 then
    299391    for i := 0 to filelist.Items.Count - 1 do
    300       if OniDataConnection.ExtractFileID(filelist.Items.Strings[i]) = id then
     392      if FConnection.ExtractFileID(filelist.Items.Strings[i]) = id then
    301393      begin
    302394        filelist.ItemIndex := i;
     
    321413begin
    322414  FAllowedExts := exts;
    323   RecreateList;
     415  RecreateExtList;
    324416end;
    325417
     
    368460  Self.Height := 300;
    369461  FOnNewFileSelected := nil;
     462  FOnNewConnection := nil;
    370463  FAllowedExts := '';
    371464  FAllowMultiSelect := False;
  • oup/current/Tools/TxmpReplace.dfm

    r46 r86  
    11inherited Form_TxmpReplace: TForm_TxmpReplace
    22  Caption = 'TxmpReplace'
     3  ExplicitWidth = 320
     4  ExplicitHeight = 240
    35  PixelsPerInch = 96
    46  TextHeight = 13
     
    1214    object image_txmppreview: TImage [0]
    1315      Left = 0
    14       Top = 283
     16      Top = 307
    1517      Width = 200
    16       Height = 31
     18      Height = 7
    1719      Align = alClient
    1820      ExplicitTop = 111
     
    2123    object splitter_txmp: TSplitter [1]
    2224      Left = 0
    23       Top = 275
     25      Top = 299
    2426      Width = 200
    2527      Height = 8
     
    3537      Height = 146
    3638      Align = alTop
     39      ExplicitTop = 153
    3740      ExplicitHeight = 146
    3841    end
  • oup/current/Tools/TxmpReplace.pas

    r54 r86  
    5858  check_transparency.Checked := (depthbyte and $04) > 0;
    5959
    60   OniImage_Old.LoadFromTXMP(fileid);
     60  OniImage_Old.LoadFromTXMP(connection, fileid);
    6161  old_size := OniImage_Old.GetImageDataSize((fadingbyte and $01) > 0);
    6262  Data := OniImage_Old.GetAsBMP;
Note: See TracChangeset for help on using the changeset viewer.