Пример #1
0
        private static void AddFilterFromNode(XmlNode node, Profile profile)
        {
            if (!XmlUtil.TryGetStringFromNode(node[XmlNameFilterName], out string name))
            {
                return;
            }

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

            if (XmlUtil.TryGetIntFromNode(node[XmlNameFilterSoftware], out int game))
            {
                filter.Game = game;
            }

            if (XmlUtil.TryGetIntFromNode(node[XmlNameFilterSoftware], out int software))
            {
                filter.Software = software;
            }

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

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

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

            XmlNodeList filterNodes = node.SelectNodes(XmlNameFilterAllow);

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

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

            filterNodes = node.SelectNodes(XmlNameFilterExclude);
            if (filterNodes != null)
            {
                foreach (XmlNode fNode in filterNodes)
                {
                    if (XmlUtil.TryGetStringFromNode(fNode, out string catName))
                    {
                        filter.Exclude.Add(profile.GameData.GetCategory(catName));
                    }
                }
            }
        }
Пример #2
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);
        }
Пример #3
0
        public static Profile Load(string path)
        {
            Program.Logger.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.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();
            }

            Program.Logger.Info(GlobalStrings.MainForm_ProfileLoaded);
            return(profile);
        }
Пример #4
0
        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.List_OwnedOnly = listOwnedOnly;
            }

            float listWeightFactor;

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

            int listMinScore;

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

            int listTagsPerGame;

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

            bool listScoreSort;

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

            bool listExcludeGenres;

            if (XmlUtil.TryGetBoolFromNode(xElement[XmlName_ListExcludeGenres], out 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);
        }
Пример #5
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();
                }
            }
        }