public static Game GetGameInfoFromShortcut(string linkPathName) { Game game = new Game(); if (Path.GetExtension(linkPathName) != ".lnk") return game; string gameExecutablePath = WindowsShortcutResolver .ResolveShortcut(linkPathName); FileVersionInfo myFileVersionInfo = FileVersionInfo .GetVersionInfo(gameExecutablePath); string gameTitle = myFileVersionInfo.ProductName; IList<GameSearchResult> results = GamesDB.GetGames(gameTitle) as IList<GameSearchResult>; if (results == null) return game; foreach (var gameSearchResult in results) { if (gameSearchResult.Platform != "PC") continue; game = GamesDB.GetGame(gameSearchResult.ID); return game; } return game; }
/// <summary> /// Gets the data for a specific game. /// </summary> /// <param name="ID">The game ID to return data for</param> /// <returns>A Game-object containing all the data about the game, or null if no game was found</returns> public static Game GetGame(int ID) { XmlDocument doc = new XmlDocument(); doc.Load(@"http://thegamesdb.net/api/GetGame.php?id=" + ID); XmlNode root = doc.DocumentElement; IEnumerator ienum = root.GetEnumerator(); XmlNode platformNode = root.FirstChild.NextSibling; Game game = new Game(); IEnumerator ienumGame = platformNode.GetEnumerator(); XmlNode attributeNode; while (ienumGame.MoveNext()) { attributeNode = (XmlNode)ienumGame.Current; // Iterate through all platform attributes switch (attributeNode.Name) { case "id": int.TryParse(attributeNode.InnerText, out game.ID); break; case "Overview": game.Overview = attributeNode.InnerText; break; case "GameTitle": game.Title = attributeNode.InnerText; break; case "Platform": game.Platform = attributeNode.InnerText; break; case "ReleaseDate": game.ReleaseDate = attributeNode.InnerText; break; case "overview": game.Overview = attributeNode.InnerText; break; case "ESRB": game.ESRB = attributeNode.InnerText; break; case "Players": game.Players = attributeNode.InnerText; break; case "Publisher": game.Publisher = attributeNode.InnerText; break; case "Developer": game.Developer = attributeNode.InnerText; break; case "Rating": //double.TryParse(attributeNode.InnerText, out game.Rating); game.Rating = attributeNode.InnerText; break; case "AlternateTitles": IEnumerator ienumAlternateTitles = attributeNode.GetEnumerator(); while (ienumAlternateTitles.MoveNext()) { game.AlternateTitles.Add(((XmlNode) ienumAlternateTitles.Current).InnerText); } break; case "Genres": IEnumerator ienumGenres = attributeNode.GetEnumerator(); while (ienumGenres.MoveNext()) { game.Genres.Add(((XmlNode) ienumGenres.Current).InnerText); } break; case "Images": game.Images.FromXmlNode(attributeNode); break; } } return game; }