| 1 | unit MetaEditor; | 
 
 
 
 
 | 2 | interface | 
 
 
 
 
 | 3 | uses | 
 
 
 
 
 | 4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | 
 
 
 
 
 | 5 | Dialogs, VirtualTrees, _MetaManager, StdCtrls; | 
 
 
 
 
 | 6 |  | 
 
 
 
 
 | 7 | type | 
 
 
 
 
 | 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 |  | 
 
 
 
 
 | 28 | var | 
 
 
 
 
 | 29 | Form_Meta: TForm_Meta; | 
 
 
 
 
 | 30 |  | 
 
 
 
 
 | 31 | implementation | 
 
 
 
 
 | 32 | uses | 
 
 
 
 
 | 33 | Data, _DataTypes, _FileTypes, ConnectionManager, TypeDefs, StrUtils; | 
 
 
 
 
 | 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 |  | 
 
 
 
 
 | 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 |  | 
 
 
 
 
 | 116 | procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction); | 
 
 
 
 
 | 117 | begin | 
 
 
 
 
 | 118 | MetaManager.Free; | 
 
 
 
 
 | 119 | Action := caFree; | 
 
 
 
 
 | 120 | end; | 
 
 
 
 
 | 121 |  | 
 
 
 
 
 | 122 |  | 
 
 
 
 
 | 123 | procedure TForm_Meta.FormCreate(Sender: TObject); | 
 
 
 
 
 | 124 | var | 
 
 
 
 
 | 125 | i: Integer; | 
 
 
 
 
 | 126 |  | 
 
 
 
 
 | 127 | fn, datatype, boxstring: String; | 
 
 
 
 
 | 128 | level: Integer; | 
 
 
 
 
 | 129 | begin | 
 
 
 
 
 | 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; | 
 
 
 
 
 | 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 | 
 
 
 
 
 | 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; | 
 
 
 
 
 | 192 | end; | 
 
 
 
 
 | 193 |  | 
 
 
 
 
 | 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 | 
 
 
 
 
 | 207 | if Length(TFile(Data.Field).FileName) = 0 then | 
 
 
 
 
 | 208 | TargetCanvas.Font.Color := $000060; | 
 
 
 
 
 | 209 | end; | 
 
 
 
 
 | 210 | end; | 
 
 
 
 
 | 211 | end; | 
 
 
 
 
 | 212 | end; | 
 
 
 
 
 | 213 |  | 
 
 
 
 
 | 214 | { | 
 
 
 
 
 | 215 |  | 
 
 
 
 
 | 216 | procedure WriteStructureInfos; | 
 
 
 
 
 | 217 | var | 
 
 
 
 
 | 218 | i, j:    Integer; | 
 
 
 
 
 | 219 | pdata:   PNodeData; | 
 
 
 
 
 | 220 | Data:    TNodeData; | 
 
 
 
 
 | 221 | node:    PVirtualNode; | 
 
 
 
 
 | 222 | begin | 
 
 
 
 
 | 223 | VST.BeginUpdate; | 
 
 
 
 
 | 224 | if VST.RootNodeCount = 0 then | 
 
 
 
 
 | 225 | begin | 
 
 
 
 
 | 226 | structs := LoadStructureDefinition(ConID, fileid); | 
 
 
 
 
 | 227 | if structs.Data then | 
 
 
 
 
 | 228 | begin | 
 
 
 
 
 | 229 | if Length(structs.Global) > 0 then | 
 
 
 
 
 | 230 | begin | 
 
 
 
 
 | 231 | for i := 0 to High(structs.Global) do | 
 
 
 
 
 | 232 | begin | 
 
 
 
 
 | 233 | Data.Caption  := structs.Global[i].Name; | 
 
 
 
 
 | 234 | Data.Offset   := structs.Global[i].offset; | 
 
 
 
 
 | 235 | Data.DataType := structs.Global[i].datatype; | 
 
 
 
 
 | 236 | Data.Value    := GetValue(structs.Global[i].datatype, structs.Global[i].offset); | 
 
 
 
 
 | 237 | Data.Description := structs.Global[i].description; | 
 
 
 
 
 | 238 | AddVSTEntry(VST, nil, Data); | 
 
 
 
 
 | 239 | end; | 
 
 
 
 
 | 240 | end; | 
 
 
 
 
 | 241 | if Length(structs.Subs) > 0 then | 
 
 
 
 
 | 242 | begin | 
 
 
 
 
 | 243 | for i := 0 to High(structs.Subs) do | 
 
 
 
 
 | 244 | begin | 
 
 
 
 
 | 245 | with structs.Subs[i] do | 
 
 
 
 
 | 246 | begin | 
 
 
 
 
 | 247 | if Length(Entries) > 0 then | 
 
 
 
 
 | 248 | begin | 
 
 
 
 
 | 249 | if Pos('#', SubName) > 0 then | 
 
 
 
 
 | 250 | begin | 
 
 
 
 
 | 251 | Data.Offset  := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8)); | 
 
 
 
 
 | 252 | Data.Value   := '$' + | 
 
 
 
 
 | 253 | MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8); | 
 
 
 
 
 | 254 | Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1); | 
 
 
 
 
 | 255 | Data.Description := SubDesc; | 
 
 
 
 
 | 256 | end | 
 
 
 
 
 | 257 | else | 
 
 
 
 
 | 258 | begin | 
 
 
 
 
 | 259 | Data.Caption := SubName; | 
 
 
 
 
 | 260 | Data.Description := SubDesc; | 
 
 
 
 
 | 261 | Data.Offset := 0; | 
 
 
 
 
 | 262 | Data.Value := ''; | 
 
 
 
 
 | 263 | end; | 
 
 
 
 
 | 264 | Data.DataType := 0; | 
 
 
 
 
 | 265 | node := AddVSTEntry(VST, nil, Data); | 
 
 
 
 
 | 266 | Data.Description := ''; | 
 
 
 
 
 | 267 | for j := 0 to High(Entries) do | 
 
 
 
 
 | 268 | begin | 
 
 
 
 
 | 269 | Data.Caption  := Entries[j].Name; | 
 
 
 
 
 | 270 | Data.Offset   := Entries[j].offset; | 
 
 
 
 
 | 271 | Data.DataType := Entries[j].datatype; | 
 
 
 
 
 | 272 | Data.Value    := GetValue(Entries[j].datatype, Entries[j].offset); | 
 
 
 
 
 | 273 | Data.Description := Entries[j].description; | 
 
 
 
 
 | 274 | AddVSTEntry(VST, node, Data); | 
 
 
 
 
 | 275 | end; | 
 
 
 
 
 | 276 | end; | 
 
 
 
 
 | 277 | end; | 
 
 
 
 
 | 278 | end; | 
 
 
 
 
 | 279 | end; | 
 
 
 
 
 | 280 | end; | 
 
 
 
 
 | 281 | if VST.RootNodeCount > 0 then | 
 
 
 
 
 | 282 | VST.FocusedNode := VST.GetFirst; | 
 
 
 
 
 | 283 | end | 
 
 
 
 
 | 284 | else | 
 
 
 
 
 | 285 | begin | 
 
 
 
 
 | 286 | Node := VST.GetFirst; | 
 
 
 
 
 | 287 | while Assigned(Node) do | 
 
 
 
 
 | 288 | begin | 
 
 
 
 
 | 289 | pdata := VST.GetNodeData(Node); | 
 
 
 
 
 | 290 | if pdata.DataType > 0 then | 
 
 
 
 
 | 291 | pdata.Value := GetValue(pdata.Datatype, pdata.Offset); | 
 
 
 
 
 | 292 | Node := VST.GetNext(Node); | 
 
 
 
 
 | 293 | end; | 
 
 
 
 
 | 294 | end; | 
 
 
 
 
 | 295 | VST.EndUpdate; | 
 
 
 
 
 | 296 | end; | 
 
 
 
 
 | 297 | } | 
 
 
 
 
 | 298 | end. |