ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Tools/MetaEditor.pas
(Generate patch)

Comparing oup/current/Tools/MetaEditor.pas (file contents):
Revision 214 by alloc, Tue Jun 12 17:35:56 2007 UTC vs.
Revision 232 by alloc, Thu Jun 28 09:24:08 2007 UTC

# Line 1 | Line 1
1   unit MetaEditor;
2 +
3   interface
4 +
5   uses
6    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 <  Dialogs, VirtualTrees, _MetaManager, StdCtrls, ExtCtrls;
7 >  Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls, ComCtrls, Grids,
8 >  MPHexEditor, Wrapgrid;
9  
10   type
11 <  TForm_Meta = class(TForm)
11 >  TForm_Meta = class(TForm_BaseTemplate)
12      VST: TVirtualStringTree;
13 <    Panel1: TPanel;
14 <    Button1: TButton;
15 <    combo_connection: TComboBox;
16 <    Label3: TLabel;
17 <    Splitter1: TSplitter;
18 <    Panel2: TPanel;
19 <    procedure FormClose(Sender: TObject; var Action: TCloseAction);
13 >    splitter: TSplitter;
14 >    rightPages: TPageControl;
15 >    tab_hex: TTabSheet;
16 >    tab_meta: TTabSheet;
17 >    panel_hex_actions: TPanel;
18 >    hex: TMPHexEditor;
19 >    splitter_hex_1: TSplitter;
20 >    value_viewer: TWrapGrid;
21 >    splitter_hex_2: TSplitter;
22 >    structviewer: TVirtualStringTree;
23      procedure FormCreate(Sender: TObject);
18    procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
19      Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
20    procedure Button1Click(Sender: TObject);
24      procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
25        var ChildCount: Cardinal);
26 <    procedure VSTPaintText(Sender: TBaseVirtualTree;
24 <      const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
25 <      TextType: TVSTTextType);
26 >    procedure FormClose(Sender: TObject; var Action: TCloseAction);
27      procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode;
28        Column: TColumnIndex);
29      procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
30        NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
31        var Allowed: Boolean);
32 +    procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
33 +      Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
34 +    procedure VSTPaintText(Sender: TBaseVirtualTree;
35 +      const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
36 +      TextType: TVSTTextType);
37    private
38 +    procedure NewCon(ID: Integer);
39    public
40    end;
41  
35 var
36  Form_Meta: TForm_Meta;
42  
43   implementation
39 uses
40  Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils;
44   {$R *.dfm}
45 + uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes;
46  
47   type
48    PNodeData = ^TNodeData;
# Line 59 | Line 63 | begin
63   end;
64  
65  
66 <
63 < procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
64 <  Node: PVirtualNode; var ChildCount: Cardinal);
65 < var
66 <  data: PNodeData;
67 <  newdata: TNodeData;
68 <  newnode: PVirtualNode;
69 <  i: Integer;
70 <  id: Integer;
71 < begin
72 <  data := VST.GetNodeData(node);
73 <  for i := 0 to Meta.FileById[TFile(data.Field).FileID].ChildCount - 1 do
74 <  begin
75 <    id := Meta.FileById[TFile(data.Field).FileID].LinkByIndex[i].DestID;
76 <    Meta.InitFile(id);
77 <    newdata.Field := Meta.FileById[id];
78 <    newnode := AddVSTEntry(VST, Node, newdata);
79 <    if Meta.FileById[id].ChildCount > 0 then
80 <      VST.HasChildren[newnode] := True;
81 <  end;
82 <  ChildCount := Meta.FileById[TFile(data.Field).FileID].ChildCount;
83 < end;
84 <
85 <
86 < procedure TForm_Meta.Button1Click(Sender: TObject);
66 > procedure TForm_Meta.NewCon(ID: Integer);
67   var
88  name: String;
89  conid: Integer;
90
91  a,b,c: Int64;
68    i: Integer;
69    data: TNodeData;
70    node: PVirtualNode;
71 +  Meta: TMetaManager;
72 +  root: TExtensions;
73   begin
74 <  if combo_connection.ItemIndex >= 0 then
74 >  if ID >= 0 then
75    begin
76 <    name := combo_connection.Items.Strings[combo_connection.ItemIndex];
99 <    conid := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name)  - 1));
100 <
101 <    QueryPerformanceFrequency(c);
102 <    QueryPerformanceCounter(a);
103 <    if not Assigned(Meta) then
104 <      Meta := TMetaManager.Create(conid);
105 <    QueryPerformanceCounter(b);
106 <    ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
107 <
76 >    //VST
77      VST.Clear;
78      VST.BeginUpdate;
79 <    for i := 0 to Meta.FileCount - 1 do
79 >    root := ConManager.Connection[FConnectionID].MetaData.Root;
80 >    for i := 0 to High(root) do
81      begin
82 <      if Assigned(Meta.FileById[i]) then
83 <      begin
84 <        data.Field := Meta.FileById[i];
115 <        node := AddVSTEntry(VST, nil, data);
116 <        if Meta.FileById[i].ChildCount > 0 then
117 <          VST.HasChildren[node] := True;
118 <      end;
82 >      data.Field := root[i];
83 >      node := AddVSTEntry(VST, nil, data);
84 >      VST.HasChildren[node] := True;
85      end;
86      VST.EndUpdate;
87    end;
88   end;
89  
124 procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
125 begin
126  Meta.Free;
127  Action := caFree;
128 end;
90  
91 <
92 < procedure TForm_Meta.FormCreate(Sender: TObject);
91 > procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
92 >  Node: PVirtualNode; var ChildCount: Cardinal);
93   var
94 +  data: PNodeData;
95 +  newdata: TNodeData;
96 +  newnode: PVirtualNode;
97    i: Integer;
98 <
99 <  fn, datatype, boxstring: String;
136 <  level: Integer;
98 >  id: Integer;
99 >  Meta: TMetaManager;
100   begin
101 <  combo_connection.ItemIndex := -1;
102 <  combo_connection.Items.Clear;
103 <  if ConManager.Count > 0 then
101 >  data := Sender.GetNodeData(node);
102 >  Meta := ConManager.Connection[ConnectionID].MetaData;
103 >  if data.Field is TFile then
104    begin
105 <    for i := 0 to ConManager.Count - 1 do
105 >    if TFile(data.Field).ChildCount > 0 then
106      begin
107 <      level := ConManager.ConnectionByIndex[i].LevelNumber;
108 <      fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
109 <      if ConManager.ConnectionByIndex[i].Backend = DB_ONI then
110 <        datatype := 'ONI-.dat: '
111 <      else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then
112 <        datatype := 'OUP-DB: '
113 <      else
114 <        datatype := 'Unknown: ';
115 <      boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ') [' + IntToStr(ConManager.ConnectionByIndex[i].ConnectionID) + ']';
153 <      combo_connection.Items.Add(boxstring);
107 >      for i := 0 to TFile(data.Field).ChildCount - 1 do
108 >      begin
109 >        id := TFile(data.Field).LinkByIndex[i].DestID;
110 >        Meta.InitFile(id);
111 >        newdata.Field := Meta.FileById[id];
112 >        newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
113 >        if Meta.FileById[id].ChildCount > 0 then
114 >          Sender.HasChildren[newnode] := True;
115 >      end;
116      end;
117 <    if combo_connection.ItemIndex = -1 then
117 >    if TFile(data.Field).RawCount > 0 then
118      begin
119 <      combo_connection.ItemIndex := 0;
119 >      for i := 0 to TFile(data.Field).RawCount - 1 do
120 >      begin
121 > //        Exit;
122 >      end;
123      end;
124    end;
125 <
126 <
127 <  VST.NodeDataSize := SizeOf(TNodeData);
128 <  VST.Font.Charset := AppSettings.CharSet;
129 <  VST.Clear;
125 >  if data.Field is TExtension then
126 >  begin
127 >    if TExtension(data.Field).FileCount = 0 then
128 >      TExtension(data.Field).InitList;
129 >    for i := 0 to TExtension(data.Field).FileCount - 1 do
130 >    begin
131 >      id := TExtension(data.Field).Files[i];
132 >      Meta.InitFile(id);
133 >      newdata.Field := Meta.FileById[id];
134 >      newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata);
135 >      if Meta.FileById[id].ChildCount > 0 then
136 >        Sender.HasChildren[newnode] := True;
137 >    end;
138 >  end;
139 >  ChildCount := Sender.ChildCount[Node];
140   end;
141  
142  
168
143   procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
144    Node: PVirtualNode; Column: TColumnIndex);
145   var
# Line 177 | Line 151 | begin
151      TFile(data.Field).InitEditor;
152      if Assigned(TFile(data.Field).Editor) then
153      begin
154 <      panel2.InsertControl(TFile(data.Field).Editor);
154 >      TFile(data.Field).Editor.Align := alClient;
155 >      tab_meta.InsertControl(TFile(data.Field).Editor);
156        TFile(data.Field).Opened := True;
157      end;
158    end;
159   end;
160  
161 +
162   procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode,
163    NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex;
164    var Allowed: Boolean);
# Line 206 | Line 182 | begin
182      begin
183        if TFile(data.Field).Opened then
184        begin
185 <        if panel2.ControlCount > 0 then
186 <          for i := 0 to panel2.ControlCount - 1 do
187 <            panel2.RemoveControl(panel2.Controls[i]);
185 >        if tab_meta.ControlCount > 0 then
186 >          for i := 0 to tab_meta.ControlCount - 1 do
187 >            tab_meta.RemoveControl(tab_meta.Controls[i]);
188          TFile(data.Field).Opened := False;
189        end;
190      end;
191    end;
192   end;
193  
194 +
195   procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
196    Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
197   var
# Line 229 | Line 206 | begin
206          begin
207            if Data.Field is TFile then
208            begin
209 <            CellText := TFile(Data.Field).FileName;
209 >            CellText := TFile(Data.Field).FileInfo.Name;
210              if CellText = '' then
211                CellText := 'Unnamed';
212            end;
213 +          if Data.Field is TExtension then
214 +            CellText := TExtension(Data.Field).Ext;
215          end;
216        1:
217          begin
218            if Data.Field is TFile then
219 <            CellText := TFile(Data.Field).FileExt;
219 >            CellText := TFile(Data.Field).FileInfo.Extension;
220          end;
221        2:
222          begin
223            if Data.Field is TFile then
224 <            CellText := IntToStr(TFile(Data.Field).FileID);
224 >            CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
225          end;
226      end;
227    end;
228   end;
229  
230 +
231   procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
232    const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
233    TextType: TVSTTextType);
# Line 262 | Line 242 | begin
242          begin
243            if Data.Field is TFile then
244            begin
245 <            if Length(TFile(Data.Field).FileName) = 0 then
245 >            if Length(TFile(Data.Field).FileInfo.Name) = 0 then
246                TargetCanvas.Font.Color := $C06060;
247 <            if TFile(Data.Field).FileSize = 0 then
247 >            if TFile(Data.Field).FileInfo.Size = 0 then
248                TargetCanvas.Font.Color := $2020A0;
249            end;
250          end;
# Line 272 | Line 252 | begin
252    end;
253   end;
254  
275 {
255  
256 < procedure WriteStructureInfos;
257 < var
279 <  i, j:    Integer;
280 <  pdata:   PNodeData;
281 <  Data:    TNodeData;
282 <  node:    PVirtualNode;
256 >
257 > procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
258   begin
259 <  VST.BeginUpdate;
260 <  if VST.RootNodeCount = 0 then
261 <  begin
262 <    structs := LoadStructureDefinition(ConID, fileid);
263 <    if structs.Data then
264 <    begin
265 <      if Length(structs.Global) > 0 then
266 <      begin
267 <        for i := 0 to High(structs.Global) do
268 <        begin
269 <          Data.Caption  := structs.Global[i].Name;
270 <          Data.Offset   := structs.Global[i].offset;
271 <          Data.DataType := structs.Global[i].datatype;
272 <          Data.Value    := GetValue(structs.Global[i].datatype, structs.Global[i].offset);
298 <          Data.Description := structs.Global[i].description;
299 <          AddVSTEntry(VST, nil, Data);
300 <        end;
301 <      end;
302 <      if Length(structs.Subs) > 0 then
303 <      begin
304 <        for i := 0 to High(structs.Subs) do
305 <        begin
306 <          with structs.Subs[i] do
307 <          begin
308 <            if Length(Entries) > 0 then
309 <            begin
310 <              if Pos('#', SubName) > 0 then
311 <              begin
312 <                Data.Offset  := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8));
313 <                Data.Value   := '$' +
314 <                  MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8);
315 <                Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1);
316 <                Data.Description := SubDesc;
317 <              end
318 <              else
319 <              begin
320 <                Data.Caption := SubName;
321 <                Data.Description := SubDesc;
322 <                Data.Offset := 0;
323 <                Data.Value := '';
324 <              end;
325 <              Data.DataType := 0;
326 <              node := AddVSTEntry(VST, nil, Data);
327 <              Data.Description := '';
328 <              for j := 0 to High(Entries) do
329 <              begin
330 <                Data.Caption  := Entries[j].Name;
331 <                Data.Offset   := Entries[j].offset;
332 <                Data.DataType := Entries[j].datatype;
333 <                Data.Value    := GetValue(Entries[j].datatype, Entries[j].offset);
334 <                Data.Description := Entries[j].description;
335 <                AddVSTEntry(VST, node, Data);
336 <              end;
337 <            end;
338 <          end;
339 <        end;
340 <      end;
341 <    end;
342 <    if VST.RootNodeCount > 0 then
343 <      VST.FocusedNode := VST.GetFirst;
344 <  end
345 <  else
346 <  begin
347 <    Node := VST.GetFirst;
348 <    while Assigned(Node) do
349 <    begin
350 <      pdata := VST.GetNodeData(Node);
351 <      if pdata.DataType > 0 then
352 <        pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
353 <      Node := VST.GetNext(Node);
354 <    end;
355 <  end;
356 <  VST.EndUpdate;
259 > //  Meta.Free;
260 >  inherited;
261 > end;
262 >
263 > procedure TForm_Meta.FormCreate(Sender: TObject);
264 > begin
265 >  inherited;
266 >  OnNewConnection := NewCon;
267 >
268 >  VST.NodeDataSize := SizeOf(TNodeData);
269 >  VST.Font.Charset := AppSettings.CharSet;
270 >  VST.Clear;
271 >
272 >  UpdateConList;
273   end;
274 < }
274 >
275   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)