public static AppInfo FromNode(AppInfoNode node) { if (node == null) { return(null); } if (!node.Items.ContainsKey("appinfo") || !node["appinfo"].Items.ContainsKey("common") || !node["appinfo"]["common"].Items.ContainsKey("gameid")) { return(null); } AppInfoNode dataNode = node["appinfo"]["common"]; string gameIdNode = dataNode["gameid"].Value; if (!int.TryParse(gameIdNode, out int appId)) { return(null); } AppInfo appInfo = new AppInfo(appId); if (dataNode.Items.ContainsKey("name")) { appInfo.Name = dataNode["name"].Value; } if (dataNode.Items.ContainsKey("type")) { string typeData = dataNode["type"].Value; if (Enum.TryParse(typeData, true, out AppType type)) { appInfo.AppType = type; } else { Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "AppInfo: New AppType '{0}'", typeData)); } } if (dataNode.Items.ContainsKey("oslist")) { string osList = dataNode["oslist"].Value; if (osList.IndexOf("windows", StringComparison.OrdinalIgnoreCase) != -1) { appInfo.Platforms |= AppPlatforms.Windows; } if (osList.IndexOf("mac", StringComparison.OrdinalIgnoreCase) != -1) { appInfo.Platforms |= AppPlatforms.Mac; } if (osList.IndexOf("linux", StringComparison.OrdinalIgnoreCase) != -1) { appInfo.Platforms |= AppPlatforms.Linux; } } if (!dataNode.Items.ContainsKey("parent")) { return(appInfo); } string parentNode = dataNode["parent"].Value; if (int.TryParse(parentNode, out int parentId)) { appInfo.Parent = parentId; } return(appInfo); }
public static AppInfo FromVdfNode(VdfFileNode commonNode) { if ((commonNode == null) || (commonNode.NodeType != ValueType.Array)) { return(null); } AppInfo result = null; VdfFileNode idNode = commonNode.GetNodeAt(new[] { "gameid" }, false); int id = -1; if (idNode != null) { if (idNode.NodeType == ValueType.Int) { id = idNode.NodeInt; } else if (idNode.NodeType == ValueType.String) { if (!int.TryParse(idNode.NodeString, out id)) { id = -1; } } } if (id >= 0) { // Get name string name = null; VdfFileNode nameNode = commonNode.GetNodeAt(new[] { "name" }, false); if (nameNode != null) { name = nameNode.NodeData.ToString(); } // Get type string typeStr = null; AppTypes type = AppTypes.Unknown; VdfFileNode typeNode = commonNode.GetNodeAt(new[] { "type" }, false); if (typeNode != null) { typeStr = typeNode.NodeData.ToString(); } if (typeStr != null) { if (!Enum.TryParse(typeStr, true, out type)) { type = AppTypes.Other; } } // Get platforms string oslist = null; AppPlatforms platforms = AppPlatforms.None; VdfFileNode oslistNode = commonNode.GetNodeAt(new[] { "oslist" }, false); if (oslistNode != null) { oslist = oslistNode.NodeData.ToString(); if (oslist.IndexOf("windows", StringComparison.OrdinalIgnoreCase) != -1) { platforms |= AppPlatforms.Windows; } if (oslist.IndexOf("mac", StringComparison.OrdinalIgnoreCase) != -1) { platforms |= AppPlatforms.Mac; } if (oslist.IndexOf("linux", StringComparison.OrdinalIgnoreCase) != -1) { platforms |= AppPlatforms.Linux; } } result = new AppInfo(id, name, type, platforms); // Get parent VdfFileNode parentNode = commonNode.GetNodeAt(new[] { "parent" }, false); if (parentNode != null) { result.Parent = parentNode.NodeInt; } } return(result); }