Пример #1
0
        public int IntegrateAppList(XmlDocument doc)
        {
            int added = 0;

            foreach (XmlNode node in doc.SelectNodes("/applist/apps/app"))
            {
                int appId;
                if (XmlUtil.TryGetIntFromNode(node["appid"], out appId))
                {
                    string gameName = XmlUtil.GetStringFromNode(node["name"], null);
                    if (Games.ContainsKey(appId))
                    {
                        GameDBEntry g = Games[appId];
                        if (string.IsNullOrEmpty(g.Name) || g.Name != gameName)
                        {
                            g.Name    = gameName;
                            g.AppType = AppTypes.Unknown;
                        }
                    }
                    else
                    {
                        GameDBEntry g = new GameDBEntry();
                        g.Id   = appId;
                        g.Name = gameName;
                        Games.Add(appId, g);
                        added++;
                    }
                }
            }
            Program.Logger.Write(LoggerLevel.Info, GlobalStrings.GameDB_LoadedNewItemsFromAppList, added);
            return(added);
        }
Пример #2
0
        public static AutoCatTags LoadFromXmlElement(XmlElement xElement)
        {
            string name = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString);

            AutoCatTags result = new AutoCatTags(name)
            {
                Filter = XmlUtil.GetStringFromNode(xElement[XmlName_Filter], null)
            };

            if (XmlUtil.TryGetStringFromNode(xElement[XmlName_Prefix], out string prefix))
            {
                result.Prefix = prefix;
            }

            if (XmlUtil.TryGetIntFromNode(xElement[XmlName_MaxTags], out int maxTags))
            {
                result.MaxTags = maxTags;
            }

            if (XmlUtil.TryGetBoolFromNode(xElement[XmlName_ListOwnedOnly], out bool listOwnedOnly))
            {
                result.List_OwnedOnly = listOwnedOnly;
            }

            if (XmlUtil.TryGetFloatFromNode(xElement[XmlName_ListWeightFactor], out float listWeightFactor))
            {
                result.List_WeightFactor = listWeightFactor;
            }

            if (XmlUtil.TryGetIntFromNode(xElement[XmlName_ListMinScore], out int listMinScore))
            {
                result.List_MinScore = listMinScore;
            }

            if (XmlUtil.TryGetIntFromNode(xElement[XmlName_ListTagsPerGame], out int listTagsPerGame))
            {
                result.List_TagsPerGame = listTagsPerGame;
            }

            if (XmlUtil.TryGetBoolFromNode(xElement[XmlName_ListScoreSort], out bool listScoreSort))
            {
                result.List_ScoreSort = listScoreSort;
            }

            if (XmlUtil.TryGetBoolFromNode(xElement[XmlName_ListExcludeGenres], out bool listExcludeGenres))
            {
                result.List_ExcludeGenres = 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);
        }
Пример #3
0
        private static void AddFilterFromXmlNode(XmlNode node, Profile profile)
        {
            if (!XmlUtil.TryGetStringFromNode(node[XmlName_FilterName], out string name))
            {
                return;
            }

            Filter filter = profile.GameData.AddFilter(name);

            if (XmlUtil.TryGetIntFromNode(node[XmlName_FilterUncategorized], out int uncategorized))
            {
                filter.Uncategorized = uncategorized;
            }

            if (XmlUtil.TryGetIntFromNode(node[XmlName_FilterHidden], out int hidden))
            {
                filter.Hidden = hidden;
            }

            if (XmlUtil.TryGetIntFromNode(node[XmlName_FilterVR], out int vr))
            {
                filter.VR = vr;
            }

            XmlNodeList filterNodes = node.SelectNodes(XmlName_FilterAllow);

            foreach (XmlNode fNode in filterNodes)
            {
                if (XmlUtil.TryGetStringFromNode(fNode, out string catName))
                {
                    filter.Allow.Add(profile.GameData.GetCategory(catName));
                }
            }

            filterNodes = node.SelectNodes(XmlName_FilterRequire);
            foreach (XmlNode fNode in filterNodes)
            {
                string catName;
                if (XmlUtil.TryGetStringFromNode(fNode, out catName))
                {
                    filter.Require.Add(profile.GameData.GetCategory(catName));
                }
            }

            filterNodes = node.SelectNodes(XmlName_FilterExclude);
            foreach (XmlNode fNode in filterNodes)
            {
                string catName;
                if (XmlUtil.TryGetStringFromNode(fNode, out catName))
                {
                    filter.Exclude.Add(profile.GameData.GetCategory(catName));
                }
            }
        }
Пример #4
0
        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));
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
        private static void AddFilterFromXmlNode(XmlNode node, Profile profile)
        {
            string name;

            if (XmlUtil.TryGetStringFromNode(node[XmlName_FilterName], out name))
            {
                Filter f = profile.GameData.AddFilter(name);
                if (!XmlUtil.TryGetIntFromNode(node[XmlName_FilterUncategorized], out f.Uncategorized))
                {
                    f.Uncategorized = -1;
                }

                if (!XmlUtil.TryGetIntFromNode(node[XmlName_FilterHidden], out f.Hidden))
                {
                    f.Hidden = -1;
                }

                if (!XmlUtil.TryGetIntFromNode(node[XmlName_FilterVR], out f.VR))
                {
                    f.VR = -1;
                }

                XmlNodeList filterNodes = node.SelectNodes(XmlName_FilterAllow);
                foreach (XmlNode fNode in filterNodes)
                {
                    string catName;
                    if (XmlUtil.TryGetStringFromNode(fNode, out catName))
                    {
                        f.Allow.Add(profile.GameData.GetCategory(catName));
                    }
                }

                filterNodes = node.SelectNodes(XmlName_FilterRequire);
                foreach (XmlNode fNode in filterNodes)
                {
                    string catName;
                    if (XmlUtil.TryGetStringFromNode(fNode, out catName))
                    {
                        f.Require.Add(profile.GameData.GetCategory(catName));
                    }
                }

                filterNodes = node.SelectNodes(XmlName_FilterExclude);
                foreach (XmlNode fNode in filterNodes)
                {
                    string catName;
                    if (XmlUtil.TryGetStringFromNode(fNode, out catName))
                    {
                        f.Exclude.Add(profile.GameData.GetCategory(catName));
                    }
                }
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
        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));
                }
            }
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        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();
                }
            }
        }
Пример #10
0
        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);
        }
Пример #11
0
        /// <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);
            }
        }
Пример #12
0
        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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        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();
                }
            }
        }