public static AppInfo FromVdfNode(VdfFileNode commonNode) { if (commonNode == null || commonNode.NodeType != ValueType.Array) { return(null); } AppInfo result = null; VdfFileNode idNode = commonNode.GetNodeAt(new string[] { "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 string[] { "name" }, false); if (nameNode != null) { name = nameNode.NodeData.ToString(); } // Get type string typeStr = null; AppTypes type = AppTypes.Unknown; VdfFileNode typeNode = commonNode.GetNodeAt(new string[] { "type" }, false); if (typeNode != null) { typeStr = typeNode.NodeData.ToString(); } if (typeStr != null) { if (!Enum.TryParse <AppTypes>(typeStr, true, out type)) { type = AppTypes.Other; } } // Get platforms string oslist = null; AppPlatforms platforms = AppPlatforms.None; VdfFileNode oslistNode = commonNode.GetNodeAt(new string[] { "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 string[] { "parent" }, false); if (parentNode != null) { result.Parent = parentNode.NodeInt; } } return(result); }
public static AppInfo FromVdfNode( VdfFileNode commonNode ) { if( commonNode == null || commonNode.NodeType != ValueType.Array ) return null; AppInfo result = null; VdfFileNode idNode = commonNode.GetNodeAt( new string[] { "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 string[] { "name" }, false ); if( nameNode != null ) name = nameNode.NodeData.ToString(); // Get type string typeStr = null; AppTypes type = AppTypes.Unknown; VdfFileNode typeNode = commonNode.GetNodeAt( new string[] { "type" }, false ); if( typeNode != null ) typeStr = typeNode.NodeData.ToString(); if( typeStr != null ) { if( !Enum.TryParse<AppTypes>( typeStr, true, out type ) ) { type = AppTypes.Other; } } // Get platforms string oslist = null; AppPlatforms platforms = AppPlatforms.None; VdfFileNode oslistNode = commonNode.GetNodeAt( new string[] { "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 string[] { "parent" }, false ); if( parentNode != null ) { result.Parent = parentNode.NodeInt; } } return result; }