Index: oup/rewrite/DataAccess/Access_OUP_ADB.pas
===================================================================
--- oup/rewrite/DataAccess/Access_OUP_ADB.pas	(revision 104)
+++ oup/rewrite/DataAccess/Access_OUP_ADB.pas	(revision 105)
@@ -103,4 +103,5 @@
   FBackend := DB_ADB;
 
+  FConnectionID := ConnectionID;
   FChangeRights := [CR_EditDat, CR_EditRaw, CR_ResizeDat, CR_ResizeRaw];
 
Index: oup/rewrite/DataAccess/Access_OniArchive.pas
===================================================================
--- oup/rewrite/DataAccess/Access_OniArchive.pas	(revision 104)
+++ oup/rewrite/DataAccess/Access_OniArchive.pas	(revision 105)
@@ -43,5 +43,5 @@
     procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; override;
 
-    function AppendRawFile(LocSep: Boolean; Size: Integer; Src: TStream): Integer; overload; override;
+    function AppendRawFile(LocSep: Boolean; Src: TStream): Integer; overload; override;
   published
   end;
@@ -184,4 +184,5 @@
   Msg := SM_OK;
   FBackend := DB_ONI;
+  FConnectionID := ConnectionID;
   FChangeRights := [CR_EditDat, CR_EditRaw, CR_AppendRaw];
 end;
@@ -616,5 +617,5 @@
 end;
 
-function TAccess_OniArchive.AppendRawFile(LocSep: Boolean; Size: Integer; Src: TStream): Integer;
+function TAccess_OniArchive.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
 begin
   if not LocSep then
@@ -625,5 +626,5 @@
     Result := Fraw_file.Size;
     Fraw_file.Seek(0, soFromEnd);
-    Fraw_file.CopyFrom(Src, Size);
+    Fraw_file.CopyFrom(Src, Src.Size);
     if UnloadWhenUnused then
     begin
@@ -641,5 +642,5 @@
     Result := Fsep_file.Size;
     Fsep_file.Seek(0, soFromEnd);
-    Fsep_file.CopyFrom(Src, Size);
+    Fsep_file.CopyFrom(Src, Src.Size);
     if UnloadWhenUnused then
     begin
Index: oup/rewrite/DataAccess/DataAccess.pas
===================================================================
--- oup/rewrite/DataAccess/DataAccess.pas	(revision 104)
+++ oup/rewrite/DataAccess/DataAccess.pas	(revision 105)
@@ -42,5 +42,4 @@
     procedure LoadDatFilePart(FileID, Offset, Size: Integer; Target: Pointer); overload;
     procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
-    procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TByteData); overload;
     procedure UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer); overload;
 
@@ -56,9 +55,8 @@
     procedure LoadRawFilePart(FileID, DatOffset, Offset, Size: Integer; Target: Pointer); overload;
     procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TStream); overload; virtual; abstract;
-    procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TByteData); overload;
     procedure UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer); overload;
 
-    function AppendRawFile(LocSep: Boolean; Size: Integer; Src: TStream): Integer; overload; virtual;
-    function AppendRawFile(LocSep: Boolean; Size: Integer; Src: TByteData): Integer; overload;
+    function AppendRawFile(LocSep: Boolean; Src: TStream): Integer; overload; virtual;
+    function AppendRawFile(LocSep: Boolean; Src: TByteData): Integer; overload;
     function AppendRawFile(LocSep: Boolean; Size: Integer; Src: Pointer): Integer; overload;
   published
@@ -173,18 +171,4 @@
 end;
 
-procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: TByteData);
-var
-  data: TStream;
-begin
-  if fileid < GetFileCount then
-  begin
-    data := TMemoryStream.Create;
-    data.Write(Src[0], Size);
-    data.Seek(0, soFromBeginning);
-    UpdateDatFilePart(FileID, offset, size, data);
-    data.Free;
-  end;
-end;
-
 procedure TDataAccess.UpdateDatFilePart(FileID, Offset, Size: Integer; Src: Pointer);
 var
@@ -260,12 +244,12 @@
 end;
 
-procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: TByteData);
-var
-  data: TStream;
-begin
-  if fileid < GetFileCount then
-  begin
-    data := TMemoryStream.Create;
-    data.Write(Src[0], Size);
+procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer);
+var
+  data: TStream;
+begin
+  if fileid < GetFileCount then
+  begin
+    data := TMemoryStream.Create;
+    data.Write(Src^, Size);
     data.Seek(0, soFromBeginning);
     UpdateRawFilePart(FileID, DatOffset, Offset, Size, data);
@@ -274,20 +258,6 @@
 end;
 
-procedure TDataAccess.UpdateRawFilePart(FileID, DatOffset, Offset, Size: Integer; Src: Pointer);
-var
-  data: TStream;
-begin
-  if fileid < GetFileCount then
-  begin
-    data := TMemoryStream.Create;
-    data.Write(Src^, Size);
-    data.Seek(0, soFromBeginning);
-    UpdateRawFilePart(FileID, DatOffset, Offset, Size, data);
-    data.Free;
-  end;
-end;
-
-
-function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: TStream): Integer;
+
+function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TStream): Integer;
 begin
   raise ENotImplemented.Create('ERROR: AppendRawFile not implemented here!!!');
@@ -295,11 +265,12 @@
 
 
-function TDataAccess.AppendRawFile(LocSep: Boolean; Size: Integer; Src: TByteData): Integer;
+function TDataAccess.AppendRawFile(LocSep: Boolean; Src: TByteData): Integer;
 var
   data: TStream;
 begin
   data := TMemoryStream.Create;
-  data.Write(Src[0], Size);
-  AppendRawFile(LocSep, Size, data);
+  data.Write(Src[0], Length(Src));
+  data.Seek(0, soFromBeginning);
+  AppendRawFile(LocSep, data);
   data.Free;
 end;
@@ -311,5 +282,6 @@
   data := TMemoryStream.Create;
   data.Write(Src^, Size);
-  AppendRawFile(LocSep, Size, data);
+  data.Seek(0, soFromBeginning);
+  AppendRawFile(LocSep, data);
   data.Free;
 end;
Index: oup/rewrite/Global/Functions.pas
===================================================================
--- oup/rewrite/Global/Functions.pas	(revision 104)
+++ oup/rewrite/Global/Functions.pas	(revision 105)
@@ -11,4 +11,5 @@
 function Decode_Float(buffer: TByteData): Single;
 function Encode_Float(input: Single): TByteData;
+function IntToBin(Value: Byte): String;
 function DataToBin(Data: TByteData): String;
 function BinToInt(bin: String): Byte;
@@ -39,5 +40,4 @@
 
 
-
 function BoolToStr(bool: Boolean): String;
 begin
@@ -49,6 +49,4 @@
 
 
-
-
 function HexToLong(hex: String): LongWord;
 
@@ -76,31 +74,8 @@
 begin
   if NormalizeHexString(hex) then
-  begin
-    Result := StrToInt(hex);
-{
-    hex    := UpperCase(hex);
+    Result := StrToInt(hex)
+  else
     Result := 0;
-    for i := 1 to Length(hex) do
-    begin
-      Result := Result shl 4;
-      case hex[i] of
-        '0'..'9':
-          Result := Result + Ord(hex[i]) - 48;
-        'A'..'F':
-          Result := Result + Ord(hex[i]) - 55;
-        else
-          Result := 0;
-          Exit;
-      end;
-    end;
-}
-  end
-  else
-  begin
-    Result := 0;
-  end;
-end;
-
-
+end;
 
 
@@ -109,6 +84,4 @@
   Result := buffer[0] + buffer[1] * 256 + buffer[2] * 256 * 256 + buffer[3] * 256 * 256 * 256;
 end;
-
-
 
 
@@ -126,6 +99,4 @@
 
 
-
-
 function Decode_Float(buffer: TByteData): Single;
 var
@@ -139,6 +110,4 @@
 
 
-
-
 function Encode_Float(input: Single): TByteData;
 var
@@ -150,4 +119,12 @@
 
 
+function IntToBin(Value: Byte): String;
+var
+  i: Byte;
+begin
+  Result := '';
+  for i := 7 downto 0 do
+    Result := Result + IntToStr((Value shr i) and $01);
+end;
 
 
@@ -171,6 +148,4 @@
   end;
 end;
-
-
 
 
@@ -193,5 +168,4 @@
   end;
 end;
-
 
 
Index: oup/rewrite/Global/OniImgClass.pas
===================================================================
--- oup/rewrite/Global/OniImgClass.pas	(revision 104)
+++ oup/rewrite/Global/OniImgClass.pas	(revision 105)
@@ -39,11 +39,14 @@
     function GetImageDataSize(fading: Boolean): Integer;
 
-    function GetAsData: TByteData;
-    function GetAs32bit: TByteData;
+    procedure GetAsData(var Target: TStream); overload;
+    procedure GetAsData(var Target: TByteData); overload;
+    procedure GetAs32bit(var Target: TStream); overload;
+    procedure GetAs32bit(var Target: TByteData); overload;
+    procedure GetAsBMP(var Target: TStream); overload;
     procedure GetAsBMP(var Target: TByteData); overload;
-    procedure GetAsBMP(var Target: TStream); overload;
     function LoadFromBMP(filename: String): Boolean;
     function WriteToBMP(filename: String): Boolean;
-    function GetMipMappedImage(var faded: TByteData): Boolean;
+    function GetMipMappedImage(var Target: TStream): Boolean; overload;
+    function GetMipMappedImage(var Target: TByteData): Boolean; overload;
   published
   end;
@@ -369,5 +372,5 @@
   txmpimg.DecodeImage;
 //  txmpimg.WriteToBMP('C:\file.bmp');
-  txmpdata := txmpimg.GetAs32bit;
+  txmpimg.GetAs32bit(txmpdata);
 {    ShowMessage(IntToStr(txmpimg.Width)+'x'+IntToStr(txmpimg.Height));
     for i:=0 to High(txmpdata) do
@@ -615,5 +618,5 @@
 
 
-function TOniImage.GetAsData: TByteData;
+procedure TOniImage.GetAsData(var Target: TStream);
 var
   i:      Integer;
@@ -629,26 +632,44 @@
   else
     revert := False;
-  SetLength(Result, Length(Self.FData));
-  for i := 0 to High(Result) do
-    Result[i] := Self.FData[i];
+  if not Assigned(Target) then
+    Target := TMemoryStream.Create;
+  Target.Write(FData[0], Length(FData));
+  Target.Seek(0, soFromBeginning);
   if revert then
     Self.RevertImage;
 end;
 
-
-
-
-function TOniImage.GetAs32bit: TByteData;
-var
-  i: Integer;
+procedure TOniImage.GetAsData(var Target: TByteData);
+var
+  mem: TStream;
+begin
+  mem := TMemoryStream.Create;
+  GetAsData(mem);
+  SetLength(Target, mem.Size);
+  mem.Read(Target[0], mem.Size);
+  mem.Free;
+end;
+
+
+procedure TOniImage.GetAs32bit(var Target: TStream);
 begin
   if not (DT_Decoded32 in Self.FDataType) then
     Self.DecodeImage;
-  SetLength(Result, Length(Self.FData));
-  for i := 0 to High(Result) do
-    Result[i] := Self.FData[i];
-end;
-
-
+  if not Assigned(Target) then
+    Target := TMemoryStream.Create;
+  Target.Write(FData[0], Length(FData));
+  Target.Seek(0, soFromBeginning);
+end;
+
+procedure TOniImage.GetAs32bit(var Target: TByteData);
+var
+  mem: TStream;
+begin
+  mem := TMemoryStream.Create;
+  GetAs32bit(mem);
+  SetLength(Target, mem.Size);
+  mem.Read(Target[0], mem.Size);
+  mem.Free;
+end;
 
 
@@ -786,6 +807,5 @@
 
 
-
-function TOniImage.GetMipMappedImage(var faded: TByteData): Boolean;
+function TOniImage.GetMipMappedImage(var Target: TByteData): Boolean;
 var
   i:      Integer;
@@ -810,9 +830,9 @@
   x := Self.FWidth;
   y := Self.FHeight;
-  SetLength(faded, x * y * Self.FDepth div 8);
+  SetLength(Target, x * y * Self.FDepth div 8);
   SetLength(fadelvldata, x * y * Self.FDepth div 8);
-  for i := 0 to Length(faded) - 1 do
-  begin
-    faded[i] := Self.FData[i];
+  for i := 0 to Length(Target) - 1 do
+  begin
+    Target[i] := Self.FData[i];
     fadelvldata[i] := Self.FData[i];
   end;
@@ -821,7 +841,7 @@
     x := x div 2;
     y := y div 2;
-    SetLength(faded, Length(faded) + x * y * Self.FDepth div 8);
+    SetLength(Target, Length(Target) + x * y * Self.FDepth div 8);
     for i := 0 to Length(fadelvldata) - 1 do
-      faded[Length(faded) - x * y * Self.FDepth div 8 + i] := fadelvldata[i];
+      Target[Length(Target) - x * y * Self.FDepth div 8 + i] := fadelvldata[i];
   until (x = 1) or (y = 1) or ((x mod 2) = 1) or ((y mod 2) = 1);
   if (x > 1) and (y > 1) then
@@ -834,3 +854,17 @@
 
 
+function TOniImage.GetMipMappedImage(var Target: TStream): Boolean;
+var
+  data: TByteData;
+  streampos: Integer;
+begin
+  Result := GetMipMappedImage(data);
+  if not Assigned(Target) then
+    Target := TMemoryStream.Create;
+  streampos := Target.Position;
+  Target.Write(data[0], Length(data));
+  Target.Seek(streampos, soFromBeginning);
+end;
+
+
 end.
Index: oup/rewrite/Global/RawList.pas
===================================================================
--- oup/rewrite/Global/RawList.pas	(revision 104)
+++ oup/rewrite/Global/RawList.pas	(revision 105)
@@ -18,4 +18,5 @@
       FRawListHandlers: TRawListHandlers;
     public
+      property RawListHandlers: TRawListHandlers read FRawListHandlers;
       procedure InsertRawListHandler(ext: String; needed: Boolean; handler: THandler);
       function GetRawList(ConnectionID, FileID: Integer): TRawDataList;
Index: oup/rewrite/Helper/Helper_LevelDB.dfm
===================================================================
--- oup/rewrite/Helper/Helper_LevelDB.dfm	(revision 104)
+++ 	(revision )
@@ -1,61 +1,0 @@
-object Form_LevelDB: TForm_LevelDB
-  Left = 0
-  Top = 0
-  BorderStyle = bsNone
-  Caption = 'Creating DB'
-  ClientHeight = 89
-  ClientWidth = 400
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -11
-  Font.Name = 'Tahoma'
-  Font.Style = []
-  OldCreateOrder = False
-  Position = poScreenCenter
-  PixelsPerInch = 96
-  TextHeight = 13
-  object group_progress: TGroupBox
-    Left = 0
-    Top = 0
-    Width = 400
-    Height = 89
-    Caption = 'Progress ...'
-    TabOrder = 0
-    object lbl_progress: TLabel
-      Left = 2
-      Top = 32
-      Width = 396
-      Height = 17
-      Align = alTop
-      AutoSize = False
-    end
-    object lbl_estimation: TLabel
-      Left = 2
-      Top = 49
-      Width = 396
-      Height = 17
-      Align = alTop
-      AutoSize = False
-      Caption = 'Estimated finishing time:'
-    end
-    object progress: TProgressBar
-      Left = 2
-      Top = 15
-      Width = 396
-      Height = 17
-      Align = alTop
-      Smooth = True
-      TabOrder = 0
-    end
-    object btn_abortok: TButton
-      Left = 3
-      Top = 64
-      Width = 60
-      Height = 22
-      Caption = 'Abort...'
-      TabOrder = 1
-      OnClick = btn_abortokClick
-    end
-  end
-end
Index: oup/rewrite/Helper/Helper_LevelDB.pas
===================================================================
--- oup/rewrite/Helper/Helper_LevelDB.pas	(revision 104)
+++ 	(revision )
@@ -1,1771 +1,0 @@
-unit Helper_LevelDB;
-
-interface
-
-uses
-  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
-  Dialogs, ComCtrls, StdCtrls, StrUtils;
-
-type
-  TForm_LevelDB = class(TForm)
-    group_progress: TGroupBox;
-    progress:     TProgressBar;
-    lbl_progress: TLabel;
-    btn_abortok:  TButton;
-    lbl_estimation: TLabel;
-    procedure btn_abortokClick(Sender: TObject);
-  private
-    procedure HandleFile(ext: String; fileid: Integer; dir_dat2db: Boolean);
-    procedure stop_convert;
-  public
-    procedure CreateDatabase(Source, Target: String);
-    procedure CreateLevel(Source, Target: String);
-  end;
-
-
-var
-  Form_LevelDB: TForm_LevelDB;
-
-implementation
-
-{$R *.dfm}
-
-uses ABSMain, ABSDecUtil, Main, Functions, Data, OniImgClass, DataStructures, ConnectionManager;
-
-type
-  THandler = procedure(fileid: LongWord; dir_dat2db: Boolean);
-
-  TConvertHandlers = record
-    Ext:     String[4];
-    needed:  Boolean;
-    Handler: THandler;
-  end;
-
-var
-  ConvertHandlers: array of TConvertHandlers;
-  loaded_filename: String;
-  converting: Boolean = False;
-  abort:     Boolean = False;
-  DataBase:  TABSDatabase;
-  Query:     TABSQuery;
-  MimeCoder: TStringFormat_MIME64;
-
-var
-  DatHeader:   THeader;
-  FilesHeader: TFilesMap;
-  NamedFilesHeader: TNamedFilesMap;
-  ExtensionsHeader: TExtensionsMap;
-  Stream_Body, Stream_Names: TMemoryStream;
-  Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
-  OniDataConnection: TOniData;
-
-
-
-
-procedure TForm_LevelDB.CreateLevel(Source, target: String);
-var
-  files: LongWord;
-
-  i, j:     LongWord;
-  temps, temps2: String;
-  Data, rawdata: Tdata;
-  absolutebegintime, begintime: Double;
-  step:     Byte;
-  rawlist:  TRawList;
-  extlist:  TExtensionsMap;
-  fileinfo: TFileInfo;
-  datlinks: TDatLinks;
-  OniImage: TOniImage;
-  levelid:  LongWord;
-  timeformat: TFormatSettings;
-
-  conIndex: Integer;
-  connection: TOniData;
-const
-  steps: Byte = 3;
-
-
-
-
-  procedure DoStep(stepname: String);
-  begin
-    Inc(step);
-    if stepname <> 'FIN' then
-      group_progress.Caption :=
-        'Creating Dat (Step ' + IntToStr(step) + '/' + IntToStr(steps) + ': ' + stepname + ')'
-    else
-      group_progress.Caption := 'Creating Dat (FINISHED)';
-  end;
-
-begin
-
-  //
-  // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
-  //
-
-  timeformat.ShortTimeFormat := 'hh:nn:ss';
-  timeformat.LongTimeFormat := 'hh:nn:ss';
-  timeformat.TimeSeparator := ':';
-
-  connection := ConnectionExists(target);
-  if connection <> nil then
-  begin
-    ShowMessage('Destination-file is opened, close it in order to proceed conversion?');
-    Exit;
-  end;
-
-  connection := ConnectionExists(source);
-  if connection <> nil then
-  begin
-    ShowMessage('Source-file is opened, close it in order to proceed conversion?');
-    Exit;
-  end;
-
-
-  if CreateDataConnection(Source, ODB_ADB) = nil then
-  begin
-    ShowMessage('Could not connect to .oldb-file');
-    Exit;
-  end;
-  levelid  := OniDataConnection.LevelInfo.LevelNumber;
-  levelid  := (levelid * 2) * 256 * 256 * 256 + $01;
-  OniImage := TOniImage.Create;
-
-  absolutebegintime := Time;
-
-  Self.Visible := True;
-  Form_Main.Visible := False;
-  step  := 0;
-  converting := True;
-  abort := False;
-  btn_abortok.Caption := '&Abort...';
-  btn_abortok.Default := False;
-  absolutebegintime := Time;
-
-  Stream_Body  := TMemoryStream.Create;
-  Stream_Names := TMemoryStream.Create;
-  Stream_Dat   := TFileStream.Create(target, fmCreate);
-  Stream_Raw   := TFileStream.Create(AnsiReplaceStr(target, '.dat', '.raw'), fmCreate);
-  if OniDataConnection.OSisMac then
-    Stream_Sep := TFileStream.Create(AnsiReplaceStr(target, '.dat', '.sep'), fmCreate);
-
-  DoStep('Creating header');
-  progress.Position      := 0;
-  lbl_progress.Caption   := '';
-  lbl_estimation.Caption := 'Estimated finishing time: unknown';
-  Application.ProcessMessages;
-
-  NamedFilesHeader := TOniDataADB(OniDataConnection).GetNamedFilesMap;
-  extlist := OniDataConnection.GetExtendedExtensionsList;
-  for i := 0 to High(DatHeader.Ident) do
-    DatHeader.Ident[i] := OniDataConnection.LevelInfo.Ident[i];
-  DatHeader.Files := OniDataConnection.GetFilesCount;
-  DatHeader.NamedFiles := Length(NamedFilesHeader);
-  DatHeader.Extensions := Length(extlist);
-  DatHeader.DataAddr   := 0;
-  DatHeader.DataSize   := 0;
-  DatHeader.NamesAddr  := 0;
-  DatHeader.NamesSize  := 0;
-  for i := 0 to High(DatHeader.Ident2) do
-    DatHeader.Ident2[i] := 0;
-  SetLength(FilesHeader, DatHeader.Files);
-  SetLength(ExtensionsHeader, DatHeader.Extensions);
-
-  DoStep('Writing extensions-header');
-  progress.Max := Length(OniDataConnection.GetExtensionsList);
-  Application.ProcessMessages;
-
-  for i := 0 to High(ExtensionsHeader) do
-  begin
-    ExtensionsHeader[i].Ident     := extlist[i].Ident;
-    ExtensionsHeader[i].Extension := extlist[i].Extension;
-    SetLength(temps, 4);
-    for j := 0 to 3 do
-      temps[j + 1] := ExtensionsHeader[i].Extension[3 - j];
-    ExtensionsHeader[i].ExtCount :=
-      Length(OniDataConnection.GetFilesList(temps, '', False, stIDAsc));
-    progress.Position    := i + 1;
-    lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
-      IntToStr(Length(extlist));
-    Application.ProcessMessages;
-  end;
-
-  DoStep('Storing files-data');
-  progress.Position := 0;
-  progress.Max      := DatHeader.Files;
-  lbl_progress.Caption := '';
-  lbl_estimation.Caption := 'Estimated finishing time: unknown';
-  Application.ProcessMessages;
-
-  begintime := Time;
-  for i := 0 to DatHeader.Files - 1 do
-  begin
-    fileinfo := OniDataConnection.GetFileInfo(i);
-    for j := 0 to 3 do
-      FilesHeader[i].Extension[j] := fileinfo.Extension[4 - j];
-    if fileinfo.Size > 0 then
-    begin
-      //        DatLinks:=;
-      FilesHeader[i].DataAddr := Stream_Body.Size + 8;
-      Data    := OniDataConnection.LoadDatFile(i);
-      Data[4] := (levelid) and $FF;
-      Data[5] := (levelid shr 8) and $FF;
-      Data[6] := (levelid shr 16) and $FF;
-      Data[7] := (levelid shr 24) and $FF;
-
-      if (Pos(UpperCase(fileinfo.Extension), UpperCase(raws)) mod 4) = 1 then
-      begin
-        rawlist := OniDataConnection.GetRawList(i);
-        if Length(rawlist) > 0 then
-        begin
-          for j := 0 to High(rawlist) do
-          begin
-            if rawlist[j].raw_size > 0 then
-            begin
-              if (UpperCase(fileinfo.Extension) = 'TXMP') and
-                ((Data[$88] and $01) > 0) then
-              begin
-                OniImage.LoadFromTXMP(Connection, i);
-                OniImage.GetMipMappedImage(rawdata);
-                rawlist[j].raw_size := OniImage.GetImageDataSize(True);
-                Data[$90] := $08;
-                Data[$89] := 32;
-{                  if data[$90]<>OniImage.StoreType then begin
-                    data[$90]:=OniImage.StoreType;
-                    data[$89]:=(data[$89] and $CF) or $20;
-                  end;
-}                end
-              else
-              begin
-                SetLength(rawdata, rawlist[j].raw_size);
-                OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, @rawdata[0]);
-              end;
-              //                data[$88]:=data[$88] and $FE;
-
-              if rawlist[j].loc_sep then
-              begin
-                rawlist[j].raw_addr := Stream_Sep.Size;
-                Stream_Sep.Write(rawdata[0], Length(rawdata));
-              end
-              else
-              begin
-                rawlist[j].raw_addr := Stream_Raw.Size;
-                Stream_Raw.Write(rawdata[0], Length(rawdata));
-              end;
-            end
-            else
-              rawlist[j].raw_addr := 0;
-            Data[rawlist[j].src_offset + 0] := (rawlist[j].raw_addr) and $FF;
-            Data[rawlist[j].src_offset + 1] := (rawlist[j].raw_addr shr 8) and $FF;
-            Data[rawlist[j].src_offset + 2] := (rawlist[j].raw_addr shr 16) and $FF;
-            Data[rawlist[j].src_offset + 3] := (rawlist[j].raw_addr shr 24) and $FF;
-          end;
-        end;
-      end;
-
-      Stream_Body.Write(Data[0], Length(Data));
-      //
-    end
-    else
-      FilesHeader[i].DataAddr := 0;
-    if Length(fileinfo.Name) > 0 then
-    begin
-      FilesHeader[i].NameAddr := Stream_Names.Size;
-      temps := fileinfo.Extension + fileinfo.Name + Chr(0);
-      Stream_Names.Write(temps[1], Length(temps));
-    end
-    else
-      FilesHeader[i].NameAddr := 0;
-    FilesHeader[i].FileSize := fileinfo.Size;
-    FilesHeader[i].FileType := fileinfo.FileType;
-
-    if ((i mod 10) = 0) and (i >= 100) then
-      lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
-        (Time - begintime) / i * (progress.Max - i + 1) * 1.1, timeformat );
-    progress.Position := i + 1;
-    lbl_progress.Caption := 'Files done: ' + IntToStr(i + 1) + '/' + IntToStr(progress.Max);
-    Application.ProcessMessages;
-  end;
-
-  Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
-  for i := 0 to High(FilesHeader) do
-    Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
-  for i := 0 to High(NamedFilesHeader) do
-    Stream_Dat.Write(NamedFilesHeader[i], SizeOf(NamedFilesHeader[i]));
-  for i := 0 to High(ExtensionsHeader) do
-    Stream_Dat.Write(ExtensionsHeader[i], SizeOf(ExtensionsHeader[i]));
-
-  DatHeader.DataSize  := Stream_Body.Size;
-  DatHeader.NamesSize := Stream_Names.Size;
-  DatHeader.DataAddr  := Stream_Dat.Size;
-  Stream_Body.Seek(0, soFromBeginning);
-  Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
-  DatHeader.NamesAddr := Stream_Dat.Size;
-  Stream_Names.Seek(0, soFromBeginning);
-  Stream_Dat.CopyFrom(Stream_Names, Stream_Names.Size);
-
-  Stream_Dat.Seek(0, soFromBeginning);
-  Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
-
-  Stream_Dat.Free;
-  Stream_Body.Free;
-  Stream_Names.Free;
-  Stream_Raw.Free;
-  if OniDataConnection.OSisMac then
-    Stream_Sep.Free;
-
-  progress.Position      := progress.Max;
-  lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
-    IntToStr(progress.Max);
-  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime, timeformat) + ')';
-
-  DoStep('FIN');
-  btn_abortok.Caption := '&OK';
-  btn_abortok.Default := True;
-
-  OniImage.Free;
-
-  converting := False;
-
-  CloseDataConnection(DataConnections[conIndex]);
-end;
-
-
-
-
-procedure TForm_LevelDB.HandleFile;
-var
-  i: Byte;
-begin
-  for i := 1 to Length(ConvertHandlers) do
-    if UpperCase(ConvertHandlers[i].Ext) = UpperCase(ext) then
-      if ConvertHandlers[i].needed then
-      begin
-        ConvertHandlers[i].Handler(fileid, dir_dat2db);
-        Break;
-      end
-      else
-        Break;
-end;
-
-
-
-
-procedure TForm_LevelDB.CreateDatabase(Source, target: String);
-var
-  i, j:     LongWord;
-  temps, temps2: String;
-  Data:     Tdata;
-  absolutebegintime, begintime: Double;
-  step:     Byte;
-  rawlist:  TRawList;
-  extlist:  TExtensionsMap;
-  fileinfo: TFileInfo;
-  timeformat: TFormatSettings;
-
-  conIndex: Integer;
-const
-  steps: Byte = 4;
-
-
-
-
-  procedure DoStep(stepname: String);
-  begin
-    Inc(step);
-    if stepname <> 'FIN' then
-      group_progress.Caption :=
-        'Creating DB (Step ' + IntToStr(step) + '/' + IntToStr(steps) + ': ' + stepname + ')'
-    else
-      group_progress.Caption := 'Creating DB (FINISHED)';
-  end;
-
-begin
-  if CreateDataConnection(Source, ODB_Dat) = nil then
-  begin
-    ShowMessage('Could not connect to .dat-file');
-    Exit;
-  end
-  else
-  begin
-    TOniDataDat(OniDataConnection).UnloadWhenUnused := False;
-  end;
-
-  timeformat.LongTimeFormat := 'hh:nn:ss';
-  timeformat.ShortTimeFormat := 'hh:nn:ss';
-  timeformat.TimeSeparator := ':';
-
-  Self.Visible := True;
-  Form_Main.Visible := False;
-  step  := 0;
-  converting := True;
-  abort := False;
-  btn_abortok.Caption := '&Abort...';
-  btn_abortok.Default := False;
-  loaded_filename := target;
-
-  absolutebegintime := Time;
-
-  DataBase := TABSDatabase.Create(Self);
-  DataBase.DatabaseName := 'OLDB';
-  DataBase.DatabaseFileName := target;
-  DataBase.CreateDatabase;
-
-  DoStep('Creating tables');
-  progress.Position      := 0;
-  lbl_progress.Caption   := '';
-  lbl_estimation.Caption := 'Estimated finishing time: unknown';
-  Application.ProcessMessages;
-
-  Query := TABSQuery.Create(Self);
-  Query.DatabaseName := 'OLDB';
-  Query.SQL.Text :=
-    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), value STRING(128) );';
-  Query.ExecSQL;
-  Query.SQL.Text :=
-    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, target_id INTEGER );';
-  Query.ExecSQL;
-  Query.SQL.Text :=
-    'CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, sep BOOLEAN, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
-  //    Query.SQL.Text:='CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
-  Query.ExecSQL;
-  Query.SQL.Text :=
-    'CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
-  //    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
-  Query.ExecSQL;
-  Query.SQL.Text :=
-    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
-  Query.ExecSQL;
-
-  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
-    dbversion + '");';
-  Query.ExecSQL;
-  SetLength(Data, Length(OniDataConnection.LevelInfo.Ident));
-  for i := 0 to High(OniDataConnection.LevelInfo.Ident) do
-    Data[i] := OniDataConnection.LevelInfo.Ident[i];
-  temps := CreateHexString(Data, True);
-  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("ident","' + temps + '");';
-  Query.ExecSQL;
-  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
-    IntToStr(OniDataConnection.LevelInfo.LevelNumber) + '");';
-  Query.ExecSQL;
-  if OniDataConnection.OSisMAC then
-    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","MAC");'
-  else
-    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","PC");';
-  Query.ExecSQL;
-
-  DoStep('Writing extensionslist');
-  progress.Max := Length(OniDataConnection.GetExtensionsList);
-  Application.ProcessMessages;
-
-  extlist := OniDataConnection.GetExtendedExtensionsList;
-  for i := 0 to High(extlist) do
-  begin
-    SetLength(Data, Length(extlist[i].Ident));
-    for j := 0 to High(extlist[i].Ident) do
-      Data[j] := extlist[i].Ident[j];
-    temps := CreateHexString(Data, True);
-    temps2 := extlist[i].Extension[3] + extlist[i].Extension[2] +
-      extlist[i].Extension[1] + extlist[i].Extension[0];
-    Query.SQL.Text := 'INSERT INTO extlist (ext,ident) VALUES ("' +
-      temps2 + '","' + temps + '");';
-    Query.ExecSQL;
-    progress.Position    := i;
-    lbl_progress.Caption := 'Extensions done: ' + IntToStr(i) + '/' +
-      IntToStr(Length(extlist));
-    Application.ProcessMessages;
-    if abort then
-    begin
-      stop_convert;
-      Exit;
-    end;
-  end;
-  lbl_progress.Caption := '';
-
-  progress.Position      := 0;
-  lbl_progress.Caption   := 'Files done: ' + IntToStr(0) + '/' + IntToStr(
-    OniDataConnection.GetFilesCount);
-  lbl_estimation.Caption := 'Estimated finishing time: unknown';
-
-  DoStep('Loading .dat into memory');
-  Application.ProcessMessages;
-
-  progress.Max := OniDataConnection.GetFilesCount;
-  begintime    := Time;
-  DoStep('Writing .dat-fileslist');
-  Application.ProcessMessages;
-
-  Database.StartTransaction;
-  for i := 0 to OniDataConnection.GetFilesCount - 1 do
-  begin
-    fileinfo := OniDataConnection.GetFileInfo(i);
-    if (fileinfo.FileType and $02) = 0 then
-    begin
-      mimecoder := TStringFormat_MIME64.Create;
-      Data      := OniDataConnection.LoadDatFile(i);
-      Query.SQL.Text :=
-        'INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES (' +
-        IntToStr(i) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
-        fileinfo.FileType, 8) + '",' + IntToStr(fileinfo.Size) + ',MimeToBin("' +
-        MimeCoder.StrTo(@Data[0], Length(Data)) + '") );';
-      Query.ExecSQL;
-      mimecoder.Free;
-
-      rawlist := OniDataConnection.GetRawList(i);
-      if Length(rawlist) > 0 then
-      begin
-        for j := 0 to High(rawlist) do
-        begin
-          if rawlist[j].raw_size > 0 then
-          begin
-            SetLength(Data, rawlist[j].raw_size);
-            OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, Data);
-            mimecoder      := TStringFormat_MIME64.Create;
-            Query.SQL.Text :=
-              'INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES (' +
-              IntToStr(i) + ',' + IntToStr(rawlist[j].src_offset) + ',' + BoolToStr(
-              rawlist[j].loc_sep) + ',' + IntToStr(rawlist[j].raw_size) + ',MimeToBin("' +
-              MimeCoder.StrTo(@Data[0], rawlist[j].raw_size) + '") );';
-            Query.ExecSQL;
-            mimecoder.Free;
-          end
-          else
-          begin
-            Query.SQL.Text :=
-              'INSERT INTO rawmap (src_id,src_link_offset,sep,size) VALUES (' +
-              IntToStr(i) + ',' + IntToStr(rawlist[j].src_offset) + ',' + BoolToStr(rawlist[j].loc_sep) + ',0);';
-            Query.ExecSQL;
-          end;
-        end;
-      end;
-
-      HandleFile(fileinfo.Extension, i, True);
-    end
-    else
-    begin
-      Query.SQL.Text :=
-        'INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES (' +
-        IntToStr(i) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
-        fileinfo.FileType, 8) + '",0);';
-      Query.ExecSQL;
-    end;
-    if ((i mod 100) = 0) and (i > 0) then
-    begin
-      Database.Commit(False);
-      Database.StartTransaction;
-    end;
-    if ((i mod 10) = 0) and (i >= 100) then
-      lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
-        (Time - begintime) / i * (progress.Max - i + 1) * 1.1, timeformat );
-    progress.Position := i;
-    lbl_progress.Caption := 'Files done: ' + IntToStr(i) + '/' + IntToStr(progress.Max);
-    Application.ProcessMessages;
-    if abort then
-    begin
-      stop_convert;
-      Exit;
-    end;
-  end;
-  Database.Commit(False);
-  progress.Position      := progress.Max;
-  lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
-    IntToStr(progress.Max);
-
-  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime, timeformat) + ')';
-
-  DoStep('FIN');
-  btn_abortok.Caption := '&OK';
-  btn_abortok.Default := True;
-
-  converting := False;
-
-  database.Close;
-  database.Free;
-
-  CloseDataConnection(DataConnections[conIndex]);
-end;
-
-
-
-
-procedure TForm_LevelDB.stop_convert;
-begin
-  btn_abortok.Caption := '&Close';
-  btn_abortok.Default := True;
-  converting := False;
-  lbl_estimation.Caption := 'ABORTED';
-  group_progress.Caption := 'Creating DB (ABORTED)';
-  DataBase.Close;
-  if MessageBox(Self.Handle, PChar('Delete the unfinished DB-file?'),
-    PChar('Delete file?'), MB_YESNO) = idYes then
-  begin
-    DeleteFile(loaded_filename);
-  end;
-end;
-
-
-
-
-procedure TForm_LevelDB.btn_abortokClick(Sender: TObject);
-begin
-  if converting then
-  begin
-    if MessageBox(Self.Handle,
-      PChar('Do you really want to cancel the convert-progress?'),
-      PChar('Warning: Converting'), MB_YESNO) = idYes then
-      abort := True;
-  end
-  else
-  begin
-    Self.Visible := False;
-    Form_Main.Visible  := True;
-  end;
-end;
-
-
-
-
-procedure InsertDatLinkToDB(fileid: LongWord; offset: LongWord);
-var
-  link: LongWord;
-begin
-  OniDataConnection.LoadDatFilePart(fileid, offset, 4, @link);
-  if link = 0 then
-    link := $FFFFFFFF
-  else
-    link := link div 256;
-  Query.SQL.Text := 'INSERT INTO linkmap (src_id,src_link_offset,target_id) VALUES (' +
-    IntToStr(fileid) + ',' + IntToStr(offset) + ',' + IntToStr(link) + ');';
-  Query.ExecSQL;
-end;
-
-
-
-
-procedure AISA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  packages: Word;
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
-    if packages > 0 then
-    begin
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * $160 + $28);
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * $160 + $150);
-    end;
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure AKEV(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 16 do
-      InsertDatLinkToDB(fileid, $8 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure AKOT(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 4 do
-      InsertDatLinkToDB(fileid, $8 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure CBPI(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 56 do
-      InsertDatLinkToDB(fileid, $8 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure CBPM(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 18 do
-      InsertDatLinkToDB(fileid, $8 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure CONS(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 1 do
-      InsertDatLinkToDB(fileid, $24 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure CRSA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  packages: LongWord;
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $14, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 1100 + $A0);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure DOOR(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $08);
-    InsertDatLinkToDB(fileid, $10);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure DPGE(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $40);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure HPGE(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $0C);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure IGHH(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $24);
-    InsertDatLinkToDB(fileid, $28);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure IGPA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  links: LongWord;
-  i:     LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
-    if links > 0 then
-      for i := 0 to links - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure IGPG(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 1 do
-      InsertDatLinkToDB(fileid, $1C + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure IGSA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  links: LongWord;
-  i:     LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
-    if links > 0 then
-      for i := 0 to links - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure IMPT(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $10);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure IPGE(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $0C);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure KEYI(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 9 do
-      InsertDatLinkToDB(fileid, $08 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure M3GA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  links: LongWord;
-  i:     LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
-    if links > 0 then
-      for i := 0 to links - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure M3GM(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 6 do
-      InsertDatLinkToDB(fileid, $0C + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure MTRL(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $10);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure OBDC(fileid: LongWord; dir_dat2db: Boolean);
-var
-  packages: Word;
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * $18 + $4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure OBOA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  packages: Word;
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-      begin
-        InsertDatLinkToDB(fileid, $20 + i * 240 + $0);
-        InsertDatLinkToDB(fileid, $20 + i * 240 + $4);
-        InsertDatLinkToDB(fileid, $20 + i * 240 + $8);
-      end;
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure OFGA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  packages: LongWord;
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 12 + $04);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure ONCC(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $28);
-    InsertDatLinkToDB(fileid, $434);
-    InsertDatLinkToDB(fileid, $438);
-    InsertDatLinkToDB(fileid, $43C);
-    InsertDatLinkToDB(fileid, $C3C);
-    InsertDatLinkToDB(fileid, $C40);
-    InsertDatLinkToDB(fileid, $C44);
-    InsertDatLinkToDB(fileid, $C48);
-    InsertDatLinkToDB(fileid, $C88);
-    InsertDatLinkToDB(fileid, $C8C);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure ONCV(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $08);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure ONLV(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 5 do
-      InsertDatLinkToDB(fileid, $48 + i * 4);
-    for i := 0 to 5 do
-      InsertDatLinkToDB(fileid, $64 + i * 4);
-    InsertDatLinkToDB(fileid, $300);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure ONOA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  packages: LongWord;
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 8 + $04);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure ONSK(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $08);
-    InsertDatLinkToDB(fileid, $0C);
-    InsertDatLinkToDB(fileid, $10);
-    InsertDatLinkToDB(fileid, $14);
-    InsertDatLinkToDB(fileid, $18);
-    InsertDatLinkToDB(fileid, $20);
-    InsertDatLinkToDB(fileid, $44);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure ONVL(fileid: LongWord; dir_dat2db: Boolean);
-var
-  packages: LongWord;
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure ONWC(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $28);
-    InsertDatLinkToDB(fileid, $34);
-    InsertDatLinkToDB(fileid, $40);
-    InsertDatLinkToDB(fileid, $54);
-    InsertDatLinkToDB(fileid, $58);
-    InsertDatLinkToDB(fileid, $5C);
-    InsertDatLinkToDB(fileid, $60);
-    InsertDatLinkToDB(fileid, $6FC);
-    InsertDatLinkToDB(fileid, $700);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure OPGE(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $0C);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure PSPC(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $50);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure PSPL(fileid: LongWord; dir_dat2db: Boolean);
-var
-  packages: LongWord;
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 8 + $4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure PSUI(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 43 do
-      InsertDatLinkToDB(fileid, $08 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure STNA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  packages: Word;
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TRAC(fileid: LongWord; dir_dat2db: Boolean);
-var
-  packages: Word;
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $18);
-    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 12 + 8);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TRAM(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $40);
-    InsertDatLinkToDB(fileid, $44);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TRAS(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $08);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TRBS(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 4 do
-      InsertDatLinkToDB(fileid, $08 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TRCM(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    for i := 0 to 2 do
-      InsertDatLinkToDB(fileid, $5C + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TRGA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-  packages: Word;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TRGE(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $20);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TRIG(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $18);
-    InsertDatLinkToDB(fileid, $24);
-    InsertDatLinkToDB(fileid, $28);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TRMA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-  packages: Word;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TRSC(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-  packages: Word;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TSFF(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-  packages: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TSFT(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $1C);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TURR(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $60);
-    InsertDatLinkToDB(fileid, $6C);
-    InsertDatLinkToDB(fileid, $74);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TXAN(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-  packages: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TXMA(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-  packages: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TXMB(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-  packages: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TXMP(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $94);
-    InsertDatLinkToDB(fileid, $98);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure TXTC(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $08);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure WMCL(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-  packages: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 8 + $4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure WMDD(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-  packages: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $11C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $120 + i * $124 + $114);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure WMMB(fileid: LongWord; dir_dat2db: Boolean);
-var
-  i: LongWord;
-  packages: LongWord;
-begin
-  if dir_dat2db then
-  begin
-    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
-    if packages > 0 then
-      for i := 0 to packages - 1 do
-        InsertDatLinkToDB(fileid, $20 + i * 4);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure WPGE(fileid: LongWord; dir_dat2db: Boolean);
-begin
-  if dir_dat2db then
-  begin
-    InsertDatLinkToDB(fileid, $08);
-    InsertDatLinkToDB(fileid, $0C);
-  end
-  else
-  begin
-  end;
-end;
-
-
-
-
-procedure InsertHandler(ext: String; needed: Boolean; handler: THandler);
-begin
-  SetLength(ConvertHandlers, Length(ConvertHandlers) + 1);
-  ConvertHandlers[High(ConvertHandlers)].Ext     := ext;
-  ConvertHandlers[High(ConvertHandlers)].needed  := needed;
-  ConvertHandlers[High(ConvertHandlers)].handler := handler;
-end;
-
-begin
-  InsertHandler('ABNA', False, nil);
-  //  InsertHandler('AGDB',True,AGDB);
-  InsertHandler('AGDB', False, nil);
-  InsertHandler('AGQC', False, nil);
-  InsertHandler('AGQG', False, nil);
-  InsertHandler('AGQR', False, nil);
-  InsertHandler('AISA', True, AISA);
-  InsertHandler('AITR', False, nil);
-  InsertHandler('AKAA', False, nil);
-  InsertHandler('AKBA', False, nil);
-  InsertHandler('AKBP', False, nil);
-  InsertHandler('AKDA', False, nil);
-  InsertHandler('AKEV', True, AKEV);
-  InsertHandler('AKOT', True, AKOT);
-  InsertHandler('AKVA', False, nil);
-  InsertHandler('BINA', False, nil);
-  InsertHandler('CBPI', True, CBPI);
-  InsertHandler('CBPM', True, CBPM);
-  InsertHandler('CONS', True, CONS);
-  InsertHandler('CRSA', True, CRSA);
-  InsertHandler('DOOR', True, DOOR);
-  InsertHandler('DPGE', True, DPGE);
-  InsertHandler('ENVP', False, nil);
-  InsertHandler('FILM', False, nil);
-  InsertHandler('HPGE', True, HPGE);
-  InsertHandler('IDXA', False, nil);
-  InsertHandler('IGHH', True, IGHH);
-  InsertHandler('IGPA', True, IGPA);
-  InsertHandler('IGPG', True, IGPG);
-  InsertHandler('IGSA', True, IGSA);
-  InsertHandler('IMPT', True, IMPT);
-  InsertHandler('IPGE', True, IPGE);
-  InsertHandler('KEYI', True, KEYI);
-  InsertHandler('M3GA', True, M3GA);
-  InsertHandler('M3GM', True, M3GM);
-  InsertHandler('MTRL', True, MTRL);
-  InsertHandler('OBAN', False, nil);
-  InsertHandler('OBDC', True, OBDC);
-  InsertHandler('OBOA', True, OBOA);
-  InsertHandler('OFGA', True, OFGA);
-  InsertHandler('ONCC', True, ONCC);
-  InsertHandler('ONCP', False, nil);
-  InsertHandler('ONCV', True, ONCV);
-  InsertHandler('ONFA', False, nil);
-  InsertHandler('ONGS', False, nil);
-  InsertHandler('ONIA', False, nil);
-  InsertHandler('ONLD', False, nil);
-  InsertHandler('ONLV', True, ONLV);
-  InsertHandler('ONMA', False, nil);
-  InsertHandler('ONOA', True, ONOA);
-  InsertHandler('ONSA', False, nil);
-  InsertHandler('ONSK', True, ONSK);
-  InsertHandler('ONTA', False, nil);
-  InsertHandler('ONVL', True, ONVL);
-  InsertHandler('ONWC', True, ONWC);
-  InsertHandler('OPGE', True, OPGE);
-  InsertHandler('OSBD', False, nil);
-  InsertHandler('OTIT', False, nil);
-  InsertHandler('OTLF', False, nil);
-  InsertHandler('PLEA', False, nil);
-  InsertHandler('PNTA', False, nil);
-  InsertHandler('PSPC', True, PSPC);
-  InsertHandler('PSPL', True, PSPL);
-  InsertHandler('PSUI', True, PSUI);
-  InsertHandler('QTNA', False, nil);
-  InsertHandler('SNDD', False, nil);
-  InsertHandler('STNA', True, STNA);
-  InsertHandler('SUBT', False, nil);
-  InsertHandler('TRAC', True, TRAC);
-  InsertHandler('TRAM', True, TRAM);
-  InsertHandler('TRAS', True, TRAS);
-  InsertHandler('TRBS', True, TRBS);
-  InsertHandler('TRCM', True, TRCM);
-  InsertHandler('TRGA', True, TRGA);
-  InsertHandler('TRGE', True, TRGE);
-  InsertHandler('TRIA', False, nil);
-  InsertHandler('TRIG', True, TRIG);
-  InsertHandler('TRMA', True, TRMA);
-  InsertHandler('TRSC', True, TRSC);
-  InsertHandler('TRTA', False, nil);
-  InsertHandler('TSFF', True, TSFF);
-  InsertHandler('TSFL', False, nil);
-  InsertHandler('TSFT', True, TSFT);
-  InsertHandler('TSGA', False, nil);
-  InsertHandler('TSTR', False, nil);
-  InsertHandler('TURR', True, TURR);
-  InsertHandler('TXAN', True, TXAN);
-  InsertHandler('TXCA', False, nil);
-  InsertHandler('TXMA', True, TXMA);
-  InsertHandler('TXMB', True, TXMB);
-  InsertHandler('TXMP', True, TXMP);
-  InsertHandler('TXTC', True, TXTC);
-  InsertHandler('VCRA', False, nil);
-  InsertHandler('WMCL', True, WMCL);
-  InsertHandler('WMDD', True, WMDD);
-  InsertHandler('WMM_', False, nil);
-  InsertHandler('WMMB', True, WMMB);
-  InsertHandler('WPGE', True, WPGE);
-end.
Index: oup/rewrite/Helper/LevelDB.dfm
===================================================================
--- oup/rewrite/Helper/LevelDB.dfm	(revision 105)
+++ oup/rewrite/Helper/LevelDB.dfm	(revision 105)
@@ -0,0 +1,61 @@
+object Form_LevelDB: TForm_LevelDB
+  Left = 0
+  Top = 0
+  BorderStyle = bsNone
+  Caption = 'Creating DB'
+  ClientHeight = 89
+  ClientWidth = 400
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -11
+  Font.Name = 'Tahoma'
+  Font.Style = []
+  OldCreateOrder = False
+  Position = poScreenCenter
+  PixelsPerInch = 96
+  TextHeight = 13
+  object group_progress: TGroupBox
+    Left = 0
+    Top = 0
+    Width = 400
+    Height = 89
+    Caption = 'Progress ...'
+    TabOrder = 0
+    object lbl_progress: TLabel
+      Left = 2
+      Top = 32
+      Width = 396
+      Height = 17
+      Align = alTop
+      AutoSize = False
+    end
+    object lbl_estimation: TLabel
+      Left = 2
+      Top = 49
+      Width = 396
+      Height = 17
+      Align = alTop
+      AutoSize = False
+      Caption = 'Estimated finishing time:'
+    end
+    object progress: TProgressBar
+      Left = 2
+      Top = 15
+      Width = 396
+      Height = 17
+      Align = alTop
+      Smooth = True
+      TabOrder = 0
+    end
+    object btn_abortok: TButton
+      Left = 3
+      Top = 64
+      Width = 60
+      Height = 22
+      Caption = 'Abort...'
+      TabOrder = 1
+      OnClick = btn_abortokClick
+    end
+  end
+end
Index: oup/rewrite/Helper/LevelDB.pas
===================================================================
--- oup/rewrite/Helper/LevelDB.pas	(revision 105)
+++ oup/rewrite/Helper/LevelDB.pas	(revision 105)
@@ -0,0 +1,1771 @@
+unit Helper_LevelDB;
+
+interface
+
+uses
+  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+  Dialogs, ComCtrls, StdCtrls, StrUtils;
+
+type
+  TForm_LevelDB = class(TForm)
+    group_progress: TGroupBox;
+    progress:     TProgressBar;
+    lbl_progress: TLabel;
+    btn_abortok:  TButton;
+    lbl_estimation: TLabel;
+    procedure btn_abortokClick(Sender: TObject);
+  private
+    procedure HandleFile(ext: String; fileid: Integer; dir_dat2db: Boolean);
+    procedure stop_convert;
+  public
+    procedure CreateDatabase(Source, Target: String);
+    procedure CreateLevel(Source, Target: String);
+  end;
+
+
+var
+  Form_LevelDB: TForm_LevelDB;
+
+implementation
+
+{$R *.dfm}
+
+uses ABSMain, ABSDecUtil, Main, Functions, Data, OniImgClass, DataStructures, ConnectionManager;
+
+type
+  THandler = procedure(fileid: LongWord; dir_dat2db: Boolean);
+
+  TConvertHandlers = record
+    Ext:     String[4];
+    needed:  Boolean;
+    Handler: THandler;
+  end;
+
+var
+  ConvertHandlers: array of TConvertHandlers;
+  loaded_filename: String;
+  converting: Boolean = False;
+  abort:     Boolean = False;
+  DataBase:  TABSDatabase;
+  Query:     TABSQuery;
+  MimeCoder: TStringFormat_MIME64;
+
+var
+  DatHeader:   THeader;
+  FilesHeader: TFilesMap;
+  NamedFilesHeader: TNamedFilesMap;
+  ExtensionsHeader: TExtensionsMap;
+  Stream_Body, Stream_Names: TMemoryStream;
+  Stream_Dat, Stream_Raw, Stream_Sep: TFileStream;
+  OniDataConnection: TOniData;
+
+
+
+
+procedure TForm_LevelDB.CreateLevel(Source, target: String);
+var
+  files: LongWord;
+
+  i, j:     LongWord;
+  temps, temps2: String;
+  Data, rawdata: Tdata;
+  absolutebegintime, begintime: Double;
+  step:     Byte;
+  rawlist:  TRawList;
+  extlist:  TExtensionsMap;
+  fileinfo: TFileInfo;
+  datlinks: TDatLinks;
+  OniImage: TOniImage;
+  levelid:  LongWord;
+  timeformat: TFormatSettings;
+
+  conIndex: Integer;
+  connection: TOniData;
+const
+  steps: Byte = 3;
+
+
+
+
+  procedure DoStep(stepname: String);
+  begin
+    Inc(step);
+    if stepname <> 'FIN' then
+      group_progress.Caption :=
+        'Creating Dat (Step ' + IntToStr(step) + '/' + IntToStr(steps) + ': ' + stepname + ')'
+    else
+      group_progress.Caption := 'Creating Dat (FINISHED)';
+  end;
+
+begin
+
+  //
+  // FILE EXISTS CHECK FÜR DAT/RAW/SEP!!!
+  //
+
+  timeformat.ShortTimeFormat := 'hh:nn:ss';
+  timeformat.LongTimeFormat := 'hh:nn:ss';
+  timeformat.TimeSeparator := ':';
+
+  connection := ConnectionExists(target);
+  if connection <> nil then
+  begin
+    ShowMessage('Destination-file is opened, close it in order to proceed conversion?');
+    Exit;
+  end;
+
+  connection := ConnectionExists(source);
+  if connection <> nil then
+  begin
+    ShowMessage('Source-file is opened, close it in order to proceed conversion?');
+    Exit;
+  end;
+
+
+  if CreateDataConnection(Source, ODB_ADB) = nil then
+  begin
+    ShowMessage('Could not connect to .oldb-file');
+    Exit;
+  end;
+  levelid  := OniDataConnection.LevelInfo.LevelNumber;
+  levelid  := (levelid * 2) * 256 * 256 * 256 + $01;
+  OniImage := TOniImage.Create;
+
+  absolutebegintime := Time;
+
+  Self.Visible := True;
+  Form_Main.Visible := False;
+  step  := 0;
+  converting := True;
+  abort := False;
+  btn_abortok.Caption := '&Abort...';
+  btn_abortok.Default := False;
+  absolutebegintime := Time;
+
+  Stream_Body  := TMemoryStream.Create;
+  Stream_Names := TMemoryStream.Create;
+  Stream_Dat   := TFileStream.Create(target, fmCreate);
+  Stream_Raw   := TFileStream.Create(AnsiReplaceStr(target, '.dat', '.raw'), fmCreate);
+  if OniDataConnection.OSisMac then
+    Stream_Sep := TFileStream.Create(AnsiReplaceStr(target, '.dat', '.sep'), fmCreate);
+
+  DoStep('Creating header');
+  progress.Position      := 0;
+  lbl_progress.Caption   := '';
+  lbl_estimation.Caption := 'Estimated finishing time: unknown';
+  Application.ProcessMessages;
+
+  NamedFilesHeader := TOniDataADB(OniDataConnection).GetNamedFilesMap;
+  extlist := OniDataConnection.GetExtendedExtensionsList;
+  for i := 0 to High(DatHeader.Ident) do
+    DatHeader.Ident[i] := OniDataConnection.LevelInfo.Ident[i];
+  DatHeader.Files := OniDataConnection.GetFilesCount;
+  DatHeader.NamedFiles := Length(NamedFilesHeader);
+  DatHeader.Extensions := Length(extlist);
+  DatHeader.DataAddr   := 0;
+  DatHeader.DataSize   := 0;
+  DatHeader.NamesAddr  := 0;
+  DatHeader.NamesSize  := 0;
+  for i := 0 to High(DatHeader.Ident2) do
+    DatHeader.Ident2[i] := 0;
+  SetLength(FilesHeader, DatHeader.Files);
+  SetLength(ExtensionsHeader, DatHeader.Extensions);
+
+  DoStep('Writing extensions-header');
+  progress.Max := Length(OniDataConnection.GetExtensionsList);
+  Application.ProcessMessages;
+
+  for i := 0 to High(ExtensionsHeader) do
+  begin
+    ExtensionsHeader[i].Ident     := extlist[i].Ident;
+    ExtensionsHeader[i].Extension := extlist[i].Extension;
+    SetLength(temps, 4);
+    for j := 0 to 3 do
+      temps[j + 1] := ExtensionsHeader[i].Extension[3 - j];
+    ExtensionsHeader[i].ExtCount :=
+      Length(OniDataConnection.GetFilesList(temps, '', False, stIDAsc));
+    progress.Position    := i + 1;
+    lbl_progress.Caption := 'Extensions done: ' + IntToStr(i + 1) + '/' +
+      IntToStr(Length(extlist));
+    Application.ProcessMessages;
+  end;
+
+  DoStep('Storing files-data');
+  progress.Position := 0;
+  progress.Max      := DatHeader.Files;
+  lbl_progress.Caption := '';
+  lbl_estimation.Caption := 'Estimated finishing time: unknown';
+  Application.ProcessMessages;
+
+  begintime := Time;
+  for i := 0 to DatHeader.Files - 1 do
+  begin
+    fileinfo := OniDataConnection.GetFileInfo(i);
+    for j := 0 to 3 do
+      FilesHeader[i].Extension[j] := fileinfo.Extension[4 - j];
+    if fileinfo.Size > 0 then
+    begin
+      //        DatLinks:=;
+      FilesHeader[i].DataAddr := Stream_Body.Size + 8;
+      Data    := OniDataConnection.LoadDatFile(i);
+      Data[4] := (levelid) and $FF;
+      Data[5] := (levelid shr 8) and $FF;
+      Data[6] := (levelid shr 16) and $FF;
+      Data[7] := (levelid shr 24) and $FF;
+
+      if (Pos(UpperCase(fileinfo.Extension), UpperCase(raws)) mod 4) = 1 then
+      begin
+        rawlist := OniDataConnection.GetRawList(i);
+        if Length(rawlist) > 0 then
+        begin
+          for j := 0 to High(rawlist) do
+          begin
+            if rawlist[j].raw_size > 0 then
+            begin
+              if (UpperCase(fileinfo.Extension) = 'TXMP') and
+                ((Data[$88] and $01) > 0) then
+              begin
+                OniImage.LoadFromTXMP(Connection, i);
+                OniImage.GetMipMappedImage(rawdata);
+                rawlist[j].raw_size := OniImage.GetImageDataSize(True);
+                Data[$90] := $08;
+                Data[$89] := 32;
+{                  if data[$90]<>OniImage.StoreType then begin
+                    data[$90]:=OniImage.StoreType;
+                    data[$89]:=(data[$89] and $CF) or $20;
+                  end;
+}                end
+              else
+              begin
+                SetLength(rawdata, rawlist[j].raw_size);
+                OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, @rawdata[0]);
+              end;
+              //                data[$88]:=data[$88] and $FE;
+
+              if rawlist[j].loc_sep then
+              begin
+                rawlist[j].raw_addr := Stream_Sep.Size;
+                Stream_Sep.Write(rawdata[0], Length(rawdata));
+              end
+              else
+              begin
+                rawlist[j].raw_addr := Stream_Raw.Size;
+                Stream_Raw.Write(rawdata[0], Length(rawdata));
+              end;
+            end
+            else
+              rawlist[j].raw_addr := 0;
+            Data[rawlist[j].src_offset + 0] := (rawlist[j].raw_addr) and $FF;
+            Data[rawlist[j].src_offset + 1] := (rawlist[j].raw_addr shr 8) and $FF;
+            Data[rawlist[j].src_offset + 2] := (rawlist[j].raw_addr shr 16) and $FF;
+            Data[rawlist[j].src_offset + 3] := (rawlist[j].raw_addr shr 24) and $FF;
+          end;
+        end;
+      end;
+
+      Stream_Body.Write(Data[0], Length(Data));
+      //
+    end
+    else
+      FilesHeader[i].DataAddr := 0;
+    if Length(fileinfo.Name) > 0 then
+    begin
+      FilesHeader[i].NameAddr := Stream_Names.Size;
+      temps := fileinfo.Extension + fileinfo.Name + Chr(0);
+      Stream_Names.Write(temps[1], Length(temps));
+    end
+    else
+      FilesHeader[i].NameAddr := 0;
+    FilesHeader[i].FileSize := fileinfo.Size;
+    FilesHeader[i].FileType := fileinfo.FileType;
+
+    if ((i mod 10) = 0) and (i >= 100) then
+      lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
+        (Time - begintime) / i * (progress.Max - i + 1) * 1.1, timeformat );
+    progress.Position := i + 1;
+    lbl_progress.Caption := 'Files done: ' + IntToStr(i + 1) + '/' + IntToStr(progress.Max);
+    Application.ProcessMessages;
+  end;
+
+  Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
+  for i := 0 to High(FilesHeader) do
+    Stream_Dat.Write(FilesHeader[i], SizeOf(FilesHeader[i]));
+  for i := 0 to High(NamedFilesHeader) do
+    Stream_Dat.Write(NamedFilesHeader[i], SizeOf(NamedFilesHeader[i]));
+  for i := 0 to High(ExtensionsHeader) do
+    Stream_Dat.Write(ExtensionsHeader[i], SizeOf(ExtensionsHeader[i]));
+
+  DatHeader.DataSize  := Stream_Body.Size;
+  DatHeader.NamesSize := Stream_Names.Size;
+  DatHeader.DataAddr  := Stream_Dat.Size;
+  Stream_Body.Seek(0, soFromBeginning);
+  Stream_Dat.CopyFrom(Stream_Body, Stream_Body.Size);
+  DatHeader.NamesAddr := Stream_Dat.Size;
+  Stream_Names.Seek(0, soFromBeginning);
+  Stream_Dat.CopyFrom(Stream_Names, Stream_Names.Size);
+
+  Stream_Dat.Seek(0, soFromBeginning);
+  Stream_Dat.Write(DatHeader, SizeOf(DatHeader));
+
+  Stream_Dat.Free;
+  Stream_Body.Free;
+  Stream_Names.Free;
+  Stream_Raw.Free;
+  if OniDataConnection.OSisMac then
+    Stream_Sep.Free;
+
+  progress.Position      := progress.Max;
+  lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
+    IntToStr(progress.Max);
+  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime, timeformat) + ')';
+
+  DoStep('FIN');
+  btn_abortok.Caption := '&OK';
+  btn_abortok.Default := True;
+
+  OniImage.Free;
+
+  converting := False;
+
+  CloseDataConnection(DataConnections[conIndex]);
+end;
+
+
+
+
+procedure TForm_LevelDB.HandleFile;
+var
+  i: Byte;
+begin
+  for i := 1 to Length(ConvertHandlers) do
+    if UpperCase(ConvertHandlers[i].Ext) = UpperCase(ext) then
+      if ConvertHandlers[i].needed then
+      begin
+        ConvertHandlers[i].Handler(fileid, dir_dat2db);
+        Break;
+      end
+      else
+        Break;
+end;
+
+
+
+
+procedure TForm_LevelDB.CreateDatabase(Source, target: String);
+var
+  i, j:     LongWord;
+  temps, temps2: String;
+  Data:     Tdata;
+  absolutebegintime, begintime: Double;
+  step:     Byte;
+  rawlist:  TRawList;
+  extlist:  TExtensionsMap;
+  fileinfo: TFileInfo;
+  timeformat: TFormatSettings;
+
+  conIndex: Integer;
+const
+  steps: Byte = 4;
+
+
+
+
+  procedure DoStep(stepname: String);
+  begin
+    Inc(step);
+    if stepname <> 'FIN' then
+      group_progress.Caption :=
+        'Creating DB (Step ' + IntToStr(step) + '/' + IntToStr(steps) + ': ' + stepname + ')'
+    else
+      group_progress.Caption := 'Creating DB (FINISHED)';
+  end;
+
+begin
+  if CreateDataConnection(Source, ODB_Dat) = nil then
+  begin
+    ShowMessage('Could not connect to .dat-file');
+    Exit;
+  end
+  else
+  begin
+    TOniDataDat(OniDataConnection).UnloadWhenUnused := False;
+  end;
+
+  timeformat.LongTimeFormat := 'hh:nn:ss';
+  timeformat.ShortTimeFormat := 'hh:nn:ss';
+  timeformat.TimeSeparator := ':';
+
+  Self.Visible := True;
+  Form_Main.Visible := False;
+  step  := 0;
+  converting := True;
+  abort := False;
+  btn_abortok.Caption := '&Abort...';
+  btn_abortok.Default := False;
+  loaded_filename := target;
+
+  absolutebegintime := Time;
+
+  DataBase := TABSDatabase.Create(Self);
+  DataBase.DatabaseName := 'OLDB';
+  DataBase.DatabaseFileName := target;
+  DataBase.CreateDatabase;
+
+  DoStep('Creating tables');
+  progress.Position      := 0;
+  lbl_progress.Caption   := '';
+  lbl_estimation.Caption := 'Estimated finishing time: unknown';
+  Application.ProcessMessages;
+
+  Query := TABSQuery.Create(Self);
+  Query.DatabaseName := 'OLDB';
+  Query.SQL.Text :=
+    'CREATE TABLE globals  ( id AUTOINC PRIMARY KEY, name STRING(128), value STRING(128) );';
+  Query.ExecSQL;
+  Query.SQL.Text :=
+    'CREATE TABLE linkmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, target_id INTEGER );';
+  Query.ExecSQL;
+  Query.SQL.Text :=
+    'CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, sep BOOLEAN, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
+  //    Query.SQL.Text:='CREATE TABLE rawmap  ( id AUTOINC PRIMARY KEY, src_id INTEGER, src_link_offset INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
+  Query.ExecSQL;
+  Query.SQL.Text :=
+    'CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionMode 9 BlobBlockSize 1024 BlobCompressionAlgorithm ZLib );';
+  //    Query.SQL.Text:='CREATE TABLE datfiles  ( id INTEGER PRIMARY KEY, extension CHAR(4), name STRING(128), contenttype INTEGER, size INTEGER, data BLOB BlobCompressionAlgorithm None );';
+  Query.ExecSQL;
+  Query.SQL.Text :=
+    'CREATE TABLE extlist  ( id AUTOINC PRIMARY KEY, ext CHAR(4), ident CHAR(16) );';
+  Query.ExecSQL;
+
+  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("dbversion","' +
+    dbversion + '");';
+  Query.ExecSQL;
+  SetLength(Data, Length(OniDataConnection.LevelInfo.Ident));
+  for i := 0 to High(OniDataConnection.LevelInfo.Ident) do
+    Data[i] := OniDataConnection.LevelInfo.Ident[i];
+  temps := CreateHexString(Data, True);
+  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("ident","' + temps + '");';
+  Query.ExecSQL;
+  Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("lvl","' +
+    IntToStr(OniDataConnection.LevelInfo.LevelNumber) + '");';
+  Query.ExecSQL;
+  if OniDataConnection.OSisMAC then
+    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","MAC");'
+  else
+    Query.SQL.Text := 'INSERT INTO globals (name,value) VALUES ("os","PC");';
+  Query.ExecSQL;
+
+  DoStep('Writing extensionslist');
+  progress.Max := Length(OniDataConnection.GetExtensionsList);
+  Application.ProcessMessages;
+
+  extlist := OniDataConnection.GetExtendedExtensionsList;
+  for i := 0 to High(extlist) do
+  begin
+    SetLength(Data, Length(extlist[i].Ident));
+    for j := 0 to High(extlist[i].Ident) do
+      Data[j] := extlist[i].Ident[j];
+    temps := CreateHexString(Data, True);
+    temps2 := extlist[i].Extension[3] + extlist[i].Extension[2] +
+      extlist[i].Extension[1] + extlist[i].Extension[0];
+    Query.SQL.Text := 'INSERT INTO extlist (ext,ident) VALUES ("' +
+      temps2 + '","' + temps + '");';
+    Query.ExecSQL;
+    progress.Position    := i;
+    lbl_progress.Caption := 'Extensions done: ' + IntToStr(i) + '/' +
+      IntToStr(Length(extlist));
+    Application.ProcessMessages;
+    if abort then
+    begin
+      stop_convert;
+      Exit;
+    end;
+  end;
+  lbl_progress.Caption := '';
+
+  progress.Position      := 0;
+  lbl_progress.Caption   := 'Files done: ' + IntToStr(0) + '/' + IntToStr(
+    OniDataConnection.GetFilesCount);
+  lbl_estimation.Caption := 'Estimated finishing time: unknown';
+
+  DoStep('Loading .dat into memory');
+  Application.ProcessMessages;
+
+  progress.Max := OniDataConnection.GetFilesCount;
+  begintime    := Time;
+  DoStep('Writing .dat-fileslist');
+  Application.ProcessMessages;
+
+  Database.StartTransaction;
+  for i := 0 to OniDataConnection.GetFilesCount - 1 do
+  begin
+    fileinfo := OniDataConnection.GetFileInfo(i);
+    if (fileinfo.FileType and $02) = 0 then
+    begin
+      mimecoder := TStringFormat_MIME64.Create;
+      Data      := OniDataConnection.LoadDatFile(i);
+      Query.SQL.Text :=
+        'INSERT INTO datfiles (id,extension,name,contenttype,size,data) VALUES (' +
+        IntToStr(i) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
+        fileinfo.FileType, 8) + '",' + IntToStr(fileinfo.Size) + ',MimeToBin("' +
+        MimeCoder.StrTo(@Data[0], Length(Data)) + '") );';
+      Query.ExecSQL;
+      mimecoder.Free;
+
+      rawlist := OniDataConnection.GetRawList(i);
+      if Length(rawlist) > 0 then
+      begin
+        for j := 0 to High(rawlist) do
+        begin
+          if rawlist[j].raw_size > 0 then
+          begin
+            SetLength(Data, rawlist[j].raw_size);
+            OniDataConnection.LoadRawFile(i, rawlist[j].src_offset, Data);
+            mimecoder      := TStringFormat_MIME64.Create;
+            Query.SQL.Text :=
+              'INSERT INTO rawmap (src_id,src_link_offset,sep,size,data) VALUES (' +
+              IntToStr(i) + ',' + IntToStr(rawlist[j].src_offset) + ',' + BoolToStr(
+              rawlist[j].loc_sep) + ',' + IntToStr(rawlist[j].raw_size) + ',MimeToBin("' +
+              MimeCoder.StrTo(@Data[0], rawlist[j].raw_size) + '") );';
+            Query.ExecSQL;
+            mimecoder.Free;
+          end
+          else
+          begin
+            Query.SQL.Text :=
+              'INSERT INTO rawmap (src_id,src_link_offset,sep,size) VALUES (' +
+              IntToStr(i) + ',' + IntToStr(rawlist[j].src_offset) + ',' + BoolToStr(rawlist[j].loc_sep) + ',0);';
+            Query.ExecSQL;
+          end;
+        end;
+      end;
+
+      HandleFile(fileinfo.Extension, i, True);
+    end
+    else
+    begin
+      Query.SQL.Text :=
+        'INSERT INTO datfiles (id,extension,name,contenttype,size) VALUES (' +
+        IntToStr(i) + ',"' + fileinfo.Extension + '","' + fileinfo.Name + '","' + IntToHex(
+        fileinfo.FileType, 8) + '",0);';
+      Query.ExecSQL;
+    end;
+    if ((i mod 100) = 0) and (i > 0) then
+    begin
+      Database.Commit(False);
+      Database.StartTransaction;
+    end;
+    if ((i mod 10) = 0) and (i >= 100) then
+      lbl_estimation.Caption := 'Estimated time left: ' + TimeToStr(
+        (Time - begintime) / i * (progress.Max - i + 1) * 1.1, timeformat );
+    progress.Position := i;
+    lbl_progress.Caption := 'Files done: ' + IntToStr(i) + '/' + IntToStr(progress.Max);
+    Application.ProcessMessages;
+    if abort then
+    begin
+      stop_convert;
+      Exit;
+    end;
+  end;
+  Database.Commit(False);
+  progress.Position      := progress.Max;
+  lbl_progress.Caption   := 'Files done: ' + IntToStr(progress.Max) + '/' +
+    IntToStr(progress.Max);
+
+  lbl_estimation.Caption := 'FINISHED (duration: ' + TimeToStr(Time - absolutebegintime, timeformat) + ')';
+
+  DoStep('FIN');
+  btn_abortok.Caption := '&OK';
+  btn_abortok.Default := True;
+
+  converting := False;
+
+  database.Close;
+  database.Free;
+
+  CloseDataConnection(DataConnections[conIndex]);
+end;
+
+
+
+
+procedure TForm_LevelDB.stop_convert;
+begin
+  btn_abortok.Caption := '&Close';
+  btn_abortok.Default := True;
+  converting := False;
+  lbl_estimation.Caption := 'ABORTED';
+  group_progress.Caption := 'Creating DB (ABORTED)';
+  DataBase.Close;
+  if MessageBox(Self.Handle, PChar('Delete the unfinished DB-file?'),
+    PChar('Delete file?'), MB_YESNO) = idYes then
+  begin
+    DeleteFile(loaded_filename);
+  end;
+end;
+
+
+
+
+procedure TForm_LevelDB.btn_abortokClick(Sender: TObject);
+begin
+  if converting then
+  begin
+    if MessageBox(Self.Handle,
+      PChar('Do you really want to cancel the convert-progress?'),
+      PChar('Warning: Converting'), MB_YESNO) = idYes then
+      abort := True;
+  end
+  else
+  begin
+    Self.Visible := False;
+    Form_Main.Visible  := True;
+  end;
+end;
+
+
+
+
+procedure InsertDatLinkToDB(fileid: LongWord; offset: LongWord);
+var
+  link: LongWord;
+begin
+  OniDataConnection.LoadDatFilePart(fileid, offset, 4, @link);
+  if link = 0 then
+    link := $FFFFFFFF
+  else
+    link := link div 256;
+  Query.SQL.Text := 'INSERT INTO linkmap (src_id,src_link_offset,target_id) VALUES (' +
+    IntToStr(fileid) + ',' + IntToStr(offset) + ',' + IntToStr(link) + ');';
+  Query.ExecSQL;
+end;
+
+
+
+
+procedure AISA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: Word;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+    begin
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * $160 + $28);
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * $160 + $150);
+    end;
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure AKEV(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 16 do
+      InsertDatLinkToDB(fileid, $8 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure AKOT(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 4 do
+      InsertDatLinkToDB(fileid, $8 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure CBPI(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 56 do
+      InsertDatLinkToDB(fileid, $8 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure CBPM(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 18 do
+      InsertDatLinkToDB(fileid, $8 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure CONS(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 1 do
+      InsertDatLinkToDB(fileid, $24 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure CRSA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: LongWord;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $14, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 1100 + $A0);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure DOOR(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+    InsertDatLinkToDB(fileid, $10);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure DPGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $40);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure HPGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $0C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IGHH(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $24);
+    InsertDatLinkToDB(fileid, $28);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IGPA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  links: LongWord;
+  i:     LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
+    if links > 0 then
+      for i := 0 to links - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IGPG(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 1 do
+      InsertDatLinkToDB(fileid, $1C + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IGSA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  links: LongWord;
+  i:     LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
+    if links > 0 then
+      for i := 0 to links - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IMPT(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $10);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure IPGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $0C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure KEYI(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 9 do
+      InsertDatLinkToDB(fileid, $08 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure M3GA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  links: LongWord;
+  i:     LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @links);
+    if links > 0 then
+      for i := 0 to links - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure M3GM(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 6 do
+      InsertDatLinkToDB(fileid, $0C + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure MTRL(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $10);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure OBDC(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: Word;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * $18 + $4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure OBOA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: Word;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+      begin
+        InsertDatLinkToDB(fileid, $20 + i * 240 + $0);
+        InsertDatLinkToDB(fileid, $20 + i * 240 + $4);
+        InsertDatLinkToDB(fileid, $20 + i * 240 + $8);
+      end;
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure OFGA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: LongWord;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 12 + $04);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONCC(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $28);
+    InsertDatLinkToDB(fileid, $434);
+    InsertDatLinkToDB(fileid, $438);
+    InsertDatLinkToDB(fileid, $43C);
+    InsertDatLinkToDB(fileid, $C3C);
+    InsertDatLinkToDB(fileid, $C40);
+    InsertDatLinkToDB(fileid, $C44);
+    InsertDatLinkToDB(fileid, $C48);
+    InsertDatLinkToDB(fileid, $C88);
+    InsertDatLinkToDB(fileid, $C8C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONCV(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONLV(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 5 do
+      InsertDatLinkToDB(fileid, $48 + i * 4);
+    for i := 0 to 5 do
+      InsertDatLinkToDB(fileid, $64 + i * 4);
+    InsertDatLinkToDB(fileid, $300);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONOA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: LongWord;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 8 + $04);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONSK(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+    InsertDatLinkToDB(fileid, $0C);
+    InsertDatLinkToDB(fileid, $10);
+    InsertDatLinkToDB(fileid, $14);
+    InsertDatLinkToDB(fileid, $18);
+    InsertDatLinkToDB(fileid, $20);
+    InsertDatLinkToDB(fileid, $44);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONVL(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: LongWord;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure ONWC(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $28);
+    InsertDatLinkToDB(fileid, $34);
+    InsertDatLinkToDB(fileid, $40);
+    InsertDatLinkToDB(fileid, $54);
+    InsertDatLinkToDB(fileid, $58);
+    InsertDatLinkToDB(fileid, $5C);
+    InsertDatLinkToDB(fileid, $60);
+    InsertDatLinkToDB(fileid, $6FC);
+    InsertDatLinkToDB(fileid, $700);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure OPGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $0C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure PSPC(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $50);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure PSPL(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: LongWord;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 8 + $4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure PSUI(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 43 do
+      InsertDatLinkToDB(fileid, $08 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure STNA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: Word;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRAC(fileid: LongWord; dir_dat2db: Boolean);
+var
+  packages: Word;
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $18);
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 12 + 8);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRAM(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $40);
+    InsertDatLinkToDB(fileid, $44);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRAS(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRBS(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 4 do
+      InsertDatLinkToDB(fileid, $08 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRCM(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    for i := 0 to 2 do
+      InsertDatLinkToDB(fileid, $5C + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRGA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: Word;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $20);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRIG(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $18);
+    InsertDatLinkToDB(fileid, $24);
+    InsertDatLinkToDB(fileid, $28);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRMA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: Word;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TRSC(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: Word;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1E, 2, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TSFF(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TSFT(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $1C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TURR(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $60);
+    InsertDatLinkToDB(fileid, $6C);
+    InsertDatLinkToDB(fileid, $74);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TXAN(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TXMA(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TXMB(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TXMP(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $94);
+    InsertDatLinkToDB(fileid, $98);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure TXTC(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure WMCL(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 8 + $4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure WMDD(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $11C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $120 + i * $124 + $114);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure WMMB(fileid: LongWord; dir_dat2db: Boolean);
+var
+  i: LongWord;
+  packages: LongWord;
+begin
+  if dir_dat2db then
+  begin
+    OniDataConnection.LoadDatFilePart(fileid, $1C, 4, @packages);
+    if packages > 0 then
+      for i := 0 to packages - 1 do
+        InsertDatLinkToDB(fileid, $20 + i * 4);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure WPGE(fileid: LongWord; dir_dat2db: Boolean);
+begin
+  if dir_dat2db then
+  begin
+    InsertDatLinkToDB(fileid, $08);
+    InsertDatLinkToDB(fileid, $0C);
+  end
+  else
+  begin
+  end;
+end;
+
+
+
+
+procedure InsertHandler(ext: String; needed: Boolean; handler: THandler);
+begin
+  SetLength(ConvertHandlers, Length(ConvertHandlers) + 1);
+  ConvertHandlers[High(ConvertHandlers)].Ext     := ext;
+  ConvertHandlers[High(ConvertHandlers)].needed  := needed;
+  ConvertHandlers[High(ConvertHandlers)].handler := handler;
+end;
+
+begin
+  InsertHandler('ABNA', False, nil);
+  //  InsertHandler('AGDB',True,AGDB);
+  InsertHandler('AGDB', False, nil);
+  InsertHandler('AGQC', False, nil);
+  InsertHandler('AGQG', False, nil);
+  InsertHandler('AGQR', False, nil);
+  InsertHandler('AISA', True, AISA);
+  InsertHandler('AITR', False, nil);
+  InsertHandler('AKAA', False, nil);
+  InsertHandler('AKBA', False, nil);
+  InsertHandler('AKBP', False, nil);
+  InsertHandler('AKDA', False, nil);
+  InsertHandler('AKEV', True, AKEV);
+  InsertHandler('AKOT', True, AKOT);
+  InsertHandler('AKVA', False, nil);
+  InsertHandler('BINA', False, nil);
+  InsertHandler('CBPI', True, CBPI);
+  InsertHandler('CBPM', True, CBPM);
+  InsertHandler('CONS', True, CONS);
+  InsertHandler('CRSA', True, CRSA);
+  InsertHandler('DOOR', True, DOOR);
+  InsertHandler('DPGE', True, DPGE);
+  InsertHandler('ENVP', False, nil);
+  InsertHandler('FILM', False, nil);
+  InsertHandler('HPGE', True, HPGE);
+  InsertHandler('IDXA', False, nil);
+  InsertHandler('IGHH', True, IGHH);
+  InsertHandler('IGPA', True, IGPA);
+  InsertHandler('IGPG', True, IGPG);
+  InsertHandler('IGSA', True, IGSA);
+  InsertHandler('IMPT', True, IMPT);
+  InsertHandler('IPGE', True, IPGE);
+  InsertHandler('KEYI', True, KEYI);
+  InsertHandler('M3GA', True, M3GA);
+  InsertHandler('M3GM', True, M3GM);
+  InsertHandler('MTRL', True, MTRL);
+  InsertHandler('OBAN', False, nil);
+  InsertHandler('OBDC', True, OBDC);
+  InsertHandler('OBOA', True, OBOA);
+  InsertHandler('OFGA', True, OFGA);
+  InsertHandler('ONCC', True, ONCC);
+  InsertHandler('ONCP', False, nil);
+  InsertHandler('ONCV', True, ONCV);
+  InsertHandler('ONFA', False, nil);
+  InsertHandler('ONGS', False, nil);
+  InsertHandler('ONIA', False, nil);
+  InsertHandler('ONLD', False, nil);
+  InsertHandler('ONLV', True, ONLV);
+  InsertHandler('ONMA', False, nil);
+  InsertHandler('ONOA', True, ONOA);
+  InsertHandler('ONSA', False, nil);
+  InsertHandler('ONSK', True, ONSK);
+  InsertHandler('ONTA', False, nil);
+  InsertHandler('ONVL', True, ONVL);
+  InsertHandler('ONWC', True, ONWC);
+  InsertHandler('OPGE', True, OPGE);
+  InsertHandler('OSBD', False, nil);
+  InsertHandler('OTIT', False, nil);
+  InsertHandler('OTLF', False, nil);
+  InsertHandler('PLEA', False, nil);
+  InsertHandler('PNTA', False, nil);
+  InsertHandler('PSPC', True, PSPC);
+  InsertHandler('PSPL', True, PSPL);
+  InsertHandler('PSUI', True, PSUI);
+  InsertHandler('QTNA', False, nil);
+  InsertHandler('SNDD', False, nil);
+  InsertHandler('STNA', True, STNA);
+  InsertHandler('SUBT', False, nil);
+  InsertHandler('TRAC', True, TRAC);
+  InsertHandler('TRAM', True, TRAM);
+  InsertHandler('TRAS', True, TRAS);
+  InsertHandler('TRBS', True, TRBS);
+  InsertHandler('TRCM', True, TRCM);
+  InsertHandler('TRGA', True, TRGA);
+  InsertHandler('TRGE', True, TRGE);
+  InsertHandler('TRIA', False, nil);
+  InsertHandler('TRIG', True, TRIG);
+  InsertHandler('TRMA', True, TRMA);
+  InsertHandler('TRSC', True, TRSC);
+  InsertHandler('TRTA', False, nil);
+  InsertHandler('TSFF', True, TSFF);
+  InsertHandler('TSFL', False, nil);
+  InsertHandler('TSFT', True, TSFT);
+  InsertHandler('TSGA', False, nil);
+  InsertHandler('TSTR', False, nil);
+  InsertHandler('TURR', True, TURR);
+  InsertHandler('TXAN', True, TXAN);
+  InsertHandler('TXCA', False, nil);
+  InsertHandler('TXMA', True, TXMA);
+  InsertHandler('TXMB', True, TXMB);
+  InsertHandler('TXMP', True, TXMP);
+  InsertHandler('TXTC', True, TXTC);
+  InsertHandler('VCRA', False, nil);
+  InsertHandler('WMCL', True, WMCL);
+  InsertHandler('WMDD', True, WMDD);
+  InsertHandler('WMM_', False, nil);
+  InsertHandler('WMMB', True, WMMB);
+  InsertHandler('WPGE', True, WPGE);
+end.
Index: oup/rewrite/Helper/ValueEdit.pas
===================================================================
--- oup/rewrite/Helper/ValueEdit.pas	(revision 104)
+++ oup/rewrite/Helper/ValueEdit.pas	(revision 105)
@@ -33,5 +33,5 @@
 implementation
 
-uses BinEdit, {RawEdit, }DatStructureLoader, Main;
+uses BinEdit, RawEdit, DatStructureLoader, Main;
 
 {$R *.dfm}
Index: oup/rewrite/Main.dfm
===================================================================
--- oup/rewrite/Main.dfm	(revision 104)
+++ oup/rewrite/Main.dfm	(revision 105)
@@ -370,5 +370,5 @@
       'Compatible level files|*.dat;*.oldb|Oni level (*.dat)|*.dat|OUP ' +
       'level database (*.oldb)|*.oldb|Any (*.*)|*'
-    Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing]
+    Options = [ofAllowMultiSelect, ofPathMustExist, ofFileMustExist, ofEnableSizing]
     Left = 32
     Top = 64
Index: oup/rewrite/Main.pas
===================================================================
--- oup/rewrite/Main.pas	(revision 104)
+++ oup/rewrite/Main.pas	(revision 105)
@@ -11,6 +11,5 @@
   Settings, {Helper_LevelDB, }
   Template,
-  Preview;
-//  BinEdit, Extractor, RawEdit, TxmpReplace;
+  RawEdit, BinEdit, Extractor, Preview, TxmpReplace;
 
 type
@@ -162,4 +161,5 @@
   begin
     UpdateStatBar;
+    UpdateConLists;
   end;
 end;
@@ -497,5 +497,5 @@
 procedure TForm_Main.LoadFile(typedb: Boolean);
 var
-  ext: String;
+  i: Integer;
 begin
   opend.InitialDir := AppSettings.DatPath;
@@ -507,13 +507,7 @@
   if opend.Execute then
   begin
-    ext := ExtractFileExt(opend.FileName);
-    if ext = '.dat' then
-    begin
-      CreateConnection(opend.FileName);
-    end else if ext = '.oldb' then
-    begin
-      CreateConnection(opend.FileName);
-    end else
-      ShowMessage('Incompatible file');
+    if opend.Files.Count > 0 then
+      for i := 0 to opend.Files.Count - 1 do
+        CreateConnection(opend.Files.Strings[i]);
     AppSettings.DatPath := ExtractFilepath(opend.FileName);
   end;
@@ -693,4 +687,6 @@
     CheckConnectionCloseable(index);
     ConManager.CloseConnectionByIndex(index, RepMsg);
+    ShowOpenMsg(RepMsg);
+    UpdateConLists;
   end;
   UpdateStatBar;
@@ -751,5 +747,5 @@
   if window_context = 'binedit' then
   begin
-//    toolform         := TForm_BinEdit.Create(Self);
+    toolform         := TForm_BinEdit.Create(Self);
     toolform.Caption := 'Binary .dat-Editor ' + caption_end;
     iconindex        := 5;
@@ -757,5 +753,5 @@
   if window_context = 'extractor' then
   begin
-//    toolform         := TForm_Extractor.Create(Self);
+    toolform         := TForm_Extractor.Create(Self);
     toolform.Caption := 'Extractor ' + caption_end;
     iconindex        := 8;
@@ -769,5 +765,5 @@
   if window_context = 'rawedit' then
   begin
-//    toolform         := TForm_RawEdit.Create(Self);
+    toolform         := TForm_RawEdit.Create(Self);
     toolform.Caption := 'Binary .raw-Editor ' + caption_end;
     iconindex        := 6;
@@ -775,5 +771,5 @@
   if window_context = 'txmpreplace' then
   begin
-//    toolform         := TForm_TxmpReplace.Create(Application);
+    toolform         := TForm_TxmpReplace.Create(Self);
     toolform.Caption := 'TXMP Replacer ' + caption_end;
     iconindex        := 7;
Index: oup/rewrite/OniUnPacker.bdsproj
===================================================================
--- oup/rewrite/OniUnPacker.bdsproj	(revision 104)
+++ oup/rewrite/OniUnPacker.bdsproj	(revision 105)
@@ -178,5 +178,4 @@
 		</Language>  
     
-    
     <Excluded_Packages>
       <Excluded_Packages Name="d:\programme\borland\bds\3.0\Bin\dbwebxprt.bpl">Borland Web Wizard Package</Excluded_Packages>
Index: oup/rewrite/OniUnPacker.dpr
===================================================================
--- oup/rewrite/OniUnPacker.dpr	(revision 104)
+++ oup/rewrite/OniUnPacker.dpr	(revision 105)
@@ -23,5 +23,7 @@
   ValueEdit in 'Helper\ValueEdit.pas' {Form_ValueEdit},
   BinEdit in 'Tools\BinEdit.pas' {Form_BinEdit},
-  RawEdit in 'Tools\RawEdit.pas' {Form_RawEdit};
+  RawEdit in 'Tools\RawEdit.pas' {Form_RawEdit},
+  Extractor in 'Tools\Extractor.pas' {Form_Extractor},
+  TxmpReplace in 'Tools\TxmpReplace.pas' {Form_TxmpReplace};
 
 {$R *.res}
@@ -34,5 +36,4 @@
   Application.CreateForm(TForm_Settings, Form_Settings);
   Application.CreateForm(TForm_ValueEdit, Form_ValueEdit);
-  Application.CreateForm(TForm_RawEdit, Form_RawEdit);
   Application.Run;
 end.
Index: oup/rewrite/Tools/BinEdit.dfm
===================================================================
--- oup/rewrite/Tools/BinEdit.dfm	(revision 104)
+++ oup/rewrite/Tools/BinEdit.dfm	(revision 105)
@@ -3,4 +3,5 @@
   KeyPreview = True
   OnCloseQuery = FormCloseQuery
+  OnCreate = FormCreate
   OnKeyUp = FormKeyUp
   ExplicitWidth = 500
Index: oup/rewrite/Tools/BinEdit.pas
===================================================================
--- oup/rewrite/Tools/BinEdit.pas	(revision 104)
+++ oup/rewrite/Tools/BinEdit.pas	(revision 105)
@@ -176,17 +176,4 @@
   end;
 end;
-
-
-
-
-function IntToBin(Value: Byte): String;
-var
-  i: Byte;
-begin
-  Result := '';
-  for i := 7 downto 0 do
-    Result := Result + IntToStr((Value shr i) and $01);
-end;
-
 
 
Index: oup/rewrite/Tools/Extractor.dfm
===================================================================
--- oup/rewrite/Tools/Extractor.dfm	(revision 104)
+++ oup/rewrite/Tools/Extractor.dfm	(revision 105)
@@ -22,4 +22,5 @@
       Width = 333
       Height = 338
+      MultiSelect = True
       ExplicitWidth = 333
       ExplicitHeight = 338
Index: oup/rewrite/Tools/Extractor.pas
===================================================================
--- oup/rewrite/Tools/Extractor.pas	(revision 104)
+++ oup/rewrite/Tools/Extractor.pas	(revision 105)
@@ -36,5 +36,5 @@
 implementation
 {$R *.dfm}
-uses Main, Functions, Data, OniDataClass, FolderBrowser, Exporters;
+uses Main, Functions, Data, ConnectionManager, FolderBrowser, Exporters;
 
 
@@ -105,12 +105,12 @@
     if (selonly and filelist.Selected[i]) or not selonly then
     begin
-      fileid := Connection.ExtractFileID(filelist.Items.Strings[i]);
+      fileid := ConManager.Connection[ConnectionID].ExtractFileIDOfName(filelist.Items.Strings[i]);
       filename := GetWinFilename(filelist.Items.Strings[i]);
       if check_dat.Checked then
-        ExportDatFile(Connection, fileid, path + filename);
+        ExportDatFile(ConnectionID, fileid, path + filename);
       if check_raw.Checked then
-        ExportRawFiles(Connection, fileid, path + filename);
+        ExportRawFiles(ConnectionID, fileid, path + filename);
       if check_convert.Checked then
-        ExportConverted(Connection, fileid, path + filename);
+        ExportConverted(ConnectionID, fileid, path + filename);
       Inc(done);
     end;
Index: oup/rewrite/Tools/RawEdit.dfm
===================================================================
--- oup/rewrite/Tools/RawEdit.dfm	(revision 104)
+++ oup/rewrite/Tools/RawEdit.dfm	(revision 105)
@@ -3,4 +3,5 @@
   KeyPreview = True
   OnCloseQuery = FormCloseQuery
+  OnCreate = FormCreate
   OnKeyUp = FormKeyUp
   ExplicitWidth = 500
Index: oup/rewrite/Tools/RawEdit.pas
===================================================================
--- oup/rewrite/Tools/RawEdit.pas	(revision 104)
+++ oup/rewrite/Tools/RawEdit.pas	(revision 105)
@@ -63,5 +63,5 @@
 implementation
 {$R *.dfm}
-uses Main, ValueEdit;
+uses Main, ValueEdit, RawList;
 
 procedure TForm_RawEdit.NewFile(fileinfo: TFileInfo);
@@ -115,5 +115,5 @@
     for i := 0 to filelist.Count - 1 do
     begin
-      if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[i]) = RawInfo.SrcID then
+      if ConManager.Connection[ConID].ExtractFileIDOfName(filelist.Items.Strings[i]) = Raw_Info.SrcID then
       begin
         filelist.ItemIndex := i;
@@ -132,5 +132,5 @@
   end;
   mem := nil;
-  ConManager.Connection[ConID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, mem);
+  ConManager.Connection[ConID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, TStream(mem));
   hex.LoadFromStream(mem);
   ClearValues;
@@ -146,21 +146,7 @@
 begin
   ClearValues;
-  dat_offset := StrToInt('$' + MidStr(
+  datoffset := StrToInt('$' + MidStr(
     list_offset.Items.Strings[list_offset.ItemIndex], 3, 8));
-  LoadRaw(Connection.GetRawInfo(fileid, dat_offset));
-end;
-
-
-
-
-function IntToBin(Value: Byte): String;
-var
-  i: Byte;
-begin
-  Result := '';
-  for i := 7 downto 0 do
-  begin
-    Result := Result + IntToStr((Value shr i) and $01);
-  end;
+  LoadRaw(ConManager.Connection[ConID].GetRawInfo(fileid, datoffset));
 end;
 
@@ -170,5 +156,5 @@
 function TForm_RawEdit.GetValue(datatype: Word; offset: LongWord): String;
 var
-  Data: Tdata;
+  Data: TByteData;
   i:    Word;
   floatformat: TFormatSettings;
@@ -231,7 +217,5 @@
 begin
   for i := 1 to value_viewer.RowCount - 1 do
-  begin
     value_viewer.Cells[1, i] := '';
-  end;
 end;
 
@@ -242,5 +226,5 @@
 var
   i, j:  Integer;
-  Data:  Tdata;
+  Data:  TByteData;
   str:   String;
   Value: LongWord;
@@ -363,11 +347,11 @@
 
   exts := '';
-  if Length(RawListHandlers) > 0 then
-  begin
-    for i := 0 to High(RawListHandlers) do
+  if Length(RawLists.RawListHandlers) > 0 then
+  begin
+    for i := 0 to High(RawLists.RawListHandlers) do
       if Length(exts) > 0 then
-        exts := exts + ',' + RawListHandlers[i].Ext
+        exts := exts + ',' + RawLists.RawListHandlers[i].Ext
       else
-        exts := RawListHandlers[i].Ext;
+        exts := RawLists.RawListHandlers[i].Ext;
   end;
   Self.AllowedExts := exts;
@@ -404,9 +388,8 @@
 var
   mem:  TMemoryStream;
-  Data: Tdata;
   i:    LongWord;
 begin
   case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' +
-      Connection.GetFileInfo(fileid).FileName + '?'), PChar('Data changed...'),
+      ConManager.Connection[ConID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'),
       MB_YESNOCANCEL) of
     idYes:
@@ -415,9 +398,6 @@
       hex.SaveToStream(mem);
       mem.Seek(0, soFromBeginning);
-      SetLength(Data, mem.Size);
-      mem.Read(Data[0], mem.Size);
+      ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, mem);
       mem.Free;
-      Connection.UpdateRawFile(fileid_opened, dat_offset_opened,
-        Length(Data), @Data[0]);
       hex.Modified := False;
       for i := 0 to hex.Datasize - 1 do
@@ -428,7 +408,5 @@
       Result := True;
     idCancel:
-    begin
       Result := False;
-    end;
   end;
 end;
@@ -440,8 +418,6 @@
 begin
   if hex.Modified then
-  begin
     if not Save then
       CanClose := False;
-  end;
 end;
 
@@ -529,8 +505,9 @@
   fs: TFileStream;
 begin
-  saved.Filter     := 'Files of matching extension (*.' + Connection.GetFileInfo(
-    fileid).Extension + ')|*.' + Connection.GetFileInfo(fileid).Extension +
+  saved.Filter     := 'Files of matching extension (*.' +
+    ConManager.Connection[ConID].GetFileInfo(fileid).Extension + ')|*.' +
+    ConManager.Connection[ConID].GetFileInfo(fileid).Extension +
     '|All files|*.*';
-  saved.DefaultExt := Connection.GetFileInfo(fileid).Extension;
+  saved.DefaultExt := ConManager.Connection[ConID].GetFileInfo(fileid).Extension;
   if saved.Execute then
   begin
@@ -548,7 +525,11 @@
 //  Data: Tdata;
   fs:   TFileStream;
-begin
-  opend.Filter := 'Files of matching extension (*.' + Connection.GetFileInfo(
-    fileid).Extension + ')|*.' + Connection.GetFileInfo(fileid).Extension +
+  data: TByteData;
+  i: Integer;
+  rawinfo: TRawDataInfo;
+begin
+  opend.Filter := 'Files of matching extension (*.' +
+    ConManager.Connection[ConID].GetFileInfo(fileid).Extension + ')|*.' +
+    ConManager.Connection[ConID].GetFileInfo(fileid).Extension +
     '|All files|*.*';
   if opend.Execute then
@@ -557,14 +538,38 @@
     if fs.Size <> hex.DataSize then
     begin
-      ShowMessage('Can''t import ' + ExtractFilename(opend.FileName) +
-        ', file has to have same size as file in .dat.' + CrLf +
-        'Size of file in .dat: ' + FormatFileSize(hex.datasize) + CrLf +
-        'Size of chosen file: ' + FormatFileSize(fs.Size));
-    end
-    else
-    begin
-      hex.LoadFromStream(fs);
-      hex.Modified := True;
-    end;
+      if (not (CR_ResizeRaw in ConManager.Connection[ConID].ChangeRights)) and (not (CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights)) then
+      begin
+        ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) +
+            ', file has to have same size as file in .raw with this backend.' + CrLf +
+            'Size of file in .raw: ' + FormatFileSize(hex.DataSize) + CrLf +
+            'Size of chosen file: ' + FormatFileSize(fs.Size));
+        Exit;
+      end else begin
+        if MessageBox(Self.Handle,
+              PChar('File has different size from the file in the .raw.' + CrLf +
+                    'Size of file in .dat: ' + FormatFileSize(hex.DataSize) + CrLf +
+                    'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf +
+                    'Replace anyway?' + CrLf +
+                    'WARNING: This only replaces the raw-data. It doesn''t' + CrLf +
+                    'do the according changes in the .dat. Oni probably' + CrLf +
+                    'won''t be able to use the data correctly!'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then
+        begin
+          Exit;
+        end;
+      end;
+      rawinfo := ConManager.Connection[ConID].GetRawInfo(fileid, datoffset);
+      if CR_ResizeRaw in ConManager.Connection[ConID].ChangeRights then
+        ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, fs)
+      else if CR_AppendRaw in ConManager.Connection[ConID].ChangeRights then
+        i := ConManager.Connection[ConID].AppendRawFile(rawinfo.LocSep, fs);
+        ConManager.Connection[ConID].UpdateDatFilePart(fileid, datoffset, 4, @i);
+    end else begin
+      ConManager.Connection[ConID].UpdateRawFile(fileid, datoffset, fs);
+    end;
+    fs.Seek(0, soFromBeginning);
+    hex.LoadFromStream(fs);
+    hex.Modified := False;
+    for i := 0 to hex.Datasize - 1 do
+      hex.ByteChanged[i] := False;
     fs.Free;
   end;
@@ -691,5 +696,5 @@
 procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String);
 var
-  Data: Tdata;
+  Data: TByteData;
   value_int: LongWord;
   value_float: Single;
Index: oup/rewrite/Tools/Template.dfm
===================================================================
--- oup/rewrite/Tools/Template.dfm	(revision 104)
+++ oup/rewrite/Tools/Template.dfm	(revision 105)
@@ -242,5 +242,5 @@
         Style = csDropDownList
         Anchors = [akLeft, akTop, akRight]
-        DropDownCount = 12
+        DropDownCount = 20
         Font.Charset = DEFAULT_CHARSET
         Font.Color = clWindowText
@@ -288,4 +288,5 @@
         Style = csDropDownList
         Anchors = [akLeft, akTop, akRight]
+        DropDownCount = 12
         ItemHeight = 13
         TabOrder = 4
Index: oup/rewrite/Tools/Template.pas
===================================================================
--- oup/rewrite/Tools/Template.pas	(revision 104)
+++ oup/rewrite/Tools/Template.pas	(revision 105)
@@ -117,5 +117,5 @@
       else
         datatype := 'Unknown: ';
-      boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ')';
+      boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ') [' + IntToStr(ConManager.ConnectionByIndex[i].ConnectionID) + ']';
       combo_connection.Items.Add(boxstring);
       if ConManager.ConnectionByIndex[i].ConnectionID = FConnectionID then
@@ -276,5 +276,8 @@
 begin
   if combo_connection.ItemIndex >= 0 then
-    FConnectionID := combo_connection.ItemIndex
+  begin
+    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
+    FConnectionID := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name)  - 1));
+  end
   else
     FConnectionID := -1;
Index: oup/rewrite/Tools/TxmpReplace.dfm
===================================================================
--- oup/rewrite/Tools/TxmpReplace.dfm	(revision 104)
+++ oup/rewrite/Tools/TxmpReplace.dfm	(revision 105)
@@ -1,4 +1,5 @@
 inherited Form_TxmpReplace: TForm_TxmpReplace
   Caption = 'TxmpReplace'
+  OnCreate = FormCreate
   PixelsPerInch = 96
   TextHeight = 13
Index: oup/rewrite/Tools/TxmpReplace.pas
===================================================================
--- oup/rewrite/Tools/TxmpReplace.pas	(revision 104)
+++ oup/rewrite/Tools/TxmpReplace.pas	(revision 105)
@@ -47,20 +47,18 @@
 procedure TForm_TxmpReplace.SelectFile(fileinfo: TFileInfo);
 var
-  Data: TByteData;
   mem:  TMemoryStream;
   fadingbyte, depthbyte, storebyte: Byte;
 begin
   fileid := fileinfo.ID;
-  Connection.LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte);
-  Connection.LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte);
-  Connection.LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte);
+  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte);
+  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte);
+  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte);
   check_fading.Checked := (fadingbyte and $01) > 0;
   check_transparency.Checked := (depthbyte and $04) > 0;
 
-  OniImage_Old.LoadFromTXMP(connection, fileid);
+  OniImage_Old.LoadFromTXMP(ConnectionID, fileid);
   old_size := OniImage_Old.GetImageDataSize((fadingbyte and $01) > 0);
-  Data := OniImage_Old.GetAsBMP;
   mem  := TMemoryStream.Create;
-  mem.Write(Data[0], Length(Data));
+  OniImage_Old.GetAsBMP(TStream(mem));
   mem.Seek(0, soFromBeginning);
   image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
@@ -74,12 +72,10 @@
 var
   mem:   TMemoryStream;
-  tempd: Tdata;
 begin
   if opend.Execute then
   begin
     OniImage_New.LoadFromBMP(opend.FileName);
-    tempd := OniImage_New.GetAsBMP;
     mem   := TMemoryStream.Create;
-    mem.Write(tempd[0], Length(tempd));
+    OniImage_New.GetAsBMP(TStream(mem));
     mem.Seek(0, soFromBeginning);
     image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
@@ -97,36 +93,37 @@
   old_rawaddr, new_rawaddr: LongWord;
   oldfading: Byte;
-  tempd:     Tdata;
-
   datbyte: Word;
+  mem: TMemoryStream;
 begin
   if filelist.ItemIndex >= 0 then
   begin
-    Connection.LoadDatFilePart(fileid, $88, 1, @oldfading);
-    if Connection.OSisMac then
-      Connection.UpdateDatFilePart(fileid, $A0, 4, @old_rawaddr)
+    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, 1, @oldfading);
+    if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then
+      ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $A0, 4, @old_rawaddr)
     else
-      Connection.LoadDatFilePart(fileid, $9C, 4, @old_rawaddr);
+      ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, 4, @old_rawaddr);
 
     if (OniImage_Old.Width <> OniImage_New.Width) or
       (OniImage_Old.Height <> OniImage_New.Height) then
     begin
-      if MessageBox(Self.Handle, PChar(
-        'Current image and new image have different size' + CrLf +
-        '(Current: ' + IntToStr(OniImage_Old.Width) +
-        'x' + IntToStr(OniImage_Old.Height) + ' - New: ' +
-        IntToStr(OniImage_New.Width) + 'x' + IntToStr(OniImage_New.Height) + ')' + CrLf +
-        'Replace anyways?'),
-        PChar(filelist.Items.Strings[filelist.ItemIndex]),
-        MB_YESNO) = idNo then
+      if MessageBox(Self.Handle,
+            PChar(
+              'Current image and new image have different size' + CrLf +
+              '(Current: ' + IntToStr(OniImage_Old.Width) + 'x' +
+              IntToStr(OniImage_Old.Height) + ' - New: ' +
+              IntToStr(OniImage_New.Width) + 'x' + IntToStr(OniImage_New.Height) +
+              ')' + CrLf + 'Replace anyway?'),
+            PChar(filelist.Items.Strings[filelist.ItemIndex]), MB_YESNO) = idNo then
         Exit;
     end;
 
+    mem := TMemoryStream.Create;
+
     if check_fading.Checked then
-      if not OniImage_New.GetMipMappedImage(tempd) then
+      if not OniImage_New.GetMipMappedImage(TStream(mem)) then
         if MessageBox(Self.Handle,
-          PChar('Can not create a MipMapped-image (probably because of a wrong dimension).' +
-          #13 + #10 + 'Do you want to continue without MipMapping?'), PChar('Warning'),
-          MB_YESNO) = ID_YES then
+              PChar('Can not create a MipMapped-image (probably because of a wrong dimension).' +
+                #13 + #10 + 'Do you want to continue without MipMapping?'), PChar('Warning'),
+                MB_YESNO) = ID_YES then
           check_fading.Checked := False
         else
@@ -134,15 +131,18 @@
 
     if not check_fading.Checked then
-      tempd := OniImage_New.GetAsData;
+    begin
+      mem.Clear;
+      OniImage_New.GetAsData(TStream(mem));
+    end;
 
     newsize := OniImage_New.GetImageDataSize(check_fading.Checked);
 
-    if (newsize > old_size) and (Connection.Backend = ODB_Dat) then
-      new_rawaddr := Connection.AppendRawFile(
-        Connection.OSisMac, Length(tempd), tempd)
+    if (newsize > old_size) and (ConManager.Connection[ConnectionID].Backend = DB_ONI) then
+      new_rawaddr := ConManager.Connection[ConnectionID].AppendRawFile(
+        not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN), mem.Size, mem)
     else
     begin
       new_rawaddr := old_rawaddr;
-      Connection.UpdateRawFile(fileid, $9C, Length(tempd), tempd);
+      ConManager.Connection[ConnectionID].UpdateRawFile(fileid, $9C, mem);
     end;
 
@@ -150,17 +150,17 @@
     if check_fading.Checked then
       datbyte := datbyte or $01;
-    Connection.UpdateDatFilePart(fileid, $88, 1, @datbyte);
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $88, 1, @datbyte);
     datbyte := $10;
     if check_transparency.Checked then
       datbyte := datbyte or $04;
-    Connection.UpdateDatFilePart(fileid, $89, 1, @datbyte);
-    Connection.UpdateDatFilePart(fileid, $8C, 2, @OniImage_New.Width);
-    Connection.UpdateDatFilePart(fileid, $8E, 2, @OniImage_New.Height);
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $89, 1, @datbyte);
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8C, 2, @OniImage_New.Width);
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8E, 2, @OniImage_New.Height);
     datbyte := $08;
-    Connection.UpdateDatFilePart(fileid, $90, 1, @datbyte);
-    if Connection.OSisMac then
-      Connection.UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr)
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $90, 1, @datbyte);
+    if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then
+      ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr)
     else
-      Connection.UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr);
+      ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr);
 
     ShowMessage('TXMP-image replaced');
