コード例 #1
0
        protected override void OnMainFormClosed(object sender, EventArgs e)
        {
            // Action was NEW PROFILE: check if valid, if not exit
            if (sender is LanguageSelector)
            {
                if (_profileManager.Profile != null) // Profile creation succesful
                {
                    IBoxForm boxForm = _container.Resolve <IBoxForm>();
                    Pandora.BoxForm = boxForm;
                    MainForm        = boxForm as Form;
                    MainForm.Show();
                    return;
                }
                else
                {
                    Pandora.Log.WriteError(null, "Profile creation aborted");
                }
            }

            // PROFILE CHOOSER: exit/new profile/load profile
            if (sender is ProfileChooser)
            {
                ProfileChooser chooser = sender as ProfileChooser;

                switch (chooser.Action)
                {
                case ProfileChooser.Actions.Exit:
                    break;

                case ProfileChooser.Actions.LoadProfile:
                    if (chooser.UseDefault)
                    {
                        _profileManager.DefaultProfile = chooser.SelectedProfile;
                    }
                    LoadProfile(chooser.SelectedProfile);
                    return;

                case ProfileChooser.Actions.MakeNewProfile:
                    MakeNewProfile();
                    return;
                }
            }

            if (sender is IBoxForm)
            {
                string next = (sender as IBoxForm).NextProfile;

                if (next != null)
                {
                    LoadProfile(next);
                    return;
                }
            }

            base.OnMainFormClosed(sender, e);
        }
コード例 #2
0
        /// <summary>
        /// Loads a profile
        /// Should be part of the profile manager and need a return value
        /// </summary>
        /// <param name="name">The name of the profile</param>
        private void LoadProfile(string name)
        {
            _splash.SetStatusText("Loading profile");

            try
            {
                _profileManager.LoadProfile(name);
            }
            catch (Exception err)
            {
                Pandora.Log.WriteError(err, "Couldn't load profile {0}", name);

                if (name == _profileManager.DefaultProfile)
                {
                    _profileManager.DefaultProfile = "";
                }

                DoProfile();
                return;
            }

            if (_profileManager.Profile == null)
            {
                string msg = string.Format("The profile {0} is corrupt, therefore it can't be loaded. Would you like to attempt to restore it?", name);

                if (MessageBox.Show(null, msg, "Profile Error", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Profile p = new Profile();
                    p.Name = name;
                    p.Save();
                    LoadProfile(name);
                }
                else
                {
                    DoProfile();
                }
                return;
            }

            try
            {
                // To Test show the new form

                /*
                 * // Should be handled through the LightCoreBuilder
                 * // Uncomment to get a first preview of the new form
                 * BoxForm newBoxForm = new BoxForm();
                 * Pandora.Localization.LocalizeControl(_newBoxForm);
                 * newBoxForm.Show();
                 */

                IBoxForm boxForm = _container.Resolve <IBoxForm>();
                Pandora.BoxForm = boxForm;
                MainForm        = boxForm as Form;
                MainForm.Show();
            }
            catch (Exception err)
            {
                Pandora.Log.WriteError(err, string.Format("Profile {0} failed.", name));
                // Issue 6:      Improve error management - Tarion
                // Application.Exit(); Did not worked correctly
                // We could use:  Environment.Exit(1);
                // But better forward the exception to the main function an cancel program there
                throw err;
                // End Issue 6
            }
        }