Example #1
0
        void IUpdatesServiceHost.CloseAllWorkspaces(out bool cancelled)
        {
            CloseAllWorkspacesAction performMe = new CloseAllWorkspacesAction();

            this.appWorkspace.PerformAction(performMe);
            cancelled = performMe.Cancelled;
        }
Example #2
0
        public void Finish(AppWorkspace appWorkspace)
        {
            // Assumes we are running in the main UI thread

            if (this.finishing)
            {
                return;
            }

            try
            {
                if (this.haveFinished)
                {
                    throw new ApplicationException("already called Finish()");
                }

                this.finishing    = true;
                this.haveFinished = true;

                // Verify the update's signature
                bool verified = Security.VerifySignedFile(StateMachine.UIContext, this.installerPath, true, false);
                CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction();
                appWorkspace.PerformAction(cawa);

                if (verified && !cawa.Cancelled)
                {
                    // we're in the clear, launch the update!
                    Settings.CurrentUser.SetString(PdnSettings.UpdateMsiFileName, this.installerPath);

                    if (0 == string.Compare(Path.GetExtension(this.installerPath), ".exe", true))
                    {
                        const string arguments = "/skipConfig";
                        Shell.Execute(appWorkspace, this.installerPath, arguments, true, Shell.ExecuteWaitType.RelaunchPdnOnExit);
                        Startup.CloseApplication();
                    }
                    else
                    {
                    }
                }
                else
                {
                    try
                    {
                        File.Delete(this.installerPath);
                    }

                    catch (Exception)
                    {
                    }
                }
            }

            finally
            {
                this.finishing = false;
            }
        }
Example #3
0
        private void OnLanguageChangedFromSettingsDialog(CultureInfo oldLanguage)
        {
            CultureInfo parent    = AppSettings.Instance.UI.Language.Value;
            Icon        icon      = PdnResources.GetImageResource("Icons.MenuUtilitiesLanguageIcon.png").Reference.ToIcon();
            string      str       = PdnResources.GetString("ConfirmLanguageDialog.Title");
            Image       image     = null;
            string      str2      = PdnResources.GetString("ConfirmLanguageDialog.IntroText");
            Image       reference = PdnResources.GetImageResource("Icons.RightArrowBlue.png").Reference;
            string      format    = PdnResources.GetString("ConfirmLanguageDialog.RestartTB.ExplanationText.Format");
            CultureInfo info2     = new CultureInfo("en-US");

            if (parent.Equals(info2))
            {
                parent = parent.Parent;
            }
            string     nativeName      = parent.NativeName;
            string     explanationText = string.Format(format, nativeName);
            TaskButton button          = new TaskButton(reference, PdnResources.GetString("ConfirmLanguageDialog.RestartTB.ActionText"), explanationText);
            TaskButton button2         = new TaskButton(PdnResources.GetImageResource("Icons.CancelIcon.png").Reference, PdnResources.GetString("ConfirmLanguageDialog.CancelTB.ActionText"), PdnResources.GetString("ConfirmLanguageDialog.CancelTB.ExplanationText"));
            int        num             = (TaskDialog.DefaultPixelWidth96Dpi * 5) / 4;
            TaskDialog dialog2         = new TaskDialog {
                Icon                  = icon,
                Title                 = str,
                TaskImage             = image,
                ScaleTaskImageWithDpi = true,
                IntroText             = str2
            };

            dialog2.TaskButtons     = new TaskButton[] { button, button2 };
            dialog2.AcceptButton    = button;
            dialog2.CancelButton    = button2;
            dialog2.PixelWidth96Dpi = num;
            TaskDialog dialog = dialog2;

            if (dialog.Show(this.AppWorkspace) == button)
            {
                if (ShellUtil.IsActivityQueuedForRestart)
                {
                    MessageBoxUtil.ErrorBox(this.AppWorkspace, PdnResources.GetString("Effect.PluginErrorDialog.CantQueue2ndRestart"));
                }
                else
                {
                    CloseAllWorkspacesAction action = new CloseAllWorkspacesAction();
                    action.PerformAction(this.AppWorkspace);
                    if (!action.Cancelled)
                    {
                        ShellUtil.RestartApplication();
                        Startup.CloseApplication();
                    }
                }
            }
            else
            {
                AppSettings.Instance.UI.Language.Value = oldLanguage;
            }
        }
Example #4
0
        protected override void OnClosing(CancelEventArgs e)
        {
            if (!e.Cancel)
            {
                if (this.appWorkspace != null)
                {
                    CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction();
                    this.appWorkspace.PerformAction(cawa);
                    e.Cancel = cawa.Cancelled;
                }
            }

            if (!e.Cancel)
            {
                SaveSettings();

                if (this.floaters != null)
                {
                    foreach (Form hideMe in this.floaters)
                    {
                        hideMe.Hide();
                    }
                }

                this.Hide();

                if (this.queuedInstanceMessages != null)
                {
                    this.queuedInstanceMessages.Clear();
                }

                SingleInstanceManager sim2 = this.singleInstanceManager;
                SingleInstanceManager = null;

                if (sim2 != null)
                {
                    sim2.Dispose();
                    sim2 = null;
                }
            }

            base.OnClosing(e);
        }
Example #5
0
 protected override void OnClosing(CancelEventArgs e)
 {
     if ((!e.Cancel && (this.appWorkspace != null)) && !this.appWorkspace.IsDisposed)
     {
         CloseAllWorkspacesAction performMe = new CloseAllWorkspacesAction();
         this.appWorkspace.PerformAction(performMe);
         e.Cancel = performMe.Cancelled;
     }
     if (!e.Cancel)
     {
         if (base.Visible)
         {
             this.SaveSettings();
         }
         if (this.floatingToolForms != null)
         {
             FloatingToolForm[] floatingToolForms = this.floatingToolForms;
             for (int i = 0; i < floatingToolForms.Length; i++)
             {
                 floatingToolForms[i].Hide();
             }
         }
         base.Hide();
         if (this.queuedInstanceMessages != null)
         {
             this.queuedInstanceMessages.Clear();
         }
         PaintDotNet.SystemLayer.SingleInstanceManager singleInstanceManager = this.singleInstanceManager;
         this.SingleInstanceManager = null;
         if (singleInstanceManager != null)
         {
             singleInstanceManager.Dispose();
             singleInstanceManager = null;
         }
     }
     base.OnClosing(e);
 }
Example #6
0
        private void LanguageMenuItem_Click(object sender, EventArgs e)
        {
            // Save off the old locale name in case they decide to cancel
            string oldLocaleName = PdnResources.Culture.Name;

            // Now, apply the chosen language so that the confirmation buttons show up in the right language
            ToolStripMenuItem miwt          = (ToolStripMenuItem)sender;
            string            newLocaleName = (string)miwt.Tag;

            PdnResources.SetNewCulture(newLocaleName);

            // Load the text and buttons in the new language
            Icon   formIcon  = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuHelpLanguageIcon.png").Reference);
            string title     = PdnResources.GetString("ConfirmLanguageDialog.Title");
            Image  taskImage = null;
            string introText = PdnResources.GetString("ConfirmLanguageDialog.IntroText");

            Image       restartImage          = PdnResources.GetImageResource("Icons.RightArrowBlue.png").Reference;
            string      explanationTextFormat = PdnResources.GetString("ConfirmLanguageDialog.RestartTB.ExplanationText.Format");
            CultureInfo newCI = new CultureInfo(newLocaleName);

            // We prefer to show "English (United States)" as just "English"
            CultureInfo en_US = new CultureInfo("en-US");

            if (newCI.Equals(en_US))
            {
                newCI = newCI.Parent;
            }

            string languageName    = newCI.NativeName;
            string explanationText = string.Format(explanationTextFormat, languageName);

            TaskButton restartTB = new TaskButton(
                restartImage,
                PdnResources.GetString("ConfirmLanguageDialog.RestartTB.ActionText"),
                explanationText);

            Image      cancelImage = PdnResources.GetImageResource("Icons.CancelIcon.png").Reference;
            TaskButton cancelTB    = new TaskButton(
                cancelImage,
                PdnResources.GetString("ConfirmLanguageDialog.CancelTB.ActionText"),
                PdnResources.GetString("ConfirmLanguageDialog.CancelTB.ExplanationText"));

            int width96dpi = (TaskDialog.DefaultPixelWidth96Dpi * 5) / 4;

            TaskButton clickedTB = TaskDialog.Show(
                AppWorkspace,
                formIcon,
                title,
                taskImage,
                true,
                introText,
                new TaskButton[] { restartTB, cancelTB },
                restartTB,
                cancelTB,
                width96dpi);

            if (clickedTB == restartTB)
            {
                // Next, apply restart logic
                CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction();
                cawa.PerformAction(AppWorkspace);

                if (!cawa.Cancelled)
                {
                    SystemLayer.Shell.RestartApplication();
                    Startup.CloseApplication();
                }
            }
            else
            {
                // Revert to the old language
                PdnResources.SetNewCulture(oldLocaleName);
            }
        }
Example #7
0
        private void HandleEffectException(AppWorkspace appWorkspace, Effect effect, Exception ex)
        {
            try
            {
                AppWorkspace.Widgets.StatusBarProgress.ResetProgressStatusBar();
                AppWorkspace.Widgets.StatusBarProgress.EraseProgressStatusBar();
            }

            catch (Exception)
            {
            }

            // Figure out if it's a built-in effect, or a plug-in
            if (IsBuiltInEffect(effect))
            {
                // For built-in effects, tear down Paint.NET which will result in a crash log
                throw new ApplicationException("Effect threw an exception", ex);
            }
            else
            {
                Icon formIcon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.BugWarning.png").Reference);

                string formTitle = PdnResources.GetString("Effect.PluginErrorDialog.Title");

                Image taskImage = null;

                string introText = PdnResources.GetString("Effect.PluginErrorDialog.IntroText");

                TaskButton restartTB = new TaskButton(
                    PdnResources.GetImageResource("Icons.RightArrowBlue.png").Reference,
                    PdnResources.GetString("Effect.PluginErrorDialog.RestartTB.ActionText"),
                    PdnResources.GetString("Effect.PluginErrorDialog.RestartTB.ExplanationText"));

                TaskButton doNotRestartTB = new TaskButton(
                    PdnResources.GetImageResource("Icons.WarningIcon.png").Reference,
                    PdnResources.GetString("Effect.PluginErrorDialog.DoNotRestartTB.ActionText"),
                    PdnResources.GetString("Effect.PluginErrorDialog.DoNotRestartTB.ExplanationText"));

                string auxButtonText = PdnResources.GetString("Effect.PluginErrorDialog.AuxButton1.Text");

                void AuxButtonClickHandler(object sender, EventArgs e)
                {
                    using (PdnBaseForm textBoxForm = new PdnBaseForm())
                    {
                        textBoxForm.Name = "EffectCrash";

                        TextBox exceptionBox = new TextBox();

                        textBoxForm.Icon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.WarningIcon.png").Reference);
                        textBoxForm.Text = PdnResources.GetString("Effect.PluginErrorDialog.Title");

                        exceptionBox.Dock      = DockStyle.Fill;
                        exceptionBox.ReadOnly  = true;
                        exceptionBox.Multiline = true;

                        string exceptionText = AppWorkspace.GetLocalizedEffectErrorMessage(effect.GetType().Assembly, effect.GetType(), ex);

                        exceptionBox.Font       = new Font(FontFamily.GenericMonospace, exceptionBox.Font.Size);
                        exceptionBox.Text       = exceptionText;
                        exceptionBox.ScrollBars = ScrollBars.Vertical;

                        textBoxForm.StartPosition = FormStartPosition.CenterParent;
                        textBoxForm.ShowInTaskbar = false;
                        textBoxForm.MinimizeBox   = false;
                        textBoxForm.Controls.Add(exceptionBox);
                        textBoxForm.Width = UI.ScaleWidth(700);

                        textBoxForm.ShowDialog();
                    }
                }

                TaskButton clickedTB = TaskDialog.Show(
                    appWorkspace,
                    formIcon,
                    formTitle,
                    taskImage,
                    true,
                    introText,
                    new TaskButton[] { restartTB, doNotRestartTB },
                    restartTB,
                    doNotRestartTB,
                    TaskDialog.DefaultPixelWidth96Dpi * 2,
                    auxButtonText,
                    AuxButtonClickHandler);

                if (clickedTB == restartTB)
                {
                    // Next, apply restart logic
                    CloseAllWorkspacesAction cawa = new CloseAllWorkspacesAction();
                    cawa.PerformAction(appWorkspace);

                    if (!cawa.Cancelled)
                    {
                        SystemLayer.Shell.RestartApplication();
                        Startup.CloseApplication();
                    }
                }
            }
        }