source: oup/current/Tools/MetaEditor.pas@ 213

Last change on this file since 213 was 213, checked in by alloc, 17 years ago
File size: 8.5 KB
Line 
1unit MetaEditor;
2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, VirtualTrees, _MetaManager, StdCtrls;
6
7type
8 TForm_Meta = class(TForm)
9 VST: TVirtualStringTree;
10 Button1: TButton;
11 Label3: TLabel;
12 combo_connection: TComboBox;
13 procedure FormClose(Sender: TObject; var Action: TCloseAction);
14 procedure FormCreate(Sender: TObject);
15 procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
16 Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
17 procedure Button1Click(Sender: TObject);
18 procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode;
19 var ChildCount: Cardinal);
20 procedure VSTPaintText(Sender: TBaseVirtualTree;
21 const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
22 TextType: TVSTTextType);
23 private
24 public
25 MetaManager: TMetaManager;
26 end;
27
28var
29 Form_Meta: TForm_Meta;
30
31implementation
32uses
33 Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils;
34{$R *.dfm}
35
36type
37 PNodeData = ^TNodeData;
38
39 TNodeData = record
40 Field: TObject;
41 end;
42
43function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode;
44 ARecord: TNodeData): PVirtualNode;
45var
46 Data: PNodeData;
47begin
48 Result := AVST.AddChild(ANode);
49 Data := AVST.GetNodeData(Result);
50 AVST.ValidateNode(Result, False);
51 Data^ := ARecord;
52end;
53
54
55
56procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
57 Node: PVirtualNode; var ChildCount: Cardinal);
58var
59 data: PNodeData;
60 newdata: TNodeData;
61 newnode: PVirtualNode;
62 i: Integer;
63 id: Integer;
64begin
65 data := VST.GetNodeData(node);
66 for i := 0 to MetaManager.FileById[TFile(data.Field).FileID].ChildCount - 1 do
67 begin
68 id := MetaManager.FileById[TFile(data.Field).FileID].LinkByIndex[i].DestID;
69 MetaManager.InitFile(id);
70 newdata.Field := MetaManager.FileById[id];
71 newnode := AddVSTEntry(VST, Node, newdata);
72 if MetaManager.FileById[id].ChildCount > 0 then
73 VST.HasChildren[newnode] := True;
74 end;
75 ChildCount := MetaManager.FileById[TFile(data.Field).FileID].ChildCount;
76end;
77
78
79procedure TForm_Meta.Button1Click(Sender: TObject);
80var
81 name: String;
82 conid: Integer;
83
84 a,b,c: Int64;
85 i: Integer;
86 data: TNodeData;
87 node: PVirtualNode;
88begin
89 if combo_connection.ItemIndex >= 0 then
90 begin
91 name := combo_connection.Items.Strings[combo_connection.ItemIndex];
92 conid := StrToInt(MidStr(name, Pos('[', name) + 1, Pos(']', name) - Pos('[', name) - 1));
93
94 QueryPerformanceFrequency(c);
95 QueryPerformanceCounter(a);
96 MetaManager := TMetaManager.Create(conid);
97 QueryPerformanceCounter(b);
98 ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
99
100 VST.Clear;
101 VST.BeginUpdate;
102 for i := 0 to MetaManager.FileCount - 1 do
103 begin
104 if Assigned(MetaManager.FileById[i]) then
105 begin
106 data.Field := MetaManager.FileById[i];
107 node := AddVSTEntry(VST, nil, data);
108 if MetaManager.FileById[i].ChildCount > 0 then
109 VST.HasChildren[node] := True;
110 end;
111 end;
112 VST.EndUpdate;
113 end;
114end;
115
116procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
117begin
118 MetaManager.Free;
119 Action := caFree;
120end;
121
122
123procedure TForm_Meta.FormCreate(Sender: TObject);
124var
125 i: Integer;
126
127 fn, datatype, boxstring: String;
128 level: Integer;
129begin
130 combo_connection.ItemIndex := -1;
131 combo_connection.Items.Clear;
132 if ConManager.Count > 0 then
133 begin
134 for i := 0 to ConManager.Count - 1 do
135 begin
136 level := ConManager.ConnectionByIndex[i].LevelNumber;
137 fn := ExtractFileName(ConManager.ConnectionByIndex[i].FileName);
138 if ConManager.ConnectionByIndex[i].Backend = DB_ONI then
139 datatype := 'ONI-.dat: '
140 else if ConManager.ConnectionByIndex[i].Backend = DB_ADB then
141 datatype := 'OUP-DB: '
142 else
143 datatype := 'Unknown: ';
144 boxstring := datatype + fn + ' (Level: ' + IntToStr(level) + ') [' + IntToStr(ConManager.ConnectionByIndex[i].ConnectionID) + ']';
145 combo_connection.Items.Add(boxstring);
146 end;
147 if combo_connection.ItemIndex = -1 then
148 begin
149 combo_connection.ItemIndex := 0;
150 end;
151 end;
152
153
154 VST.NodeDataSize := SizeOf(TNodeData);
155 VST.Font.Charset := AppSettings.CharSet;
156 VST.Clear;
157end;
158
159
160
161procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
162 Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
163var
164 Data: PNodeData;
165begin
166 Data := Sender.GetNodeData(Node);
167 CellText := '';
168 if TextType = ttNormal then
169 begin
170 case Column of
171 0:
172 begin
173 if Data.Field is TFile then
174 begin
175 CellText := TFile(Data.Field).FileName;
176 if CellText = '' then
177 CellText := 'Unnamed';
178 end;
179 end;
180 1:
181 begin
182 if Data.Field is TFile then
183 CellText := TFile(Data.Field).FileExt;
184 end;
185 2:
186 begin
187 if Data.Field is TFile then
188 CellText := IntToStr(TFile(Data.Field).FileID);
189 end;
190 end;
191 end;
192end;
193
194procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
195 const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
196 TextType: TVSTTextType);
197var
198 Data: PNodeData;
199begin
200 Data := Sender.GetNodeData(Node);
201 if TextType = ttNormal then
202 begin
203 case Column of
204 0:
205 begin
206 if Data.Field is TFile then
207 begin
208 if Length(TFile(Data.Field).FileName) = 0 then
209 TargetCanvas.Font.Color := $C06060;
210 if TFile(Data.Field).FileSize = 0 then
211 TargetCanvas.Font.Color := $2020A0;
212 end;
213 end;
214 end;
215 end;
216end;
217
218{
219
220procedure WriteStructureInfos;
221var
222 i, j: Integer;
223 pdata: PNodeData;
224 Data: TNodeData;
225 node: PVirtualNode;
226begin
227 VST.BeginUpdate;
228 if VST.RootNodeCount = 0 then
229 begin
230 structs := LoadStructureDefinition(ConID, fileid);
231 if structs.Data then
232 begin
233 if Length(structs.Global) > 0 then
234 begin
235 for i := 0 to High(structs.Global) do
236 begin
237 Data.Caption := structs.Global[i].Name;
238 Data.Offset := structs.Global[i].offset;
239 Data.DataType := structs.Global[i].datatype;
240 Data.Value := GetValue(structs.Global[i].datatype, structs.Global[i].offset);
241 Data.Description := structs.Global[i].description;
242 AddVSTEntry(VST, nil, Data);
243 end;
244 end;
245 if Length(structs.Subs) > 0 then
246 begin
247 for i := 0 to High(structs.Subs) do
248 begin
249 with structs.Subs[i] do
250 begin
251 if Length(Entries) > 0 then
252 begin
253 if Pos('#', SubName) > 0 then
254 begin
255 Data.Offset := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8));
256 Data.Value := '$' +
257 MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8);
258 Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1);
259 Data.Description := SubDesc;
260 end
261 else
262 begin
263 Data.Caption := SubName;
264 Data.Description := SubDesc;
265 Data.Offset := 0;
266 Data.Value := '';
267 end;
268 Data.DataType := 0;
269 node := AddVSTEntry(VST, nil, Data);
270 Data.Description := '';
271 for j := 0 to High(Entries) do
272 begin
273 Data.Caption := Entries[j].Name;
274 Data.Offset := Entries[j].offset;
275 Data.DataType := Entries[j].datatype;
276 Data.Value := GetValue(Entries[j].datatype, Entries[j].offset);
277 Data.Description := Entries[j].description;
278 AddVSTEntry(VST, node, Data);
279 end;
280 end;
281 end;
282 end;
283 end;
284 end;
285 if VST.RootNodeCount > 0 then
286 VST.FocusedNode := VST.GetFirst;
287 end
288 else
289 begin
290 Node := VST.GetFirst;
291 while Assigned(Node) do
292 begin
293 pdata := VST.GetNodeData(Node);
294 if pdata.DataType > 0 then
295 pdata.Value := GetValue(pdata.Datatype, pdata.Offset);
296 Node := VST.GetNext(Node);
297 end;
298 end;
299 VST.EndUpdate;
300end;
301}
302end.
Note: See TracBrowser for help on using the repository browser.