/// <summary> /// Restarts Chummer5a. /// </summary> /// <param name="strText">Text to display in the prompt to restart. If empty, no prompt is displayed.</param> public static void RestartApplication(string strText = "Message_Options_Restart") { if (!string.IsNullOrEmpty(strText)) { string text = LanguageManager.GetString(strText); string caption = LanguageManager.GetString("MessageTitle_Options_CloseForms"); if (MessageBox.Show(text, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } // Need to do this here in case filenames are changed while closing forms (because a character who previously did not have a filename was saved when prompted) // Cannot use foreach because saving a character as created removes the current form and adds a new one for (int i = 0; i < GlobalOptions.MainForm.OpenCharacterForms.Count; ++i) { CharacterShared objOpenCharacterForm = GlobalOptions.MainForm.OpenCharacterForms[i]; if (objOpenCharacterForm.IsDirty) { string strCharacterName = objOpenCharacterForm.CharacterObject.Alias; if (string.IsNullOrWhiteSpace(strCharacterName)) { strCharacterName = LanguageManager.GetString("String_UnnamedCharacter"); } DialogResult objResult = MessageBox.Show(LanguageManager.GetString("Message_UnsavedChanges").Replace("{0}", strCharacterName), LanguageManager.GetString("MessageTitle_UnsavedChanges"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (objResult == DialogResult.Yes) { // Attempt to save the Character. If the user cancels the Save As dialogue that may open, cancel the closing event so that changes are not lost. bool blnResult = objOpenCharacterForm.SaveCharacter(); if (!blnResult) { return; } // We saved a character as created, which closed the current form and added a new one // This works regardless of dispose, because dispose would just set the objOpenCharacterForm pointer to null, so OpenCharacterForms would never contain it else if (!GlobalOptions.MainForm.OpenCharacterForms.Contains(objOpenCharacterForm)) { i -= 1; } } else if (objResult == DialogResult.Cancel) { return; } } } Log.Info("Restart Chummer"); GlobalOptions.MainForm.Cursor = Cursors.WaitCursor; // Get the parameters/arguments passed to program if any string arguments = string.Empty; foreach (Character objOpenCharacter in GlobalOptions.MainForm.OpenCharacters) { arguments += "\"" + objOpenCharacter.FileName + "\" "; } arguments = arguments.Trim(); // Restart current application, with same arguments/parameters foreach (Form objForm in GlobalOptions.MainForm.MdiChildren) { objForm.Close(); } ProcessStartInfo startInfo = new ProcessStartInfo { FileName = Application.StartupPath + "\\" + AppDomain.CurrentDomain.FriendlyName, Arguments = arguments }; Application.Exit(); Process.Start(startInfo); }
/// <summary> /// Restarts Chummer5a. /// </summary> /// <param name="strLanguage">Language in which to display any prompts or warnings.</param> /// <param name="strText">Text to display in the prompt to restart. If empty, no prompt is displayed.</param> public static void RestartApplication(string strLanguage, string strText) { if (!string.IsNullOrEmpty(strText)) { string text = LanguageManager.GetString(strText, strLanguage); string caption = LanguageManager.GetString("MessageTitle_Options_CloseForms", strLanguage); if (Program.MainForm.ShowMessageBox(text, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } // Need to do this here in case file names are changed while closing forms (because a character who previously did not have a filename was saved when prompted) // Cannot use foreach because saving a character as created removes the current form and adds a new one for (int i = 0; i < Program.MainForm.OpenCharacterForms.Count; ++i) { CharacterShared objOpenCharacterForm = Program.MainForm.OpenCharacterForms[i]; if (objOpenCharacterForm.IsDirty) { string strCharacterName = objOpenCharacterForm.CharacterObject.CharacterName; DialogResult objResult = Program.MainForm.ShowMessageBox(string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("Message_UnsavedChanges", strLanguage), strCharacterName), LanguageManager.GetString("MessageTitle_UnsavedChanges", strLanguage), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (objResult == DialogResult.Yes) { // Attempt to save the Character. If the user cancels the Save As dialogue that may open, cancel the closing event so that changes are not lost. bool blnResult = objOpenCharacterForm.SaveCharacter(); if (!blnResult) { return; } // We saved a character as created, which closed the current form and added a new one // This works regardless of dispose, because dispose would just set the objOpenCharacterForm pointer to null, so OpenCharacterForms would never contain it else if (!Program.MainForm.OpenCharacterForms.Contains(objOpenCharacterForm)) { i -= 1; } } else if (objResult == DialogResult.Cancel) { return; } } } Log.Info("Restart Chummer"); Application.UseWaitCursor = true; // Get the parameters/arguments passed to program if any StringBuilder sbdArguments = new StringBuilder(); foreach (CharacterShared objOpenCharacterForm in Program.MainForm.OpenCharacterForms) { sbdArguments.Append('\"').Append(objOpenCharacterForm.CharacterObject.FileName).Append("\" "); } if (sbdArguments.Length > 0) { sbdArguments.Length -= 1; } // Restart current application, with same arguments/parameters foreach (Form objForm in Program.MainForm.MdiChildren) { objForm.Close(); } ProcessStartInfo startInfo = new ProcessStartInfo { FileName = GetStartupPath + Path.DirectorySeparatorChar + AppDomain.CurrentDomain.FriendlyName, Arguments = sbdArguments.ToString() }; Application.Exit(); Process.Start(startInfo); }