public void RefreshView()
{
if (pcc == null)
{
return;
}
listBox1.BeginUpdate();
treeView1.BeginUpdate();
listBox1.Items.Clear();
IReadOnlyList<ImportEntry> imports = pcc.Imports;
IReadOnlyList<IExportEntry> Exports = pcc.Exports;
if (CurrentView == View.Names)
{
for (int i = 0; i < pcc.Names.Count; i++)
{
listBox1.Items.Add(i + " : " + pcc.getNameEntry(i));
}
}
if (CurrentView == View.Imports)
{
for (int i = 0; i < imports.Count; i++)
{
string importStr = i + " (0x" + (pcc.ImportOffset + (i * ImportEntry.byteSize)).ToString("X4") + "): (" + imports[i].PackageFile + ") ";
if (imports[i].PackageFullName != "Class" && imports[i].PackageFullName != "Package")
{
importStr += imports[i].PackageFullName + ".";
}
importStr += imports[i].ObjectName;
listBox1.Items.Add(importStr);
}
}
if (CurrentView == View.Exports)
{
List<string> exps = new List<string>(Exports.Count);
for (int i = 0; i < Exports.Count; i++)
{
string s = $"{i}:";
IExportEntry exp = pcc.getExport(i);
string PackageFullName = exp.PackageFullName;
if (PackageFullName != "Class" && PackageFullName != "Package")
s += PackageFullName + ".";
s += exp.ObjectName;
string ClassName = exp.ClassName;
if (ClassName == "ObjectProperty" || ClassName == "StructProperty")
{
//attempt to find type
byte[] data = exp.Data;
int importindex = BitConverter.ToInt32(data, data.Length - 4);
if (importindex < 0)
{
//import
importindex *= -1;
if (importindex > 0) importindex--;
if (importindex <= imports.Count)
{
s += " (" + imports[importindex].ObjectName + ")";
}
}
else
{
//export
if (importindex > 0) importindex--;
if (importindex <= Exports.Count)
{
s += " [" + Exports[importindex].ObjectName + "]";
}
}
}
exps.Add(s);
}
listBox1.Items.AddRange(exps.ToArray());
}
if (CurrentView == View.Tree)
{
listBox1.Visible = false;
treeView1.Visible = true;
treeView1.Nodes.Clear();
int importsOffset = Exports.Count;
int link;
List<TreeNode> nodeList = new List<TreeNode>(Exports.Count + imports.Count + 1);
TreeNode node = new TreeNode(pcc.FileName);
node.Tag = true;
nodeList.Add(node);
for (int i = 0; i < Exports.Count; i++)
{
node = new TreeNode($"(Exp){i} : {Exports[i].ObjectName}({Exports[i].ClassName})");
node.Name = i.ToString();
nodeList.Add(node);
}
for (int i = 0; i < imports.Count; i++)
{
node = new TreeNode($"(Imp){i} : {imports[i].ObjectName}({imports[i].ClassName})");
node.Name = (-i - 1).ToString();
nodeList.Add(node);
}
int curIndex;
for (int i = 1; i <= Exports.Count; i++)
{
node = nodeList[i];
curIndex = i;
while (node.Tag as bool? != true)
{
node.Tag = true;
curIndex = pcc.getEntry(curIndex).idxLink;
link = curIndex >= 0 ? curIndex : (-curIndex + importsOffset);
nodeList[link].Nodes.Add(node);
node = nodeList[link];
}
}
for (int i = 1; i <= imports.Count; i++)
{
node = nodeList[i + importsOffset];
curIndex = -i;
while (node.Tag as bool? != true)
{
node.Tag = true;
curIndex = pcc.getEntry(curIndex).idxLink;
link = curIndex >= 0 ? curIndex : (-curIndex + importsOffset);
nodeList[link].Nodes.Add(node);
node = nodeList[link];
}
}
treeView1.Nodes.Add(nodeList[0]);
treeView1.Nodes[0].Expand();
}
else
{
treeView1.Visible = false;
listBox1.Visible = true;
}
treeView1.EndUpdate();
listBox1.EndUpdate();
}