Index: /oup/current/Code/OniDataClass.pas
===================================================================
--- /oup/current/Code/OniDataClass.pas	(revision 50)
+++ /oup/current/Code/OniDataClass.pas	(revision 51)
@@ -2,5 +2,5 @@
 interface
 uses Data, DataStructures, Classes, SysUtils, StrUtils,
-  Dialogs, ABSDecUtil, ABSMain, DB;
+  Dialogs, ABSDecUtil, ABSMain, DB, Windows;
 
 type
@@ -103,4 +103,6 @@
     FDatabase: TABSDatabase;
     FQuery:    TABSQuery;
+    Fdat_files:    TFiles;
+    Fdat_extensionsmap: TExtensionsMap;
   protected
   public
@@ -108,4 +110,5 @@
     procedure Close; override;
 
+    procedure UpdateListCache;
     //      function GetDatLinks(srcid:LongWord):TDatLinks;
     function GetFileInfo(fileid: LongWord): TFileInfo; override;
@@ -849,4 +852,6 @@
   FQuery.Close;
 
+  UpdateListCache;
+
   Result   := True;
   FBackend := ODB_ADB;
@@ -865,99 +870,28 @@
 
 
-
-function TOniDataADB.GetFileInfo(fileid: LongWord): TFileInfo;
-begin
-  if fileid < Self.GetFilesCount then
-  begin
-    FQuery.SQL.Text := 'SELECT * FROM datfiles WHERE id=' + IntToStr(
-      fileid) + ' ORDER BY id ASC;';
-    FQuery.Open;
-    if FQuery.RecordCount = 1 then
-    begin
-      FQuery.First;
-      Result.ID      := FQuery.FieldByName('id').AsInteger;
-      Result.Name    := FQuery.FieldByName('name').AsString;
-      Result.Extension := FQuery.FieldByName('extension').AsString;
-      Result.FileName := FormatNumber(Result.ID, 5, '0') + '-' + Result.Name + '.' +
-        Result.Extension;
-      Result.Size    := FQuery.FieldByName('size').AsInteger;
-      Result.FileType := HexToLong(FQuery.FieldByName('contenttype').AsString);
-      Result.DatAddr := 0;
-      Result.opened  := False;
-    end;
-    FQuery.Close;
-  end
-  else
-  begin
-    Result.ID := -1;
-  end;
-end;
-
-
-
-
-function TOniDataADB.GetFilesList(ext: String; pattern: String;
-  NoEmptyFiles: Boolean; sort: TSortType): TStringArray;
+procedure TOniDataADB.UpdateListCache;
 var
   i:     LongWord;
-  where: String;
-  where_ext: String;
-  order: String;
-begin
-  where := '';
-  if Length(ext) > 0 then
-  begin
-    if Length(where) > 0 then
-      where := where + ' AND ';
-    if Pos(',', ext) > 0 then
-    begin
-      i := 1;
-      where_ext := '';
-      while i < Length(ext) do
-      begin
-        if Length(where_ext) > 0 then
-          where_ext := where_ext + ' OR ';
-        where_ext := where_ext + '(extension="' + MidStr(ext, i, 4) + '")';
-        i := i + 5;
-      end;
-      where := where + '(' + where_ext + ')';
-    end
-    else
-    begin
-      where := where + '(extension="' + ext + '")';
-    end;
-  end;
-  if Length(pattern) > 0 then
-  begin
-    if Length(where) > 0 then
-      where := where + ' AND ';
-    where := where + '(name LIKE "%' + pattern + '%")';
-  end;
-  if NoEmptyFiles then
-  begin
-    if Length(where) > 0 then
-      where := where + ' AND ';
-    where := where + '(contenttype<>2)';
-  end;
-  if Length(where) > 0 then
-    where := ' WHERE ' + where;
-  case sort of
-    stIDAsc:    order := ' ORDER BY id ASC';
-    stIDDesc:   order := ' ORDER BY id DESC';
-    stNameAsc:  order := ' ORDER BY name ASC, id ASC';
-    stNameDesc: order := ' ORDER BY name DESC, id ASC';
-    stExtAsc:   order := ' ORDER BY extension ASC, id ASC';
-    stExtDesc:  order := ' ORDER BY extension DESC, id ASC';
-  end;
-  FQuery.SQL.Text := 'SELECT id,name,extension FROM datfiles' + where + order + ';';
+  temps: String;
+begin
+  FQuery.SQL.Text := 'SELECT id,name,extension,[size],contenttype FROM datfiles ORDER BY id ASC;';
   FQuery.Open;
   if FQuery.RecordCount > 0 then
   begin
     FQuery.First;
-    SetLength(Result, FQuery.RecordCount);
+    SetLength(Fdat_files, FQuery.RecordCount);
     i := 0;
     repeat
-      Result[i] := FormatNumber(FQuery.FieldByName('id').AsInteger, 5, '0') + '-' +
-        FQuery.FieldByName('name').AsString + '.' + FQuery.FieldByName('extension').AsString;
+      Fdat_files[i].ID := FQuery.FieldByName('id').AsInteger;
+      Fdat_files[i].Name := FQuery.FieldByName('name').AsString;
+      Fdat_files[i].Extension := FQuery.FieldByName('extension').AsString;
+      Fdat_files[i].FileName := FormatNumber(Fdat_files[i].ID, 5, '0') + '-' +
+          Fdat_files[i].Name + '.' + Fdat_files[0].Extension;
+      Fdat_files[i].FileNameHex := IntToHex(Fdat_files[i].ID, 4) + '-' +
+          Fdat_files[i].Name + '.' + Fdat_files[0].Extension;
+      Fdat_files[i].Size := FQuery.FieldByName('size').AsInteger;
+      Fdat_files[i].FileType := HexToLong(FQuery.FieldByName('contenttype').AsString);
+      Fdat_files[i].DatAddr := 0;
+      Fdat_files[i].opened := False;
       Inc(i);
       FQuery.Next;
@@ -965,31 +899,6 @@
   end;
   FQuery.Close;
-end;
-
-
-
-
-function TOniDataADB.GetFilesCount: LongWord;
-begin
-  FQuery.SQL.Text := 'SELECT Count(*) AS cnumber FROM datfiles;';
-  FQuery.Open;
-  if FQuery.RecordCount > 0 then
-  begin
-    FQuery.First;
-    Result := FQuery.FieldByName('cnumber').AsInteger;
-  end
-  else
-    Result := 0;
-  FQuery.Close;
-end;
-
-
-
-
-function TOniDataADB.GetExtensionsList: TStringArray;
-var
-  i: LongWord;
-begin
-  SetLength(Result, 0);
+
+  SetLength(Fdat_extensionsmap, 0);
   FQuery.SQL.Text :=
     'SELECT extension,count(extension) AS x FROM datfiles GROUP BY extension ORDER BY extension ASC;';
@@ -997,9 +906,13 @@
   if FQuery.RecordCount > 0 then
   begin
-    SetLength(Result, FQuery.RecordCount);
+    SetLength(Fdat_extensionsmap, FQuery.RecordCount);
     i := 0;
     repeat
-      Result[i] := FQuery.FieldByName('extension').AsString + ' (' +
-        IntToStr(FQuery.FieldByName('x').AsInteger) + ')';
+      temps := FQuery.FieldByName('extension').AsString[1];
+      Fdat_extensionsmap[i].Extension[3] := temps[1];
+      Fdat_extensionsmap[i].Extension[2] := temps[2];
+      Fdat_extensionsmap[i].Extension[1] := temps[3];
+      Fdat_extensionsmap[i].Extension[0] := temps[4];
+      Fdat_extensionsmap[i].ExtCount := FQuery.FieldByName('x').AsInteger;
       Inc(i);
       FQuery.Next;
@@ -1007,4 +920,129 @@
   end;
   FQuery.Close;
+end;
+
+
+function TOniDataADB.GetFileInfo(fileid: LongWord): TFileInfo;
+var
+  i: Integer;
+begin
+  if fileid < Self.GetFilesCount then
+  begin
+    for i := 0 to High(Fdat_files) do
+      if Fdat_files[i].ID = fileid then
+        Break;
+    if i < Length(Fdat_files) then
+      Result := Fdat_files[i]
+    else
+      Result.ID := -1;
+  end
+  else
+  begin
+    Result.ID := -1;
+  end;
+end;
+
+
+
+
+function TOniDataADB.GetFilesList(ext: String; pattern: String;
+  NoEmptyFiles: Boolean; sort: TSortType): TStringArray;
+var
+  i: LongWord;
+  list: TStringList;
+  id, name, extension: String;
+  fields: TStrings;
+
+  procedure getfields;
+  begin
+     fields.CommaText := StringReplace(AnsiQuotedStr(list.Strings[i], '"'), ';', '","', [rfReplaceAll]);
+    if sort in [stIDAsc, stIDDesc] then
+    begin
+      id := fields.Strings[0];
+      name := fields.Strings[1];
+      extension := fields.Strings[2];
+    end;
+    if sort in [stNameAsc, stNameDesc] then
+    begin
+      id := fields.Strings[1];
+      name := fields.Strings[0];
+      extension := fields.Strings[2];
+    end;
+    if sort in [stExtAsc, stExtDesc] then
+    begin
+      id := fields.Strings[1];
+      name := fields.Strings[2];
+      extension := fields.Strings[0];
+    end;
+  end;
+
+begin
+  list := TStringList.Create;
+  list.Sorted := True;
+  for i := 0 to High(Fdat_files) do
+  begin
+    if ((Length(ext) = 0) or (Pos(Fdat_files[i].Extension, ext) > 0)) and
+      ((Length(pattern) = 0) or
+      (Pos(UpperCase(pattern), UpperCase(Fdat_files[i].Name)) > 0)) then
+    begin
+      if (NoEmptyFiles = False) or ((Fdat_files[i].FileType and $02) = 0) then
+      begin
+        if AppSettings.FilenumbersAsHex then
+          id := IntToHex(Fdat_files[i].ID, 4)
+        else
+          id := FormatNumber(Fdat_files[i].ID, 5, '0');
+        name := Fdat_files[i].Name;
+        extension := Fdat_files[i].Extension;
+
+        case sort of
+          stIDAsc, stIDDesc:     list.Add(id + ';' + name + ';' + extension);
+          stNameAsc, stNameDesc: list.Add(name + ';' + id + ';' + extension);
+          stExtAsc, stExtDesc:   list.Add(extension + ';' + id + ';' + name);
+        end;
+      end;
+    end;
+  end;
+  SetLength(Result, list.Count);
+  fields := TStringList.Create;
+  if sort in [stIDAsc, stNameAsc, stExtAsc] then
+    for i := 0 to list.Count - 1 do
+    begin
+      getfields;
+      Result[i] := id + '-' + name + '.' + extension;
+    end
+  else
+    for i := list.Count - 1 downto 0 do
+    begin
+      getfields;
+      Result[list.Count - i - 1] := id + '-' + name + '.' + extension;
+    end;
+  list.Free;
+  fields.Free;
+end;
+
+
+
+
+function TOniDataADB.GetFilesCount: LongWord;
+begin
+  Result := Length(Fdat_files);
+end;
+
+
+
+
+function TOniDataADB.GetExtensionsList: TStringArray;
+var
+  i: LongWord;
+begin
+  SetLength(Result, Length(Fdat_extensionsmap));
+  for i := 0 to High(Result) do
+  begin
+    with Fdat_extensionsmap[i] do
+    begin
+      Result[i] := Extension[3] + Extension[2] + Extension[1] + Extension[0] +
+        ' (' + IntToStr(ExtCount) + ')';
+    end;
+  end;
 end;
 
@@ -1139,9 +1177,11 @@
     mem.Seek(0, soFromBeginning);
     FQuery.SQL.Text := 'UPDATE datfiles SET data=MimeToBin("' +
-      MimeCoder.StrTo(mem.Memory, mem.Size) + '") WHERE id=' + IntToStr(fileid) + ';';
+      MimeCoder.StrTo(mem.Memory, mem.Size) + '"), size=' + IntToStr(mem.Size) +
+      ' WHERE id=' + IntToStr(fileid) + ';';
     FQuery.ExecSQL;
     mem.Free;
     mimecoder.Free;
   end;
+  UpdateListCache;
 end;
 
Index: /oup/current/Main.dfm
===================================================================
--- /oup/current/Main.dfm	(revision 50)
+++ /oup/current/Main.dfm	(revision 51)
@@ -52,4 +52,5 @@
       Caption = 'MainMenu'
       CloseButton = False
+      DragHandleStyle = dhDouble
       FullSize = True
       Images = MenuImages
@@ -124,4 +125,10 @@
           ShortCut = 16453
           OnClick = menu_extractorClick
+        end
+        object menu_meta: TTBItem
+          Caption = '&Meta Editor'
+          Enabled = False
+          ShortCut = 16461
+          OnClick = menu_metaClick
         end
         object menu_filecompare: TTBItem
@@ -198,6 +205,8 @@
       Top = 23
       Caption = 'Toolbar'
+      DragHandleStyle = dhDouble
       Images = MenuImages
       TabOrder = 1
+      OnDockChanged = ToolbarDockChanged
       object tbOpen: TTBItem
         Caption = 'Open file'
@@ -207,4 +216,18 @@
       end
       object tb_separator1: TTBSeparatorItem
+      end
+      object tb_dat2db: TTBItem
+        Caption = '.dat -> DB'
+        DisplayMode = nbdmImageAndText
+        ImageIndex = 1
+        OnClick = menu_createdbClick
+      end
+      object tb_db2dat: TTBItem
+        Caption = 'DB -> .dat'
+        DisplayMode = nbdmImageAndText
+        ImageIndex = 2
+        OnClick = menu_createlvlClick
+      end
+      object TBSeparatorItem1: TTBSeparatorItem
       end
       object tb_preview: TTBItem
@@ -242,4 +265,10 @@
         ImageIndex = 7
         OnClick = menu_extractorClick
+      end
+      object tb_meta: TTBItem
+        Caption = 'Meta Editor'
+        DisplayMode = nbdmImageAndText
+        Enabled = False
+        OnClick = menu_metaClick
       end
       object tb_compare: TTBItem
@@ -264,4 +293,5 @@
       DockPos = 0
       DockRow = 2
+      DragHandleStyle = dhDouble
       TabOrder = 2
       object TBControlItem1: TTBControlItem
Index: /oup/current/Main.pas
===================================================================
--- /oup/current/Main.pas	(revision 50)
+++ /oup/current/Main.pas	(revision 51)
@@ -67,4 +67,9 @@
     tb_datedit: TTBItem;
     menu_windows_tilevert: TTBItem;
+    tb_meta: TTBItem;
+    menu_meta: TTBItem;
+    TBSeparatorItem1: TTBSeparatorItem;
+    tb_db2dat: TTBItem;
+    tb_dat2db: TTBItem;
     function TryCloseAll: Boolean;
     procedure menu_AboutClick(Sender: TObject);
@@ -99,4 +104,6 @@
       Shift: TShiftState; X, Y: Integer);
     procedure menu_windows_tilevertClick(Sender: TObject);
+    procedure menu_metaClick(Sender: TObject);
+    procedure ToolbarDockChanged(Sender: TObject);
   private
   public
@@ -280,4 +287,26 @@
 
 
+procedure TForm_Main.ToolbarDockChanged(Sender: TObject);
+var
+  toolbar: TTBToolbar;
+  position: TTBDockPosition;
+  mode: TTBItemDisplayMode;
+  i: Integer;
+  isEnabled: Boolean;
+begin
+  toolbar := TTBToolbar(Sender);
+  if toolbar.Floating then
+    mode := nbdmImageAndText
+  else begin
+    position := toolbar.CurrentDock.Position;
+    if position in [dpLeft, dpRight] then
+      mode := nbdmDefault
+    else
+      mode := nbdmImageAndText;
+  end;
+  for i := 0 to toolbar.Items.Count - 1 do
+    toolbar.Items.Items[i].DisplayMode := mode;
+end;
+
 function TForm_Main.TryCloseAll: Boolean;
 begin
@@ -426,4 +455,10 @@
 
 
+procedure TForm_Main.menu_metaClick(Sender: TObject);
+begin
+  ShowMessage('TBD');
+end;
+
+
 procedure TForm_Main.menu_filecompareClick(Sender: TObject);
 begin
Index: /oup/current/Tools/Template.dfm
===================================================================
--- /oup/current/Tools/Template.dfm	(revision 50)
+++ /oup/current/Tools/Template.dfm	(revision 51)
@@ -29,5 +29,5 @@
     AutoSnap = False
     Beveled = True
-    MinSize = 150
+    MinSize = 155
     ExplicitHeight = 473
   end
@@ -62,4 +62,32 @@
         200
         129)
+      object Label2: TLabel
+        Left = 100
+        Top = 105
+        Width = 17
+        Height = 18
+        AutoSize = False
+        Caption = '.'
+        Font.Charset = DEFAULT_CHARSET
+        Font.Color = clWindowText
+        Font.Height = -13
+        Font.Name = 'Tahoma'
+        Font.Style = [fsBold]
+        ParentFont = False
+      end
+      object Label1: TLabel
+        Left = 47
+        Top = 105
+        Width = 17
+        Height = 18
+        AutoSize = False
+        Caption = '-'
+        Font.Charset = DEFAULT_CHARSET
+        Font.Color = clWindowText
+        Font.Height = -13
+        Font.Name = 'Tahoma'
+        Font.Style = [fsBold]
+        ParentFont = False
+      end
       object label_ext: TLabel
         Left = 2
@@ -72,7 +100,7 @@
       end
       object btn_sort_id_asc: TSpeedButton
-        Left = 16
-        Top = 101
-        Width = 23
+        Left = 3
+        Top = 101
+        Width = 20
         Height = 22
         Hint = 'Sort files by id, ascending'
@@ -93,7 +121,7 @@
       end
       object btn_sort_id_desc: TSpeedButton
-        Left = 40
-        Top = 101
-        Width = 23
+        Left = 23
+        Top = 101
+        Width = 20
         Height = 22
         Hint = 'Sort files by id, descending'
@@ -113,7 +141,7 @@
       end
       object btn_sort_name_asc: TSpeedButton
-        Left = 64
-        Top = 101
-        Width = 23
+        Left = 58
+        Top = 101
+        Width = 20
         Height = 22
         Hint = 'Sort files by name, ascending'
@@ -133,7 +161,7 @@
       end
       object btn_sort_name_desc: TSpeedButton
-        Left = 88
-        Top = 101
-        Width = 23
+        Left = 78
+        Top = 101
+        Width = 20
         Height = 22
         Hint = 'Sort files by name, descending'
@@ -153,10 +181,19 @@
       end
       object btn_sort_ext_asc: TSpeedButton
-        Left = 112
-        Top = 101
-        Width = 23
+        Left = 108
+        Top = 101
+        Width = 20
         Height = 22
         Hint = 'Sort files by extension, ascending'
         GroupIndex = 1
+        Glyph.Data = {
+          F6000000424DF600000000000000760000002800000010000000100000000100
+          0400000000008000000000000000000000001000000000000000C0C0C0000000
+          9900990000000000000000000000000000000000000000000000000000000000
+          0000000000000000000000000000000000000000000000000000000000000000
+          0000011111100000300001100010000030000011000000033300000110000003
+          3300000011000033333001000110000030000111111000003000000000000000
+          3000022202220000300000200020000030000022222000003000000202000000
+          3000000222000000300000002000000030000000200000003000}
         ParentShowHint = False
         ShowHint = True
@@ -164,10 +201,19 @@
       end
       object btn_sort_ext_desc: TSpeedButton
-        Left = 136
-        Top = 101
-        Width = 23
+        Left = 128
+        Top = 101
+        Width = 20
         Height = 22
         Hint = 'Sort files by extension, descending'
         GroupIndex = 1
+        Glyph.Data = {
+          F6000000424DF600000000000000760000002800000010000000100000000100
+          0400000000008000000000000000000000001000000000000000C0C0C0000000
+          9900990000000000000000000000000000000000000000000000000000000000
+          0000000000000000000000000000000000000000000000000000000000000000
+          0000022202220000300000200020000030000022222000033300000202000003
+          3300000222000033333000002000000030000000200000003000000000000000
+          3000011111100000300001100010000030000011000000003000000110000000
+          3000000011000000300001000110000030000111111000003000}
         ParentShowHint = False
         ShowHint = True
@@ -187,5 +233,5 @@
         Font.Name = 'Tahoma'
         Font.Style = []
-        ItemHeight = 0
+        ItemHeight = 13
         ParentFont = False
         Sorted = True
Index: /oup/current/Tools/Template.pas
===================================================================
--- /oup/current/Tools/Template.pas	(revision 50)
+++ /oup/current/Tools/Template.pas	(revision 51)
@@ -34,4 +34,6 @@
     btn_sort_ext_asc: TSpeedButton;
     btn_sort_ext_desc: TSpeedButton;
+    Label1: TLabel;
+    Label2: TLabel;
     procedure RecreateList;
     procedure LoadFileNames;
@@ -82,5 +84,9 @@
   i:    LongWord;
   exts: TStringArray;
-begin
+f, c1,c2: Int64;
+time1,time2,time3: Double;
+begin
+QueryPerformanceFrequency(f);
+QueryPerformanceCounter(c1);
   combo_extension.Items.Clear;
   combo_extension.Items.Add('_All files_ (' +
@@ -96,6 +102,11 @@
     end else
       combo_extension.Items.Add(exts[i]);
+QueryPerformanceCounter(c2);
+time1 := (c2 - c1) / f;
   combo_extension.ItemIndex := 0;
   combo_extensionClick(Self);
+QueryPerformanceCounter(c1);
+time2 := (c1 - c2) / f;
+ShowMessage(FloatToStr(time1) +#13+#10+ FloatToStr(time2));
 end;
 
Index: /oup/current/text/todo.txt
===================================================================
--- /oup/current/text/todo.txt	(revision 50)
+++ /oup/current/text/todo.txt	(revision 51)
@@ -49,7 +49,4 @@
 -Cursor Sanduhr bei Wartezeiten (db-access etc)
 
--RawMap: was ist laut link+size used bereich, was nicht
--StructViewer Raw: DynamicInfos aus .dat
-
 -Exporter: Checkboxes für was man im einzelnen will (zb Checkbox "in eine Datei ja/nein")
 -Extrahier-Ordner-Option (mit Platzhalter für .dat-Name)
@@ -57,6 +54,4 @@
 
 -Hex: Paste
-
--Persist.dat editor
 
 
