| 4 |
|
|
| 5 |
|
uses |
| 6 |
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 7 |
< |
Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls; |
| 7 |
> |
Dialogs, _BaseTemplate, ExtCtrls, VirtualTrees, StdCtrls, ComCtrls, Grids, |
| 8 |
> |
MPHexEditor, Wrapgrid, VTHeaderPopup, Menus, _TreeElement; |
| 9 |
|
|
| 10 |
|
type |
| 11 |
|
TForm_Meta = class(TForm_BaseTemplate) |
| 12 |
|
VST: TVirtualStringTree; |
| 12 |
– |
Panel2: TPanel; |
| 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 |
+ |
value_viewer_context: TPopupMenu; |
| 24 |
+ |
value_viewer_context_copy: TMenuItem; |
| 25 |
+ |
value_viewer_context_copyasdec: TMenuItem; |
| 26 |
+ |
value_viewer_context_copyasfloat: TMenuItem; |
| 27 |
+ |
value_viewer_context_copyasbitset: TMenuItem; |
| 28 |
+ |
value_viewer_context_copyasstring: TMenuItem; |
| 29 |
+ |
value_viewer_context_copyashex: TMenuItem; |
| 30 |
+ |
VTHPopup: TVTHeaderPopupMenu; |
| 31 |
+ |
btn_export: TButton; |
| 32 |
+ |
btn_import: TButton; |
| 33 |
+ |
vst_popup: TPopupMenu; |
| 34 |
+ |
vst_newRoot: TMenuItem; |
| 35 |
+ |
vst_setRoot: TMenuItem; |
| 36 |
|
procedure FormCreate(Sender: TObject); |
| 37 |
|
procedure VSTInitChildren(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 38 |
|
var ChildCount: Cardinal); |
| 47 |
|
procedure VSTPaintText(Sender: TBaseVirtualTree; |
| 48 |
|
const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; |
| 49 |
|
TextType: TVSTTextType); |
| 50 |
+ |
procedure VSTGetPopupMenu(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 51 |
+ |
Column: TColumnIndex; const P: TPoint; var AskParent: Boolean; |
| 52 |
+ |
var PopupMenu: TPopupMenu); |
| 53 |
+ |
procedure vst_setRootClick(Sender: TObject); |
| 54 |
+ |
procedure vst_newRootClick(Sender: TObject); |
| 55 |
+ |
procedure VSTGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 56 |
+ |
Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; |
| 57 |
+ |
var HintText: WideString); |
| 58 |
|
private |
| 59 |
+ |
root: TTreeElement; |
| 60 |
|
procedure NewCon(ID: Integer); |
| 61 |
|
public |
| 62 |
+ |
procedure SetRoot(TreeElem: TTreeElement); |
| 63 |
|
end; |
| 64 |
|
|
| 33 |
– |
var |
| 34 |
– |
Form_Meta: TForm_Meta; |
| 65 |
|
|
| 66 |
|
implementation |
| 67 |
|
{$R *.dfm} |
| 68 |
< |
uses _MetaManager, _FileTypes, Data; |
| 68 |
> |
uses _MetaManager, _MetaTypes, ConnectionManager, Data, _FileTypes, Main, |
| 69 |
> |
TypeDefs; |
| 70 |
|
|
| 71 |
|
type |
| 72 |
|
PNodeData = ^TNodeData; |
| 73 |
|
|
| 74 |
|
TNodeData = record |
| 75 |
< |
Field: TObject; |
| 75 |
> |
Field: TTreeElement; |
| 76 |
|
end; |
| 77 |
|
|
| 78 |
|
function AddVSTEntry(AVST: TCustomVirtualStringTree; ANode: PVirtualNode; |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
procedure TForm_Meta.NewCon(ID: Integer); |
| 91 |
+ |
begin |
| 92 |
+ |
if ID >= 0 then |
| 93 |
+ |
SetRoot(ConManager.Connection[FConnectionID].MetaData.Root); |
| 94 |
+ |
//SetRoot(ConManager.Connection[FConnectionID].MetaData.FileById[454]); |
| 95 |
+ |
end; |
| 96 |
+ |
|
| 97 |
+ |
|
| 98 |
+ |
procedure TForm_Meta.SetRoot(TreeElem: TTreeElement); |
| 99 |
|
var |
| 61 |
– |
a,b,c: Int64; |
| 100 |
|
i: Integer; |
| 101 |
|
data: TNodeData; |
| 102 |
|
node: PVirtualNode; |
| 103 |
+ |
basenode: PVirtualNode; |
| 104 |
|
begin |
| 105 |
< |
if ID >= 0 then |
| 105 |
> |
if FConnectionID <> TreeElem.ConnectionID then |
| 106 |
> |
SelectConnection(TreeElem.ConnectionID); |
| 107 |
> |
root := TreeElem; |
| 108 |
> |
VST.Clear; |
| 109 |
> |
VST.BeginUpdate; |
| 110 |
> |
data.Field := root; |
| 111 |
> |
basenode := AddVSTEntry(VST, nil, data); |
| 112 |
> |
for i := 0 to root.ChildCount - 1 do |
| 113 |
|
begin |
| 114 |
< |
QueryPerformanceFrequency(c); |
| 115 |
< |
QueryPerformanceCounter(a); |
| 116 |
< |
if not Assigned(Meta) then |
| 117 |
< |
Meta := TMetaManager.Create(ID); |
| 72 |
< |
QueryPerformanceCounter(b); |
| 73 |
< |
ShowMessage('Loading Done - ' + FloatToStr((b-a)/c) + 's'); |
| 74 |
< |
|
| 75 |
< |
VST.Clear; |
| 76 |
< |
VST.BeginUpdate; |
| 77 |
< |
for i := 0 to Meta.FileCount - 1 do |
| 78 |
< |
begin |
| 79 |
< |
if Assigned(Meta.FileById[i]) then |
| 80 |
< |
begin |
| 81 |
< |
data.Field := Meta.FileById[i]; |
| 82 |
< |
node := AddVSTEntry(VST, nil, data); |
| 83 |
< |
if Meta.FileById[i].ChildCount > 0 then |
| 84 |
< |
VST.HasChildren[node] := True; |
| 85 |
< |
end; |
| 86 |
< |
end; |
| 87 |
< |
VST.EndUpdate; |
| 114 |
> |
data.Field := root.Child[i]; |
| 115 |
> |
node := AddVSTEntry(VST, basenode, data); |
| 116 |
> |
if data.Field.ChildCount > 0 then |
| 117 |
> |
VST.HasChildren[node] := True; |
| 118 |
|
end; |
| 119 |
+ |
VST.EndUpdate; |
| 120 |
|
end; |
| 121 |
|
|
| 91 |
– |
|
| 122 |
|
procedure TForm_Meta.VSTInitChildren(Sender: TBaseVirtualTree; |
| 123 |
|
Node: PVirtualNode; var ChildCount: Cardinal); |
| 124 |
|
var |
| 126 |
|
newdata: TNodeData; |
| 127 |
|
newnode: PVirtualNode; |
| 128 |
|
i: Integer; |
| 99 |
– |
id: Integer; |
| 129 |
|
begin |
| 130 |
< |
data := VST.GetNodeData(node); |
| 131 |
< |
for i := 0 to Meta.FileById[TFile(data.Field).FileID].ChildCount - 1 do |
| 130 |
> |
data := Sender.GetNodeData(node); |
| 131 |
> |
|
| 132 |
> |
if data.Field.ChildCount > 0 then |
| 133 |
|
begin |
| 134 |
< |
id := Meta.FileById[TFile(data.Field).FileID].LinkByIndex[i].DestID; |
| 135 |
< |
Meta.InitFile(id); |
| 136 |
< |
newdata.Field := Meta.FileById[id]; |
| 137 |
< |
newnode := AddVSTEntry(VST, Node, newdata); |
| 138 |
< |
if Meta.FileById[id].ChildCount > 0 then |
| 139 |
< |
VST.HasChildren[newnode] := True; |
| 134 |
> |
for i := 0 to data.Field.ChildCount - 1 do |
| 135 |
> |
begin |
| 136 |
> |
newdata.Field := data.Field.Child[i]; |
| 137 |
> |
newnode := AddVSTEntry(TCustomVirtualStringTree(Sender), Node, newdata); |
| 138 |
> |
if newdata.Field.ChildCount > 0 then |
| 139 |
> |
Sender.HasChildren[newnode] := True; |
| 140 |
> |
end; |
| 141 |
|
end; |
| 142 |
< |
ChildCount := Meta.FileById[TFile(data.Field).FileID].ChildCount; |
| 142 |
> |
ChildCount := Sender.ChildCount[Node]; |
| 143 |
|
end; |
| 144 |
|
|
| 145 |
|
|
| 146 |
+ |
|
| 147 |
|
procedure TForm_Meta.VSTFocusChanged(Sender: TBaseVirtualTree; |
| 148 |
|
Node: PVirtualNode; Column: TColumnIndex); |
| 149 |
|
var |
| 150 |
|
data: PNodeData; |
| 151 |
+ |
ffile: TResource; |
| 152 |
|
begin |
| 153 |
|
data := Sender.GetNodeData(Node); |
| 154 |
< |
if data.Field is TFile then |
| 154 |
> |
ffile := nil; |
| 155 |
> |
if data.Field is TResource then |
| 156 |
> |
ffile := TResource(data.Field); |
| 157 |
> |
if data.Field is _MetaTypes.TDatLink then |
| 158 |
> |
if Assigned(_MetaTypes.TDatLink(data.Field).TargetFile) then |
| 159 |
> |
ffile := TResource(_MetaTypes.TDatLink(data.Field).TargetFile); |
| 160 |
> |
if Assigned(ffile) then |
| 161 |
|
begin |
| 162 |
< |
TFile(data.Field).InitEditor; |
| 124 |
< |
if Assigned(TFile(data.Field).Editor) then |
| 162 |
> |
if Assigned(ffile.Editor) then |
| 163 |
|
begin |
| 164 |
< |
panel2.InsertControl(TFile(data.Field).Editor); |
| 165 |
< |
TFile(data.Field).Opened := True; |
| 164 |
> |
ffile.Editor.Align := alClient; |
| 165 |
> |
tab_meta.InsertControl(ffile.Editor); |
| 166 |
> |
ffile.Opened := True; |
| 167 |
|
end; |
| 168 |
|
end; |
| 169 |
|
end; |
| 177 |
|
i: Integer; |
| 178 |
|
begin |
| 179 |
|
data := Sender.GetNodeData(NewNode); |
| 180 |
< |
if data.Field is TFile then |
| 180 |
> |
if data.Field is TResource then |
| 181 |
|
begin |
| 182 |
< |
TFile(data.Field).InitEditor; |
| 183 |
< |
if Assigned(TFile(data.Field).Editor) then |
| 145 |
< |
Allowed := not TFile(data.Field).Opened |
| 182 |
> |
if Assigned(TResource(data.Field).Editor) then |
| 183 |
> |
Allowed := not TResource(data.Field).Opened |
| 184 |
|
else |
| 185 |
|
Allowed := True; |
| 186 |
|
end; |
| 187 |
|
if Allowed and Assigned(OldNode) then |
| 188 |
|
begin |
| 189 |
|
data := Sender.GetNodeData(OldNode); |
| 190 |
< |
if data.Field is TFile then |
| 190 |
> |
if data.Field is TResource then |
| 191 |
|
begin |
| 192 |
< |
if TFile(data.Field).Opened then |
| 192 |
> |
if TResource(data.Field).Opened then |
| 193 |
|
begin |
| 194 |
< |
if panel2.ControlCount > 0 then |
| 195 |
< |
for i := 0 to panel2.ControlCount - 1 do |
| 196 |
< |
panel2.RemoveControl(panel2.Controls[i]); |
| 197 |
< |
TFile(data.Field).Opened := False; |
| 194 |
> |
if tab_meta.ControlCount > 0 then |
| 195 |
> |
for i := 0 to tab_meta.ControlCount - 1 do |
| 196 |
> |
tab_meta.RemoveControl(tab_meta.Controls[i]); |
| 197 |
> |
TResource(data.Field).Opened := False; |
| 198 |
|
end; |
| 199 |
|
end; |
| 200 |
|
end; |
| 211 |
|
if TextType = ttNormal then |
| 212 |
|
begin |
| 213 |
|
case Column of |
| 214 |
< |
0: |
| 215 |
< |
begin |
| 178 |
< |
if Data.Field is TFile then |
| 179 |
< |
begin |
| 180 |
< |
CellText := TFile(Data.Field).FileName; |
| 181 |
< |
if CellText = '' then |
| 182 |
< |
CellText := 'Unnamed'; |
| 183 |
< |
end; |
| 184 |
< |
end; |
| 185 |
< |
1: |
| 186 |
< |
begin |
| 187 |
< |
if Data.Field is TFile then |
| 188 |
< |
CellText := TFile(Data.Field).FileExt; |
| 189 |
< |
end; |
| 214 |
> |
0: CellText := Data.Field.Caption; |
| 215 |
> |
1: CellText := data.Field.VType; |
| 216 |
|
2: |
| 217 |
|
begin |
| 218 |
< |
if Data.Field is TFile then |
| 219 |
< |
CellText := IntToStr(TFile(Data.Field).FileID); |
| 218 |
> |
if Data.Field is TDataField then |
| 219 |
> |
CellText := TDataField(Data.Field).ValueAsString; |
| 220 |
|
end; |
| 221 |
|
end; |
| 222 |
|
end; |
| 235 |
|
case Column of |
| 236 |
|
0: |
| 237 |
|
begin |
| 238 |
< |
if Data.Field is TFile then |
| 238 |
> |
if Data.Field is TResource then |
| 239 |
|
begin |
| 240 |
< |
if Length(TFile(Data.Field).FileName) = 0 then |
| 240 |
> |
if Length(TResource(Data.Field).FileInfo.Name) = 0 then |
| 241 |
|
TargetCanvas.Font.Color := $C06060; |
| 242 |
< |
if TFile(Data.Field).FileSize = 0 then |
| 242 |
> |
if TResource(Data.Field).FileInfo.Size = 0 then |
| 243 |
|
TargetCanvas.Font.Color := $2020A0; |
| 244 |
|
end; |
| 245 |
|
end; |
| 249 |
|
|
| 250 |
|
|
| 251 |
|
|
| 252 |
+ |
procedure TForm_Meta.VSTGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; |
| 253 |
+ |
Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; |
| 254 |
+ |
var HintText: WideString); |
| 255 |
+ |
var |
| 256 |
+ |
data: PNodeData; |
| 257 |
+ |
CellText: WideString; |
| 258 |
+ |
|
| 259 |
+ |
ifile: TResource; |
| 260 |
+ |
begin |
| 261 |
+ |
inherited; |
| 262 |
+ |
if Assigned(Node) then |
| 263 |
+ |
begin |
| 264 |
+ |
VSTGetText(Sender, Node, Column, ttNormal, CellText); |
| 265 |
+ |
if Length(CellText) > 0 then |
| 266 |
+ |
begin |
| 267 |
+ |
data := Sender.GetNodeData(Node); |
| 268 |
+ |
if data.Field is TDataField then |
| 269 |
+ |
begin |
| 270 |
+ |
case Column of |
| 271 |
+ |
0,1: HintText := TDataField(data.Field).Description; |
| 272 |
+ |
2: HintText := ''; |
| 273 |
+ |
end; |
| 274 |
+ |
end; |
| 275 |
+ |
if data.Field is TResource then |
| 276 |
+ |
begin |
| 277 |
+ |
ifile := TResource(data.Field); |
| 278 |
+ |
case Column of |
| 279 |
+ |
0: HintText := |
| 280 |
+ |
'FileID: ' + IntToStr(ifile.FileInfo.ID) + #13#10 + |
| 281 |
+ |
'Name: ' + ifile.FileInfo.Name + #13#10 + |
| 282 |
+ |
'Extension: ' + ifile.FileInfo.Extension + #13#10 + |
| 283 |
+ |
'.dat-size: ' + IntToStr(ifile.FileInfo.Size) + #13#10; |
| 284 |
+ |
end; |
| 285 |
+ |
end; |
| 286 |
+ |
end; |
| 287 |
+ |
end |
| 288 |
+ |
else |
| 289 |
+ |
HintText := ''; |
| 290 |
+ |
end; |
| 291 |
+ |
|
| 292 |
+ |
procedure TForm_Meta.VSTGetPopupMenu(Sender: TBaseVirtualTree; |
| 293 |
+ |
Node: PVirtualNode; Column: TColumnIndex; const P: TPoint; |
| 294 |
+ |
var AskParent: Boolean; var PopupMenu: TPopupMenu); |
| 295 |
+ |
var |
| 296 |
+ |
data: PNodeData; |
| 297 |
+ |
begin |
| 298 |
+ |
inherited; |
| 299 |
+ |
AskParent := False; |
| 300 |
+ |
if Assigned(Node) then |
| 301 |
+ |
begin |
| 302 |
+ |
Sender.Selected[Node] := True; |
| 303 |
+ |
Sender.FocusedNode := Node; |
| 304 |
+ |
data := Sender.GetNodeData(Node); |
| 305 |
+ |
if Column = 0 then |
| 306 |
+ |
begin |
| 307 |
+ |
if TTreeElement(data.Field).ChildCount > 0 then |
| 308 |
+ |
PopupMenu := vst_popup |
| 309 |
+ |
else |
| 310 |
+ |
PopupMenu := nil; |
| 311 |
+ |
end; |
| 312 |
+ |
end; |
| 313 |
+ |
end; |
| 314 |
+ |
|
| 315 |
+ |
procedure TForm_Meta.vst_newRootClick(Sender: TObject); |
| 316 |
+ |
var |
| 317 |
+ |
data: PNodeData; |
| 318 |
+ |
form: TForm_BaseTemplate; |
| 319 |
+ |
begin |
| 320 |
+ |
inherited; |
| 321 |
+ |
data := VST.GetNodeData(VST.FocusedNode); |
| 322 |
+ |
form := nil; |
| 323 |
+ |
form := Form_Main.open_child('meta'); |
| 324 |
+ |
if form is TForm_Meta then |
| 325 |
+ |
TForm_Meta(form).SetRoot(data.Field); |
| 326 |
+ |
end; |
| 327 |
+ |
|
| 328 |
+ |
procedure TForm_Meta.vst_setRootClick(Sender: TObject); |
| 329 |
+ |
var |
| 330 |
+ |
data: PNodeData; |
| 331 |
+ |
begin |
| 332 |
+ |
inherited; |
| 333 |
+ |
data := VST.GetNodeData(VST.FocusedNode); |
| 334 |
+ |
SetRoot(data.Field); |
| 335 |
+ |
end; |
| 336 |
+ |
|
| 337 |
|
procedure TForm_Meta.FormClose(Sender: TObject; var Action: TCloseAction); |
| 338 |
|
begin |
| 339 |
< |
Meta.Free; |
| 339 |
> |
// Meta.Free; |
| 340 |
|
inherited; |
| 341 |
|
end; |
| 342 |
|
|
| 344 |
|
begin |
| 345 |
|
inherited; |
| 346 |
|
OnNewConnection := NewCon; |
| 236 |
– |
FConnectionID := -1; |
| 347 |
|
|
| 348 |
|
VST.NodeDataSize := SizeOf(TNodeData); |
| 349 |
|
VST.Font.Charset := AppSettings.CharSet; |