public override void Entry(IModHelper helper)
        {
            this.config = this.Helper.ReadConfig <ModUpdateMenuConfig>();
            this.button = new UpdateButton(helper);
            this.menu   = new UpdateMenu();

            GameEvents.UpdateTick            += this.GameEvents_UpdateTick;
            GraphicsEvents.OnPostRenderEvent += this.GraphicsEvents_OnPostRenderHudEvent;
            InputEvents.ButtonPressed        += this.InputEvents_ButtonPressed;

            new Thread(() =>
            {
                IUpdateStatusRetriever statusRetriever = new UpdateStatusRetriever(this.Helper);
                int attempts = 50;
                while (true)
                {
                    Thread.Sleep(1000);
                    try
                    {
                        if (statusRetriever.GetUpdateStatuses(out IList <ModStatus> statuses))
                        {
                            if (this.currentStatuses != null && this.currentStatuses.Count == statuses.Count)
                            {
                                this.Notify(statuses);

                                try
                                {
                                    this.NotifySMAPI(statusRetriever.GetSMAPIUpdateVersion());
                                }
                                catch
                                {
                                    this.NotifySMAPI(null);
                                }


                                break;
                            }
                            else
                            {
                                this.currentStatuses = statuses;
                            }
                        }

                        attempts--;
                        if (attempts == 0)
                        {
                            throw new Exception("All update attempts failed.");
                        }
                    }
                    catch (Exception e)
                    {
                        this.Monitor.Log("Failed retrieving update info from SMAPI: ", LogLevel.Debug);
                        this.Monitor.Log(e.ToString(), LogLevel.Debug);
                        this.Notify(null);
                        this.NotifySMAPI(null);
                        break;
                    }
                }
            }).Start();
        }
Exemple #2
0
        /// <summary>Raised after the game is launched, right before the first update tick. </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnGameLaunched(object sender, GameLaunchedEventArgs e)
        {
            this.menu = new UpdateMenu();
            new Thread(() =>
            {
                IUpdateStatusRetriever statusRetriever = new UpdateStatusRetriever(this.Helper);
                int attempts = 50;
                while (true)
                {
                    Thread.Sleep(1000);
                    try
                    {
                        if (statusRetriever.GetUpdateStatuses(out IList <ModStatus> statuses))
                        {
                            if (this.currentStatuses != null && this.currentStatuses.Count == statuses.Count)
                            {
                                this.Notify(statuses);

                                try
                                {
                                    this.NotifySMAPI(statusRetriever.GetSMAPIUpdateVersion());
                                }
                                catch
                                {
                                    this.NotifySMAPI(null);
                                }


                                break;
                            }
                            else
                            {
                                this.currentStatuses = statuses;
                            }
                        }

                        attempts--;
                        if (attempts == 0)
                        {
                            throw new Exception("All update attempts failed.");
                        }
                    }
                    catch (Exception ex)
                    {
                        this.Monitor.Log("Failed retrieving update info from SMAPI: ", LogLevel.Debug);
                        this.Monitor.Log(ex.ToString(), LogLevel.Debug);
                        this.Notify(null);
                        this.NotifySMAPI(null);
                        break;
                    }
                }
            }).Start();
        }