| 1 | unit MetaEditor; | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | interface | 
 
 
 
 
 | 4 |  | 
 
 
 
 
 | 5 | uses | 
 
 
 
 
 | 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | 
 
 
 
 
 | 7 | Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls, ComCtrls, Grids, | 
 
 
 
 
 | 8 | MPHexEditor, Wrapgrid; | 
 
 
 
 
 | 9 |  | 
 
 
 
 
 | 10 | type | 
 
 
 
 
 | 11 | TForm_Meta = class(TForm_BaseTemplate) | 
 
 
 
 
 | 12 | VST: TVirtualStringTree; | 
 
 
 
 
 | 13 | splitter: TSplitter; | 
 
 
 
 
 | 14 | rightPages: TPageControl; | 
 
 
 
 
 | 15 | tab_hex: TTabSheet; | 
 
 
 
 
 | 16 | tab_meta: TTabSheet; | 
 
 
 
 
 | 17 | panel_hex_actions: TPanel; | 
 
 
 
 
 | 18 | hex: TMPHexEditor; | 
 
 
 
 
 | 19 | splitter_hex_1: TSplitter; | 
 
 
 
 
 | 20 | value_viewer: TWrapGrid; | 
 
 
 
 
 | 21 | splitter_hex_2: TSplitter; | 
 
 
 
 
 | 22 | structviewer: TVirtualStringTree; | 
 
 
 
 
 | 23 | procedure FormCreate(Sender: TObject); | 
 
 
 
 
 | 24 | procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; | 
 
 
 
 
 | 25 | var ChildCount: Cardinal); | 
 
 
 
 
 | 26 | procedure FormClose(Sender: TObject; var Action: TCloseAction); | 
 
 
 
 
 | 27 | procedure VSTFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; | 
 
 
 
 
 | 28 | Column: TColumnIndex); | 
 
 
 
 
 | 29 | procedure VSTFocusChanging(Sender: TBaseVirtualTree; OldNode, | 
 
 
 
 
 | 30 | NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; | 
 
 
 
 
 | 31 | var Allowed: Boolean); | 
 
 
 
 
 | 32 | procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; | 
 
 
 
 
 | 33 | Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); | 
 
 
 
 
 | 34 | procedure VSTPaintText(Sender: TBaseVirtualTree; | 
 
 
 
 
 | 35 | const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; | 
 
 
 
 
 | 36 | TextType: TVSTTextType); | 
 
 
 
 
 | 37 | private | 
 
 
 
 
 | 38 | procedure NewCon(ID: Integer); | 
 
 
 
 
 | 39 | public | 
 
 
 
 
 | 40 | end; | 
 
 
 
 
 | 41 |  | 
 
 
 
 
 | 42 |  | 
 
 
 
 
 | 43 | implementation | 
 
 
 
 
 | 44 | {$R *.dfm} | 
 
 
 
 
 | 45 | uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes; | 
 
 
 
 
 | 46 |  | 
 
 
 
 
 | 47 | type | 
 
 
 
 
 | 48 | PNodeData = ^TNodeData; | 
 
 
 
 
 | 49 |  | 
 
 
 
 
 | 50 | TNodeData = record | 
 
 
 
 
 | 51 | Field: TObject; | 
 
 
 
 
 | 52 | end; | 
 
 
 
 
 | 53 |  | 
 
 
 
 
 | 54 | function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; | 
 
 
 
 
 | 55 | ARecord: TNodeData): PVirtualNode; | 
 
 
 
 
 | 56 | var | 
 
 
 
 
 | 57 | Data: PNodeData; | 
 
 
 
 
 | 58 | begin | 
 
 
 
 
 | 59 | Result := AVST.AddChild(ANode); | 
 
 
 
 
 | 60 | Data   := AVST.GetNodeData(Result); | 
 
 
 
 
 | 61 | AVST.ValidateNode(Result, False); | 
 
 
 
 
 | 62 | Data^ := ARecord; | 
 
 
 
 
 | 63 | end; | 
 
 
 
 
 | 64 |  | 
 
 
 
 
 | 65 |  | 
 
 
 
 
 | 66 | procedure TForm_Meta.NewCon(ID: Integer); | 
 
 
 
 
 | 67 | var | 
 
 
 
 
 | 68 | i: Integer; | 
 
 
 
 
 | 69 | data: TNodeData; | 
 
 
 
 
 | 70 | node: PVirtualNode; | 
 
 
 
 
 | 71 | Meta: TMetaManager; | 
 
 
 
 
 | 72 | root: TExtensions; | 
 
 
 
 
 | 73 | begin | 
 
 
 
 
 | 74 | if ID >= 0 then | 
 
 
 
 
 | 75 | begin | 
 
 
 
 
 | 76 | //VST | 
 
 
 
 
 | 77 | VST.Clear; | 
 
 
 
 
 | 78 | VST.BeginUpdate; | 
 
 
 
 
 | 79 | root := ConManager.Connection[FConnectionID].MetaData.Root; | 
 
 
 
 
 | 80 | for i := 0 to High(root) do | 
 
 
 
 
 | 81 | begin | 
 
 
 
 
 | 82 | data.Field := root[i]; | 
 
 
 
 
 | 83 | node := AddVSTEntry(VST, nil, data); | 
 
 
 
 
 | 84 | VST.HasChildren[node] := True; | 
 
 
 
 
 | 85 | end; | 
 
 
 
 
 | 86 | VST.EndUpdate; | 
 
 
 
 
 | 87 | end; | 
 
 
 
 
 | 88 | end; | 
 
 
 
 
 | 89 |  | 
 
 
 
 
 | 90 |  | 
 
 
 
 
 | 91 | procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree; | 
 
 
 
 
 | 92 | Node: PVirtualNode; var ChildCount: Cardinal); | 
 
 
 
 
 | 93 | var | 
 
 
 
 
 | 94 | data: PNodeData; | 
 
 
 
 
 | 95 | newdata: TNodeData; | 
 
 
 
 
 | 96 | newnode: PVirtualNode; | 
 
 
 
 
 | 97 | i: Integer; | 
 
 
 
 
 | 98 | id: Integer; | 
 
 
 
 
 | 99 | Meta: TMetaManager; | 
 
 
 
 
 | 100 | begin | 
 
 
 
 
 | 101 | data := Sender.GetNodeData(node); | 
 
 
 
 
 | 102 | Meta := ConManager.Connection[ConnectionID].MetaData; | 
 
 
 
 
 | 103 | if data.Field is TFile then | 
 
 
 
 
 | 104 | begin | 
 
 
 
 
 | 105 | if TFile(data.Field).ChildCount > 0 then | 
 
 
 
 
 | 106 | begin | 
 
 
 
 
 | 107 | for i := 0 to TFile(data.Field).ChildCount - 1 do | 
 
 
 
 
 | 108 | begin | 
 
 
 
 
 | 109 | id := TFile(data.Field).LinkByIndex[i].DestID; | 
 
 
 
 
 | 110 | Meta.InitFile(id); | 
 
 
 
 
 | 111 | newdata.Field := Meta.FileById[id]; | 
 
 
 
 
 | 112 | newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata); | 
 
 
 
 
 | 113 | if Meta.FileById[id].ChildCount > 0 then | 
 
 
 
 
 | 114 | Sender.HasChildren[newnode] := True; | 
 
 
 
 
 | 115 | end; | 
 
 
 
 
 | 116 | end; | 
 
 
 
 
 | 117 | if TFile(data.Field).RawCount > 0 then | 
 
 
 
 
 | 118 | begin | 
 
 
 
 
 | 119 | for i := 0 to TFile(data.Field).RawCount - 1 do | 
 
 
 
 
 | 120 | begin | 
 
 
 
 
 | 121 | //        Exit; | 
 
 
 
 
 | 122 | end; | 
 
 
 
 
 | 123 | end; | 
 
 
 
 
 | 124 | end; | 
 
 
 
 
 | 125 | if data.Field is TExtension then | 
 
 
 
 
 | 126 | begin | 
 
 
 
 
 | 127 | if TExtension(data.Field).FileCount = 0 then | 
 
 
 
 
 | 128 | TExtension(data.Field).InitList; | 
 
 
 
 
 | 129 | for i := 0 to TExtension(data.Field).FileCount - 1 do | 
 
 
 
 
 | 130 | begin | 
 
 
 
 
 | 131 | id := TExtension(data.Field).Files[i]; | 
 
 
 
 
 | 132 | Meta.InitFile(id); | 
 
 
 
 
 | 133 | newdata.Field := Meta.FileById[id]; | 
 
 
 
 
 | 134 | newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata); | 
 
 
 
 
 | 135 | if Meta.FileById[id].ChildCount > 0 then | 
 
 
 
 
 | 136 | Sender.HasChildren[newnode] := True; | 
 
 
 
 
 | 137 | end; | 
 
 
 
 
 | 138 | end; | 
 
 
 
 
 | 139 | ChildCount := Sender.ChildCount[Node]; | 
 
 
 
 
 | 140 | end; | 
 
 
 
 
 | 141 |  | 
 
 
 
 
 | 142 |  | 
 
 
 
 
 | 143 | procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree; | 
 
 
 
 
 | 144 | Node: PVirtualNode; Column: TColumnIndex); | 
 
 
 
 
 | 145 | var | 
 
 
 
 
 | 146 | data: PNodeData; | 
 
 
 
 
 | 147 | begin | 
 
 
 
 
 | 148 | data := Sender.GetNodeData(Node); | 
 
 
 
 
 | 149 | if data.Field is TFile then | 
 
 
 
 
 | 150 | begin | 
 
 
 
 
 | 151 | TFile(data.Field).InitEditor; | 
 
 
 
 
 | 152 | if Assigned(TFile(data.Field).Editor) then | 
 
 
 
 
 | 153 | begin | 
 
 
 
 
 | 154 | TFile(data.Field).Editor.Align := alClient; | 
 
 
 
 
 | 155 | tab_meta.InsertControl(TFile(data.Field).Editor); | 
 
 
 
 
 | 156 | TFile(data.Field).Opened := True; | 
 
 
 
 
 | 157 | end; | 
 
 
 
 
 | 158 | end; | 
 
 
 
 
 | 159 | end; | 
 
 
 
 
 | 160 |  | 
 
 
 
 
 | 161 |  | 
 
 
 
 
 | 162 | procedure TForm_Meta.VSTFocusChanging(Sender: TBaseVirtualTree; OldNode, | 
 
 
 
 
 | 163 | NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; | 
 
 
 
 
 | 164 | var Allowed: Boolean); | 
 
 
 
 
 | 165 | var | 
 
 
 
 
 | 166 | data: PNodeData; | 
 
 
 
 
 | 167 | i: Integer; | 
 
 
 
 
 | 168 | begin | 
 
 
 
 
 | 169 | data := Sender.GetNodeData(NewNode); | 
 
 
 
 
 | 170 | if data.Field is TFile then | 
 
 
 
 
 | 171 | begin | 
 
 
 
 
 | 172 | TFile(data.Field).InitEditor; | 
 
 
 
 
 | 173 | if Assigned(TFile(data.Field).Editor) then | 
 
 
 
 
 | 174 | Allowed := not TFile(data.Field).Opened | 
 
 
 
 
 | 175 | else | 
 
 
 
 
 | 176 | Allowed := True; | 
 
 
 
 
 | 177 | end; | 
 
 
 
 
 | 178 | if Allowed and Assigned(OldNode) then | 
 
 
 
 
 | 179 | begin | 
 
 
 
 
 | 180 | data := Sender.GetNodeData(OldNode); | 
 
 
 
 
 | 181 | if data.Field is TFile then | 
 
 
 
 
 | 182 | begin | 
 
 
 
 
 | 183 | if TFile(data.Field).Opened then | 
 
 
 
 
 | 184 | begin | 
 
 
 
 
 | 185 | if tab_meta.ControlCount > 0 then | 
 
 
 
 
 | 186 | for i := 0 to tab_meta.ControlCount - 1 do | 
 
 
 
 
 | 187 | tab_meta.RemoveControl(tab_meta.Controls[i]); | 
 
 
 
 
 | 188 | TFile(data.Field).Opened := False; | 
 
 
 
 
 | 189 | end; | 
 
 
 
 
 | 190 | end; | 
 
 
 
 
 | 191 | end; | 
 
 
 
 
 | 192 | end; | 
 
 
 
 
 | 193 |  | 
 
 
 
 
 | 194 |  | 
 
 
 
 
 | 195 | procedure TForm_Meta.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; | 
 
 
 
 
 | 196 | Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString); | 
 
 
 
 
 | 197 | var | 
 
 
 
 
 | 198 | Data: PNodeData; | 
 
 
 
 
 | 199 | begin | 
 
 
 
 
 | 200 | Data     := Sender.GetNodeData(Node); | 
 
 
 
 
 | 201 | CellText := ''; | 
 
 
 
 
 | 202 | if TextType = ttNormal then | 
 
 
 
 
 | 203 | begin | 
 
 
 
 
 | 204 | case Column of | 
 
 
 
 
 | 205 | 0: | 
 
 
 
 
 | 206 | begin | 
 
 
 
 
 | 207 | if Data.Field is TFile then | 
 
 
 
 
 | 208 | begin | 
 
 
 
 
 | 209 | CellText := TFile(Data.Field).FileInfo.Name; | 
 
 
 
 
 | 210 | if CellText = '' then | 
 
 
 
 
 | 211 | CellText := 'Unnamed'; | 
 
 
 
 
 | 212 | end; | 
 
 
 
 
 | 213 | if Data.Field is TExtension then | 
 
 
 
 
 | 214 | CellText := TExtension(Data.Field).Ext; | 
 
 
 
 
 | 215 | end; | 
 
 
 
 
 | 216 | 1: | 
 
 
 
 
 | 217 | begin | 
 
 
 
 
 | 218 | if Data.Field is TFile then | 
 
 
 
 
 | 219 | CellText := TFile(Data.Field).FileInfo.Extension; | 
 
 
 
 
 | 220 | end; | 
 
 
 
 
 | 221 | 2: | 
 
 
 
 
 | 222 | begin | 
 
 
 
 
 | 223 | if Data.Field is TFile then | 
 
 
 
 
 | 224 | CellText := IntToStr(TFile(Data.Field).FileInfo.ID); | 
 
 
 
 
 | 225 | end; | 
 
 
 
 
 | 226 | end; | 
 
 
 
 
 | 227 | end; | 
 
 
 
 
 | 228 | end; | 
 
 
 
 
 | 229 |  | 
 
 
 
 
 | 230 |  | 
 
 
 
 
 | 231 | procedure TForm_Meta.VSTPaintText(Sender: TBaseVirtualTree; | 
 
 
 
 
 | 232 | const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; | 
 
 
 
 
 | 233 | TextType: TVSTTextType); | 
 
 
 
 
 | 234 | var | 
 
 
 
 
 | 235 | Data: PNodeData; | 
 
 
 
 
 | 236 | begin | 
 
 
 
 
 | 237 | Data     := Sender.GetNodeData(Node); | 
 
 
 
 
 | 238 | if TextType = ttNormal then | 
 
 
 
 
 | 239 | begin | 
 
 
 
 
 | 240 | case Column of | 
 
 
 
 
 | 241 | 0: | 
 
 
 
 
 | 242 | begin | 
 
 
 
 
 | 243 | if Data.Field is TFile then | 
 
 
 
 
 | 244 | begin | 
 
 
 
 
 | 245 | if Length(TFile(Data.Field).FileInfo.Name) = 0 then | 
 
 
 
 
 | 246 | TargetCanvas.Font.Color := $C06060; | 
 
 
 
 
 | 247 | if TFile(Data.Field).FileInfo.Size = 0 then | 
 
 
 
 
 | 248 | TargetCanvas.Font.Color := $2020A0; | 
 
 
 
 
 | 249 | end; | 
 
 
 
 
 | 250 | end; | 
 
 
 
 
 | 251 | end; | 
 
 
 
 
 | 252 | end; | 
 
 
 
 
 | 253 | end; | 
 
 
 
 
 | 254 |  | 
 
 
 
 
 | 255 |  | 
 
 
 
 
 | 256 |  | 
 
 
 
 
 | 257 | procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction); | 
 
 
 
 
 | 258 | begin | 
 
 
 
 
 | 259 | //  Meta.Free; | 
 
 
 
 
 | 260 | inherited; | 
 
 
 
 
 | 261 | end; | 
 
 
 
 
 | 262 |  | 
 
 
 
 
 | 263 | procedure TForm_Meta.FormCreate(Sender: TObject); | 
 
 
 
 
 | 264 | begin | 
 
 
 
 
 | 265 | inherited; | 
 
 
 
 
 | 266 | OnNewConnection := NewCon; | 
 
 
 
 
 | 267 |  | 
 
 
 
 
 | 268 | VST.NodeDataSize := SizeOf(TNodeData); | 
 
 
 
 
 | 269 | VST.Font.Charset := AppSettings.CharSet; | 
 
 
 
 
 | 270 | VST.Clear; | 
 
 
 
 
 | 271 |  | 
 
 
 
 
 | 272 | UpdateConList; | 
 
 
 
 
 | 273 | end; | 
 
 
 
 
 | 274 |  | 
 
 
 
 
 | 275 | end. |