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