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("/" + 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.Write(LoggerLevel.Info, GlobalStrings.MainForm_ProfileLoaded); return(profile); }
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); }
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); }