public static PackageInfo FromNode(VDFNode node) { VDFNode idNode = node.GetNodeAt(new[] { "packageId" }, false); if ((idNode != null) && (idNode.NodeType == ValueType.Int)) { int id = idNode.NodeInt; string name = null; VDFNode nameNode = node.GetNodeAt(new[] { "name" }, false); if ((nameNode != null) && (nameNode.NodeType == ValueType.String)) { name = nameNode.NodeString; } PackageInfo package = new PackageInfo(id, name); VDFNode billingtypeNode = node["billingtype"]; if (((billingtypeNode != null) && (billingtypeNode.NodeType == ValueType.String)) || (billingtypeNode.NodeType == ValueType.Int)) { int bType = billingtypeNode.NodeInt; package.BillingType = (PackageBillingType)bType; } VDFNode appsNode = node["appids"]; if ((appsNode != null) && (appsNode.NodeType == ValueType.Array)) { foreach (VDFNode aNode in appsNode.NodeArray.Values) { if (aNode.NodeType == ValueType.Int) { package.AppIds.Add(aNode.NodeInt); } } } return(package); } return(null); }
public VDFNode GetNodeAt(string[] args, bool create, int index) { if (index >= args.Length) { return(this); } if (NodeType != ValueType.Array) { return(null); } if (!(NodeData is Dictionary <string, VDFNode> arrayData)) { throw new InvalidCastException("NodeData is not a Dictionary<string, VDFNode>"); } if (ContainsKey(args[index])) { return(arrayData[args[index]].GetNodeAt(args, create, index + 1)); } if (!create) { return(null); } VDFNode newNode = new VDFNode(); arrayData.Add(args[index], newNode); return(newNode.GetNodeAt(args, true, index + 1)); }