Index: oup/current/Tools/MetaEditor.dfm
===================================================================
--- oup/current/Tools/MetaEditor.dfm	(revision 209)
+++ oup/current/Tools/MetaEditor.dfm	(revision 212)
@@ -3,6 +3,6 @@
   Top = 0
   Caption = 'Form_Meta'
-  ClientHeight = 293
-  ClientWidth = 426
+  ClientHeight = 365
+  ClientWidth = 446
   Color = clBtnFace
   Font.Charset = DEFAULT_CHARSET
@@ -18,13 +18,20 @@
   OnCreate = FormCreate
   DesignSize = (
-    426
-    293)
+    446
+    365)
   PixelsPerInch = 96
   TextHeight = 13
+  object Label3: TLabel
+    Left = 3
+    Top = 6
+    Width = 61
+    Height = 13
+    Caption = 'Connection: '
+  end
   object VST: TVirtualStringTree
-    Left = 8
-    Top = 8
-    Width = 389
-    Height = 265
+    Left = 4
+    Top = 44
+    Width = 409
+    Height = 321
     Anchors = [akLeft, akTop, akRight, akBottom]
     AnimationDuration = 0
@@ -37,17 +44,49 @@
     Header.Options = [hoColumnResize, hoDrag, hoVisible]
     TabOrder = 0
+    TreeOptions.AutoOptions = [toAutoDropExpand, toAutoScrollOnExpand, toAutoDeleteMovedNodes]
     TreeOptions.MiscOptions = [toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning]
-    TreeOptions.PaintOptions = [toShowDropmark, toShowRoot, toShowTreeLines, toThemeAware, toUseBlendedImages]
     OnGetText = VSTGetText
+    OnPaintText = VSTPaintText
+    OnInitChildren = VSTInitChildren
     Columns = <
       item
         Position = 0
         Width = 150
-        WideText = 'Main'
+        WideText = 'FName'
       end
       item
         Position = 1
+        WideText = 'FType'
+      end
+      item
+        Position = 2
+        WideText = 'FID'
+      end
+      item
+        Position = 3
         WideText = 'Data'
       end>
   end
+  object Button1: TButton
+    Left = 204
+    Top = 1
+    Width = 75
+    Height = 25
+    Anchors = [akTop, akRight]
+    Caption = 'Load'
+    Default = True
+    TabOrder = 1
+    OnClick = Button1Click
+  end
+  object combo_connection: TComboBox
+    Left = 64
+    Top = 3
+    Width = 134
+    Height = 21
+    Style = csDropDownList
+    Anchors = [akLeft, akTop, akRight]
+    DropDownCount = 12
+    ItemHeight = 13
+    TabOrder = 2
+  end
 end
Index: oup/current/Tools/MetaEditor.pas
===================================================================
--- oup/current/Tools/MetaEditor.pas	(revision 209)
+++ oup/current/Tools/MetaEditor.pas	(revision 212)
@@ -3,16 +3,25 @@
 uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, VirtualTrees, _FileManager;
+  Dialogs, VirtualTrees, _MetaManager, StdCtrls;
 
 type
   TForm_Meta = class(TForm)
     VST: TVirtualStringTree;
+    Button1: TButton;
+    Label3: TLabel;
+    combo_connection: TComboBox;
     procedure FormClose(Sender: TObject; var Action: TCloseAction);
     procedure FormCreate(Sender: TObject);
     procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
       Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
+    procedure Button1Click(Sender: TObject);
+    procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
+      var ChildCount: Cardinal);
+    procedure VSTPaintText(Sender: TBaseVirtualTree;
+      const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
+      TextType: TVSTTextType);
   private
   public
-    FileManager: TFileManager;
+    MetaManager: TMetaManager;
   end;
 
@@ -22,5 +31,5 @@
 implementation
 uses
-  Data, _DataTypes, _FileTypes;
+  Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils;
 {$R *.dfm}
 
@@ -45,32 +54,105 @@
 
 
-procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
-begin
-  FileManager.Free;
-  Action := caFree;
-end;
-
-
-procedure TForm_Meta.FormCreate(Sender: TObject);
-var
+procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
+  Node: PVirtualNode; var ChildCount: Cardinal);
+var
+  data: PNodeData;
+  newdata: TNodeData;
+  newnode: PVirtualNode;
+  i: Integer;
+  id: Integer;
+begin
+  data := VST.GetNodeData(node);
+  for i := 0 to MetaManager.FileById[TFile(data.Field).FileID].ChildCount - 1 do
+  begin
+    id := MetaManager.FileById[TFile(data.Field).FileID].LinkByIndex[i].DestID;
+    MetaManager.InitFile(id);
+    newdata.Field := MetaManager.FileById[id];
+    newnode := AddVSTEntry(VST, Node, newdata);
+    if MetaManager.FileById[id].ChildCount > 0 then
+      VST.HasChildren[newnode] := True;
+  end;
+  ChildCount := MetaManager.FileById[TFile(data.Field).FileID].ChildCount;
+end;
+
+
+procedure TForm_Meta.Button1Click(Sender: TObject);
+var
+  name: String;
+  conid: Integer;
+
   a,b,c: Int64;
   i: Integer;
   data: TNodeData;
-begin
+  node: PVirtualNode;
+begin
+  if combo_connection.ItemIndex >= 0 then
+  begin
+    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
+    conid := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name)  - 1));
+
+    QueryPerformanceFrequency(c);
+    QueryPerformanceCounter(a);
+    MetaManager := TMetaManager.Create(conid);
+    QueryPerformanceCounter(b);
+    ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
+
+    VST.Clear;
+    VST.BeginUpdate;
+    for i := 0 to MetaManager.FileCount - 1 do
+    begin
+      if Assigned(MetaManager.FileById[i]) then
+      begin
+        data.Field := MetaManager.FileById[i];
+        node := AddVSTEntry(VST, nil, data);
+        if MetaManager.FileById[i].ChildCount > 0 then
+          VST.HasChildren[node] := True;
+      end;
+    end;
+    VST.EndUpdate;
+  end;
+end;
+
+procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
+begin
+  MetaManager.Free;
+  Action := caFree;
+end;
+
+
+procedure TForm_Meta.FormCreate(Sender: TObject);
+var
+  i: Integer;
+
+  fn, datatype, boxstring: String;
+  level: Integer;
+begin
+  combo_connection.ItemIndex := -1;
+  combo_connection.Items.Clear;
+  if ConManager.Count > 0 then
+  begin
+    for i := 0 to ConManager.Count - 1 do
+    begin
+      level := ConManager.ConnectionByIndex[i].LevelNumber;
+      fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
+      if ConManager.ConnectionByIndex[i].Backend = DB_ONI then
+        datatype := 'ONI-.dat: '
+      else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then
+        datatype := 'OUP-DB: '
+      else
+        datatype := 'Unknown: ';
+      boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ') [' + IntToStr(ConManager.ConnectionByIndex[i].ConnectionID) + ']';
+      combo_connection.Items.Add(boxstring);
+    end;
+    if combo_connection.ItemIndex = -1 then
+    begin
+      combo_connection.ItemIndex := 0;
+    end;
+  end;
+
+
   VST.NodeDataSize := SizeOf(TNodeData);
   VST.Font.Charset := AppSettings.CharSet;
   VST.Clear;
-
-  QueryPerformanceFrequency(c);
-  QueryPerformanceCounter(a);
-  FileManager := TFileManager.Create(1);
-  QueryPerformanceCounter(b);
-  ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
-
-  for i := 0 to FileManager.FileCount - 1 do
-  begin
-    data.Field := FileManager.FileById[i];
-    AddVSTEntry(VST, nil, data);
-  end;
 end;
 
@@ -87,28 +169,44 @@
   begin
     case Column of
-      0: begin
-        if Data.Field is TFile then
-        begin
-          CellText := TFile(Data.Field).FileName;
-        end;
-      end;
-{      0:
-        CellText := Data.Caption;
+      0:
+        begin
+          if Data.Field is TFile then
+          begin
+            CellText := TFile(Data.Field).FileName;
+            if CellText = '' then
+              CellText := 'Unnamed';
+          end;
+        end;
       1:
-        if Data.DataType > 0 then
-          CellText := '0x' + IntToHex(Data.Offset, 8)
-        else if Data.Offset > 0 then
-          CellText := '0x' + IntToHex(Data.Offset, 8);
+        begin
+          if Data.Field is TFile then
+            CellText := TFile(Data.Field).FileExt;
+        end;
       2:
-        if Data.DataType > 0 then
-          CellText := GetDataType(Data.DataType);
-      3:
-        if Data.DataType > 0 then
-          CellText := Data.Value //GetValue(data.DataType, data.Offset)
-        else if Length(Data.Value) > 0 then
-          CellText := IntToStr(StrToInt(Data.Value)) + ' Bytes';
-      4:
-        CellText := Data.Description;
-}    end;
+        begin
+          if Data.Field is TFile then
+            CellText := IntToStr(TFile(Data.Field).FileID);
+        end;
+    end;
+  end;
+end;
+
+procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
+  const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
+  TextType: TVSTTextType);
+var
+  Data: PNodeData;
+begin
+  Data     := Sender.GetNodeData(Node);
+  if TextType = ttNormal then
+  begin
+    case Column of
+      0:
+        begin
+          if Data.Field is TFile then
+            if Length(TFile(Data.Field).FileName) = 0 then
+              TargetCanvas.Font.Color := $000060;
+        end;
+    end;
   end;
 end;
