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