private void DrawUpdater()
        {
            //Draw updating text and show progress bar...

            if (updateBatch == null)
            {
                updateBatch = new SpriteBatch(GraphicsDevice);
            }

            updateBatch.Begin(SpriteSortMode.Immediate);

            //Default Window Size is 800x480
            if (updaterBackground != null)
            {
                updateBatch.Draw(
                    updaterBackground, new Rectangle(0, 0, 800, 480),
                    new Rectangle?(new Rectangle(0, 0, updaterBackground.Width, updaterBackground.Height)),
                    Microsoft.Xna.Framework.Color.White
                    );
            }

            var status          = "";
            var progressPercent = 0f;
            var progress        = "";
            var filesRemaining  = "";
            var sizeRemaining   = "";

            switch (mUpdater.Status)
            {
            case UpdateStatus.Checking:
                status = Strings.Update.Checking;
                break;

            case UpdateStatus.Updating:
                status          = Strings.Update.Updating;
                progressPercent = mUpdater.Progress / 100f;
                progress        = Strings.Update.Percent.ToString((int)mUpdater.Progress);
                filesRemaining  = mUpdater.FilesRemaining + " Files Remaining";
                sizeRemaining   = mUpdater.GetHumanReadableFileSize(mUpdater.SizeRemaining) + " Left";
                break;

            case UpdateStatus.Restart:
                status          = Strings.Update.Restart.ToString(Strings.Main.gamename);
                progressPercent = 100;
                progress        = Strings.Update.Percent.ToString(100);
                break;

            case UpdateStatus.Done:
                status          = Strings.Update.Done;
                progressPercent = 100;
                progress        = Strings.Update.Percent.ToString(100);
                break;

            case UpdateStatus.Error:
                status          = Strings.Update.Error;
                progress        = mUpdater.Exception?.Message ?? "";
                progressPercent = 100;
                break;

            case UpdateStatus.None:
                //Nothing here!
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (updaterFont != null)
            {
                var size = updaterFont.MeasureString(status);
                updateBatch.DrawString(
                    updaterFont, status, new Vector2(800 / 2 - size.X / 2, 360),
                    Microsoft.Xna.Framework.Color.White
                    );
            }

            //Bar will exist at 400 to 432
            if (updaterProgressBar != null)
            {
                updateBatch.Draw(
                    updaterProgressBar, new Rectangle(100, 400, (int)(600 * progressPercent), 32),
                    new Rectangle?(new Rectangle(0, 0, (int)(updaterProgressBar.Width * progressPercent), updaterProgressBar.Height)),
                    Microsoft.Xna.Framework.Color.White
                    );
            }

            //Bar will be 600 pixels wide
            if (updaterFontSmall != null)
            {
                //Draw % in center of bar
                var size = updaterFontSmall.MeasureString(progress);
                updateBatch.DrawString(
                    updaterFontSmall, progress, new Vector2(800 / 2 - size.X / 2, 405),
                    Microsoft.Xna.Framework.Color.White
                    );

                //Draw files remaining on bottom left
                updateBatch.DrawString(
                    updaterFontSmall, filesRemaining, new Vector2(100, 440),
                    Microsoft.Xna.Framework.Color.White
                    );

                //Draw total remaining on bottom right
                size = updaterFontSmall.MeasureString(sizeRemaining);
                updateBatch.DrawString(
                    updaterFontSmall, sizeRemaining, new Vector2(700 - size.X, 440),
                    Microsoft.Xna.Framework.Color.White
                    );
            }

            updateBatch.End();
        }
Ejemplo n.º 2
0
        private void tmrUpdate_Tick(object sender, EventArgs e)
        {
            if (mUpdater != null)
            {
                progressBar.Style = mUpdater.Status == UpdateStatus.Checking
                    ? ProgressBarStyle.Marquee
                    : ProgressBarStyle.Continuous;

                switch (mUpdater.Status)
                {
                case UpdateStatus.Checking:
                    lblStatus.Text = Strings.Update.Checking;
                    break;

                case UpdateStatus.Updating:
                    lblFiles.Show();
                    lblSize.Show();
                    lblFiles.Text     = Strings.Update.Files.ToString(mUpdater.FilesRemaining);
                    lblSize.Text      = Strings.Update.Size.ToString(mUpdater.GetHumanReadableFileSize(mUpdater.SizeRemaining));
                    lblStatus.Text    = Strings.Update.Updating.ToString((int)mUpdater.Progress);
                    progressBar.Value = (int)mUpdater.Progress;
                    break;

                case UpdateStatus.Restart:
                    lblFiles.Hide();
                    lblSize.Hide();
                    progressBar.Value = 100;
                    lblStatus.Text    = Strings.Update.Restart.ToString();
                    tmrUpdate.Enabled = false;
                    Process.Start(
                        Environment.GetCommandLineArgs()[0],
                        Environment.GetCommandLineArgs().Length > 1
                                ? string.Join(" ", Environment.GetCommandLineArgs().Skip(1))
                                : null
                        );

                    this.Close();

                    break;

                case UpdateStatus.Done:
                    lblFiles.Hide();
                    lblSize.Hide();
                    progressBar.Value = 100;
                    lblStatus.Text    = Strings.Update.Done;
                    tmrUpdate.Enabled = false;
                    Hide();
                    Globals.LoginForm.Show();
                    break;

                case UpdateStatus.Error:
                    lblFiles.Hide();
                    lblSize.Hide();
                    progressBar.Value = 100;
                    lblStatus.Text    = Strings.Update.Error.ToString(mUpdater.Exception?.Message ?? "");
                    break;

                case UpdateStatus.None:
                    lblFiles.Hide();
                    lblSize.Hide();
                    tmrUpdate.Enabled = false;
                    Hide();
                    Globals.LoginForm.Show();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }