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 209 by alloc, Mon Jun 4 22:07:29 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, _FileManager;
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 <    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);
24 +    procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
25 +      var ChildCount: Cardinal);
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
16    FileManager: TFileManager;
40    end;
41  
19 var
20  Form_Meta: TForm_Meta;
42  
43   implementation
23 uses
24  Data, _DataTypes, _FileTypes;
44   {$R *.dfm}
45 + uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes;
46  
47   type
48    PNodeData = ^TNodeData;
# Line 43 | Line 63 | begin
63   end;
64  
65  
66 <
67 < procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
66 > procedure TForm_Meta.NewCon(ID: Integer);
67 > var
68 >  i: Integer;
69 >  data: TNodeData;
70 >  node: PVirtualNode;
71 >  Meta: TMetaManager;
72 >  root: TExtensions;
73   begin
74 <  FileManager.Free;
75 <  Action := caFree;
74 >  if ID >= 0 then
75 >  begin
76 >    //VST
77 >    VST.Clear;
78 >    VST.BeginUpdate;
79 >    root := ConManager.Connection[FConnectionID].MetaData.Root;
80 >    for i := 0 to High(root) do
81 >    begin
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  
90  
91 < procedure TForm_Meta.FormCreate(Sender: TObject);
91 > procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
92 >  Node: PVirtualNode; var ChildCount: Cardinal);
93   var
94 <  a,b,c: Int64;
94 >  data: PNodeData;
95 >  newdata: TNodeData;
96 >  newnode: PVirtualNode;
97    i: Integer;
98 <  data: TNodeData;
98 >  id: Integer;
99 >  Meta: TMetaManager;
100   begin
101 <  VST.NodeDataSize := SizeOf(TNodeData);
102 <  VST.Font.Charset := AppSettings.CharSet;
103 <  VST.Clear;
101 >  data := Sender.GetNodeData(node);
102 >  Meta := ConManager.Connection[ConnectionID].MetaData;
103 >  if data.Field is TFile then
104 >  begin
105 >    if TFile(data.Field).ChildCount > 0 then
106 >    begin
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 TFile(data.Field).RawCount > 0 then
118 >    begin
119 >      for i := 0 to TFile(data.Field).RawCount - 1 do
120 >      begin
121 > //        Exit;
122 >      end;
123 >    end;
124 >  end;
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  
64  QueryPerformanceFrequency(c);
65  QueryPerformanceCounter(a);
66  FileManager := TFileManager.Create(1);
67  QueryPerformanceCounter(b);
68  ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
142  
143 <  for i := 0 to FileManager.FileCount - 1 do
143 > procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree;
144 >  Node: PVirtualNode; Column: TColumnIndex);
145 > var
146 >  data: PNodeData;
147 > begin
148 >  data := Sender.GetNodeData(Node);
149 >  if data.Field is TFile then
150    begin
151 <    data.Field := FileManager.FileById[i];
152 <    AddVSTEntry(VST, nil, data);
151 >    TFile(data.Field).InitEditor;
152 >    if Assigned(TFile(data.Field).Editor) then
153 >    begin
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);
165 + var
166 +  data: PNodeData;
167 +  i: Integer;
168 + begin
169 +  data := Sender.GetNodeData(NewNode);
170 +  if data.Field is TFile then
171 +  begin
172 +    TFile(data.Field).InitEditor;
173 +    if Assigned(TFile(data.Field).Editor) then
174 +      Allowed := not TFile(data.Field).Opened
175 +    else
176 +      Allowed := True;
177 +  end;
178 +  if Allowed and Assigned(OldNode) then
179 +  begin
180 +    data := Sender.GetNodeData(OldNode);
181 +    if data.Field is TFile then
182 +    begin
183 +      if TFile(data.Field).Opened then
184 +      begin
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);
# Line 86 | Line 202 | begin
202    if TextType = ttNormal then
203    begin
204      case Column of
205 <      0: begin
90 <        if Data.Field is TFile then
205 >      0:
206          begin
207 <          CellText := TFile(Data.Field).FileName;
207 >          if Data.Field is TFile then
208 >          begin
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;
94      end;
95 {      0:
96        CellText := Data.Caption;
216        1:
217 <        if Data.DataType > 0 then
218 <          CellText := '0x' + IntToHex(Data.Offset, 8)
219 <        else if Data.Offset > 0 then
220 <          CellText := '0x' + IntToHex(Data.Offset, 8);
217 >        begin
218 >          if Data.Field is TFile then
219 >            CellText := TFile(Data.Field).FileInfo.Extension;
220 >        end;
221        2:
222 <        if Data.DataType > 0 then
223 <          CellText := GetDataType(Data.DataType);
224 <      3:
225 <        if Data.DataType > 0 then
226 <          CellText := Data.Value //GetValue(data.DataType, data.Offset)
108 <        else if Length(Data.Value) > 0 then
109 <          CellText := IntToStr(StrToInt(Data.Value)) + ' Bytes';
110 <      4:
111 <        CellText := Data.Description;
112 < }    end;
222 >        begin
223 >          if Data.Field is TFile then
224 >            CellText := IntToStr(TFile(Data.Field).FileInfo.ID);
225 >        end;
226 >    end;
227    end;
228   end;
229  
116 {
230  
231 < procedure WriteStructureInfos;
231 > procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
232 >  const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
233 >  TextType: TVSTTextType);
234   var
235 <  i, j:    Integer;
121 <  pdata:   PNodeData;
122 <  Data:    TNodeData;
123 <  node:    PVirtualNode;
235 >  Data: PNodeData;
236   begin
237 <  VST.BeginUpdate;
238 <  if VST.RootNodeCount = 0 then
237 >  Data     := Sender.GetNodeData(Node);
238 >  if TextType = ttNormal then
239    begin
240 <    structs := LoadStructureDefinition(ConID, fileid);
241 <    if structs.Data then
130 <    begin
131 <      if Length(structs.Global) > 0 then
132 <      begin
133 <        for i := 0 to High(structs.Global) do
134 <        begin
135 <          Data.Caption  := structs.Global[i].Name;
136 <          Data.Offset   := structs.Global[i].offset;
137 <          Data.DataType := structs.Global[i].datatype;
138 <          Data.Value    := GetValue(structs.Global[i].datatype, structs.Global[i].offset);
139 <          Data.Description := structs.Global[i].description;
140 <          AddVSTEntry(VST, nil, Data);
141 <        end;
142 <      end;
143 <      if Length(structs.Subs) > 0 then
144 <      begin
145 <        for i := 0 to High(structs.Subs) do
240 >    case Column of
241 >      0:
242          begin
243 <          with structs.Subs[i] do
243 >          if Data.Field is TFile then
244            begin
245 <            if Length(Entries) > 0 then
246 <            begin
247 <              if Pos('#', SubName) > 0 then
248 <              begin
153 <                Data.Offset  := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8));
154 <                Data.Value   := '$' +
155 <                  MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8);
156 <                Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1);
157 <                Data.Description := SubDesc;
158 <              end
159 <              else
160 <              begin
161 <                Data.Caption := SubName;
162 <                Data.Description := SubDesc;
163 <                Data.Offset := 0;
164 <                Data.Value := '';
165 <              end;
166 <              Data.DataType := 0;
167 <              node := AddVSTEntry(VST, nil, Data);
168 <              Data.Description := '';
169 <              for j := 0 to High(Entries) do
170 <              begin
171 <                Data.Caption  := Entries[j].Name;
172 <                Data.Offset   := Entries[j].offset;
173 <                Data.DataType := Entries[j].datatype;
174 <                Data.Value    := GetValue(Entries[j].datatype, Entries[j].offset);
175 <                Data.Description := Entries[j].description;
176 <                AddVSTEntry(VST, node, Data);
177 <              end;
178 <            end;
245 >            if Length(TFile(Data.Field).FileInfo.Name) = 0 then
246 >              TargetCanvas.Font.Color := $C06060;
247 >            if TFile(Data.Field).FileInfo.Size = 0 then
248 >              TargetCanvas.Font.Color := $2020A0;
249            end;
250          end;
181      end;
182    end;
183    if VST.RootNodeCount > 0 then
184      VST.FocusedNode := VST.GetFirst;
185  end
186  else
187  begin
188    Node := VST.GetFirst;
189    while Assigned(Node) do
190    begin
191      pdata := VST.GetNodeData(Node);
192      if pdata.DataType > 0 then
193        pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
194      Node := VST.GetNext(Node);
251      end;
252    end;
197  VST.EndUpdate;
253   end;
254 < }
254 >
255 >
256 >
257 > procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
258 > begin
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 >
275   end.

Diff Legend

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