--- oup/current/Tools/MetaEditor.pas 2007/06/12 17:35:56 214 +++ oup/current/Tools/MetaEditor.pas 2007/06/29 12:38:24 233 @@ -1,50 +1,65 @@ unit MetaEditor; + interface + uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, - Dialogs, VirtualTrees, _MetaManager, StdCtrls, ExtCtrls; + Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls, ComCtrls, Grids, + MPHexEditor, Wrapgrid, VTHeaderPopup, Menus, _TreeElement; type - TForm_Meta = class(TForm) + TForm_Meta = class(TForm_BaseTemplate) VST: TVirtualStringTree; - Panel1: TPanel; - Button1: TButton; - combo_connection: TComboBox; - Label3: TLabel; - Splitter1: TSplitter; - Panel2: TPanel; - procedure FormClose(Sender: TObject; var Action: TCloseAction); + splitter: TSplitter; + rightPages: TPageControl; + tab_hex: TTabSheet; + tab_meta: TTabSheet; + panel_hex_actions: TPanel; + hex: TMPHexEditor; + splitter_hex_1: TSplitter; + value_viewer: TWrapGrid; + splitter_hex_2: TSplitter; + structviewer: TVirtualStringTree; + value_viewer_context: TPopupMenu; + value_viewer_context_copy: TMenuItem; + value_viewer_context_copyasdec: TMenuItem; + value_viewer_context_copyasfloat: TMenuItem; + value_viewer_context_copyasbitset: TMenuItem; + value_viewer_context_copyasstring: TMenuItem; + value_viewer_context_copyashex: TMenuItem; + VTHPopup: TVTHeaderPopupMenu; + btn_export: TButton; + btn_import: TButton; procedure FormCreate(Sender: TObject); - procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; - Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); - procedure Button1Click(Sender: TObject); procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; var ChildCount: Cardinal); - procedure VSTPaintText(Sender: TBaseVirtualTree; - const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; - TextType: TVSTTextType); + procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex); procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean); + procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; + Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); + procedure VSTPaintText(Sender: TBaseVirtualTree; + const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; + TextType: TVSTTextType); private + root: TTreeElement; + procedure NewCon(ID: Integer); public end; -var - Form_Meta: TForm_Meta; implementation -uses - Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils; {$R *.dfm} +uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes; type PNodeData = ^TNodeData; TNodeData = record - Field: TObject; + Field: TTreeElement; end; function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; @@ -59,113 +74,60 @@ begin end; - -procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree; - Node: PVirtualNode; var ChildCount: Cardinal); -var - data: PNodeData; - newdata: TNodeData; - newnode: PVirtualNode; - i: Integer; - id: Integer; -begin - data := VST.GetNodeData(node); - for i := 0 to Meta.FileById[TFile(data.Field).FileID].ChildCount - 1 do - begin - id := Meta.FileById[TFile(data.Field).FileID].LinkByIndex[i].DestID; - Meta.InitFile(id); - newdata.Field := Meta.FileById[id]; - newnode := AddVSTEntry(VST, Node, newdata); - if Meta.FileById[id].ChildCount > 0 then - VST.HasChildren[newnode] := True; - end; - ChildCount := Meta.FileById[TFile(data.Field).FileID].ChildCount; -end; - - -procedure TForm_Meta.Button1Click(Sender: TObject); +procedure TForm_Meta.NewCon(ID: Integer); var - name: String; - conid: Integer; - - a,b,c: Int64; i: Integer; data: TNodeData; node: PVirtualNode; + Meta: TMetaManager; + root: TTreeElement; begin - if combo_connection.ItemIndex >= 0 then + if ID >= 0 then begin - name := combo_connection.Items.Strings[combo_connection.ItemIndex]; - conid := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name) - 1)); - - QueryPerformanceFrequency(c); - QueryPerformanceCounter(a); - if not Assigned(Meta) then - Meta := TMetaManager.Create(conid); - QueryPerformanceCounter(b); - ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's'); - + //VST VST.Clear; VST.BeginUpdate; - for i := 0 to Meta.FileCount - 1 do + root := ConManager.Connection[FConnectionID].MetaData.Root; + for i := 0 to root.ChildCount - 1 do begin - if Assigned(Meta.FileById[i]) then - begin - data.Field := Meta.FileById[i]; - node := AddVSTEntry(VST, nil, data); - if Meta.FileById[i].ChildCount > 0 then - VST.HasChildren[node] := True; - end; + data.Field := root.Child[i]; + node := AddVSTEntry(VST, nil, data); + VST.HasChildren[node] := True; end; VST.EndUpdate; end; end; -procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction); -begin - Meta.Free; - Action := caFree; -end; - -procedure TForm_Meta.FormCreate(Sender: TObject); +procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree; + Node: PVirtualNode; var ChildCount: Cardinal); var + data: PNodeData; + newdata: TNodeData; + newnode: PVirtualNode; i: Integer; - - fn, datatype, boxstring: String; - level: Integer; + Meta: TMetaManager; begin - combo_connection.ItemIndex := -1; - combo_connection.Items.Clear; - if ConManager.Count > 0 then + data := Sender.GetNodeData(node); + Meta := ConManager.Connection[ConnectionID].MetaData; + if data.Field is TExtension then + if TExtension(data.Field).ChildCount = 0 then + TExtension(data.Field).InitList; + + if data.Field.ChildCount > 0 then begin - for i := 0 to ConManager.Count - 1 do - begin - level := ConManager.ConnectionByIndex[i].LevelNumber; - fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName); - if ConManager.ConnectionByIndex[i].Backend = DB_ONI then - datatype := 'ONI-.dat: ' - else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then - datatype := 'OUP-DB: ' - else - datatype := 'Unknown: '; - boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ') [' + IntToStr(ConManager.ConnectionByIndex[i].ConnectionID) + ']'; - combo_connection.Items.Add(boxstring); - end; - if combo_connection.ItemIndex = -1 then + for i := 0 to data.Field.ChildCount - 1 do begin - combo_connection.ItemIndex := 0; + newdata.Field := data.Field.Child[i]; + newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata); + if newdata.Field.ChildCount > 0 then + Sender.HasChildren[newnode] := True; end; end; - - - VST.NodeDataSize := SizeOf(TNodeData); - VST.Font.Charset := AppSettings.CharSet; - VST.Clear; + ChildCount := Sender.ChildCount[Node]; end; - procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex); var @@ -177,12 +139,14 @@ begin TFile(data.Field).InitEditor; if Assigned(TFile(data.Field).Editor) then begin - panel2.InsertControl(TFile(data.Field).Editor); + TFile(data.Field).Editor.Align := alClient; + tab_meta.InsertControl(TFile(data.Field).Editor); TFile(data.Field).Opened := True; end; end; end; + procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean); @@ -206,15 +170,16 @@ begin begin if TFile(data.Field).Opened then begin - if panel2.ControlCount > 0 then - for i := 0 to panel2.ControlCount - 1 do - panel2.RemoveControl(panel2.Controls[i]); + if tab_meta.ControlCount > 0 then + for i := 0 to tab_meta.ControlCount - 1 do + tab_meta.RemoveControl(tab_meta.Controls[i]); TFile(data.Field).Opened := False; end; end; end; end; + procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); var @@ -227,27 +192,23 @@ begin case Column of 0: begin - if Data.Field is TFile then - begin - CellText := TFile(Data.Field).FileName; - if CellText = '' then - CellText := 'Unnamed'; - end; + CellText := Data.Field.GetCaption; end; 1: begin if Data.Field is TFile then - CellText := TFile(Data.Field).FileExt; + CellText := TFile(Data.Field).FileInfo.Extension; end; 2: begin if Data.Field is TFile then - CellText := IntToStr(TFile(Data.Field).FileID); + CellText := IntToStr(TFile(Data.Field).FileInfo.ID); end; end; end; end; + procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType); @@ -262,9 +223,9 @@ begin begin if Data.Field is TFile then begin - if Length(TFile(Data.Field).FileName) = 0 then + if Length(TFile(Data.Field).FileInfo.Name) = 0 then TargetCanvas.Font.Color := $C06060; - if TFile(Data.Field).FileSize = 0 then + if TFile(Data.Field).FileInfo.Size = 0 then TargetCanvas.Font.Color := $2020A0; end; end; @@ -272,88 +233,24 @@ begin end; end; -{ -procedure WriteStructureInfos; -var - i, j: Integer; - pdata: PNodeData; - Data: TNodeData; - node: PVirtualNode; + +procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction); begin - VST.BeginUpdate; - if VST.RootNodeCount = 0 then - begin - structs := LoadStructureDefinition(ConID, fileid); - if structs.Data then - begin - if Length(structs.Global) > 0 then - begin - for i := 0 to High(structs.Global) do - begin - Data.Caption := structs.Global[i].Name; - Data.Offset := structs.Global[i].offset; - Data.DataType := structs.Global[i].datatype; - Data.Value := GetValue(structs.Global[i].datatype, structs.Global[i].offset); - Data.Description := structs.Global[i].description; - AddVSTEntry(VST, nil, Data); - end; - end; - if Length(structs.Subs) > 0 then - begin - for i := 0 to High(structs.Subs) do - begin - with structs.Subs[i] do - begin - if Length(Entries) > 0 then - begin - if Pos('#', SubName) > 0 then - begin - Data.Offset := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8)); - Data.Value := '$' + - MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8); - Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1); - Data.Description := SubDesc; - end - else - begin - Data.Caption := SubName; - Data.Description := SubDesc; - Data.Offset := 0; - Data.Value := ''; - end; - Data.DataType := 0; - node := AddVSTEntry(VST, nil, Data); - Data.Description := ''; - for j := 0 to High(Entries) do - begin - Data.Caption := Entries[j].Name; - Data.Offset := Entries[j].offset; - Data.DataType := Entries[j].datatype; - Data.Value := GetValue(Entries[j].datatype, Entries[j].offset); - Data.Description := Entries[j].description; - AddVSTEntry(VST, node, Data); - end; - end; - end; - end; - end; - end; - if VST.RootNodeCount > 0 then - VST.FocusedNode := VST.GetFirst; - end - else - begin - Node := VST.GetFirst; - while Assigned(Node) do - begin - pdata := VST.GetNodeData(Node); - if pdata.DataType > 0 then - pdata.Value := GetValue(pdata.Datatype, pdata.Offset); - Node := VST.GetNext(Node); - end; - end; - VST.EndUpdate; +// Meta.Free; + inherited; end; -} + +procedure TForm_Meta.FormCreate(Sender: TObject); +begin + inherited; + OnNewConnection := NewCon; + + VST.NodeDataSize := SizeOf(TNodeData); + VST.Font.Charset := AppSettings.CharSet; + VST.Clear; + + UpdateConList; +end; + end.