コード例 #1
0
ファイル: AutoCatGroup.cs プロジェクト: satma/depressurizer
        public static AutoCatGroup LoadFromXmlElement(XmlElement xElement)
        {
            string        name     = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString);
            string        filter   = XmlUtil.GetStringFromNode(xElement[XmlName_Filter], null);
            List <string> autocats = XmlUtil.GetStringsFromNodeList(xElement.SelectNodes(XmlName_Autocats + "/" + XmlName_Autocat));

            return(new AutoCatGroup(name, filter, autocats));
        }
コード例 #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
        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();
                }
            }
        }
コード例 #4
0
ファイル: Database.cs プロジェクト: Thundernerd/Depressurizer
        /// <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);
            }
        }