[209] | 1 | unit MetaEditor;
|
---|
| 2 | interface
|
---|
| 3 | uses
|
---|
| 4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
[212] | 5 | Dialogs, VirtualTrees, _MetaManager, StdCtrls;
|
---|
[209] | 6 |
|
---|
| 7 | type
|
---|
| 8 | TForm_Meta = class(TForm)
|
---|
| 9 | VST: TVirtualStringTree;
|
---|
[212] | 10 | Button1: TButton;
|
---|
| 11 | Label3: TLabel;
|
---|
| 12 | combo_connection: TComboBox;
|
---|
[209] | 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);
|
---|
[212] | 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);
|
---|
[209] | 23 | private
|
---|
| 24 | public
|
---|
[212] | 25 | MetaManager: TMetaManager;
|
---|
[209] | 26 | end;
|
---|
| 27 |
|
---|
| 28 | var
|
---|
| 29 | Form_Meta: TForm_Meta;
|
---|
| 30 |
|
---|
| 31 | implementation
|
---|
| 32 | uses
|
---|
[212] | 33 | Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils;
|
---|
[209] | 34 | {$R *.dfm}
|
---|
| 35 |
|
---|
| 36 | type
|
---|
| 37 | PNodeData = ^TNodeData;
|
---|
| 38 |
|
---|
| 39 | TNodeData = record
|
---|
| 40 | Field: TObject;
|
---|
| 41 | end;
|
---|
| 42 |
|
---|
| 43 | function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode;
|
---|
| 44 | ARecord: TNodeData): PVirtualNode;
|
---|
| 45 | var
|
---|
| 46 | Data: PNodeData;
|
---|
| 47 | begin
|
---|
| 48 | Result := AVST.AddChild(ANode);
|
---|
| 49 | Data := AVST.GetNodeData(Result);
|
---|
| 50 | AVST.ValidateNode(Result, False);
|
---|
| 51 | Data^ := ARecord;
|
---|
| 52 | end;
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 |
|
---|
[212] | 56 | procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree;
|
---|
| 57 | Node: PVirtualNode; var ChildCount: Cardinal);
|
---|
| 58 | var
|
---|
| 59 | data: PNodeData;
|
---|
| 60 | newdata: TNodeData;
|
---|
| 61 | newnode: PVirtualNode;
|
---|
| 62 | i: Integer;
|
---|
| 63 | id: Integer;
|
---|
| 64 | begin
|
---|
| 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;
|
---|
| 76 | end;
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | procedure TForm_Meta.Button1Click(Sender: TObject);
|
---|
| 80 | var
|
---|
| 81 | name: String;
|
---|
| 82 | conid: Integer;
|
---|
| 83 |
|
---|
| 84 | a,b,c: Int64;
|
---|
| 85 | i: Integer;
|
---|
| 86 | data: TNodeData;
|
---|
| 87 | node: PVirtualNode;
|
---|
| 88 | begin
|
---|
| 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;
|
---|
| 114 | end;
|
---|
| 115 |
|
---|
[209] | 116 | procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 117 | begin
|
---|
[212] | 118 | MetaManager.Free;
|
---|
[209] | 119 | Action := caFree;
|
---|
| 120 | end;
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | procedure TForm_Meta.FormCreate(Sender: TObject);
|
---|
| 124 | var
|
---|
| 125 | i: Integer;
|
---|
[212] | 126 |
|
---|
| 127 | fn, datatype, boxstring: String;
|
---|
| 128 | level: Integer;
|
---|
[209] | 129 | begin
|
---|
[212] | 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 |
|
---|
[209] | 154 | VST.NodeDataSize := SizeOf(TNodeData);
|
---|
| 155 | VST.Font.Charset := AppSettings.CharSet;
|
---|
| 156 | VST.Clear;
|
---|
| 157 | end;
|
---|
| 158 |
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
---|
| 162 | Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
|
---|
| 163 | var
|
---|
| 164 | Data: PNodeData;
|
---|
| 165 | begin
|
---|
| 166 | Data := Sender.GetNodeData(Node);
|
---|
| 167 | CellText := '';
|
---|
| 168 | if TextType = ttNormal then
|
---|
| 169 | begin
|
---|
| 170 | case Column of
|
---|
[212] | 171 | 0:
|
---|
[209] | 172 | begin
|
---|
[212] | 173 | if Data.Field is TFile then
|
---|
| 174 | begin
|
---|
| 175 | CellText := TFile(Data.Field).FileName;
|
---|
| 176 | if CellText = '' then
|
---|
| 177 | CellText := 'Unnamed';
|
---|
| 178 | end;
|
---|
[209] | 179 | end;
|
---|
| 180 | 1:
|
---|
[212] | 181 | begin
|
---|
| 182 | if Data.Field is TFile then
|
---|
| 183 | CellText := TFile(Data.Field).FileExt;
|
---|
| 184 | end;
|
---|
[209] | 185 | 2:
|
---|
[212] | 186 | begin
|
---|
| 187 | if Data.Field is TFile then
|
---|
| 188 | CellText := IntToStr(TFile(Data.Field).FileID);
|
---|
| 189 | end;
|
---|
| 190 | end;
|
---|
[209] | 191 | end;
|
---|
| 192 | end;
|
---|
| 193 |
|
---|
[212] | 194 | procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree;
|
---|
| 195 | const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
|
---|
| 196 | TextType: TVSTTextType);
|
---|
| 197 | var
|
---|
| 198 | Data: PNodeData;
|
---|
| 199 | begin
|
---|
| 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
|
---|
[213] | 207 | begin
|
---|
[212] | 208 | if Length(TFile(Data.Field).FileName) = 0 then
|
---|
[213] | 209 | TargetCanvas.Font.Color := $C06060;
|
---|
| 210 | if TFile(Data.Field).FileSize = 0 then
|
---|
| 211 | TargetCanvas.Font.Color := $2020A0;
|
---|
| 212 | end;
|
---|
[212] | 213 | end;
|
---|
| 214 | end;
|
---|
| 215 | end;
|
---|
| 216 | end;
|
---|
| 217 |
|
---|
[209] | 218 | {
|
---|
| 219 |
|
---|
| 220 | procedure WriteStructureInfos;
|
---|
| 221 | var
|
---|
| 222 | i, j: Integer;
|
---|
| 223 | pdata: PNodeData;
|
---|
| 224 | Data: TNodeData;
|
---|
| 225 | node: PVirtualNode;
|
---|
| 226 | begin
|
---|
| 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;
|
---|
| 300 | end;
|
---|
| 301 | }
|
---|
| 302 | end.
|
---|