public static AutoCatHltb 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 includeUnknown = XmlUtil.GetBoolFromNode(xElement[XmlName_IncludeUnknown], false); string unknownText = XmlUtil.GetStringFromNode(xElement[XmlName_UnknownText], string.Empty); XmlNodeList rulesNodeList = xElement.SelectNodes(XmlName_Rule); List <HowLongToBeatRule> rules = new List <HowLongToBeatRule>(); if (rulesNodeList != null) { foreach (XmlNode node in rulesNodeList) { string ruleName = XmlUtil.GetStringFromNode(node[XmlName_Rule_Text], string.Empty); float ruleMin = XmlUtil.GetFloatFromNode(node[XmlName_Rule_MinHours], 0); float ruleMax = XmlUtil.GetFloatFromNode(node[XmlName_Rule_MaxHours], 0); string type = XmlUtil.GetStringFromNode(node[XmlName_Rule_TimeType], string.Empty); TimeType ruleTimeType; switch (type) { case "Extras": ruleTimeType = TimeType.Extras; break; case "Completionist": ruleTimeType = TimeType.Completionist; break; default: ruleTimeType = TimeType.Main; break; } rules.Add(new HowLongToBeatRule(ruleName, ruleMin, ruleMax, ruleTimeType)); } } AutoCatHltb result = new AutoCatHltb(name, filter, prefix, includeUnknown, unknownText) { Rules = rules }; return(result); }
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) { if (XmlUtil.TryGetStringFromNode(node, out string 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) { if (XmlUtil.TryGetStringFromNode(node, out string s)) { pubs.Add(s); } } } AutoCatDevPub result = new AutoCatDevPub(name, filter, prefix, owned, count, AllDevelopers, AllPublishers, devs, pubs); return(result); }
public int IntegrateAppList(XmlDocument document) { int added = 0; lock (Games) { XmlNodeList appNodes = document.SelectNodes("/applist/apps/app"); if (appNodes == null) { return(added); } foreach (XmlNode node in appNodes) { if (!XmlUtil.TryGetIntFromNode(node["appid"], out int appId)) { continue; } string appName = XmlUtil.GetStringFromNode(node["name"], null); if (Contains(appId)) { DatabaseEntry entry = Games[appId]; if (!string.IsNullOrWhiteSpace(entry.Name) && (entry.Name == appName)) { continue; } entry.Name = appName; entry.AppType = AppType.Unknown; } else { DatabaseEntry entry = new DatabaseEntry(appId, appName); AddOrUpdate(entry); added++; } } Logger.Instance.Info("Loaded {0} new items from the app list.", added); } return(added); }
public static AutoCatManual LoadFromXmlElement(XmlElement xElement) { string name = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString); string filter = XmlUtil.GetStringFromNode(xElement[XmlName_Filter], null); bool removeAll = XmlUtil.GetBoolFromNode(xElement[XmlName_RemoveAll], false); string prefix = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], null); List <string> remove = new List <string>(); XmlElement removeListElement = xElement[XmlName_RemoveList]; if (removeListElement != null) { XmlNodeList removeNodes = removeListElement.SelectNodes(XmlName_RemoveItem); foreach (XmlNode node in removeNodes) { string s; if (XmlUtil.TryGetStringFromNode(node, out s)) { remove.Add(s); } } } List <string> add = new List <string>(); XmlElement addListElement = xElement[XmlName_AddList]; if (addListElement != null) { XmlNodeList addNodes = addListElement.SelectNodes(XmlName_AddItem); foreach (XmlNode node in addNodes) { string s; if (XmlUtil.TryGetStringFromNode(node, out s)) { add.Add(s); } } } AutoCatManual result = new AutoCatManual(name, filter, prefix, removeAll, remove, add); return(result); }
public static AutoCatTags LoadFromXmlElement(XmlElement xElement) { string name = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString); AutoCatTags result = new AutoCatTags(name); result.Filter = XmlUtil.GetStringFromNode(xElement[XmlName_Filter], null); string prefix; if (XmlUtil.TryGetStringFromNode(xElement[XmlName_Prefix], out prefix)) result.Prefix = prefix; int maxTags; if (XmlUtil.TryGetIntFromNode(xElement[XmlName_MaxTags], out maxTags)) result.MaxTags = maxTags; bool listOwnedOnly; if (XmlUtil.TryGetBoolFromNode(xElement[XmlName_ListOwnedOnly], out listOwnedOnly)) result.ListOwnedOnly = listOwnedOnly; float listWeightFactor; if (XmlUtil.TryGetFloatFromNode(xElement[XmlName_ListWeightFactor], out listWeightFactor)) result.ListWeightFactor = listWeightFactor; int listMinScore; if (XmlUtil.TryGetIntFromNode(xElement[XmlName_ListMinScore], out listMinScore)) result.ListMinScore = listMinScore; int listTagsPerGame; if (XmlUtil.TryGetIntFromNode(xElement[XmlName_ListTagsPerGame], out listTagsPerGame)) result.ListTagsPerGame = listTagsPerGame; bool listScoreSort; if (XmlUtil.TryGetBoolFromNode(xElement[XmlName_ListScoreSort], out listScoreSort)) result.ListScoreSort = listScoreSort; bool listExcludeGenres; if (XmlUtil.TryGetBoolFromNode(xElement[XmlName_ListExcludeGenres], out listExcludeGenres)) result.ListExcludeGenres = listExcludeGenres; List<string> tagList = XmlUtil.GetStringsFromNodeList(xElement.SelectNodes(XmlName_TagList + "/" + XmlName_Tag)); result.IncludedTags = (tagList == null) ? new HashSet<string>() : new HashSet<string>(tagList); 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 static AutoCatUserScore LoadFromXmlElement(XmlElement xElement) { string name = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString); string prefix = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], string.Empty); 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, prefix); result.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<GameListingSource>( 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 = Convert.ToDateTime(XmlUtil.GetStringFromNode(node[XmlName_Game_LastPlayed], null)); 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 static AutoCatFlags LoadFromXmlElement(XmlElement xElement) { string name = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString); string prefix = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], null); List <string> flags = new List <string>(); XmlElement flagListElement = xElement[XmlName_FlagList]; if (flagListElement != null) { XmlNodeList flagElements = flagListElement.SelectNodes(XmlName_Flag); foreach (XmlNode n in flagElements) { string flag; if (XmlUtil.TryGetStringFromNode(n, out flag)) { flags.Add(flag); } } } return(new AutoCatFlags(name, prefix, flags)); }
private static void AddGameFromXmlNode(XmlNode node, Profile profile) { int id; if (XmlUtil.TryGetIntFromNode(node["id"], out id)) { if (profile.IgnoreList.Contains(id) || (profile.IgnoreDlc && Program.GameDB.IsDlc(id))) { return; } string name = XmlUtil.GetStringFromNode(node["name"], null); Game game = new Game(id, name); profile.GameData.Games.Add(id, game); string catName; if (XmlUtil.TryGetStringFromNode(node["category"], out catName)) { game.Category = profile.GameData.GetCategory(catName); } game.Favorite = (node.SelectSingleNode("favorite") != null); } }
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(); } } }
public static Profile Load(string path) { Logger.Info(GlobalStrings.Profile_LoadingProfile, path); Profile profile = new Profile(); profile.FilePath = path; XmlDocument doc = new XmlDocument(); try { doc.Load(path); } catch (Exception e) { Logger.Warn(GlobalStrings.Profile_FailedToLoadProfile, e.Message); throw new ApplicationException(GlobalStrings.Profile_ErrorLoadingProfile + e.Message, e); } XmlNode profileNode = doc.SelectSingleNode("/" + XmlName_Profile); if (profileNode != null) { // Get the profile version that we're loading XmlAttribute versionAttr = profileNode.Attributes[XmlName_Version]; int profileVersion = 0; if (versionAttr != null) { if (!int.TryParse(versionAttr.Value, out profileVersion)) { profileVersion = 0; } } // Get the 64-bit Steam ID long accId = XmlUtil.GetInt64FromNode(profileNode[XmlName_SteamID], 0); if (accId == 0) { string oldAcc = XmlUtil.GetStringFromNode(profileNode[XmlName_Old_SteamIDShort], null); if (oldAcc != null) { accId = DirNametoID64(oldAcc); } } profile.SteamID64 = accId; // Get other attributes profile.AutoUpdate = XmlUtil.GetBoolFromNode(profileVersion < 3 ? profileNode[XmlName_Old_AutoDownload] : profileNode[XmlName_AutoUpdate], profile.AutoUpdate); profile.AutoImport = XmlUtil.GetBoolFromNode(profileNode[XmlName_AutoImport], profile.AutoImport); profile.AutoExport = XmlUtil.GetBoolFromNode(profileNode[XmlName_AutoExport], profile.AutoExport); profile.LocalUpdate = XmlUtil.GetBoolFromNode(profileNode[XmlName_LocalUpdate], profile.LocalUpdate); profile.WebUpdate = XmlUtil.GetBoolFromNode(profileNode[XmlName_WebUpdate], profile.WebUpdate); profile.IncludeUnknown = XmlUtil.GetBoolFromNode(profileNode[XmlName_IncludeUnknown], profile.IncludeUnknown); profile.BypassIgnoreOnImport = XmlUtil.GetBoolFromNode(profileNode[XmlName_BypassIgnoreOnImport], profile.BypassIgnoreOnImport); profile.ExportDiscard = XmlUtil.GetBoolFromNode(profileNode[XmlName_ExportDiscard], profile.ExportDiscard); profile.AutoIgnore = XmlUtil.GetBoolFromNode(profileNode[XmlName_AutoIgnore], profile.AutoIgnore); profile.OverwriteOnDownload = XmlUtil.GetBoolFromNode(profileNode[XmlName_OverwriteNames], profile.OverwriteOnDownload); if (profileVersion < 2) { bool ignoreShortcuts = false; if (XmlUtil.TryGetBoolFromNode(profileNode[XmlName_Old_IgnoreExternal], out ignoreShortcuts)) { profile.IncludeShortcuts = !ignoreShortcuts; } } else { profile.IncludeShortcuts = XmlUtil.GetBoolFromNode(profileNode[XmlName_IncludeShortcuts], profile.IncludeShortcuts); } XmlNode exclusionListNode = profileNode.SelectSingleNode(XmlName_ExclusionList); if (exclusionListNode != null) { XmlNodeList exclusionNodes = exclusionListNode.SelectNodes(XmlName_Exclusion); foreach (XmlNode node in exclusionNodes) { int id; if (XmlUtil.TryGetIntFromNode(node, out id)) { profile.IgnoreList.Add(id); } } } XmlNode gameListNode = profileNode.SelectSingleNode(XmlName_GameList); if (gameListNode != null) { XmlNodeList gameNodes = gameListNode.SelectNodes(XmlName_Game); foreach (XmlNode node in gameNodes) { AddGameFromXmlNode(node, profile, profileVersion); } } XmlNode filterListNode = profileNode.SelectSingleNode(XmlName_FilterList); if (filterListNode != null) { XmlNodeList filterNodes = filterListNode.SelectNodes(XmlName_Filter); foreach (XmlNode node in filterNodes) { AddFilterFromXmlNode(node, profile); } } XmlNode autocatListNode = profileNode.SelectSingleNode(XmlName_AutoCatList); if (autocatListNode != null) { XmlNodeList autoCatNodes = autocatListNode.ChildNodes; foreach (XmlNode node in autoCatNodes) { XmlElement autocatElement = node as XmlElement; if (node != null) { AutoCat autocat = AutoCat.LoadACFromXmlElement(autocatElement); if (autocat != null) { profile.AutoCats.Add(autocat); } } } } else { GenerateDefaultAutoCatSet(profile.AutoCats); } //profile.AutoCats.Sort(); } Logger.Info(GlobalStrings.MainForm_ProfileLoaded); return(profile); }
/// <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 static Profile Load(string path) { Program.Logger.Write(LoggerLevel.Info, GlobalStrings.Profile_LoadingProfile, path); Profile profile = new Profile(); profile.FilePath = path; XmlDocument doc = new XmlDocument(); try { doc.Load(path); } catch (Exception e) { Program.Logger.Write(LoggerLevel.Warning, GlobalStrings.Profile_FailedToLoadProfile, e.Message); throw new ApplicationException(GlobalStrings.Profile_ErrorLoadingProfile + e.Message, e); } XmlNode profileNode = doc.SelectSingleNode("/profile"); if (profileNode != null) { Int64 accId = XmlUtil.GetInt64FromNode(profileNode["steam_id_64"], 0); if (accId == 0) { string oldAcc = XmlUtil.GetStringFromNode(profileNode["account_id"], null); if (oldAcc != null) { accId = DirNametoID64(oldAcc); } } profile.SteamID64 = accId; profile.AutoDownload = XmlUtil.GetBoolFromNode(profileNode["auto_download"], profile.AutoDownload); profile.AutoImport = XmlUtil.GetBoolFromNode(profileNode["auto_import"], profile.AutoImport); profile.AutoExport = XmlUtil.GetBoolFromNode(profileNode["auto_export"], profile.AutoExport); profile.ExportDiscard = XmlUtil.GetBoolFromNode(profileNode["export_discard"], profile.ExportDiscard); profile.AutoIgnore = XmlUtil.GetBoolFromNode(profileNode["auto_ignore"], profile.AutoIgnore); profile.OverwriteOnDownload = XmlUtil.GetBoolFromNode(profileNode["overwrite_names"], profile.OverwriteOnDownload); profile.IgnoreDlc = XmlUtil.GetBoolFromNode(profileNode["ignore_dlc"], profile.IgnoreDlc); // jpodadera. Ignored non-Steam games profile.IgnoreExternal = XmlUtil.GetBoolFromNode(profileNode["ignore_external"], profile.IgnoreExternal); XmlNode exclusionListNode = profileNode.SelectSingleNode("exclusions"); if (exclusionListNode != null) { XmlNodeList exclusionNodes = exclusionListNode.SelectNodes("exclusion"); foreach (XmlNode node in exclusionNodes) { int id; if (XmlUtil.TryGetIntFromNode(node, out id)) { profile.IgnoreList.Add(id); } } } XmlNode gameListNode = profileNode.SelectSingleNode("games"); if (gameListNode != null) { XmlNodeList gameNodes = gameListNode.SelectNodes("game"); foreach (XmlNode node in gameNodes) { AddGameFromXmlNode(node, profile); } } } Program.Logger.Write(LoggerLevel.Info, GlobalStrings.MainForm_ProfileLoaded); return(profile); }
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(); } } }
public static Profile Load(string path) { Logger.Info(GlobalStrings.Profile_LoadingProfile, path); Profile profile = new Profile { FilePath = path }; XmlDocument doc = new XmlDocument(); try { doc.Load(path); } catch (Exception e) { Logger.Warn(GlobalStrings.Profile_FailedToLoadProfile, e.Message); throw new ApplicationException(GlobalStrings.Profile_ErrorLoadingProfile + e.Message, e); } XmlNode profileNode = doc.SelectSingleNode("/" + XmlNameProfile); if (profileNode != null) { // Get the 64-bit Steam ID long accId = XmlUtil.GetInt64FromNode(profileNode[XmlNameSteamId], 0); if (accId == 0) { string oldAcc = XmlUtil.GetStringFromNode(profileNode[XmlNameOldSteamIdShort], null); if (oldAcc != null) { accId = ToSteamId64(oldAcc); } } profile.SteamID64 = accId; // Get other attributes profile.AutoUpdate = XmlUtil.GetBoolFromNode(profileNode[XmlNameAutoUpdate], profile.AutoUpdate); profile.AutoImport = XmlUtil.GetBoolFromNode(profileNode[XmlNameAutoImport], profile.AutoImport); profile.AutoExport = XmlUtil.GetBoolFromNode(profileNode[XmlNameAutoExport], profile.AutoExport); profile.LocalUpdate = XmlUtil.GetBoolFromNode(profileNode[XmlNameLocalUpdate], profile.LocalUpdate); profile.WebUpdate = XmlUtil.GetBoolFromNode(profileNode[XmlNameWebUpdate], profile.WebUpdate); profile.IncludeUnknown = XmlUtil.GetBoolFromNode(profileNode[XmlNameIncludeUnknown], profile.IncludeUnknown); profile.BypassIgnoreOnImport = XmlUtil.GetBoolFromNode(profileNode[XmlNameBypassIgnoreOnImport], profile.BypassIgnoreOnImport); profile.ExportDiscard = XmlUtil.GetBoolFromNode(profileNode[XmlNameExportDiscard], profile.ExportDiscard); profile.AutoIgnore = XmlUtil.GetBoolFromNode(profileNode[XmlNameAutoIgnore], profile.AutoIgnore); profile.OverwriteOnDownload = XmlUtil.GetBoolFromNode(profileNode[XmlNameOverwriteNames], profile.OverwriteOnDownload); profile.IncludeShortcuts = XmlUtil.GetBoolFromNode(profileNode[XmlNameIncludeShortcuts], profile.IncludeShortcuts); XmlNode exclusionListNode = profileNode.SelectSingleNode(XmlNameExclusionList); XmlNodeList exclusionNodes = exclusionListNode?.SelectNodes(XmlNameExclusion); if (exclusionNodes != null) { foreach (XmlNode node in exclusionNodes) { if (XmlUtil.TryGetIntFromNode(node, out int id)) { profile.IgnoreList.Add(id); } } } XmlNode gameListNode = profileNode.SelectSingleNode(XmlNameGameList); XmlNodeList gameNodes = gameListNode?.SelectNodes(XmlNameGame); if (gameNodes != null) { foreach (XmlNode node in gameNodes) { AddGameFromNode(node, profile); } } XmlNode filterListNode = profileNode.SelectSingleNode(XmlNameFilterList); XmlNodeList filterNodes = filterListNode?.SelectNodes(XmlNameFilter); if (filterNodes != null) { foreach (XmlNode node in filterNodes) { AddFilterFromNode(node, profile); } } XmlNode autocatListNode = profileNode.SelectSingleNode(XmlNameAutoCatList); if (autocatListNode != null) { XmlNodeList autoCatNodes = autocatListNode.ChildNodes; foreach (XmlNode node in autoCatNodes) { XmlElement autocatElement = node as XmlElement; if (node == null) { continue; } AutoCat autocat = AutoCat.LoadACFromXmlElement(autocatElement); if (autocat != null) { profile.AutoCats.Add(autocat); } } } else { GenerateDefaultAutoCatSet(profile.AutoCats); } //profile.AutoCats.Sort(); } Logger.Info(GlobalStrings.MainForm_ProfileLoaded); return(profile); }