public ISettings Create() { var document = new XmlDocument(); document.Load(Stream); var settings = new StandardSettingsFactory().Create(); var parent = document["Settings"]; var version = SettingsHelper.ParseAttributeVersion(parent); var keyStart = parent["SplitKey"]; if (!string.IsNullOrEmpty(keyStart.InnerText)) settings.SplitKey = new KeyOrButton(keyStart.InnerText); else settings.SplitKey = null; var keyReset = parent["ResetKey"]; if (!string.IsNullOrEmpty(keyReset.InnerText)) settings.ResetKey = new KeyOrButton(keyReset.InnerText); else settings.ResetKey = null; var keySkip = parent["SkipKey"]; if (!string.IsNullOrEmpty(keySkip.InnerText)) settings.SkipKey = new KeyOrButton(keySkip.InnerText); else settings.SkipKey = null; var keyUndo = parent["UndoKey"]; if (!string.IsNullOrEmpty(keyUndo.InnerText)) settings.UndoKey = new KeyOrButton(keyUndo.InnerText); else settings.UndoKey = null; settings.GlobalHotkeysEnabled = SettingsHelper.ParseBool(parent["GlobalHotkeysEnabled"]); settings.WarnOnReset = SettingsHelper.ParseBool(parent["WarnOnReset"], settings.WarnOnReset); settings.DoubleTapPrevention = SettingsHelper.ParseBool(parent["DoubleTapPrevention"], settings.DoubleTapPrevention); settings.LastTimingMethod = SettingsHelper.ParseEnum<TimingMethod>(parent["LastTimingMethod"], settings.LastTimingMethod); settings.SimpleSumOfBest = SettingsHelper.ParseBool(parent["SimpleSumOfBest"], settings.SimpleSumOfBest); settings.LastComparison = SettingsHelper.ParseString(parent["LastComparison"], settings.LastComparison); settings.DeactivateHotkeysForOtherPrograms = SettingsHelper.ParseBool(parent["DeactivateHotkeysForOtherPrograms"], settings.DeactivateHotkeysForOtherPrograms); settings.HotkeyDelay = SettingsHelper.ParseFloat(parent["HotkeyDelay"], settings.HotkeyDelay); settings.AgreedToSRLRules = SettingsHelper.ParseBool(parent["AgreedToSRLRules"], settings.AgreedToSRLRules); var recentLayouts = parent["RecentLayouts"]; foreach (var layoutNode in recentLayouts.GetElementsByTagName("LayoutPath")) { var layoutElement = layoutNode as XmlElement; settings.RecentLayouts.Add(layoutElement.InnerText); } if (version > new Version(1, 0, 0, 0)) { var keyPause = parent["PauseKey"]; if (!string.IsNullOrEmpty(keyPause.InnerText)) settings.PauseKey = new KeyOrButton(keyPause.InnerText); else settings.PauseKey = null; var keyToggle = parent["ToggleGlobalHotkeys"]; if (!string.IsNullOrEmpty(keyToggle.InnerText)) settings.ToggleGlobalHotkeys = new KeyOrButton(keyToggle.InnerText); else settings.ToggleGlobalHotkeys = null; } if (version >= new Version(1, 3)) { var switchComparisonPrevious = parent["SwitchComparisonPrevious"]; if (!string.IsNullOrEmpty(switchComparisonPrevious.InnerText)) settings.SwitchComparisonPrevious = new KeyOrButton(switchComparisonPrevious.InnerText); else settings.SwitchComparisonPrevious = null; var switchComparisonNext = parent["SwitchComparisonNext"]; if (!string.IsNullOrEmpty(switchComparisonNext.InnerText)) settings.SwitchComparisonNext = new KeyOrButton(switchComparisonNext.InnerText); else settings.SwitchComparisonNext = null; settings.RaceViewer = RaceViewer.FromName(parent["RaceViewer"].InnerText); } if (version >= new Version(1, 4)) { var activeAutoSplitters = parent["ActiveAutoSplitters"]; foreach (var splitter in activeAutoSplitters.GetElementsByTagName("AutoSplitter").OfType<XmlElement>()) { settings.ActiveAutoSplitters.Add(splitter.InnerText); } } var recentSplits = parent["RecentSplits"]; if (version >= new Version(1, 6)) { foreach (var generatorNode in parent["ComparisonGeneratorStates"].ChildNodes.OfType<XmlElement>()) { settings.ComparisonGeneratorStates[generatorNode.GetAttribute("name")] = Boolean.Parse(generatorNode.InnerText); } foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsFile")) { var splitElement = splitNode as XmlElement; string gameName = splitElement.GetAttribute("gameName"); string categoryName = splitElement.GetAttribute("categoryName"); var path = splitElement.InnerText; var recentSplitsFile = new RecentSplitsFile(path, gameName, categoryName); settings.RecentSplits.Add(recentSplitsFile); } } else { var comparisonsFactory = new StandardComparisonGeneratorsFactory(); var runFactory = new StandardFormatsRunFactory(); foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsPath")) { var splitElement = splitNode as XmlElement; var path = splitElement.InnerText; try { using (var stream = File.OpenRead(path)) { runFactory.FilePath = path; runFactory.Stream = stream; var run = runFactory.Create(comparisonsFactory); var recentSplitsFile = new RecentSplitsFile(path, run.GameName, run.CategoryName); settings.RecentSplits.Add(recentSplitsFile); } } catch { } } } LoadDrift(parent); return settings; }
public ISettings Create() { var document = new XmlDocument(); document.Load(Stream); var settings = new StandardSettingsFactory().Create(); var parent = document["Settings"]; var version = parent.HasAttribute("version") ? Version.Parse(parent.Attributes["version"].Value) : new Version(1,0,0,0); var keyStart = parent["SplitKey"]; if (!string.IsNullOrEmpty(keyStart.InnerText)) settings.SplitKey = new KeyOrButton(keyStart.InnerText); else settings.SplitKey = null; var keyReset = parent["ResetKey"]; if (!string.IsNullOrEmpty(keyReset.InnerText)) settings.ResetKey = new KeyOrButton(keyReset.InnerText); else settings.ResetKey = null; var keySkip = parent["SkipKey"]; if (!string.IsNullOrEmpty(keySkip.InnerText)) settings.SkipKey = new KeyOrButton(keySkip.InnerText); else settings.SkipKey = null; var keyUndo = parent["UndoKey"]; if (!string.IsNullOrEmpty(keyUndo.InnerText)) settings.UndoKey = new KeyOrButton(keyUndo.InnerText); else settings.UndoKey = null; settings.GlobalHotkeysEnabled = SettingsHelper.ParseBool(parent["GlobalHotkeysEnabled"]); settings.WarnOnReset = SettingsHelper.ParseBool(parent["WarnOnReset"], settings.WarnOnReset); settings.DoubleTapPrevention = SettingsHelper.ParseBool(parent["DoubleTapPrevention"], settings.DoubleTapPrevention); settings.LastTimingMethod = SettingsHelper.ParseEnum<TimingMethod>(parent["LastTimingMethod"], settings.LastTimingMethod); settings.SimpleSumOfBest = SettingsHelper.ParseBool(parent["SimpleSumOfBest"], settings.SimpleSumOfBest); settings.LastComparison = SettingsHelper.ParseString(parent["LastComparison"], settings.LastComparison); settings.DeactivateHotkeysForOtherPrograms = SettingsHelper.ParseBool(parent["DeactivateHotkeysForOtherPrograms"], settings.DeactivateHotkeysForOtherPrograms); settings.HotkeyDelay = SettingsHelper.ParseFloat(parent["HotkeyDelay"], settings.HotkeyDelay); settings.AgreedToSRLRules = SettingsHelper.ParseBool(parent["AgreedToSRLRules"], settings.AgreedToSRLRules); var recentSplits = parent["RecentSplits"]; foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsPath")) { var splitElement = splitNode as XmlElement; settings.RecentSplits.Add(splitElement.InnerText); } var recentLayouts = parent["RecentLayouts"]; foreach (var layoutNode in recentLayouts.GetElementsByTagName("LayoutPath")) { var layoutElement = layoutNode as XmlElement; settings.RecentLayouts.Add(layoutElement.InnerText); } if (version > new Version(1, 0, 0, 0)) { var keyPause = parent["PauseKey"]; if (!string.IsNullOrEmpty(keyPause.InnerText)) settings.PauseKey = new KeyOrButton(keyPause.InnerText); else settings.PauseKey = null; var keyToggle = parent["ToggleGlobalHotkeys"]; if (!string.IsNullOrEmpty(keyToggle.InnerText)) settings.ToggleGlobalHotkeys = new KeyOrButton(keyToggle.InnerText); else settings.ToggleGlobalHotkeys = null; } if (version >= new Version(1, 3)) { var switchComparisonPrevious = parent["SwitchComparisonPrevious"]; if (!string.IsNullOrEmpty(switchComparisonPrevious.InnerText)) settings.SwitchComparisonPrevious = new KeyOrButton(switchComparisonPrevious.InnerText); else settings.SwitchComparisonPrevious = null; var switchComparisonNext = parent["SwitchComparisonNext"]; if (!string.IsNullOrEmpty(switchComparisonNext.InnerText)) settings.SwitchComparisonNext = new KeyOrButton(switchComparisonNext.InnerText); else settings.SwitchComparisonNext = null; settings.RaceViewer = RaceViewer.FromName(parent["RaceViewer"].InnerText); } if (version >= new Version(1, 4)) { var activeAutoSplitters = parent["ActiveAutoSplitters"]; foreach (var splitter in activeAutoSplitters.GetElementsByTagName("AutoSplitter").OfType<XmlElement>()) { settings.ActiveAutoSplitters.Add(splitter.InnerText); } } if (version >= new Version(1, 6)) { foreach (var generatorNode in parent["ComparisonGeneratorStates"].ChildNodes) { settings.ComparisonGeneratorStates[((XmlNode)generatorNode).Attributes["name"].Value] = Boolean.Parse(((XmlNode)generatorNode).InnerText); } } return settings; }
private void LoadSettings() { try { using (var stream = File.OpenRead(Path.Combine(BasePath, SETTINGS_PATH))) { Settings = new XMLSettingsFactory(stream).Create(); } } catch (Exception e) { Log.Error(e); Settings = new StandardSettingsFactory().Create(); } }
public ISettings Create() { var document = new XmlDocument(); document.Load(Stream); var settings = new StandardSettingsFactory().Create(); var parent = document["Settings"]; var version = SettingsHelper.ParseAttributeVersion(parent); var keyStart = parent["SplitKey"]; if (!string.IsNullOrEmpty(keyStart.InnerText)) { settings.SplitKey = new KeyOrButton(keyStart.InnerText); } else { settings.SplitKey = null; } var keyReset = parent["ResetKey"]; if (!string.IsNullOrEmpty(keyReset.InnerText)) { settings.ResetKey = new KeyOrButton(keyReset.InnerText); } else { settings.ResetKey = null; } var keySkip = parent["SkipKey"]; if (!string.IsNullOrEmpty(keySkip.InnerText)) { settings.SkipKey = new KeyOrButton(keySkip.InnerText); } else { settings.SkipKey = null; } var keyUndo = parent["UndoKey"]; if (!string.IsNullOrEmpty(keyUndo.InnerText)) { settings.UndoKey = new KeyOrButton(keyUndo.InnerText); } else { settings.UndoKey = null; } settings.GlobalHotkeysEnabled = SettingsHelper.ParseBool(parent["GlobalHotkeysEnabled"]); settings.WarnOnReset = SettingsHelper.ParseBool(parent["WarnOnReset"], settings.WarnOnReset); settings.DoubleTapPrevention = SettingsHelper.ParseBool(parent["DoubleTapPrevention"], settings.DoubleTapPrevention); settings.LastTimingMethod = SettingsHelper.ParseEnum <TimingMethod>(parent["LastTimingMethod"], settings.LastTimingMethod); settings.SimpleSumOfBest = SettingsHelper.ParseBool(parent["SimpleSumOfBest"], settings.SimpleSumOfBest); settings.LastComparison = SettingsHelper.ParseString(parent["LastComparison"], settings.LastComparison); settings.DeactivateHotkeysForOtherPrograms = SettingsHelper.ParseBool(parent["DeactivateHotkeysForOtherPrograms"], settings.DeactivateHotkeysForOtherPrograms); settings.HotkeyDelay = SettingsHelper.ParseFloat(parent["HotkeyDelay"], settings.HotkeyDelay); settings.AgreedToSRLRules = SettingsHelper.ParseBool(parent["AgreedToSRLRules"], settings.AgreedToSRLRules); var recentLayouts = parent["RecentLayouts"]; foreach (var layoutNode in recentLayouts.GetElementsByTagName("LayoutPath")) { var layoutElement = layoutNode as XmlElement; settings.RecentLayouts.Add(layoutElement.InnerText); } if (version > new Version(1, 0, 0, 0)) { var keyPause = parent["PauseKey"]; if (!string.IsNullOrEmpty(keyPause.InnerText)) { settings.PauseKey = new KeyOrButton(keyPause.InnerText); } else { settings.PauseKey = null; } var keyToggle = parent["ToggleGlobalHotkeys"]; if (!string.IsNullOrEmpty(keyToggle.InnerText)) { settings.ToggleGlobalHotkeys = new KeyOrButton(keyToggle.InnerText); } else { settings.ToggleGlobalHotkeys = null; } } if (version >= new Version(1, 3)) { var switchComparisonPrevious = parent["SwitchComparisonPrevious"]; if (!string.IsNullOrEmpty(switchComparisonPrevious.InnerText)) { settings.SwitchComparisonPrevious = new KeyOrButton(switchComparisonPrevious.InnerText); } else { settings.SwitchComparisonPrevious = null; } var switchComparisonNext = parent["SwitchComparisonNext"]; if (!string.IsNullOrEmpty(switchComparisonNext.InnerText)) { settings.SwitchComparisonNext = new KeyOrButton(switchComparisonNext.InnerText); } else { settings.SwitchComparisonNext = null; } settings.RaceViewer = RaceViewer.FromName(parent["RaceViewer"].InnerText); } if (version >= new Version(1, 4)) { var activeAutoSplitters = parent["ActiveAutoSplitters"]; foreach (var splitter in activeAutoSplitters.GetElementsByTagName("AutoSplitter").OfType <XmlElement>()) { settings.ActiveAutoSplitters.Add(splitter.InnerText); } } var recentSplits = parent["RecentSplits"]; if (version >= new Version(1, 6)) { foreach (var generatorNode in parent["ComparisonGeneratorStates"].ChildNodes.OfType <XmlElement>()) { settings.ComparisonGeneratorStates[generatorNode.GetAttribute("name")] = Boolean.Parse(generatorNode.InnerText); } foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsFile")) { var splitElement = splitNode as XmlElement; string gameName = splitElement.GetAttribute("gameName"); string categoryName = splitElement.GetAttribute("categoryName"); var path = splitElement.InnerText; var recentSplitsFile = new RecentSplitsFile(path, gameName, categoryName); settings.RecentSplits.Add(recentSplitsFile); } } else { var comparisonsFactory = new StandardComparisonGeneratorsFactory(); var runFactory = new StandardFormatsRunFactory(); foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsPath")) { var splitElement = splitNode as XmlElement; var path = splitElement.InnerText; try { using (var stream = File.OpenRead(path)) { runFactory.FilePath = path; runFactory.Stream = stream; var run = runFactory.Create(comparisonsFactory); var recentSplitsFile = new RecentSplitsFile(path, run.GameName, run.CategoryName); settings.RecentSplits.Add(recentSplitsFile); } } catch { } } } return(settings); }
public ISettings Create() { var document = new XmlDocument(); document.Load(Stream); var settings = new StandardSettingsFactory().Create(); var parent = document["Settings"]; var version = ParseAttributeVersion(parent); settings.WarnOnReset = ParseBool(parent["WarnOnReset"], settings.WarnOnReset); settings.SimpleSumOfBest = ParseBool(parent["SimpleSumOfBest"], settings.SimpleSumOfBest); settings.LastComparison = ParseString(parent["LastComparison"], settings.LastComparison); settings.AgreedToSRLRules = ParseBool(parent["AgreedToSRLRules"], settings.AgreedToSRLRules); var recentLayouts = parent["RecentLayouts"]; foreach (var layoutNode in recentLayouts.GetElementsByTagName("LayoutPath")) { var layoutElement = layoutNode as XmlElement; settings.RecentLayouts.Add(layoutElement.InnerText); } if (version >= new Version(1, 3)) { settings.RaceViewer = RaceViewer.FromName(parent["RaceViewer"].InnerText); } if (version >= new Version(1, 4)) { var activeAutoSplitters = parent["ActiveAutoSplitters"]; foreach (var splitter in activeAutoSplitters.GetElementsByTagName("AutoSplitter").OfType <XmlElement>()) { settings.ActiveAutoSplitters.Add(splitter.InnerText); } } var recentSplits = parent["RecentSplits"]; if (version >= new Version(1, 6)) { foreach (var generatorNode in parent["ComparisonGeneratorStates"].ChildNodes.OfType <XmlElement>()) { var comparisonName = generatorNode.GetAttribute("name"); if (settings.ComparisonGeneratorStates.ContainsKey(comparisonName)) { settings.ComparisonGeneratorStates[comparisonName] = bool.Parse(generatorNode.InnerText); } } foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsFile")) { var splitElement = splitNode as XmlElement; string gameName = splitElement.GetAttribute("gameName"); string categoryName = splitElement.GetAttribute("categoryName"); var method = TimingMethod.RealTime; if (version >= new Version(1, 6, 1)) { method = (TimingMethod)Enum.Parse(typeof(TimingMethod), splitElement.GetAttribute("lastTimingMethod")); } var hotkeyProfile = HotkeyProfile.DefaultHotkeyProfileName; if (version >= new Version(1, 8)) { hotkeyProfile = splitElement.GetAttribute("lastHotkeyProfile"); } var path = splitElement.InnerText; var recentSplitsFile = new RecentSplitsFile(path, method, hotkeyProfile, gameName, categoryName); settings.RecentSplits.Add(recentSplitsFile); } } else { var comparisonsFactory = new StandardComparisonGeneratorsFactory(); var runFactory = new StandardFormatsRunFactory(); foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsPath")) { var splitElement = splitNode as XmlElement; var path = splitElement.InnerText; try { using (var stream = File.OpenRead(path)) { runFactory.FilePath = path; runFactory.Stream = stream; var run = runFactory.Create(comparisonsFactory); var recentSplitsFile = new RecentSplitsFile(path, run, TimingMethod.RealTime, HotkeyProfile.DefaultHotkeyProfileName); settings.RecentSplits.Add(recentSplitsFile); } } catch { } } } if (version >= new Version(1, 8)) { settings.HotkeyProfiles.Clear(); foreach (var hotkeyProfileNode in parent["HotkeyProfiles"].ChildNodes.OfType <XmlElement>()) { var hotkeyProfileName = hotkeyProfileNode.GetAttribute("name"); settings.HotkeyProfiles[hotkeyProfileName] = HotkeyProfile.FromXml(hotkeyProfileNode, version); } } else { var hotkeyProfile = HotkeyProfile.FromXml(parent, version); settings.HotkeyProfiles[HotkeyProfile.DefaultHotkeyProfileName] = hotkeyProfile; } LoadDrift(parent); return(settings); }
public ISettings Create() { var document = new XmlDocument(); document.Load(Stream); var settings = new StandardSettingsFactory().Create(); var parent = document["Settings"]; var version = parent.HasAttribute("version") ? Version.Parse(parent.Attributes["version"].Value) : new Version(1, 0, 0, 0); var keyStart = parent["SplitKey"]; if (!String.IsNullOrEmpty(keyStart.InnerText)) { settings.SplitKey = new KeyOrButton(keyStart.InnerText); } else { settings.SplitKey = null; } var keyReset = parent["ResetKey"]; if (!String.IsNullOrEmpty(keyReset.InnerText)) { settings.ResetKey = new KeyOrButton(keyReset.InnerText); } else { settings.ResetKey = null; } var keySkip = parent["SkipKey"]; if (!String.IsNullOrEmpty(keySkip.InnerText)) { settings.SkipKey = new KeyOrButton(keySkip.InnerText); } else { settings.SkipKey = null; } var keyUndo = parent["UndoKey"]; if (!String.IsNullOrEmpty(keyUndo.InnerText)) { settings.UndoKey = new KeyOrButton(keyUndo.InnerText); } else { settings.UndoKey = null; } if (version > new Version(1, 0, 0, 0)) { var keyPause = parent["PauseKey"]; if (!String.IsNullOrEmpty(keyPause.InnerText)) { settings.PauseKey = new KeyOrButton(keyPause.InnerText); } else { settings.PauseKey = null; } var keyToggle = parent["ToggleGlobalHotkeys"]; if (!String.IsNullOrEmpty(keyToggle.InnerText)) { settings.ToggleGlobalHotkeys = new KeyOrButton(keyToggle.InnerText); } else { settings.ToggleGlobalHotkeys = null; } settings.WarnOnReset = Boolean.Parse(parent["WarnOnReset"].InnerText); } if (version >= new Version(1, 2)) { settings.DoubleTapPrevention = Boolean.Parse(parent["DoubleTapPrevention"].InnerText); } if (version >= new Version(1, 4)) { settings.LastTimingMethod = ParseEnum <TimingMethod>(parent["LastTimingMethod"]); settings.SimpleSumOfBest = Boolean.Parse(parent["SimpleSumOfBest"].InnerText); var activeAutoSplitters = parent["ActiveAutoSplitters"]; foreach (var splitter in activeAutoSplitters.GetElementsByTagName("AutoSplitter").OfType <XmlElement>()) { settings.ActiveAutoSplitters.Add(splitter.InnerText); } } if (version >= new Version(1, 3)) { //settings.RefreshRate = Single.Parse(parent["RefreshRate"].InnerText); settings.LastComparison = parent["LastComparison"].InnerText; var switchComparisonPrevious = parent["SwitchComparisonPrevious"]; if (!String.IsNullOrEmpty(switchComparisonPrevious.InnerText)) { settings.SwitchComparisonPrevious = new KeyOrButton(switchComparisonPrevious.InnerText); } else { settings.SwitchComparisonPrevious = null; } var switchComparisonNext = parent["SwitchComparisonNext"]; if (!String.IsNullOrEmpty(switchComparisonNext.InnerText)) { settings.SwitchComparisonNext = new KeyOrButton(switchComparisonNext.InnerText); } else { settings.SwitchComparisonNext = null; } settings.HotkeyDelay = Single.Parse(parent["HotkeyDelay"].InnerText.Replace(',', '.'), CultureInfo.InvariantCulture); settings.RaceViewer = RaceViewer.FromName(parent["RaceViewer"].InnerText); var deactivateHotkeysForOtherPrograms = parent["DeactivateHotkeysForOtherPrograms"]; settings.DeactivateHotkeysForOtherPrograms = Boolean.Parse(deactivateHotkeysForOtherPrograms.InnerText); } if (version >= new Version(1, 3, 1)) { settings.AgreedToSRLRules = Boolean.Parse(parent["AgreedToSRLRules"].InnerText); } var hotkeysEnabled = parent["GlobalHotkeysEnabled"]; settings.GlobalHotkeysEnabled = Boolean.Parse(hotkeysEnabled.InnerText); var recentSplits = parent["RecentSplits"]; foreach (var splitNode in recentSplits.GetElementsByTagName("SplitsPath")) { var splitElement = splitNode as XmlElement; settings.RecentSplits.Add(splitElement.InnerText); } var recentLayouts = parent["RecentLayouts"]; foreach (var layoutNode in recentLayouts.GetElementsByTagName("LayoutPath")) { var layoutElement = layoutNode as XmlElement; settings.RecentLayouts.Add(layoutElement.InnerText); } return(settings); }