コード例 #1
0
        public static PackageInfo FromNode(VDFNode node)
        {
            VDFNode idNode = node.GetNodeAt(new[]
            {
                "packageId"
            }, false);

            if ((idNode == null) || (idNode.NodeType != ValueType.Int))
            {
                return(null);
            }

            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 packageInfo = new PackageInfo(id, name);

            VDFNode billingTypeNode = node["billingtype"];

            if ((billingTypeNode != null) && ((billingTypeNode.NodeType == ValueType.String) || (billingTypeNode.NodeType == ValueType.Int)))
            {
                int bType = billingTypeNode.NodeInt;
                packageInfo.BillingType = (PackageBillingType)bType;
            }

            VDFNode appsNode = node["appids"];

            if ((appsNode == null) || (appsNode.NodeType != ValueType.Array))
            {
                return(packageInfo);
            }

            foreach (VDFNode appNode in appsNode.NodeArray.Values)
            {
                if (appNode.NodeType == ValueType.Int)
                {
                    packageInfo.AppIds.Add(appNode.NodeInt);
                }
            }

            return(packageInfo);
        }
コード例 #2
0
ファイル: VDFNode.cs プロジェクト: noisephoenix/Depressurizer
        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));
        }