public string ImportAsComparison(IRun run, Form form = null) { var splitDialog = new OpenFileDialog(); var result = splitDialog.ShowDialog(); if (result == DialogResult.OK) { var filePath = splitDialog.FileName; using (var stream = File.OpenRead(filePath)) { var runFactory = new StandardFormatsRunFactory(); var comparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory(); runFactory.Stream = stream; runFactory.FilePath = filePath; var imported = runFactory.Create(comparisonGeneratorsFactory); var comparisonName = Path.GetFileNameWithoutExtension(splitDialog.FileName); result = InputBox.Show(form, "Enter Comparison Name", "Name:", ref comparisonName); if (result != DialogResult.Cancel) return run.AddComparisonWithNameInput(imported, comparisonName, form); } } return null; }
private static IRun LoadRunFromURL(string url, Form form = null) { try { var runFactory = new StandardFormatsRunFactory(); var comparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory(); var uri = new Uri(url); var host = uri.Host.ToLowerInvariant(); if (host == "splits.io") { return SplitsIO.Instance.DownloadRunByUri(uri, true); } if (host == "www.speedrun.com" || host == "speedrun.com") { var speedrunComRun = SpeedrunCom.Client.Runs.GetRunFromSiteUri(url); if (speedrunComRun != null && speedrunComRun.SplitsAvailable) { var run = speedrunComRun.GetRun(); run.PatchRun(speedrunComRun); return run; } } var request = WebRequest.Create(uri); using (var response = request.GetResponse()) using (var stream = response.GetResponseStream()) using (var memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); runFactory.Stream = memoryStream; runFactory.FilePath = null; try { return runFactory.Create(comparisonGeneratorsFactory); } catch (Exception ex) { Log.Error(ex); MessageBox.Show(form, "The selected file was not recognized as a splits file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { Log.Error(ex); MessageBox.Show(form, "The splits file couldn't be downloaded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return null; }
private IRun LoadRunFromURL(string url, Form form = null) { try { var runFactory = new StandardFormatsRunFactory(); var comparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory(); var uri = new Uri(url); if (uri.Host.ToLowerInvariant() == "splits.io" && uri.LocalPath.Length > 0 && !uri.LocalPath.Substring(1).Contains('/')) { uri = new Uri(string.Format("{0}/download/livesplit", url)); } if (uri.Host.ToLowerInvariant() == "ge.tt" && uri.LocalPath.Length > 0 && !uri.LocalPath.Substring(1).Contains('/')) { uri = new Uri(string.Format("http://ge.tt/api/1/files{0}/0/blob?download", uri.LocalPath)); } var request = WebRequest.Create(uri); using (var stream = request.GetResponse().GetResponseStream()) { using (var memoryStream = new MemoryStream()) { stream.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); runFactory.Stream = memoryStream; runFactory.FilePath = null; try { return runFactory.Create(comparisonGeneratorsFactory); } catch (Exception ex) { Log.Error(ex); MessageBox.Show(form, "The selected file was not recognized as a splits file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { Log.Error(ex); MessageBox.Show(form, "The splits file couldn't be downloaded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return null; }
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; }
private void SwitchComparisonGenerators() { var allGenerators = new StandardComparisonGeneratorsFactory().GetAllGenerators(CurrentState.Run); foreach (var generator in Settings.ComparisonGeneratorStates.Reverse()) { if (CurrentState.Run.ComparisonGenerators.Any(x => x.Name == generator.Key)) CurrentState.Run.ComparisonGenerators.Remove(CurrentState.Run.ComparisonGenerators.First(x => x.Name == generator.Key)); if (generator.Value == true) CurrentState.Run.ComparisonGenerators.Insert(0, allGenerators.First(x => x.Name == generator.Key)); } SwitchComparison(CurrentState.CurrentComparison); RegenerateComparisons(); }
private void Init(string splitsPath = null, string layoutPath = null) { SetWindowTitle(); SpeedrunCom.Authenticator = new SpeedrunComOAuthForm(); GlobalCache = new GraphicsCache(); Invalidator = new Invalidator(this); SetStyle(ControlStyles.SupportsTransparentBackColor, true); ComponentManager.BasePath = BasePath; SpeedRunsLiveAPI.Instance.RacesRefreshed += SRL_RacesRefreshed; SpeedRunsLiveAPI.Instance.RefreshRacesListAsync(); CurrentState = new LiveSplitState(null, this, null, null, null); ComparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory(); Model = new DoubleTapPrevention(new TimerModel()); RunFactory = new StandardFormatsRunFactory(); RunSaver = new XMLRunSaver(); LayoutSaver = new XMLLayoutSaver(); SettingsSaver = new XMLSettingsSaver(); LoadSettings(); UpdateRecentSplits(); UpdateRecentLayouts(); InTimerOnlyMode = false; var timerOnlyRun = new StandardRunFactory().Create(ComparisonGeneratorsFactory); IRun run = timerOnlyRun; try { if (!string.IsNullOrEmpty(splitsPath)) { run = LoadRunFromFile(splitsPath, TimingMethod.RealTime); } else if (Settings.RecentSplits.Count > 0) { var lastSplitFile = Settings.RecentSplits.Last(); if (!string.IsNullOrEmpty(lastSplitFile.Path)) { run = LoadRunFromFile(lastSplitFile.Path, lastSplitFile.LastTimingMethod); CurrentState.CurrentTimingMethod = lastSplitFile.LastTimingMethod; } } } catch (Exception e) { Log.Error(e); } run.FixSplits(); CurrentState.Run = run; CurrentState.Settings = Settings; try { if (!string.IsNullOrEmpty(layoutPath)) { Layout = LoadLayoutFromFile(layoutPath); } else { if (Settings.RecentLayouts.Count > 0 && !string.IsNullOrEmpty(Settings.RecentLayouts.Last())) { Layout = LoadLayoutFromFile(Settings.RecentLayouts.Last()); } else if (run == timerOnlyRun) { Layout = new TimerOnlyLayoutFactory().Create(CurrentState); InTimerOnlyMode = true; } else { Layout = new StandardLayoutFactory().Create(CurrentState); } } } catch (Exception e) { Log.Error(e); Layout = new StandardLayoutFactory().Create(CurrentState); } CurrentState.LayoutSettings = Layout.Settings; CreateAutoSplitter(); CurrentState.FixTimingMethodFromRuleset(); SwitchComparisonGenerators(); SwitchComparison(Settings.LastComparison); Model.CurrentState = CurrentState; CurrentState.OnReset += CurrentState_OnReset; CurrentState.OnStart += CurrentState_OnStart; CurrentState.OnSplit += CurrentState_OnSplit; CurrentState.OnSkipSplit += CurrentState_OnSkipSplit; CurrentState.OnUndoSplit += CurrentState_OnUndoSplit; CurrentState.OnPause += CurrentState_OnPause; CurrentState.OnResume += CurrentState_OnResume; CurrentState.OnSwitchComparisonPrevious += CurrentState_OnSwitchComparisonPrevious; CurrentState.OnSwitchComparisonNext += CurrentState_OnSwitchComparisonNext; ComponentRenderer = new ComponentRenderer(); StartPosition = FormStartPosition.Manual; SetLayout(Layout); RefreshTask = Task.Factory.StartNew(RefreshTimerWorker); InvalidationRequired = false; Hook = new CompositeHook(); Hook.KeyOrButtonPressed += hook_KeyOrButtonPressed; Settings.RegisterHotkeys(Hook); SizeChanged += TimerForm_SizeChanged; lock (BackBufferLock) { BackBuffer = new Bitmap(Width, Height); #if WITH_XSPLIT /*try { // Outputs a CosmoWright image every 50ms (20 FPS) XSplit = TimedBroadcasterPlugin.CreateInstance( "livesplit", BackBuffer, 50); if (this.XSplit != null) { // The correct version of XSplit was installed (unless they use OBS), so we can start our output. this.XSplit.StartTimer(); } } catch { }*/ #endif } TopMost = Layout.Settings.AlwaysOnTop; }
private void Init(String splitsPath = null, String layoutPath = null) { GlobalCache = new GraphicsCache(); Invalidator = new Invalidator(this); SetStyle(ControlStyles.SupportsTransparentBackColor, true); ComponentManager.BasePath = BasePath; SpeedRunsLiveAPI.Instance.RacesRefreshed += SRL_RacesRefreshed; SpeedRunsLiveAPI.Instance.RefreshRacesListAsync(); CurrentState = new LiveSplitState(null, null, null); ComparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory(); TimerOnlyLayout = new TimerOnlyLayoutFactory().Create(CurrentState); TimerOnlyRun = new StandardRunFactory().Create(ComparisonGeneratorsFactory); InTimerOnlyMode = false; Model = new TimerModel(); //LiveSplit.Web.Share.Twitch.Instance.AutoUpdateModel = Model; RunFactory = new StandardFormatsRunFactory(); RunSaver = new XMLRunSaver(); LayoutSaver = new XMLLayoutSaver(); SettingsSaver = new XMLSettingsSaver(); LoadSettings(); UpdateRecentSplits(); UpdateRecentLayouts(); IRun run = null; if (!String.IsNullOrEmpty(splitsPath)) { run = LoadRunFromFile(splitsPath, true); } else { try { run = LoadRunFromFile(Settings.RecentSplits.Last(), true); } catch (Exception e) { Log.Error(e); run = TimerOnlyRun; } } if (!String.IsNullOrEmpty(layoutPath)) { Layout = LoadLayoutFromFile(layoutPath); } else { try { Layout = LoadLayoutFromFile(Settings.RecentLayouts.Last()); } catch (Exception e) { Log.Error(e); if (run == TimerOnlyRun) { Layout = TimerOnlyLayout; InTimerOnlyMode = true; } else Layout = new StandardLayoutFactory().Create(CurrentState); } } CurrentState.Run = run; CurrentState.LayoutSettings = Layout.Settings; CurrentState.Settings = Settings; RegenerateComparisons(); SwitchComparison(Settings.LastComparison); Model.CurrentState = CurrentState; CurrentState.OnReset += CurrentState_OnReset; CurrentState.OnStart += CurrentState_OnStart; CurrentState.OnSplit += CurrentState_OnSplit; CurrentState.OnSkipSplit += CurrentState_OnSkipSplit; CurrentState.OnUndoSplit += CurrentState_OnUndoSplit; CurrentState.OnPause += CurrentState_OnPause; CurrentState.OnResume += CurrentState_OnResume; CurrentState.OnSwitchComparisonPrevious += CurrentState_OnSwitchComparisonPrevious; CurrentState.OnSwitchComparisonNext += CurrentState_OnSwitchComparisonNext; ComponentRenderer = new ComponentRenderer(); this.StartPosition = FormStartPosition.Manual; SetLayout(Layout); OldSize = -20; RefreshTimer = new System.Timers.Timer(25f); RefreshTimer.Elapsed += timer_Elapsed; RefreshTimer.Enabled = true; RefreshCounter = 0; RefreshesRemaining = 0; Hook = new CompositeHook(); Hook.KeyOrButtonPressed += hook_KeyOrButtonPressed; Settings.RegisterHotkeys(Hook); RegisterTaskbarButtons(); this.SizeChanged += TimerForm_SizeChanged; lock (BackBufferLock) { BackBuffer = new Bitmap(this.Width, this.Height); } this.TopMost = Layout.Settings.AlwaysOnTop; }