Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        void TimerElapsed()
        {
            try
            {
                this.InvokeIfRequired(() =>
                {
                    try
                    {
                        if (Hook != null)
                            Hook.Poll();

                        if (CurrentState.Run.IsAutoSplitterActive())
                            CurrentState.Run.AutoSplitter.Component.Update(null, CurrentState, 0, 0, Layout.Mode);

                        if (DontRedraw)
                            return;

                        if (OldSize <= 0 || InvalidationRequired)
                        {
                            InvalidateForm();
                            if (InvalidationRequired)
                                InvalidationRequired = false;
                        }
                        else
                        {
                            GlobalCache.Restart();
                            GlobalCache["LayoutHashCode"] = new XMLLayoutSaver().CreateLayoutNode(null, null, Layout);

                            if (GlobalCache.HasChanged)
                                InvalidateForm();
                            else
                            {
                                Invalidator.Restart();

                                this.InvokeIfRequired(() =>
                                {
                                    try
                                    {
                                        ComponentRenderer.Update(Invalidator, CurrentState, Width, Height, Layout.Mode);
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error(ex);
                                        Invalidate();
                                    }
                                });
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                        Invalidate();
                    }
                });
            }
            catch (Exception ex)
            {
                if (!(IsDisposed && ex is ObjectDisposedException))
                {
                    Log.Error(ex);
                    Invalidate();
                }
            }
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            var timer = (System.Timers.Timer)sender;

            try
            {
                timer.Enabled = false;

                Action timerAction = () =>
                {
                    try
                    {
                        if (Hook != null)
                            Hook.Poll();

                        if (DontRedraw)
                            return;

                        RefreshCounter++;

                        /*if (!CurrentState.DrawLock.TryEnterReadLock(500))
                            return;*/

                        if (OldSize <= 0 || (RefreshesRemaining > 0 && RefreshCounter >= 5))
                        {
                            InvalidateForm();
                            RefreshCounter = 0;
                            if (RefreshesRemaining > 0)
                                RefreshesRemaining--;
                        }
                        else
                        {
                            GlobalCache.Restart();
                            GlobalCache["Layout"] = new XMLLayoutSaver().GetLayoutNode(new XmlDocument(), Layout).OuterXml;

                            if (GlobalCache.HasChanged || OldSize <= 0)
                                InvalidateForm();
                            else
                            {
                                Invalidator.Restart();
                                Action x = () =>
                                {
                                    try
                                    {
                                        ComponentRenderer.Update(Invalidator, CurrentState, this.Width, this.Height, Layout.Mode);
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error(ex);
                                        this.Invalidate();
                                    }
                                };

                                if (InvokeRequired)
                                    Invoke(x);
                                else
                                    x();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                        this.Invalidate();
                    }
                };

                if (InvokeRequired)
                    Invoke(timerAction);
                else
                    timerAction();
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                this.Invalidate();
            }
            finally
            {
                timer.Enabled = true;
            }
            //CurrentState.DrawLock.ExitReadLock();
        }
Ejemplo n.º 5
0
        void TimerElapsed()
        {
            try
            {
                Action timerAction = () =>
                {
                    try
                    {
                        if (Hook != null)
                            Hook.Poll();

                        if (CurrentState.Run.IsAutoSplitterActive())
                            CurrentState.Run.AutoSplitter.Component.Update(null, CurrentState, 0, 0, Layout.Mode);

                        if (DontRedraw)
                            return;

                        if (OldSize <= 0 || (RefreshCounter > 0 && RefreshCounter % 5 == 0))
                        {
                            InvalidateForm();
                            if (RefreshCounter > 0)
                                RefreshCounter--;
                        }
                        else
                        {
                            GlobalCache.Restart();
                            GlobalCache["Layout"] = new XMLLayoutSaver().GetLayoutNode(new XmlDocument(), Layout).OuterXml;

                            if (GlobalCache.HasChanged || OldSize <= 0)
                                InvalidateForm();
                            else
                            {
                                Invalidator.Restart();
                                Action x = () =>
                                {
                                    try
                                    {
                                        ComponentRenderer.Update(Invalidator, CurrentState, Width, Height, Layout.Mode);
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error(ex);
                                        Invalidate();
                                    }
                                };

                                if (InvokeRequired)
                                    Invoke(x);
                                else
                                    x();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                        Invalidate();
                    }
                };

                if (InvokeRequired)
                    Invoke(timerAction);
                else
                    timerAction();
            }
            catch (Exception ex)
            {
                if (!(this.IsDisposed && ex is ObjectDisposedException))
                {
                    Log.Error(ex);
                    Invalidate();
                }
            }
        }