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; } }
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); }
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); } }
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 bool builtIn = IsBuiltInEffect(effect); if (builtIn) { // 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"); EventHandler auxButtonClickHandler = delegate(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(); } } } }