Exemplo n.º 1
0
        private void OnPromptChanged(object sender, EventArgs e)
        {
            var prompt           = m_updater.CurrentPrompt;
            var description      = m_updater.GameDescription;
            var customMessage    = m_updater.CustomMessage;
            var previousUsername = m_updater.PreviouslyEnteredUsername;
            var previousPassword = m_updater.PreviouslyEnteredPassword;

            Application.Invoke(delegate
            {
                if (prompt == GameUpdatePrompt.Username ||
                    prompt == GameUpdatePrompt.Password ||
                    prompt == GameUpdatePrompt.UsernameAndPassword)
                {
                    // Show credentials dialog
                    var dialog = new CredentialsDialog(
                        this,
                        (prompt != GameUpdatePrompt.Password) ?
                        ((previousUsername != null) ? previousUsername : "") :
                        null,
                        (prompt != GameUpdatePrompt.Username) ?
                        ((previousPassword != null) ? previousPassword : "") :
                        null
                        );
                    dialog.ShowAll();
                    int response    = dialog.Run();
                    string username = dialog.Username;
                    string password = dialog.Password;
                    dialog.Destroy();

                    // Inform the updater
                    if (response == (int)ResponseType.Close ||
                        response == (int)ResponseType.DeleteEvent)
                    {
                        m_updater.Cancel();
                        m_updater.AnswerPrompt(false);
                    }
                    else
                    {
                        m_updater.AnswerPrompt(
                            response == (int)ResponseType.Ok,
                            username,
                            password
                            );
                    }
                }
                else if (prompt == GameUpdatePrompt.CustomMessage)
                {
                    // Show message dialog
                    Console.WriteLine(customMessage);
                    var dialog = new MessageDialog(
                        this,
                        DialogFlags.Modal,
                        MessageType.Info,
                        ButtonsType.Ok,
                        customMessage
                        );
                    dialog.ShowAll();
                    int response = dialog.Run();
                    dialog.Destroy();

                    // Inform the updater
                    m_updater.AnswerPrompt(true);
                }
                else
                {
                    // Show question dialog
                    var dialog = new MessageDialog(
                        this,
                        DialogFlags.Modal,
                        MessageType.Question,
                        ButtonsType.YesNo,
                        prompt.GetQuestion(Program.Language, description)
                        );
                    dialog.ShowAll();
                    int response = dialog.Run();
                    dialog.Destroy();

                    // Inform the updater
                    if (response == (int)ResponseType.Close ||
                        response == (int)ResponseType.DeleteEvent)
                    {
                        m_updater.Cancel();
                        m_updater.AnswerPrompt(false);
                    }
                    else
                    {
                        m_updater.AnswerPrompt(response == (int)ResponseType.Yes);
                    }
                }
            });
        }
        private void OnPromptChanged( object sender, EventArgs e )
        {
            var prompt = m_updater.CurrentPrompt;
            var description = m_updater.GameDescription;
            var customMessage = m_updater.CustomMessage;
            var previousUsername = m_updater.PreviouslyEnteredUsername;
            var previousPassword = m_updater.PreviouslyEnteredPassword;
            Application.Invoke( delegate
            {
                if( prompt == GameUpdatePrompt.Username ||
                    prompt == GameUpdatePrompt.Password ||
                    prompt == GameUpdatePrompt.UsernameAndPassword )
                {
                    // Show credentials dialog
                    var dialog = new CredentialsDialog(
                        this,
                        (prompt != GameUpdatePrompt.Password) ?
                            ((previousUsername != null) ? previousUsername : "") :
                            null,
                        (prompt != GameUpdatePrompt.Username) ?
                            ((previousPassword != null) ? previousPassword : "") :
                            null
                    );
                    dialog.ShowAll();
                    int response = dialog.Run();
                    string username = dialog.Username;
                    string password = dialog.Password;
                    dialog.Destroy();

                    // Inform the updater
                    if( response == (int)ResponseType.Close ||
                        response == (int)ResponseType.DeleteEvent )
                    {
                        m_updater.Cancel();
                        m_updater.AnswerPrompt( false );
                    }
                    else
                    {
                        m_updater.AnswerPrompt(
                            response == (int)ResponseType.Ok,
                            username,
                            password
                        );
                    }
                }
                else if( prompt == GameUpdatePrompt.CustomMessage )
                {
                    // Show message dialog
                    Console.WriteLine( customMessage );
                    var dialog = new MessageDialog(
                        this,
                        DialogFlags.Modal,
                        MessageType.Info,
                        ButtonsType.Ok,
                        customMessage
                    );
                    dialog.ShowAll();
                    int response = dialog.Run();
                    dialog.Destroy();

                    // Inform the updater
                    m_updater.AnswerPrompt( true );
                }
                else
                {
                    // Show question dialog
                    var dialog = new MessageDialog(
                        this,
                        DialogFlags.Modal,
                        MessageType.Question,
                        ButtonsType.YesNo,
                        prompt.GetQuestion( Program.Language, description )
                    );
                    dialog.ShowAll();
                    int response = dialog.Run();
                    dialog.Destroy();

                    // Inform the updater
                    if( response == (int)ResponseType.Close ||
                        response == (int)ResponseType.DeleteEvent )
                    {
                        m_updater.Cancel();
                        m_updater.AnswerPrompt( false );
                    }
                    else
                    {
                        m_updater.AnswerPrompt( response == (int)ResponseType.Yes );
                    }
                }
            } );
        }