예제 #1
0
        public static AutoCatGenre LoadFromXmlElement(XmlElement xElement)
        {
            string name        = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString);
            string filter      = XmlUtil.GetStringFromNode(xElement[XmlName_Filter], null);
            int    maxCats     = XmlUtil.GetIntFromNode(xElement[XmlName_MaxCats], 0);
            bool   remOther    = XmlUtil.GetBoolFromNode(xElement[XmlName_RemOther], false);
            bool   tagFallback = XmlUtil.GetBoolFromNode(xElement[XmlName_TagFallback], true);
            string prefix      = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], null);

            List <string> ignore = new List <string>();

            XmlElement ignoreListElement = xElement[XmlName_IgnoreList];

            if (ignoreListElement != null)
            {
                XmlNodeList ignoreNodes = ignoreListElement.SelectNodes(XmlName_IgnoreItem);
                foreach (XmlNode node in ignoreNodes)
                {
                    if (XmlUtil.TryGetStringFromNode(node, out string s))
                    {
                        ignore.Add(s);
                    }
                }
            }

            AutoCatGenre result = new AutoCatGenre(name, filter, prefix, maxCats, remOther, tagFallback, ignore);

            return(result);
        }
예제 #2
0
        public static AutoCatHoursPlayed 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);

            XmlNodeList            rulesNodeList = xElement.SelectNodes(XmlName_Rule);
            List <HoursPlayedRule> rules         = new List <HoursPlayedRule>();

            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);

                    rules.Add(new HoursPlayedRule(ruleName, ruleMin, ruleMax));
                }
            }

            AutoCatHoursPlayed result = new AutoCatHoursPlayed(name, filter, prefix, includeUnknown)
            {
                Rules = rules
            };

            return(result);
        }
예제 #3
0
        public static AutoCatUserScore LoadFromXmlElement(XmlElement xElement)
        {
            string name           = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString);
            string filter         = XmlUtil.GetStringFromNode(xElement[XmlName_Filter], null);
            string prefix         = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], string.Empty);
            bool   useWilsonScore = XmlUtil.GetBoolFromNode(xElement[XmlName_UseWilsonScore], false);

            List <UserScore_Rule> rules = new List <UserScore_Rule>();

            foreach (XmlNode node in xElement.SelectNodes(XmlName_Rule))
            {
                string ruleName   = XmlUtil.GetStringFromNode(node[XmlName_Rule_Text], string.Empty);
                int    ruleMin    = XmlUtil.GetIntFromNode(node[XmlName_Rule_MinScore], 0);
                int    ruleMax    = XmlUtil.GetIntFromNode(node[XmlName_Rule_MaxScore], 100);
                int    ruleMinRev = XmlUtil.GetIntFromNode(node[XmlName_Rule_MinReviews], 0);
                int    ruleMaxRev = XmlUtil.GetIntFromNode(node[XmlName_Rule_MaxReviews], 0);
                rules.Add(new UserScore_Rule(ruleName, ruleMin, ruleMax, ruleMinRev, ruleMaxRev));
            }

            AutoCatUserScore result = new AutoCatUserScore(name, filter, prefix, useWilsonScore)
            {
                Rules = rules
            };

            return(result);
        }
        public static AutoCatLanguage LoadFromXmlElement(XmlElement xElement)
        {
            string        name              = XmlUtil.GetStringFromNode(xElement[XmlNameName], TypeIdString);
            string        filter            = XmlUtil.GetStringFromNode(xElement[XmlNameFilter], null);
            string        prefix            = XmlUtil.GetStringFromNode(xElement[XmlNamePrefix], null);
            bool          includeTypePrefix = XmlUtil.GetBoolFromNode(xElement[XmlNameIncludeTypePrefix], false);
            bool          typeFallback      = XmlUtil.GetBoolFromNode(xElement[XmlNameTypeFallback], false);
            List <string> interfaceList     = new List <string>();
            List <string> subtitlesList     = new List <string>();
            List <string> fullAudioList     = new List <string>();

            XmlElement interfaceLanguage = xElement[XmlNameInterfaceList];
            XmlElement subtitles         = xElement[XmlNameSubtitlesList];
            XmlElement fullAudio         = xElement[XmlNameFullAudioList];

            XmlNodeList interfaceElements = interfaceLanguage?.SelectNodes(XmlNameLanguage);

            if (interfaceElements != null)
            {
                for (int i = 0; i < interfaceElements.Count; i++)
                {
                    XmlNode n = interfaceElements[i];
                    if (XmlUtil.TryGetStringFromNode(n, out string language))
                    {
                        interfaceList.Add(language);
                    }
                }
            }

            XmlNodeList subtitlesElements = subtitles?.SelectNodes(XmlNameLanguage);

            if (subtitlesElements != null)
            {
                for (int i = 0; i < subtitlesElements.Count; i++)
                {
                    XmlNode n = subtitlesElements[i];
                    if (XmlUtil.TryGetStringFromNode(n, out string language))
                    {
                        subtitlesList.Add(language);
                    }
                }
            }

            XmlNodeList fullAudioElements = fullAudio?.SelectNodes(XmlNameLanguage);

            if (fullAudioElements != null)
            {
                for (int i = 0; i < fullAudioElements.Count; i++)
                {
                    XmlNode n = fullAudioElements[i];
                    if (XmlUtil.TryGetStringFromNode(n, out string language))
                    {
                        fullAudioList.Add(language);
                    }
                }
            }

            return(new AutoCatLanguage(name, filter, prefix, includeTypePrefix, typeFallback, interfaceList, subtitlesList, fullAudioList));
        }
예제 #5
0
        public static AutoCatYear LoadFromXmlElement(XmlElement xElement)
        {
            string name                    = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString);
            string prefix                  = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], null);
            bool   includeUnknown          = XmlUtil.GetBoolFromNode(xElement[XmlName_IncludeUnknown], true);
            string unknownText             = XmlUtil.GetStringFromNode(xElement[XmlName_UnknownText], null);
            AutoCatYear_Grouping groupMode = XmlUtil.GetEnumFromNode <AutoCatYear_Grouping>(xElement[XmlName_GroupingMode], AutoCatYear_Grouping.None);

            return(new AutoCatYear(name, prefix, includeUnknown, unknownText, groupMode));
        }
예제 #6
0
        public static AutoCatName LoadFromXmlElement(XmlElement xElement)
        {
            string name         = XmlUtil.GetStringFromNode(xElement[XmlName_Name], null);
            string prefix       = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], null);
            bool   skipThe      = XmlUtil.GetBoolFromNode(xElement[XmlName_SkipThe], true);
            bool   groupNumbers = XmlUtil.GetBoolFromNode(xElement[XmlName_GroupNumbers], true);
            bool   groupNonEnglishCharacters     = XmlUtil.GetBoolFromNode(xElement[XmlName_GroupNonEnglishCharacters], false);
            string groupNonEnglishCharactersText = XmlUtil.GetStringFromNode(xElement[XmlName_GroupNonEnglishCharactersText], null);

            return(new AutoCatName(name, prefix, skipThe, groupNumbers, groupNonEnglishCharacters, groupNonEnglishCharactersText));
        }
예제 #7
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));
                            }
                        }
                    }
                }
            }
        }
예제 #8
0
        public static AutoCatDevPub LoadFromXmlElement(XmlElement xElement)
        {
            string name          = XmlUtil.GetStringFromNode(xElement[XmlName_Name], TypeIdString);
            string filter        = XmlUtil.GetStringFromNode(xElement[XmlName_Filter], null);
            bool   AllDevelopers = XmlUtil.GetBoolFromNode(xElement[XmlName_AllDevelopers], false);
            bool   AllPublishers = XmlUtil.GetBoolFromNode(xElement[XmlName_AllPublishers], false);
            string prefix        = XmlUtil.GetStringFromNode(xElement[XmlName_Prefix], null);
            bool   owned         = XmlUtil.GetBoolFromNode(xElement[XmlName_OwnedOnly], false);
            int    count         = XmlUtil.GetIntFromNode(xElement[XmlName_MinCount], 0);

            List <string> devs = new List <string>();

            XmlElement devsListElement = xElement[XmlName_Developers];

            if (devsListElement != null)
            {
                XmlNodeList devNodes = devsListElement.SelectNodes(XmlName_Developer);
                foreach (XmlNode node in devNodes)
                {
                    string s;
                    if (XmlUtil.TryGetStringFromNode(node, out s))
                    {
                        devs.Add(s);
                    }
                }
            }

            List <string> pubs = new List <string>();

            XmlElement pubsListElement = xElement[XmlName_Publishers];

            if (pubsListElement != null)
            {
                XmlNodeList pubNodes = pubsListElement.SelectNodes(XmlName_Publisher);
                foreach (XmlNode node in pubNodes)
                {
                    string s;
                    if (XmlUtil.TryGetStringFromNode(node, out s))
                    {
                        pubs.Add(s);
                    }
                }
            }

            AutoCatDevPub result = new AutoCatDevPub(name, filter, prefix, owned, count, AllDevelopers, AllPublishers,
                                                     devs, pubs);

            return(result);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
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));
                }
            }
        }
예제 #12
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);
        }
예제 #13
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);
        }
예제 #14
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);
        }