public static AutoCatGenre LoadFromXmlElement(XmlElement xElement) { string name = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString); string filter = XmlUtil.GetStringFromNode(xElement[XmlName_Filter], null); int maxCats = XmlUtil.GetIntFromNode(xElement[XmlName_MaxCats], 0); bool remOther = XmlUtil.GetBoolFromNode(xElement[XmlName_RemOther], false); bool tagFallback = XmlUtil.GetBoolFromNode(xElement[XmlName_TagFallback], true); string prefix = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], null); List <string> ignore = new List <string>(); XmlElement ignoreListElement = xElement[XmlName_IgnoreList]; if (ignoreListElement != null) { XmlNodeList ignoreNodes = ignoreListElement.SelectNodes(XmlName_IgnoreItem); foreach (XmlNode node in ignoreNodes) { if (XmlUtil.TryGetStringFromNode(node, out string s)) { ignore.Add(s); } } } AutoCatGenre result = new AutoCatGenre(name, filter, prefix, maxCats, remOther, tagFallback, ignore); return(result); }
public static AutoCatUserScore LoadFromXmlElement(XmlElement xElement) { string name = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString); string filter = XmlUtil.GetStringFromNode(xElement[XmlName_Filter], null); string prefix = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], string.Empty); bool useWilsonScore = XmlUtil.GetBoolFromNode(xElement[XmlName_UseWilsonScore], false); List <UserScore_Rule> rules = new List <UserScore_Rule>(); foreach (XmlNode node in xElement.SelectNodes(XmlName_Rule)) { string ruleName = XmlUtil.GetStringFromNode(node[XmlName_Rule_Text], string.Empty); int ruleMin = XmlUtil.GetIntFromNode(node[XmlName_Rule_MinScore], 0); int ruleMax = XmlUtil.GetIntFromNode(node[XmlName_Rule_MaxScore], 100); int ruleMinRev = XmlUtil.GetIntFromNode(node[XmlName_Rule_MinReviews], 0); int ruleMaxRev = XmlUtil.GetIntFromNode(node[XmlName_Rule_MaxReviews], 0); rules.Add(new UserScore_Rule(ruleName, ruleMin, ruleMax, ruleMinRev, ruleMaxRev)); } AutoCatUserScore result = new AutoCatUserScore(name, filter, prefix, useWilsonScore) { Rules = rules }; return(result); }
private static void AddGameFromXmlNode(XmlNode node, Profile profile, int profileVersion) { int id; if (XmlUtil.TryGetIntFromNode(node[XmlName_Game_Id], out id)) { GameListingSource source = XmlUtil.GetEnumFromNode(node[XmlName_Game_Source], GameListingSource.Unknown); if ((source < GameListingSource.Manual) && profile.IgnoreList.Contains(id)) { return; } string name = XmlUtil.GetStringFromNode(node[XmlName_Game_Name], null); GameInfo game = new GameInfo(id, name, profile.GameData); game.Source = source; profile.GameData.Games.Add(id, game); game.Hidden = XmlUtil.GetBoolFromNode(node[XmlName_Game_Hidden], false); game.Executable = XmlUtil.GetStringFromNode(node[XmlName_Game_Executable], null); game.LastPlayed = XmlUtil.GetIntFromNode(node[XmlName_Game_LastPlayed], 0); if (profileVersion < 1) { string catName; if (XmlUtil.TryGetStringFromNode(node[XmlName_Game_Category], out catName)) { game.AddCategory(profile.GameData.GetCategory(catName)); } if (node.SelectSingleNode(XmlName_Old_Game_Favorite) != null) { game.SetFavorite(true); } } else { XmlNode catListNode = node.SelectSingleNode(XmlName_Game_CategoryList); if (catListNode != null) { XmlNodeList catNodes = catListNode.SelectNodes(XmlName_Game_Category); foreach (XmlNode cNode in catNodes) { string cat; if (XmlUtil.TryGetStringFromNode(cNode, out cat)) { game.AddCategory(profile.GameData.GetCategory(cat)); } } } } } }
public void Load(string path, bool compress) { Logger.Info(GlobalStrings.GameDB_LoadingGameDBFrom, path); XmlDocument doc = new XmlDocument(); Stream stream = null; try { stream = new FileStream(path, FileMode.Open); if (compress) { stream = new GZipStream(stream, CompressionMode.Decompress); } doc.Load(stream); Logger.Info(GlobalStrings.GameDB_GameDBXMLParsed); Games.Clear(); ClearAggregates(); XmlNode gameListNode = doc.SelectSingleNode("/" + XmlName_RootNode); int fileVersion = XmlUtil.GetIntFromNode(gameListNode[XmlName_Version], 0); LastHltbUpdate = XmlUtil.GetIntFromNode(gameListNode[XmlName_LastHltbUpdate], 0); dbLanguage = (StoreLanguage)Enum.Parse(typeof(StoreLanguage), XmlUtil.GetStringFromNode(gameListNode[XmlName_dbLanguage], "en"), true); if (fileVersion == 1) { LoadGamelistVersion1(gameListNode); } else { XmlSerializer x = new XmlSerializer(typeof(DatabaseEntry)); foreach (XmlNode gameNode in gameListNode.SelectSingleNode(XmlName_Games).ChildNodes) { XmlReader reader = new XmlNodeReader(gameNode); DatabaseEntry entry = (DatabaseEntry)x.Deserialize(reader); Games.Add(entry.Id, entry); } } Logger.Info("GameDB XML processed, load complete. Db Language: " + dbLanguage); } finally { stream?.Close(); } }
public static AutoCatDevPub LoadFromXmlElement(XmlElement xElement) { string name = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString); string filter = XmlUtil.GetStringFromNode(xElement[XmlName_Filter], null); bool AllDevelopers = XmlUtil.GetBoolFromNode(xElement[XmlName_AllDevelopers], false); bool AllPublishers = XmlUtil.GetBoolFromNode(xElement[XmlName_AllPublishers], false); string prefix = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], null); bool owned = XmlUtil.GetBoolFromNode(xElement[XmlName_OwnedOnly], false); int count = XmlUtil.GetIntFromNode(xElement[XmlName_MinCount], 0); List <string> devs = new List <string>(); XmlElement devsListElement = xElement[XmlName_Developers]; if (devsListElement != null) { XmlNodeList devNodes = devsListElement.SelectNodes(XmlName_Developer); foreach (XmlNode node in devNodes) { string s; if (XmlUtil.TryGetStringFromNode(node, out s)) { devs.Add(s); } } } List <string> pubs = new List <string>(); XmlElement pubsListElement = xElement[XmlName_Publishers]; if (pubsListElement != null) { XmlNodeList pubNodes = pubsListElement.SelectNodes(XmlName_Publisher); foreach (XmlNode node in pubNodes) { string s; if (XmlUtil.TryGetStringFromNode(node, out s)) { pubs.Add(s); } } } AutoCatDevPub result = new AutoCatDevPub(name, filter, prefix, owned, count, AllDevelopers, AllPublishers, devs, pubs); return(result); }
private static void AddGameFromNode(XmlNode node, Profile profile) { if (!XmlUtil.TryGetIntFromNode(node[XmlNameGameId], out int id)) { return; } GameListingSource source = XmlUtil.GetEnumFromNode(node[XmlNameGameSource], GameListingSource.Unknown); if (source < GameListingSource.Manual && profile.IgnoreList.Contains(id)) { return; } string name = XmlUtil.GetStringFromNode(node[XmlNameGameName], null); GameInfo game = new GameInfo(id, name, profile.GameData) { Source = source }; profile.GameData.Games.Add(id, game); game.IsHidden = XmlUtil.GetBoolFromNode(node[XmlNameGameHidden], false); game.Executable = XmlUtil.GetStringFromNode(node[XmlNameGameExecutable], null); game.LastPlayed = XmlUtil.GetIntFromNode(node[XmlNameGameLastPlayed], 0); game.HoursPlayed = XmlUtil.GetDoubleFromNode(node[XmlNameGameHoursPlayed], 0); XmlNode catListNode = node.SelectSingleNode(XmlNameGameCategoryList); XmlNodeList catNodes = catListNode?.SelectNodes(XmlNameGameCategory); if (catNodes == null) { return; } foreach (XmlNode cNode in catNodes) { if (XmlUtil.TryGetStringFromNode(cNode, out string cat)) { game.AddCategory(profile.GameData.GetCategory(cat)); } } }
public void Load(string path, bool compress) { Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameDB_LoadingGameDBFrom, path); XmlDocument doc = new XmlDocument(); Stream stream = null; try { stream = new FileStream(path, FileMode.Open); if (compress) { stream = new GZipStream(stream, CompressionMode.Decompress); } doc.Load(stream); Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameDB_GameDBXMLParsed); Games.Clear(); ClearAggregates(); XmlNode gameListNode = doc.SelectSingleNode("/" + XmlName_GameList); int fileVersion = XmlUtil.GetIntFromNode(gameListNode[XmlName_Version], 0); foreach (XmlNode gameNode in gameListNode.SelectNodes(XmlName_Game)) { int id; if (!XmlUtil.TryGetIntFromNode(gameNode[XmlName_Game_Id], out id) || Games.ContainsKey(id)) { continue; } GameDBEntry g = new GameDBEntry(); g.Id = id; g.Name = XmlUtil.GetStringFromNode(gameNode[XmlName_Game_Name], null); if (fileVersion < 1) { g.AppType = AppTypes.Unknown; string typeString; if (XmlUtil.TryGetStringFromNode(gameNode[XmlName_Game_Type], out typeString)) { if (typeString == "DLC") { g.AppType = AppTypes.DLC; } else if (typeString == "Game") { g.AppType = AppTypes.Game; } else if (typeString == "NonApp") { g.AppType = AppTypes.Other; } } } else { g.AppType = XmlUtil.GetEnumFromNode <AppTypes>(gameNode[XmlName_Game_Type], AppTypes.Unknown); } g.Platforms = XmlUtil.GetEnumFromNode <AppPlatforms>(gameNode[XmlName_Game_Platforms], AppPlatforms.All); g.ParentId = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_Parent], -1); if (fileVersion < 1) { List <string> genreList = new List <string>(); string genreString = XmlUtil.GetStringFromNode(gameNode["genre"], null); if (genreString != null) { string[] genStrList = genreString.Split(','); foreach (string s in genStrList) { genreList.Add(s.Trim()); } } g.Genres = genreList; } else { g.Genres = XmlUtil.GetStringsFromNodeList(gameNode.SelectNodes(XmlName_Game_Genre)); } g.Tags = XmlUtil.GetStringsFromNodeList(gameNode.SelectNodes(XmlName_Game_Tag)); g.Developers = XmlUtil.GetStringsFromNodeList(gameNode.SelectNodes(XmlName_Game_Developer)); if (fileVersion < 1) { List <string> pubList = new List <string>(); string pubString = XmlUtil.GetStringFromNode(gameNode["publisher"], null); if (pubString != null) { string[] pubStrList = pubString.Split(','); foreach (string s in pubStrList) { pubList.Add(s.Trim()); } } g.Publishers = pubList; } else { g.Publishers = XmlUtil.GetStringsFromNodeList(gameNode.SelectNodes(XmlName_Game_Publisher)); } if (fileVersion < 1) { int steamDate = XmlUtil.GetIntFromNode(gameNode["steamDate"], 0); if (steamDate > 0) { g.SteamReleaseDate = DateTime.FromOADate(steamDate).ToString("MMM d, yyyy"); } else { g.SteamReleaseDate = null; } } else { g.SteamReleaseDate = XmlUtil.GetStringFromNode(gameNode[XmlName_Game_Date], null); } g.Flags = XmlUtil.GetStringsFromNodeList(gameNode.SelectNodes(XmlName_Game_Flag)); g.ReviewTotal = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_ReviewTotal], 0); g.ReviewPositivePercentage = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_ReviewPositivePercent], 0); g.MC_Url = XmlUtil.GetStringFromNode(gameNode[XmlName_Game_MCUrl], null); g.LastAppInfoUpdate = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_LastAppInfoUpdate], 0); g.LastStoreScrape = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_LastStoreUpdate], 0); Games.Add(id, g); } Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameDB_GameDBXMLProcessed); } catch (Exception e) { throw e; } finally { if (stream != null) { stream.Close(); } } }
/// <summary> /// Reads GameDbEntry objects from selected node and adds them to GameDb /// Legacy method used to read data from version 1 of the database. /// </summary> /// <param name="gameListNode">Node containing GameDbEntry objects with game as element name</param> private void LoadGamelistVersion1(XmlNode gameListNode) { const string XmlName_Game = "game", XmlName_Game_Id = "id", XmlName_Game_Name = "name", XmlName_Game_LastStoreUpdate = "lastStoreUpdate", XmlName_Game_LastAppInfoUpdate = "lastAppInfoUpdate", XmlName_Game_Type = "type", XmlName_Game_Platforms = "platforms", XmlName_Game_Parent = "parent", XmlName_Game_Genre = "genre", XmlName_Game_Tag = "tag", XmlName_Game_Achievements = "achievements", XmlName_Game_Developer = "developer", XmlName_Game_Publisher = "publisher", XmlName_Game_Flag = "flag", XmlName_Game_ReviewTotal = "reviewTotal", XmlName_Game_ReviewPositivePercent = "reviewPositiveP", XmlName_Game_MCUrl = "mcUrl", XmlName_Game_Date = "steamDate", XmlName_Game_HltbMain = "hltbMain", XmlName_Game_HltbExtras = "hltbExtras", XmlName_Game_HltbCompletionist = "hltbCompletionist", XmlName_Game_vrSupport = "vrSupport", XmlName_Game_vrSupport_Headsets = "Headset", XmlName_Game_vrSupport_Input = "Input", XmlName_Game_vrSupport_PlayArea = "PlayArea", XmlName_Game_languageSupport = "languageSupport", XmlName_Game_languageSupport_Interface = "Headset", XmlName_Game_languageSupport_FullAudio = "Input", XmlName_Game_languageSupport_Subtitles = "PlayArea"; foreach (XmlNode gameNode in gameListNode.SelectNodes(XmlName_Game)) { int id; if (!XmlUtil.TryGetIntFromNode(gameNode[XmlName_Game_Id], out id) || Games.ContainsKey(id)) { continue; } DatabaseEntry g = new DatabaseEntry(); g.Id = id; g.Name = XmlUtil.GetStringFromNode(gameNode[XmlName_Game_Name], null); g.AppType = XmlUtil.GetEnumFromNode(gameNode[XmlName_Game_Type], AppTypes.Unknown); g.Platforms = XmlUtil.GetEnumFromNode(gameNode[XmlName_Game_Platforms], AppPlatforms.All); g.ParentId = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_Parent], -1); g.Genres = XmlUtil.GetStringsFromNodeList(gameNode.SelectNodes(XmlName_Game_Genre)); g.Tags = XmlUtil.GetStringsFromNodeList(gameNode.SelectNodes(XmlName_Game_Tag)); foreach (XmlNode vrNode in gameNode.SelectNodes(XmlName_Game_vrSupport)) { g.VrSupport.Headsets = XmlUtil.GetStringsFromNodeList(vrNode.SelectNodes(XmlName_Game_vrSupport_Headsets)); g.VrSupport.Input = XmlUtil.GetStringsFromNodeList(vrNode.SelectNodes(XmlName_Game_vrSupport_Input)); g.VrSupport.PlayArea = XmlUtil.GetStringsFromNodeList(vrNode.SelectNodes(XmlName_Game_vrSupport_PlayArea)); } foreach (XmlNode langNode in gameNode.SelectNodes(XmlName_Game_languageSupport)) { g.LanguageSupport.Interface = XmlUtil.GetStringsFromNodeList(langNode.SelectNodes(XmlName_Game_languageSupport_Interface)); g.LanguageSupport.FullAudio = XmlUtil.GetStringsFromNodeList(langNode.SelectNodes(XmlName_Game_languageSupport_FullAudio)); g.LanguageSupport.Subtitles = XmlUtil.GetStringsFromNodeList(langNode.SelectNodes(XmlName_Game_languageSupport_Subtitles)); } g.Developers = XmlUtil.GetStringsFromNodeList(gameNode.SelectNodes(XmlName_Game_Developer)); g.Publishers = XmlUtil.GetStringsFromNodeList(gameNode.SelectNodes(XmlName_Game_Publisher)); g.SteamReleaseDate = XmlUtil.GetStringFromNode(gameNode[XmlName_Game_Date], null); g.Flags = XmlUtil.GetStringsFromNodeList(gameNode.SelectNodes(XmlName_Game_Flag)); g.TotalAchievements = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_Achievements], 0); g.ReviewTotal = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_ReviewTotal], 0); g.ReviewPositivePercentage = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_ReviewPositivePercent], 0); g.MetacriticUrl = XmlUtil.GetStringFromNode(gameNode[XmlName_Game_MCUrl], null); g.LastAppInfoUpdate = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_LastAppInfoUpdate], 0); g.LastStoreScrape = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_LastStoreUpdate], 0); g.HltbMain = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_HltbMain], 0); g.HltbExtras = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_HltbExtras], 0); g.HltbCompletionist = XmlUtil.GetIntFromNode(gameNode[XmlName_Game_HltbCompletionist], 0); Games.Add(id, g); } }
private void Load(string path) { lock (Games) { if (!File.Exists(path)) { return; } Logger.Instance.Info("Database: Loading a database instance from '{0}'", path); XmlDocument document = new XmlDocument(); Stream stream = null; try { stream = new FileStream(path, FileMode.Open); stream = new GZipStream(stream, CompressionMode.Decompress); document.Load(stream); } catch (Exception e) { Logger.Instance.Error("Database: Error while reading database file from '{0}'", path); SentryLogger.Log(e); throw; } finally { if (stream != null) { stream.Dispose(); } } try { Games.Clear(); XmlNode gameListNode = document.SelectSingleNode("/" + XmlName_RootNode); if (gameListNode == null) { throw new InvalidDataException(); } Language = (StoreLanguage)Enum.Parse(typeof(StoreLanguage), XmlUtil.GetStringFromNode(gameListNode[XmlName_dbLanguage], "english"), true); LastHLTBUpdate = XmlUtil.GetIntFromNode(gameListNode[XmlName_LastHltbUpdate], 0); XmlNode dictonaryNode = gameListNode.SelectSingleNode(XmlName_Games); if (dictonaryNode == null) { throw new InvalidDataException(); } XmlSerializer xmlSerializer = new XmlSerializer(typeof(DatabaseEntry)); foreach (XmlNode appNode in dictonaryNode.ChildNodes) { using (XmlReader reader = new XmlNodeReader(appNode)) { DatabaseEntry entry = (DatabaseEntry)xmlSerializer.Deserialize(reader); AddOrUpdate(entry); } } } catch (Exception e) { Logger.Instance.Error("Database: Error while parsing database file from '{0}'", path); SentryLogger.Log(e); throw; } Logger.Instance.Info("Database: Loaded current instance from '{0}'", path); } }
public void Load(string path, bool compress) { Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameDB_LoadingGameDBFrom, path); XmlDocument doc = new XmlDocument(); Stream stream = null; try { stream = new FileStream(path, FileMode.Open); if (compress) { stream = new GZipStream(stream, CompressionMode.Decompress); } doc.Load(stream); Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameDB_GameDBXMLParsed); Games.Clear(); foreach (XmlNode gameNode in doc.SelectNodes("/gamelist/game")) { int id; if (!XmlUtil.TryGetIntFromNode(gameNode["id"], out id) || Games.ContainsKey(id)) { continue; } GameDBEntry g = new GameDBEntry(); g.Id = id; XmlUtil.TryGetStringFromNode(gameNode["name"], out g.Name); string typeString; if (!XmlUtil.TryGetStringFromNode(gameNode["type"], out typeString) || !Enum.TryParse <AppType>(typeString, out g.Type)) { g.Type = AppType.New; } g.Genre = XmlUtil.GetStringFromNode(gameNode["genre"], null); g.Developer = XmlUtil.GetStringFromNode(gameNode["developer"], null); g.Publisher = XmlUtil.GetStringFromNode(gameNode["publisher"], null); int steamDate = XmlUtil.GetIntFromNode(gameNode["steamDate"], 0); if (steamDate > 0) { g.SteamRelease = DateTime.FromOADate(steamDate); } foreach (XmlNode n in gameNode.SelectNodes("flag")) { string fName = XmlUtil.GetStringFromNode(n, null); if (!string.IsNullOrEmpty(fName)) { g.Flags.Add(fName); } } g.MC_Url = XmlUtil.GetStringFromNode(gameNode["mcUrl"], null); // TODO: Load MC extras Games.Add(id, g); } Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameDB_GameDBXMLProcessed); } catch (Exception e) { throw e; } finally { if (stream != null) { stream.Close(); } } }