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

Last change on this file since 211 was 209, checked in by alloc, 17 years ago
File size: 5.4 KB
Line 
1unit MetaEditor;
2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, VirtualTrees, _FileManager;
6
7type
8 TForm_Meta = class(TForm)
9 VST: TVirtualStringTree;
10 procedure FormClose(Sender: TObject; var Action: TCloseAction);
11 procedure FormCreate(Sender: TObject);
12 procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
13 Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
14 private
15 public
16 FileManager: TFileManager;
17 end;
18
19var
20 Form_Meta: TForm_Meta;
21
22implementation
23uses
24 Data, _DataTypes, _FileTypes;
25{$R *.dfm}
26
27type
28 PNodeData = ^TNodeData;
29
30 TNodeData = record
31 Field: TObject;
32 end;
33
34function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode;
35 ARecord: TNodeData): PVirtualNode;
36var
37 Data: PNodeData;
38begin
39 Result := AVST.AddChild(ANode);
40 Data := AVST.GetNodeData(Result);
41 AVST.ValidateNode(Result, False);
42 Data^ := ARecord;
43end;
44
45
46
47procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
48begin
49 FileManager.Free;
50 Action := caFree;
51end;
52
53
54procedure TForm_Meta.FormCreate(Sender: TObject);
55var
56 a,b,c: Int64;
57 i: Integer;
58 data: TNodeData;
59begin
60 VST.NodeDataSize := SizeOf(TNodeData);
61 VST.Font.Charset := AppSettings.CharSet;
62 VST.Clear;
63
64 QueryPerformanceFrequency(c);
65 QueryPerformanceCounter(a);
66 FileManager := TFileManager.Create(1);
67 QueryPerformanceCounter(b);
68 ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's');
69
70 for i := 0 to FileManager.FileCount - 1 do
71 begin
72 data.Field := FileManager.FileById[i];
73 AddVSTEntry(VST, nil, data);
74 end;
75end;
76
77
78
79procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
80 Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
81var
82 Data: PNodeData;
83begin
84 Data := Sender.GetNodeData(Node);
85 CellText := '';
86 if TextType = ttNormal then
87 begin
88 case Column of
89 0: begin
90 if Data.Field is TFile then
91 begin
92 CellText := TFile(Data.Field).FileName;
93 end;
94 end;
95{ 0:
96 CellText := Data.Caption;
97 1:
98 if Data.DataType > 0 then
99 CellText := '0x' + IntToHex(Data.Offset, 8)
100 else if Data.Offset > 0 then
101 CellText := '0x' + IntToHex(Data.Offset, 8);
102 2:
103 if Data.DataType > 0 then
104 CellText := GetDataType(Data.DataType);
105 3:
106 if Data.DataType > 0 then
107 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;
113 end;
114end;
115
116{
117
118procedure WriteStructureInfos;
119var
120 i, j: Integer;
121 pdata: PNodeData;
122 Data: TNodeData;
123 node: PVirtualNode;
124begin
125 VST.BeginUpdate;
126 if VST.RootNodeCount = 0 then
127 begin
128 structs := LoadStructureDefinition(ConID, fileid);
129 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
146 begin
147 with structs.Subs[i] do
148 begin
149 if Length(Entries) > 0 then
150 begin
151 if Pos('#', SubName) > 0 then
152 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;
179 end;
180 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);
195 end;
196 end;
197 VST.EndUpdate;
198end;
199}
200end.
Note: See TracBrowser for help on using the repository browser.