Index: oup/current/Tools/Extractor.dfm
===================================================================
--- oup/current/Tools/Extractor.dfm	(revision 83)
+++ 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 83)
+++ 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 83)
+++ 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 83)
+++ 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 83)
+++ 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 83)
+++ 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 83)
+++ 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;
