Index: oup/current/Code/Exporters.pas
===================================================================
--- oup/current/Code/Exporters.pas	(revision 85)
+++ oup/current/Code/Exporters.pas	(revision 86)
@@ -3,15 +3,22 @@
 interface
 
-uses Classes, Dialogs, StrUtils, SysUtils, Math, Data, OniImgClass;
-
-procedure ExportDatFile(fileid: LongWord; filename: String);
-procedure ExportRawFiles(fileid: LongWord; filename: String);
-procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
-function ExportConverted(fileid: LongWord; filename: String): Integer;
-
-function ExportSNDD(fileid: LongWord; filename: String): Integer;
-function ExportTRAC(fileid: LongWord; filename: String): Integer;
-function ExportTXAN(fileid: LongWord; filename: String): Integer;
-function ExportImage(fileid: LongWord; filename: String): Integer;
+uses Classes, Dialogs, StrUtils, SysUtils, Math, Data, OniImgClass, OniDataClass;
+
+type
+  TExportHandlers = record
+    Ext:     String[4];
+    needed:  Boolean;
+    Handler: function(connection: TOniData; fileid: LongWord; filename: String): Integer;
+  end;
+
+procedure ExportDatFile(connection: TOniData; fileid: LongWord; filename: String);
+procedure ExportRawFiles(connection: TOniData; fileid: LongWord; filename: String);
+procedure ExportRawFile(connection: TOniData; fileid: LongWord; dat_offset: LongWord; filename: String);
+function ExportConverted(connection: TOniData; fileid: LongWord; filename: String): Integer;
+
+function ExportSNDD(connection: TOniData; fileid: LongWord; filename: String): Integer;
+function ExportTRAC(connection: TOniData; fileid: LongWord; filename: String): Integer;
+function ExportTXAN(connection: TOniData; fileid: LongWord; filename: String): Integer;
+function ExportImage(connection: TOniData; fileid: LongWord; filename: String): Integer;
 
 var
@@ -30,14 +37,14 @@
 implementation
 
-uses Functions, DataStructures, OniDataClass;
-
-
-
-procedure ExportDatFile(fileid: LongWord; filename: String);
+uses Functions, DataStructures;
+
+
+
+procedure ExportDatFile(connection: TOniData; fileid: LongWord; filename: String);
 var
   filestream: TFileStream;
   Data: Tdata;
 begin
-  Data := OniDataConnection.LoadDatFile(fileid);
+  Data := connection.LoadDatFile(fileid);
   if FileExists(filename) then
   begin
@@ -54,22 +61,22 @@
 
 
-procedure ExportRawFiles(fileid: LongWord; filename: String);
+procedure ExportRawFiles(connection: TOniData; fileid: LongWord; filename: String);
 var
   i: Integer;
   rawlist: TRawList;
 begin
-  rawlist := OniDataConnection.GetRawList(fileid);
+  rawlist := connection.GetRawList(fileid);
   if Length(rawlist) > 0 then
     for i := 0 to High(rawlist) do
-      ExportRawFile(fileid, rawlist[i].src_offset, filename);
-end;
-
-procedure ExportRawFile(fileid: LongWord; dat_offset: LongWord; filename: String);
+      ExportRawFile(connection, fileid, rawlist[i].src_offset, filename);
+end;
+
+procedure ExportRawFile(connection: TOniData; fileid: LongWord; dat_offset: LongWord; filename: String);
 var
   filestream: TFileStream;
   Data: Tdata;
 begin
-  SetLength(Data, OniDataConnection.GetRawInfo(fileid, dat_offset).raw_size);
-  OniDataConnection.LoadRawFile(fileid, dat_offset, @Data[0]);
+  SetLength(Data, connection.GetRawInfo(fileid, dat_offset).raw_size);
+  connection.LoadRawFile(fileid, dat_offset, @Data[0]);
   if FileExists(filename + '.raw0x' + IntToHex(dat_offset, 8)) then
   begin
@@ -86,14 +93,14 @@
 end;
 
-function ExportConverted(fileid: LongWord; filename: String): Integer;
+function ExportConverted(connection: TOniData; fileid: LongWord; filename: String): Integer;
 var
   i: Integer;
   fileinfo: TFileInfo;
 begin
-  fileinfo := OniDataConnection.GetFileInfo(fileid);
+  fileinfo := connection.GetFileInfo(fileid);
   if Length(ExportHandlers) > 0 then
     for i := 0 to High(ExportHandlers) do
       if ExportHandlers[i].Ext = fileinfo.Extension then
-        ExportHandlers[i].Handler(fileid, filename);
+        ExportHandlers[i].Handler(connection, fileid, filename);
 end;
 
@@ -142,5 +149,5 @@
 begin
   Result := export_noerror;
-  OniDataConnection.LoadDatFilePart(fileid, 0, SizeOf(DatData), @DatData);
+  connection.LoadDatFilePart(fileid, 0, SizeOf(DatData), @DatData);
   with DatData do
   begin
@@ -154,5 +161,5 @@
     WAVE_DataLen := RAWSize;
     SetLength(Data, RAWSize);
-    OniDataConnection.LoadRawFile(fileid, $44, Data);
+    connection.LoadRawFile(fileid, $44, Data);
 
     //Now start packing this into a neat wave...
@@ -192,11 +199,11 @@
   Result := export_noerror;
 
-  OniDataConnection.LoadDatFilePart(fileid, $18, SizeOf(link), @link);
+  connection.LoadDatFilePart(fileid, $18, SizeOf(link), @link);
   link := link div 256;
 
-  OniDataConnection.LoadDatFilePart(fileid, $1E, SizeOf(linkcount), @linkcount);
+  connection.LoadDatFilePart(fileid, $1E, SizeOf(linkcount), @linkcount);
   for i := 1 to linkcount do
   begin
-    OniDataConnection.LoadDatFilePart(fileid, $20 + (i - 1) * 12 + 8, SizeOf(link), @link);
+    connection.LoadDatFilePart(fileid, $20 + (i - 1) * 12 + 8, SizeOf(link), @link);
     link := link div 256;
   end;
@@ -215,11 +222,11 @@
   Result := export_noerror;
 
-  OniDataConnection.LoadDatFilePart(fileid, $14, SizeOf(loop_speed), @loop_speed);
-  OniDataConnection.LoadDatFilePart(fileid, $16, SizeOf(unknown), @unknown);
-
-  OniDataConnection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
+  connection.LoadDatFilePart(fileid, $14, SizeOf(loop_speed), @loop_speed);
+  connection.LoadDatFilePart(fileid, $16, SizeOf(unknown), @unknown);
+
+  connection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
   for i := 0 to linkcount - 1 do
   begin
-    OniDataConnection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
+    connection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
     link := link div 256;
     if link = 0 then
@@ -240,5 +247,5 @@
 
   img := TOniImage.Create;
-  img.Load(fileid);
+  img.Load(connection, fileid);
   data := img.GetAsBMP;
   img.Free;
Index: oup/current/Code/Functions.pas
===================================================================
--- oup/current/Code/Functions.pas	(revision 85)
+++ oup/current/Code/Functions.pas	(revision 86)
@@ -21,5 +21,5 @@
 function DecodeHexString(hex: String): Tdata;
 function GetWinFileName(Name: String): String;
-function GetExtractPath: String;
+//function GetExtractPath: String;
 
 function Explode(_string: String; delimiter: Char): TStringArray;
@@ -352,11 +352,11 @@
 
 
-
+{
 function GetExtractPath: String;
 begin
-  Result := ExtractFilePath(OniDataConnection.FileName) + '\extracted_' +
-    ExtractFileName(OniDataConnection.Filename);
-end;
-
+  Result := ExtractFilePath(DataConnections[i].FileName) + '\extracted_' +
+    ExtractFileName(DataConnections[i].Filename);
+end;
+}
 
 end.
Index: oup/current/Code/OniDataClass.pas
===================================================================
--- oup/current/Code/OniDataClass.pas	(revision 85)
+++ oup/current/Code/OniDataClass.pas	(revision 86)
@@ -136,4 +136,36 @@
   end;
 
+  TOniDataEmpty = class(TOniData)
+  private
+  protected
+  public
+    constructor Create(OLDBFilename: String; var Result: Boolean); override;
+    procedure Close; override;
+{
+    procedure UpdateListCache;
+    //      function GetDatLinks(srcid:LongWord):TDatLinks;
+    function GetFileInfo(fileid: LongWord): TFileInfo; override;
+    function GetFilesList(ext: String; pattern: String;
+      NoEmptyFiles: Boolean; sort: TSortType): TStringArray; override;
+    function GetFilesCount: LongWord; override;
+    function GetExtensionsList: TStringArray; override;
+    function GetExtendedExtensionsList: TExtensionsMap; override;
+    function GetNamedFilesMap: TNamedFilesMap;
+
+    function LoadDatFile(fileid: LongWord): Tdata; override;
+    procedure UpdateDatFile(fileid: LongWord; Data: Tdata); override;
+    procedure LoadDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
+    procedure UpdateDatFilePart(fileid, offset, size: LongWord; target: Pointer); override;
+
+    function GetRawList(fileid: LongWord): TRawList; override;
+    procedure LoadRawFile(fileid, dat_offset: LongWord; target: Pointer); override;
+    procedure UpdateRawFile(fileid, dat_offset: LongWord; size: LongWord;
+      target: Pointer); override;
+    procedure LoadRawFilePart(fileid, dat_offset: LongWord;
+      offset, size: LongWord; target: Pointer); override;
+    procedure UpdateRawFilePart(fileid, dat_offset: LongWord;
+      offset, size: LongWord; target: Pointer); override;
+}  published
+  end;
 
 const
@@ -143,8 +175,11 @@
 
 var
+//  OniDataConnection: TOniData;
+  DataConnections: array of TOniData;
   OniDataConnection: TOniData;
 
-function CreateDataConnection(filename: String; backend: Integer): Boolean;
-procedure CloseDataConnection;
+function CreateDataConnection(filename: String; backend: Integer): TOniData;
+procedure CloseDataConnection(connection: TOniData);
+
 
 
@@ -1372,22 +1407,44 @@
 
 
-function CreateDataConnection(filename: String; backend: Integer): Boolean;
+function CreateDataConnection(filename: String; backend: Integer): TOniData;
 var
   answer: Boolean;
-begin
-  if Assigned(OniDataConnection) then
-  begin
-    OniDataConnection.Close;
-    OniDataConnection.Free;
-    OniDataConnection := nil;
-  end;
+  i: Integer;
+begin
+  if Length(DataConnections) > 0 then
+  begin
+    for i := 0 to High(DataConnections) do
+    begin
+      if ExtractFileName(DataConnections[i].FFileName) = ExtractFileName(filename) then
+      begin
+        if DataConnections[i].FFileName <> filename then
+        begin
+          Result := nil;
+          ShowMessage('You can not open two files with the same name at a time.');
+        end
+        else
+          Result := DataConnections[i];
+        Exit;
+      end;
+    end;
+  end;
+
+  if not FileExists(filename) then
+  begin
+    ShowMessage('File "' + filename + '" does not exist!');
+    Result := nil;
+    Exit;
+  end;
+
+  SetLength(DataConnections, Length(DataConnections) + 1);
+  i := High(DataConnections);
   case backend of
     ODB_Dat:
-      OniDataConnection := TOniDataDat.Create(filename, answer);
+      DataConnections[i] := TOniDataDat.Create(filename, answer);
     ODB_ADB:
-      OniDataConnection := TOniDataADB.Create(filename, answer);
+      DataConnections[i] := TOniDataADB.Create(filename, answer);
     else
       ShowMessage('Unknown Backend');
-      Result := False;
+      Result := nil;
       Exit;
   end;
@@ -1395,27 +1452,65 @@
   if answer then
   begin
-    //      ShowMessage('file loaded');
-    //      ShowMessage('Files: '+IntToStr(OniDataConnection.GetFilesCount));
-    Result := True;
+    Result := DataConnections[i];
+//    Result := True;
   end
   else
   begin
     ShowMessage('File not loaded');
-    OniDataConnection.Close;
-    OniDataConnection.Free;
-    Result := False;
-  end;
-end;
-
-
-
-
-procedure CloseDataConnection;
-begin
-  if Assigned(OniDataConnection) then
-  begin
-    OniDataConnection.Close;
-    OniDataConnection := nil;
-  end;
+    DataConnections[i].Close;
+    DataConnections[i].Free;
+    DataConnections[i] := nil;
+    SetLength(DataConnections, Length(DataConnections) - 1);
+    Result := nil;
+  end;
+end;
+
+
+
+
+procedure CloseDataConnection(connection: TOniData);
+var
+  i: Integer;
+  found: Boolean;
+begin
+  if Assigned(connection) then
+  begin
+    found := False;
+    for i := 0 to High(DataConnections) do
+    begin
+      if not found then
+      begin
+        if DataConnections[i] = connection then
+        begin
+          DataConnections[i].Close;
+          DataConnections[i].Free;
+          DataConnections[i] := nil;
+          found := True;
+        end;
+      end
+      else
+      begin
+        DataConnections[i - 1] := DataConnections[i];
+      end;
+    end;
+    if found then
+      SetLength(DataConnections, Length(DataConnections) - 1);
+  end;
+end;
+
+
+
+
+constructor TOniDataEmpty.Create(OLDBFilename: String; var Result: Boolean);
+var
+  i, j:  Byte;
+  temps: String;
+begin
+  ShowMessage('OLD');
+end;
+
+procedure TOniDataEmpty.Close;
+begin
+  ShowMessage('OLD');
 end;
 
Index: oup/current/Code/OniImgClass.pas
===================================================================
--- oup/current/Code/OniImgClass.pas	(revision 85)
+++ oup/current/Code/OniImgClass.pas	(revision 86)
@@ -33,8 +33,8 @@
 
     constructor Create;
-    function Load(fileid: LongWord): Boolean;
-    function LoadFromPSpc(fileid: LongWord): Boolean;
-    function LoadFromTXMP(fileid: LongWord): Boolean;
-    function LoadFromTXMB(fileid: LongWord): Boolean;
+    function Load(connection: TOniData; fileid: Cardinal): Boolean;
+    function LoadFromPSpc(connection: TOniData; fileid: LongWord): Boolean;
+    function LoadFromTXMP(connection: TOniData; fileid: LongWord): Boolean;
+    function LoadFromTXMB(connection: TOniData; fileid: LongWord): Boolean;
     function GetImageDataSize(fading: Boolean): LongWord;
 
@@ -303,16 +303,16 @@
 
 
-function TOniImage.Load(fileid: LongWord): Boolean;
+function TOniImage.Load(connection: TOniData; fileid: Cardinal): Boolean;
 var
   FileInfo: TFileInfo;
   ext:      String;
 begin
-  FileInfo := OniDataConnection.GetFileInfo(fileid);
+  FileInfo := connection.GetFileInfo(fileid);
   if FileInfo.Extension = 'PSpc' then
-    Result := LoadFromPSpc(fileid)
+    Result := LoadFromPSpc(connection, fileid)
   else if FileInfo.Extension = 'TXMB' then
-    Result := LoadFromTXMB(fileid)
+    Result := LoadFromTXMB(connection, fileid)
   else if FileInfo.Extension = 'TXMP' then
-    Result := LoadFromTXMP(fileid)
+    Result := LoadFromTXMP(connection, fileid)
   else
     Result := False;
@@ -322,5 +322,5 @@
 
 
-function TOniImage.LoadFromPSpc(fileid: LongWord): Boolean;
+function TOniImage.LoadFromPSpc(connection: TOniData; fileid: LongWord): Boolean;
 type
   TPoint = packed record
@@ -357,5 +357,5 @@
   col, row: Byte;
 begin
-  OniDataConnection.LoadDatFilePart(fileid, $08, SizeOf(PSpc), @PSpc);
+  connection.LoadDatFilePart(fileid, $08, SizeOf(PSpc), @PSpc);
   PSpc.TXMP := PSpc.TXMP div 256;
   if PSpc.TXMP = 0 then
@@ -365,5 +365,5 @@
   end;
   txmpimg := TOniImage.Create;
-  txmpimg.LoadFromTXMP(PSpc.TXMP);
+  txmpimg.LoadFromTXMP(connection, PSpc.TXMP);
   txmpimg.DecodeImage;
   txmpimg.WriteToBMP('C:\file.bmp');
@@ -464,17 +464,17 @@
 
 
-function TOniImage.LoadFromTXMP(fileid: LongWord): Boolean;
+function TOniImage.LoadFromTXMP(connection: TOniData; fileid: LongWord): Boolean;
 var
   img_addr: LongWord;
 begin
   Result := True;
-  OniDataConnection.LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth);
-  OniDataConnection.LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight);
-  OniDataConnection.LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType),
+  connection.LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth);
+  connection.LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight);
+  connection.LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType),
     @Self.FStoreType);
-  if not OniDataConnection.OSisMac then
-    OniDataConnection.LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr)
+  if not connection.OSisMac then
+    connection.LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr)
   else
-    OniDataConnection.LoadDatFilePart(fileid, $A0, SizeOf(img_addr), @img_addr);
+    connection.LoadDatFilePart(fileid, $A0, SizeOf(img_addr), @img_addr);
 
   case Self.FStoreType of
@@ -499,8 +499,8 @@
   end;
 
-  if not OniDataConnection.OSisMac then
-    OniDataConnection.LoadRawFile(fileid, $9C, @Self.FData[0])
+  if not connection.OSisMac then
+    connection.LoadRawFile(fileid, $9C, @Self.FData[0])
   else
-    OniDataConnection.LoadRawFile(fileid, $A0, @Self.FData[0]);
+    connection.LoadRawFile(fileid, $A0, @Self.FData[0]);
 
   Self.FDataType := [DT_OniReverted, DT_Oni];
@@ -510,5 +510,5 @@
 
 
-function TOniImage.LoadFromTXMB(fileid: LongWord): Boolean;
+function TOniImage.LoadFromTXMB(connection: TOniData; fileid: LongWord): Boolean;
 var
   i, x, y, x2, y2, pixelid, imgid: LongWord;
@@ -519,16 +519,16 @@
   x_start, y_start: LongWord;
 begin
-  OniDataConnection.LoadDatFilePart(fileid, $10, SizeOf(Self.FWidth), @Self.FWidth);
-  OniDataConnection.LoadDatFilePart(fileid, $12, SizeOf(Self.FHeight), @Self.FHeight);
-  OniDataConnection.LoadDatFilePart(fileid, $18, SizeOf(cols), @cols);
-  OniDataConnection.LoadDatFilePart(fileid, $1A, SizeOf(rows), @rows);
-  OniDataConnection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
+  connection.LoadDatFilePart(fileid, $10, SizeOf(Self.FWidth), @Self.FWidth);
+  connection.LoadDatFilePart(fileid, $12, SizeOf(Self.FHeight), @Self.FHeight);
+  connection.LoadDatFilePart(fileid, $18, SizeOf(cols), @cols);
+  connection.LoadDatFilePart(fileid, $1A, SizeOf(rows), @rows);
+  connection.LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
   SetLength(images_decoded, linkcount);
   for i := 0 to linkcount - 1 do
   begin
-    OniDataConnection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
+    connection.LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
     link := link div 256;
     images_decoded[i] := TOniImage.Create;
-    images_decoded[i].LoadFromTXMP(link);
+    images_decoded[i].LoadFromTXMP(connection, link);
     images_decoded[i].DecodeImage;
     images_decoded[i].RevertImage;
Index: oup/current/Data.pas
===================================================================
--- oup/current/Data.pas	(revision 85)
+++ oup/current/Data.pas	(revision 86)
@@ -68,10 +68,4 @@
   end;
 
-  TExportHandlers = record
-    Ext:     String[4];
-    needed:  Boolean;
-    Handler: function(fileid: LongWord; filename: String): Integer;
-  end;
-
   TStringArray = array of String;
   TExtList     = array of record
Index: oup/current/Helper_LevelDB.pas
===================================================================
--- oup/current/Helper_LevelDB.pas	(revision 85)
+++ oup/current/Helper_LevelDB.pas	(revision 86)
@@ -79,4 +79,7 @@
   levelid:  LongWord;
   timeformat: TFormatSettings;
+
+  conIndex: Integer;
+  connection: TOniData;
 const
   steps: Byte = 3;
@@ -105,5 +108,5 @@
   timeformat.TimeSeparator := ':';
 
-  if not CreateDataConnection(Source, ODB_ADB) then
+  if CreateDataConnection(Source, ODB_ADB) = nil then
   begin
     ShowMessage('Could not connect to .oldb-file');
@@ -208,5 +211,5 @@
                 ((Data[$88] and $01) > 0) then
               begin
-                OniImage.LoadFromTXMP(i);
+                OniImage.LoadFromTXMP(Connection, i);
                 OniImage.GetMipMappedImage(rawdata);
                 rawlist[j].raw_size := OniImage.GetImageDataSize(True);
@@ -310,5 +313,5 @@
   converting := False;
 
-  CloseDataConnection;
+  CloseDataConnection(DataConnections[conIndex]);
 end;
 
@@ -345,4 +348,6 @@
   fileinfo: TFileInfo;
   timeformat: TFormatSettings;
+
+  conIndex: Integer;
 const
   steps: Byte = 4;
@@ -362,5 +367,5 @@
 
 begin
-  if not CreateDataConnection(Source, ODB_Dat) then
+  if CreateDataConnection(Source, ODB_Dat) = nil then
   begin
     ShowMessage('Could not connect to .dat-file');
@@ -564,5 +569,5 @@
   database.Free;
 
-  CloseDataConnection;
+  CloseDataConnection(DataConnections[conIndex]);
 end;
 
Index: oup/current/Main.dfm
===================================================================
--- oup/current/Main.dfm	(revision 85)
+++ oup/current/Main.dfm	(revision 86)
@@ -913,5 +913,5 @@
     Top = 176
     Bitmap = {
-      494C010102000400040010001000FFFFFFFFFF00FFFFFFFFFFFFFFFF424D3600
+      494C010102000400040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
       0000000000003600000028000000400000001000000001002000000000000010
       0000000000000000000000000000000000000000000000000000000000000000
@@ -1049,5 +1049,6 @@
       8001800100000000800180010000000080018001000000008001800100000000
       8001800100000000800180010000000080018001000000008001800100000000
-      C003C00300000000FFFFFFFF00000000}
+      C003C00300000000FFFFFFFF0000000000000000000000000000000000000000
+      000000000000}
   end
 end
Index: oup/current/Main.pas
===================================================================
--- oup/current/Main.pas	(revision 85)
+++ oup/current/Main.pas	(revision 86)
@@ -75,4 +75,5 @@
     tb_opendb: TTBItem;
     Images_Close: TImageList;
+    procedure UpdateConLists;
     procedure LoadFile(typedb: Boolean);
     function TryCloseAll: Boolean;
@@ -154,5 +155,5 @@
   else if MidStr(ParamStr(1), 1, 4) = 'oldb' then
   begin
-    if not CreateDataConnection(ParamStr(2), ODB_ADB) then
+    if CreateDataConnection(ParamStr(2), ODB_ADB) = nil then
       ShowMessage('Error while loading the file:' + CrLf + ParamStr(
         2) + CrLf + 'Perhaps not an OniUnPacker-LevelDatabase-file?');
@@ -160,5 +161,5 @@
   else if MidStr(ParamStr(1), 1, 3) = 'dat' then
   begin
-    if not CreateDataConnection(ParamStr(2), ODB_Dat) then
+    if CreateDataConnection(ParamStr(2), ODB_Dat) = nil then
       ShowMessage('Error while loading the file:' + CrLf + ParamStr(
         2) + CrLf + 'Perhaps not an Oni-.dat-file?');
@@ -263,6 +264,7 @@
   pt.Y := Y;
   tabIndex := MDITab.GetTabAtPos(pt);
-  if (Button = mbRight) and (tabIndex >= 0) then
-    MDITab.MDIChildren[tabIndex].Close;
+
+//  if (Button = mbRight) and (tabIndex >= 0) then
+//    MDITab.MDIChildren[tabIndex].Close;
 
   if (Button = mbLeft) and (tabIndex >= 0) then
@@ -309,28 +311,9 @@
 procedure TForm_Main.UpdateStatBar;
 begin
-  if Assigned(OniDataConnection) then
-  begin
-    Self.Caption      := 'Oni Un/Packer ' + version + ' (' + ExtractFileName(
-      OniDataConnection.FileName) + ')';
+  if Length(DataConnections) > 0 then
+  begin
+    Self.Caption      := 'Oni Un/Packer ' + version;
     ActivateTools(True);
-    statbar.Panels.Items[1].Text := 'Files: ' + IntToStr(OniDataConnection.GetFilesCount);
-    statbar.Panels.Items[2].Text :=
-      'Extensions: ' + IntToStr(Length(OniDataConnection.GetExtensionsList));
-    case OniDataConnection.Backend of
-      ODB_Dat:
-        begin
-          statbar.Panels.Items[0].Text := '.dat loaded: ' + OniDataConnection.FileName;
-        end;
-      ODB_ADB:
-        begin
-          statbar.Panels.Items[0].Text := 'OLDB loaded: ' + OniDataConnection.FileName;
-        end;
-    else
-      Self.Caption      := 'Oni Un/Packer ' + version;
-      statbar.Panels.Items[0].Text := 'Nothing loaded';
-      statbar.Panels.Items[1].Text := 'Files: -';
-      statbar.Panels.Items[2].Text := 'Extensions: -';
-      ActivateTools(False);
-    end;
+    statbar.Panels.Items[1].Text := 'Connections: ' + IntToStr(Length(DataConnections));
   end
   else
@@ -380,4 +363,13 @@
 
 
+procedure TForm_Main.UpdateConLists;
+var
+  i: Integer;
+begin
+  for i := 0 to MDITab.MDIChildCount - 1 do
+    if MDITab.MDIChildren[i] is TForm_ToolTemplate then
+      TForm_ToolTemplate(MDITab.MDIChildren[i]).UpdateList;
+end;
+
 
 procedure TForm_Main.LoadFile(typedb: Boolean);
@@ -385,30 +377,24 @@
   ext: String;
 begin
-  if TryCloseAll then
-  begin
-    CloseDataConnection;
-    opend.InitialDir := AppSettings.DatPath;
-    opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
-    if typedb then
-      opend.FilterIndex := 3
-    else
-      opend.FilterIndex := 2;
-    if opend.Execute then
+  opend.InitialDir := AppSettings.DatPath;
+  opend.Filter     := 'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP level database (*.oldb)|*.oldb|Any (*.*)|*';
+  if typedb then
+    opend.FilterIndex := 3
+  else
+    opend.FilterIndex := 2;
+  if opend.Execute then
+  begin
+    ext := ExtractFileExt(opend.FileName);
+    if ext = '.dat' then
     begin
-      ext := ExtractFileExt(opend.FileName);
-      if ext = '.dat' then
-      begin
-        if not CreateDataConnection(opend.FileName, ODB_Dat) then
-          ShowMessage('Error while loading the file:' + CrLf + opend.FileName +
-            CrLf + 'Perhaps not an Oni-.dat-file?');
-      end else if ext = '.oldb' then
-      begin
-        if not CreateDataConnection(opend.FileName, ODB_ADB) then
-          ShowMessage('Error while loading the file:' + CrLf + opend.FileName +
-            CrLf + 'Perhaps not an OniUnPacker-LevelDatabase-file?');
-      end else
-        ShowMessage('Incompatible file');
-      AppSettings.DatPath := ExtractFilepath(opend.FileName);
-    end;
+      if CreateDataConnection(opend.FileName, ODB_Dat) <> nil then
+        UpdateConLists;
+    end else if ext = '.oldb' then
+    begin
+      if CreateDataConnection(opend.FileName, ODB_ADB) <> nil then
+        UpdateConLists;
+    end else
+      ShowMessage('Incompatible file');
+    AppSettings.DatPath := ExtractFilepath(opend.FileName);
   end;
   UpdateStatBar;
@@ -451,5 +437,5 @@
 procedure TForm_Main.menu_createdbClick(Sender: TObject);
 begin
-  if Assigned(OniDataConnection) then
+{  if Assigned(OniDataConnection) then
     if MessageBox(Self.Handle, PChar('You have currently opened a level-file. ' +
           'Do you want to close it to continue?'), PChar('Close file?'),
@@ -470,5 +456,5 @@
     if saved.Execute then
       Form_LevelDB.CreateDatabase(opend.FileName, saved.FileName);
-end;
+}end;
 
 
@@ -477,5 +463,5 @@
 procedure TForm_Main.menu_createlvlClick(Sender: TObject);
 begin
-  if Assigned(OniDataConnection) then
+{  if Assigned(OniDataConnection) then
     if MessageBox(Self.Handle, PChar('You have currently opened a level-file. ' +
           'Do you want to close it to continue?'), PChar('Close file?'),
@@ -496,5 +482,5 @@
     if saved.Execute then
       Form_LevelDB.CreateLevel(opend.FileName, saved.FileName);
-end;
+}end;
 
  {#################################}
Index: oup/current/Tools/Extractor.dfm
===================================================================
--- oup/current/Tools/Extractor.dfm	(revision 85)
+++ oup/current/Tools/Extractor.dfm	(revision 86)
@@ -2,5 +2,4 @@
   Caption = 'Extractor'
   ClientHeight = 491
-  ExplicitWidth = 500
   ExplicitHeight = 518
   PixelsPerInch = 96
@@ -22,7 +21,8 @@
     inherited filelist: TListBox
       Width = 333
-      Height = 362
+      Height = 338
+      ExplicitTop = 153
       ExplicitWidth = 333
-      ExplicitHeight = 362
+      ExplicitHeight = 338
     end
     inherited panel_extension: TPanel
Index: oup/current/Tools/Extractor.pas
===================================================================
--- oup/current/Tools/Extractor.pas	(revision 85)
+++ oup/current/Tools/Extractor.pas	(revision 86)
@@ -108,9 +108,9 @@
       filename := GetWinFilename(filelist.Items.Strings[i]);
       if check_dat.Checked then
-        ExportDatFile(fileid, path + filename);
+        ExportDatFile(Connection, fileid, path + filename);
       if check_raw.Checked then
-        ExportRawFiles(fileid, path + filename);
+        ExportRawFiles(Connection, fileid, path + filename);
       if check_convert.Checked then
-        ExportConverted(fileid, path + filename);
+        ExportConverted(Connection, fileid, path + filename);
       Inc(done);
     end;
Index: oup/current/Tools/Preview.pas
===================================================================
--- oup/current/Tools/Preview.pas	(revision 85)
+++ oup/current/Tools/Preview.pas	(revision 86)
@@ -80,5 +80,5 @@
 begin
   OniImage := TOniImage.Create;
-  OniImage.Load(fileid);
+  OniImage.Load(Connection, fileid);
   Data := OniImage.GetAsBMP;
   OniImage.Free;
@@ -137,10 +137,10 @@
   i:    Byte;
 begin
-  OniDataConnection.LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
-  OniDataConnection.LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
+  Connection.LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
+  Connection.LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
   SetBitmapCount(linkcount);
   for i := 0 to linkcount - 1 do
   begin
-    OniDataConnection.LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
+    Connection.LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
     link := link div 256;
     if link = 0 then
@@ -180,5 +180,5 @@
   else
     actualimg := High(bitmaps);
-  Self.Caption := 'Preview ' + OniDataConnection.GetFileInfo(_fileid).FileName +
+  Self.Caption := 'Preview ' + Connection.GetFileInfo(_fileid).FileName +
     ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
   DrawImage(actualimg);
@@ -192,5 +192,5 @@
   else
     actualimg := 0;
-  Self.Caption := 'Preview ' + OniDataConnection.GetFileInfo(_fileid).FileName +
+  Self.Caption := 'Preview ' + Connection.GetFileInfo(_fileid).FileName +
     ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
   DrawImage(actualimg);
Index: oup/current/Tools/Template.dfm
===================================================================
--- oup/current/Tools/Template.dfm	(revision 85)
+++ oup/current/Tools/Template.dfm	(revision 86)
@@ -43,7 +43,7 @@
     object filelist: TListBox
       Left = 0
-      Top = 129
+      Top = 153
       Width = 200
-      Height = 294
+      Height = 270
       Align = alClient
       ItemHeight = 13
@@ -52,4 +52,6 @@
       OnClick = listClick
       OnMouseDown = listMouseDown
+      ExplicitTop = 129
+      ExplicitHeight = 294
     end
     object panel_extension: TPanel
@@ -57,5 +59,5 @@
       Top = 0
       Width = 200
-      Height = 129
+      Height = 153
       Align = alTop
       BevelOuter = bvNone
@@ -63,8 +65,8 @@
       DesignSize = (
         200
-        129)
+        153)
       object Label2: TLabel
         Left = 100
-        Top = 105
+        Top = 129
         Width = 17
         Height = 18
@@ -80,5 +82,5 @@
       object Label1: TLabel
         Left = 47
-        Top = 105
+        Top = 129
         Width = 17
         Height = 18
@@ -94,5 +96,5 @@
       object label_ext: TLabel
         Left = 2
-        Top = 62
+        Top = 86
         Width = 100
         Height = 17
@@ -103,5 +105,5 @@
       object btn_sort_id_asc: TSpeedButton
         Left = 3
-        Top = 101
+        Top = 125
         Width = 20
         Height = 22
@@ -124,5 +126,5 @@
       object btn_sort_id_desc: TSpeedButton
         Left = 23
-        Top = 101
+        Top = 125
         Width = 20
         Height = 22
@@ -144,5 +146,5 @@
       object btn_sort_name_asc: TSpeedButton
         Left = 58
-        Top = 101
+        Top = 125
         Width = 20
         Height = 22
@@ -164,5 +166,5 @@
       object btn_sort_name_desc: TSpeedButton
         Left = 78
-        Top = 101
+        Top = 125
         Width = 20
         Height = 22
@@ -184,5 +186,5 @@
       object btn_sort_ext_asc: TSpeedButton
         Left = 108
-        Top = 101
+        Top = 125
         Width = 20
         Height = 22
@@ -204,5 +206,5 @@
       object btn_sort_ext_desc: TSpeedButton
         Left = 128
-        Top = 101
+        Top = 125
         Width = 20
         Height = 22
@@ -222,8 +224,23 @@
         OnClick = btn_sortClick
       end
+      object Label3: TLabel
+        Left = 3
+        Top = 6
+        Width = 61
+        Height = 13
+        Caption = 'Connection: '
+      end
+      object Bevel1: TBevel
+        Left = 0
+        Top = 25
+        Width = 199
+        Height = 3
+        Anchors = [akLeft, akTop, akRight]
+        Style = bsRaised
+      end
       object combo_extension: TComboBox
         Left = 2
-        Top = 76
-        Width = 192
+        Top = 100
+        Width = 196
         Height = 21
         Style = csDropDownList
@@ -243,5 +260,5 @@
       object check_zerobyte: TCheckBox
         Left = 2
-        Top = 44
+        Top = 68
         Width = 130
         Height = 13
@@ -252,6 +269,6 @@
       object edit_filtername: TEdit
         Left = 2
-        Top = 20
-        Width = 192
+        Top = 44
+        Width = 196
         Height = 18
         Anchors = [akLeft, akTop, akRight]
@@ -261,5 +278,5 @@
       object check_filtername: TCheckBox
         Left = 2
-        Top = 5
+        Top = 29
         Width = 130
         Height = 15
@@ -267,4 +284,15 @@
         TabOrder = 0
         OnClick = check_filternameClick
+      end
+      object combo_connection: TComboBox
+        Left = 64
+        Top = 3
+        Width = 134
+        Height = 21
+        Style = csDropDownList
+        Anchors = [akLeft, akTop, akRight]
+        ItemHeight = 13
+        TabOrder = 4
+        OnChange = combo_connectionChange
       end
     end
Index: oup/current/Tools/Template.pas
===================================================================
--- oup/current/Tools/Template.pas	(revision 85)
+++ oup/current/Tools/Template.pas	(revision 86)
@@ -10,4 +10,5 @@
 type
   TNewFileSelectedEvent = procedure(fileinfo: TFileInfo) of object;
+  TNewConnectionEvent = procedure(connection: TOniData) of object;
 
   TForm_ToolTemplate = class(TForm)
@@ -36,5 +37,10 @@
     Label1: TLabel;
     Label2: TLabel;
+    Label3: TLabel;
+    combo_connection: TComboBox;
+    Bevel1: TBevel;
     procedure RecreateList;
+    procedure UpdateList;
+    procedure RecreateExtList;
     procedure LoadFileNames;
     procedure SelectFileName(filename: String);
@@ -56,10 +62,13 @@
     procedure btn_sortClick(Sender: TObject);
     procedure FormActivate(Sender: TObject);
+    procedure combo_connectionChange(Sender: TObject);
   private
     FSortBy: TSortType;
     FOnNewFileSelected: TNewFileSelectedEvent;
+    FOnNewConnection: TNewConnectionEvent;
     FAllowedExts: String;
     FAllowMultiSelect: Boolean;
     FSelectedFile: TFileInfo;
+    FConnection: TOniData;
     procedure SetAllowedExts(exts: String);
     procedure SetMultiSelect(allow: Boolean);
@@ -69,7 +78,9 @@
   published
     property OnNewFileSelected: TNewFileSelectedEvent read FOnNewFileSelected write FOnNewFileSelected;
+    property OnNewConnection: TNewConnectionEvent read FOnNewConnection write FOnNewConnection;
     property AllowedExts: String read FAllowedExts write SetAllowedExts;
     property AllowMultiSelect: Boolean read FAllowMultiSelect write SetMultiSelect;
     property SelectedFile: TFileInfo read FSelectedFile;
+    property Connection: TOniData read FConnection;
   end;
 
@@ -83,5 +94,55 @@
 
 
+procedure TForm_ToolTemplate.UpdateList;
+var
+  i: Integer;
+  fn, datatype, boxstring: String;
+  level: Integer;
+  oldcon: String;
+begin
+  oldcon := combo_connection.Items.Strings[combo_connection.ItemIndex];
+  combo_connection.Items.Clear;
+  for i := 0 to High(DataConnections) do
+  begin
+    level := DataConnections[i].LevelInfo.LevelNumber;
+    fn := ExtractFileName(DataConnections[i].FileName);
+    if DataConnections[i].Backend = ODB_Dat then
+      datatype := 'ONI-.dat: '
+    else if DataConnections[i].Backend = ODB_ADB then
+      datatype := 'OUP-DB: '
+    else
+      datatype := 'Unknown: ';
+    boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
+    combo_connection.Items.Add(boxstring);
+    if oldcon = boxstring then
+      combo_connection.ItemIndex := combo_connection.Items.Count - 1;
+  end;
+end;
+
 procedure TForm_ToolTemplate.RecreateList;
+var
+  i: Integer;
+  fn, datatype: String;
+  level: Integer;
+begin
+  combo_connection.Items.Clear;
+  for i := 0 to High(DataConnections) do
+  begin
+    level := DataConnections[i].LevelInfo.LevelNumber;
+    fn := ExtractFileName(DataConnections[i].FileName);
+    if DataConnections[i].Backend = ODB_Dat then
+      datatype := 'ONI-.dat: '
+    else if DataConnections[i].Backend = ODB_ADB then
+      datatype := 'OUP-DB: '
+    else
+      datatype := 'Unknown: ';
+    combo_connection.Items.Add(datatype + fn + ' (Level: ' + IntToStr(level) + ')');
+  end;
+  FConnection := DataConnections[0];
+  combo_connection.ItemIndex := 0;
+  combo_connectionChange(Self);
+end;
+
+procedure TForm_ToolTemplate.RecreateExtList;
 var
   i:    LongWord;
@@ -90,6 +151,6 @@
   combo_extension.Items.Clear;
   combo_extension.Items.Add('_All files_ (' +
-    IntToStr(OniDataConnection.GetFilesCount) + ')');
-  exts := OniDataConnection.GetExtensionsList;
+    IntToStr(FConnection.GetFilesCount) + ')');
+  exts := FConnection.GetExtensionsList;
   for i := 0 to High(exts) do
     if Length(FAllowedExts) > 0 then
@@ -127,5 +188,5 @@
       Extension := '';
 
-  files := OniDataConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
+  files := FConnection.GetFilesList(extension, pattern, no_zero_bytes, FSortBy);
 
   filelist.Visible := False;
@@ -143,10 +204,10 @@
   ext: String;
 begin
-  id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
+  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
   ext := RightStr(filelist.Items.Strings[filelist.ItemIndex], 4);
   exportd.Filter := 'Files of matching extension (*.' + ext + ')|*.' + ext + '|All files|*.*';
   exportd.DefaultExt := ext;
   if exportd.Execute then
-    ExportDatFile(id, exportd.FileName);
+    ExportDatFile(FConnection, id, exportd.FileName);
 end;
 
@@ -158,6 +219,6 @@
   data: TData;
 begin
-  id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
-  finfo := OniDataConnection.GetFileInfo(id);
+  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
+  finfo := FConnection.GetFileInfo(id);
 
   importd.Filter := 'Files of matching extension (*.' + finfo.Extension + ')|*.' +
@@ -174,5 +235,5 @@
       SetLength(data, fs.Size);
       fs.Read(data[0], fs.Size);
-      OniDataConnection.UpdateDatFile(id, data);
+      FConnection.UpdateDatFile(id, data);
       Self.listClick(Self);
     end;
@@ -187,9 +248,39 @@
 begin
   sender_name := TComponent(Sender).Name;
-  id := OniDataConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
+  id := FConnection.ExtractFileID(filelist.Items.Strings[filelist.ItemIndex]);
   context := MidStr(sender_name, Pos('_', sender_name) + 1, Length(sender_name) - Pos('_', sender_name));
   Form_Main.open_child(context, id);
 end;
 
+procedure TForm_ToolTemplate.combo_connectionChange(Sender: TObject);
+var
+  name: String;
+  nstart, nend: Integer;
+  i: Integer;
+begin
+  if combo_connection.ItemIndex >= 0 then
+  begin
+    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
+    nstart := Pos(' ', name) + 1;
+    nend := Pos('(', name) - 1;
+    name := MidStr(name, nstart, nend - nstart);
+
+    for i := 0 to High(DataConnections) do
+    begin
+      if ExtractFileName(DataConnections[i].FileName) = name then
+      begin
+        FConnection := DataConnections[i];
+        Break;
+      end;
+    end;
+    if i = Length(DataConnections) then
+      FConnection := nil;
+
+    RecreateExtList;
+    if Assigned(FOnNewConnection) then
+      FOnNewConnection(FConnection);
+  end;
+end;
+
 procedure TForm_ToolTemplate.combo_extensionClick(Sender: TObject);
 begin
@@ -205,4 +296,5 @@
   inherited;
   RecreateList;
+  FConnection := nil;
   FSelectedFile.ID := -1;
   FSelectedFile.FileName := '';
@@ -270,7 +362,7 @@
   if filelist.ItemIndex > -1 then
   begin
-    fileid := OniDataConnection.ExtractFileID(
+    fileid := FConnection.ExtractFileID(
           filelist.Items.Strings[filelist.ItemIndex]);
-    FSelectedFile := OniDataConnection.GetFileInfo(fileid);
+    FSelectedFile := FConnection.GetFileInfo(fileid);
     if Assigned(FOnNewFileSelected) then
       FOnNewFileSelected(FSelectedFile);
@@ -298,5 +390,5 @@
   if filelist.Items.Count > 0 then
     for i := 0 to filelist.Items.Count - 1 do
-      if OniDataConnection.ExtractFileID(filelist.Items.Strings[i]) = id then
+      if FConnection.ExtractFileID(filelist.Items.Strings[i]) = id then
       begin
         filelist.ItemIndex := i;
@@ -321,5 +413,5 @@
 begin
   FAllowedExts := exts;
-  RecreateList;
+  RecreateExtList;
 end;
 
@@ -368,4 +460,5 @@
   Self.Height := 300;
   FOnNewFileSelected := nil;
+  FOnNewConnection := nil;
   FAllowedExts := '';
   FAllowMultiSelect := False;
Index: oup/current/Tools/TxmpReplace.dfm
===================================================================
--- oup/current/Tools/TxmpReplace.dfm	(revision 85)
+++ oup/current/Tools/TxmpReplace.dfm	(revision 86)
@@ -1,4 +1,6 @@
 inherited Form_TxmpReplace: TForm_TxmpReplace
   Caption = 'TxmpReplace'
+  ExplicitWidth = 320
+  ExplicitHeight = 240
   PixelsPerInch = 96
   TextHeight = 13
@@ -12,7 +14,7 @@
     object image_txmppreview: TImage [0]
       Left = 0
-      Top = 283
+      Top = 307
       Width = 200
-      Height = 31
+      Height = 7
       Align = alClient
       ExplicitTop = 111
@@ -21,5 +23,5 @@
     object splitter_txmp: TSplitter [1]
       Left = 0
-      Top = 275
+      Top = 299
       Width = 200
       Height = 8
@@ -35,4 +37,5 @@
       Height = 146
       Align = alTop
+      ExplicitTop = 153
       ExplicitHeight = 146
     end
Index: oup/current/Tools/TxmpReplace.pas
===================================================================
--- oup/current/Tools/TxmpReplace.pas	(revision 85)
+++ oup/current/Tools/TxmpReplace.pas	(revision 86)
@@ -58,5 +58,5 @@
   check_transparency.Checked := (depthbyte and $04) > 0;
 
-  OniImage_Old.LoadFromTXMP(fileid);
+  OniImage_Old.LoadFromTXMP(connection, fileid);
   old_size := OniImage_Old.GetImageDataSize((fadingbyte and $01) > 0);
   Data := OniImage_Old.GetAsBMP;
