public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
        {
            if ((Settings.ScriptPath != OldScriptPath && !String.IsNullOrEmpty(Settings.ScriptPath)) || DoReload)
            {
                Script = ASLParser.Parse(File.ReadAllText(Settings.ScriptPath));
                OldScriptPath = Settings.ScriptPath;
                FSWatcher.Path = Path.GetDirectoryName(Settings.ScriptPath);
                FSWatcher.Filter = Path.GetFileName(Settings.ScriptPath);
                FSWatcher.EnableRaisingEvents = true;
                DoReload = false;
            }

            if (Script != null)
                Script.Update(state);
        }
        protected void UpdateScript(LiveSplitState state)
        {
            // this is ugly, fix eventually!
            if (Settings.ScriptPath != OldScriptPath && !string.IsNullOrEmpty(Settings.ScriptPath) || DoReload)
            {
                try
                {
                    DoReload = false;
                    OldScriptPath = Settings.ScriptPath;
                    FSWatcher.Path = Path.GetDirectoryName(Settings.ScriptPath);
                    FSWatcher.Filter = Path.GetFileName(Settings.ScriptPath);
                    FSWatcher.EnableRaisingEvents = true;
                    if (Script != null)
                        Script.RefreshRateChanged -= Script_RefreshRateChanged;
                    Script = ASLParser.Parse(File.ReadAllText(Settings.ScriptPath));
                    Script.RefreshRateChanged += Script_RefreshRateChanged;
                    Script_RefreshRateChanged(this, Script.RefreshRate);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
            }

            if (Script != null)
            {
                try
                {
                    Script.RunUpdate(state);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
            }
        }
        private void ScriptCleanup()
        {
            if (_script == null)
                return;

            try
            {
                _script.RunShutdown(_state);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
            finally
            {
                _script.Dispose();
                _settings.SetGameVersion(null);
                _settings.SetASLSettings(new ASLSettings());

                // Script should no longer be used, even in case of error
                // (which the ASL shutdown method may contain)
                _script = null;
            }
        }
        private void LoadScript()
        {
            Trace.WriteLine("[ASL] Loading new script: " + _settings.ScriptPath);

            _fs_watcher.Path = Path.GetDirectoryName(_settings.ScriptPath);
            _fs_watcher.Filter = Path.GetFileName(_settings.ScriptPath);
            _fs_watcher.EnableRaisingEvents = true;

            // New script
            _script = ASLParser.Parse(File.ReadAllText(_settings.ScriptPath));

            _script.RefreshRateChanged += (sender, rate) => _update_timer.Interval = (int)Math.Round(1000 / rate);
            _update_timer.Interval = (int)Math.Round(1000 / _script.RefreshRate);

            _script.GameVersionChanged += (sender, version) => _settings.SetGameVersion(version);
            _settings.SetGameVersion(null);

            // Give custom ASL settings to GUI, which populates the list and
            // stores the ASLSetting objects which are shared between the GUI
            // and ASLScript
            try
            {
                ASLSettings settings = _script.RunStartup(_state);
                _settings.SetASLSettings(settings);
            }
            catch (Exception ex)
            {
                // Script already created, but startup failed, so clean up again
                Log.Error(ex);
                ScriptCleanup();
            }
        }