示例#1
0
        /// <summary>
        /// Shows a <see cref="SaveFileDialog"/> allowing the user to enter or select a scenario
        /// section file to save to.</summary>
        /// <param name="section">
        /// A <see cref="ScenarioSection"/> value indicating the scenario section that the file
        /// represents.</param>
        /// <param name="file">
        /// The file initially selected in the dialog, relative to the current <see
        /// cref="FilePaths.CommonFolder"/>.</param>
        /// <returns>
        /// A <see cref="RootedPath"/> wrapping the absolute file path selected by the user, or an
        /// empty path if the user cancelled the dialog.</returns>
        /// <exception cref="InvalidEnumArgumentException">
        /// <paramref name="section"/> is not a valid <see cref="ScenarioSection"/> value.
        /// </exception>
        /// <remarks>
        /// The specified <paramref name="file"/> may be a null reference or an empty string to
        /// indicate that no file should be initially selected. The dialog initially shows the
        /// default folder for the specified <paramref name="section"/>, unless overriden by an
        /// absolute <paramref name="file"/> path.</remarks>

        public static RootedPath SaveSectionDialog(ScenarioSection section, string file)
        {
            string directory = FilePaths.GetSectionFolder(section);

            return(SaveDialog(Strings.TitleSectionSave, Strings.FilterSection,
                              1, "xml", FilePaths.CreateCommonPath(file), directory));
        }
示例#2
0
        /// <summary>
        /// Shows an <see cref="OpenFileDialog"/> allowing the user to select a file with a
        /// graphical tile set to open.</summary>
        /// <param name="file">
        /// The file initially selected in the dialog, relative to the current <see
        /// cref="FilePaths.CommonFolder"/>.</param>
        /// <returns>
        /// A <see cref="RootedPath"/> wrapping the absolute file path selected by the user, or an
        /// empty path if the user cancelled the dialog.</returns>
        /// <remarks><para>
        /// <b>OpenImageDialog</b> only allows the selection of existing files.
        /// </para><para>
        /// The specified <paramref name="file"/> may be a null reference or an empty string to
        /// indicate that no file should be initially selected. The dialog initially shows the
        /// default folder for the <see cref="ScenarioSection.Images"/> section, unless overriden by
        /// an absolute <paramref name="file"/> path.</para></remarks>

        public static RootedPath OpenImageDialog(string file)
        {
            string directory = FilePaths.GetSectionFolder(ScenarioSection.Images);

            return(OpenDialog(Strings.TitleImageOpen, Strings.FilterImage, "png",
                              FilePaths.CreateCommonPath(file), directory, false));
        }
示例#3
0
        /// <summary>
        /// Shows an <see cref="OpenFileDialog"/> allowing the user to enter or select a scenario
        /// section file to open.</summary>
        /// <param name="section">
        /// A <see cref="ScenarioSection"/> value indicating the scenario section that the file
        /// represents.</param>
        /// <param name="file">
        /// The file initially selected in the dialog, relative to the current <see
        /// cref="FilePaths.CommonFolder"/>.</param>
        /// <param name="create">
        /// <c>true</c> if the user may enter nonexistent file names; or <c>false</c> if the user
        /// may only select an existing file.</param>
        /// <returns>
        /// A <see cref="RootedPath"/> wrapping the absolute file path selected by the user, or an
        /// empty path if the user cancelled the dialog.</returns>
        /// <exception cref="InvalidEnumArgumentException">
        /// <paramref name="section"/> is not a valid <see cref="ScenarioSection"/> value.
        /// </exception>
        /// <remarks>
        /// The specified <paramref name="file"/> may be a null reference or an empty string to
        /// indicate that no file should be initially selected. The dialog initially shows the
        /// default folder for the specified <paramref name="section"/>, unless overriden by an
        /// absolute <paramref name="file"/> path.</remarks>

        public static RootedPath OpenSectionDialog(
            ScenarioSection section, string file, bool create)
        {
            string directory = FilePaths.GetSectionFolder(section);

            return(OpenDialog(Strings.TitleSectionOpen, Strings.FilterSection,
                              "xml", FilePaths.CreateCommonPath(file), directory, create));
        }
示例#4
0
        /// <summary>
        /// Handles the <see cref="Application.DispatcherUnhandledException"/> event.</summary>
        /// <param name="information">
        /// Information about the <see cref="Exception"/> and the current application state, or a
        /// null reference for no available information.</param>
        /// <param name="rulesFile">
        /// The file path to the current scenario rule script, or a null reference if no such file
        /// exists.</param>
        /// <param name="saveScenario">
        /// An optional <see cref="Action{String}"/> delegate that is invoked to save the current
        /// scenario data to an XML file.</param>
        /// <param name="saveSession">
        /// An optional <see cref="Action{String}"/> delegate that is invoked to save the current
        /// session data to an XML file.</param>
        /// <remarks><para>
        /// <b>OnUnhandledException</b> creates a text file describing the error which includes the
        /// specified <paramref name="information"/>. Additionally, up to two debug XML files
        /// containing scenario and session data are created by invoking any of the supplied <see
        /// cref="Action{String}"/> delegates that are not null references.
        /// </para><para>
        /// The user is also asked to e-mail all created files, plus the specified <paramref
        /// name="rulesFile"/> if it exists, to the e-mail address specified by the <see
        /// cref="ApplicationInfo.Email"/> property via Simple MAPI, or if this fails, to send basic
        /// error information to the same address using the Explorer "mailto" method.
        /// </para><para>
        /// Finally, <b>OnUnhandledException</b> terminates the application using <see
        /// cref="Environment.Exit"/> and returns an error code of -1.</para></remarks>

        public static void OnUnhandledException(string information, string rulesFile,
                                                Action <String> saveScenario, Action <String> saveSession)
        {
            // check for original distribution package
            bool original = ApplicationInfo.IsSigned;

            // determine error and debug file names
            string errorFile    = FilePaths.CreateUserPath("FatalError.txt").AbsolutePath;
            string scenarioFile = FilePaths.GetScenarioFile(ScenarioFileType.Debug).AbsolutePath;
            string sessionFile  = FilePaths.GetSessionFile(SessionFileType.Debug).AbsolutePath;

            // create an error e-mail?
            bool wantEmail = false;

            if (original)
            {
                // ask user to create e-mail with attachments
                string message = String.Format(ApplicationInfo.Culture,
                                               Strings.DialogFatalErrorOriginal, errorFile, scenarioFile, sessionFile);

                wantEmail = ShowFatalError(message, null, true);
            }
            else
            {
                // just notify user that files are being saved
                string message = String.Format(ApplicationInfo.Culture,
                                               Strings.DialogFatalErrorModified, errorFile, scenarioFile, sessionFile);

                ShowFatalError(message, null, false);
            }

            // create state information string
            StringBuilder info = new StringBuilder();

            info.AppendFormat("{0} ", ApplicationInfo.Signature);
            info.Append(Environment.NewLine);
            info.AppendFormat("Kynosarges Signature: {0}", original);
            info.Append(Environment.NewLine);
            info.AppendFormat("Public Key Token: {0}",
                              StringUtility.Validate(ApplicationInfo.PublicKeyToken));
            info.Append(Environment.NewLine);
            info.AppendFormat("Home: \"{0}\" ", FilePaths.ApplicationFolder);
            info.Append(Environment.NewLine);
            info.Append(Environment.NewLine);
            info.AppendFormat("{0} ", Environment.OSVersion);
            info.Append(Environment.NewLine);
            info.AppendFormat("{0} ", WindowsUtility.GetMemoryStatus());
            info.Append(Environment.NewLine);
            info.Append(Environment.NewLine);

            // append additional information if specified
            if (!String.IsNullOrEmpty(information))
            {
                info.AppendFormat("{0} ", information);
                info.Append(Environment.NewLine);
            }

            // create subject for e-mail message
            string subject = String.Concat(ApplicationInfo.Signature, " ", Strings.LabelError);

            // collection to hold file attachment data
            List <MapiAddress> files = new List <MapiAddress>();

            try {
                try {
                    // always create error information file
                    files.Add(new MapiAddress(Path.GetFileName(errorFile), errorFile));
                    using (StreamWriter writer = new StreamWriter(errorFile, false, Encoding.UTF8))
                        writer.WriteLine(info.ToString());

                    // attach rule script file if specified
                    RootedPath rulesPath = FilePaths.CreateCommonPath(rulesFile);
                    if (!rulesPath.IsEmpty && File.Exists(rulesPath.AbsolutePath))
                    {
                        files.Add(new MapiAddress(rulesPath.FileName, rulesPath.AbsolutePath));
                    }

                    // create scenario debug file if possible
                    if (saveScenario != null)
                    {
                        saveScenario(scenarioFile);
                        files.Add(new MapiAddress(Path.GetFileName(scenarioFile), scenarioFile));
                    }

                    // create session debug file if possible
                    if (saveSession != null)
                    {
                        saveSession(sessionFile);
                        files.Add(new MapiAddress(Path.GetFileName(sessionFile), sessionFile));
                    }
                }
                catch (Exception e) {
                    // only proceed if user wanted e-mail
                    if (wantEmail)
                    {
                        // ask user to try simpler e-mail format
                        wantEmail = ShowFatalError(Strings.DialogFatalErrorSaveMail, e, true);
                        throw; // rethrow to try mailto:
                    }

                    // user declined e-mail, just show error
                    ShowFatalError(Strings.DialogFatalErrorSave, e, false);
                    return; // quit, nothing else to do
                }

                // quit now if user declined e-mail
                if (!wantEmail)
                {
                    return;
                }

                try {
                    // address e-mail to application author
                    MapiAddress recipient = new MapiAddress(
                        ApplicationInfo.Company, ApplicationInfo.Email);

                    // try sending e-mail with attached files
                    MapiMail.SendMail(subject, "", new[] { recipient }, files.ToArray());
                }
                catch (Exception e) {
                    // quit if user cancelled MAPI session
                    MapiException me = e as MapiException;
                    if (me != null && me.Code == MapiException.Abort)
                    {
                        return;
                    }

                    // ask user to try simpler e-mail format
                    wantEmail = ShowFatalError(Strings.DialogFatalErrorMail, e, true);
                    throw; // rethrow to try mailto:
                }
            }
            catch {
                // quit now if user declined e-mail
                if (!wantEmail)
                {
                    return;
                }

                // construct shell command to create e-mail
                string mailto = String.Format(CultureInfo.InvariantCulture,
                                              "mailto:{0}?subject={1}&body={2}", ApplicationInfo.Email, subject, info);

                try {
                    // request default e-mail client
                    Process.Start(mailto);
                }
                catch (Exception e) {
                    ShowExplorerError(null, Strings.DialogExplorerMailError, e);
                }
            }
            finally {
                // quit application upon return
                Environment.Exit(-1);
            }
        }
示例#5
0
        /// <summary>
        /// Shows a <see cref="SaveFileDialog"/> allowing the user to enter or select a session file
        /// to save to.</summary>
        /// <param name="file">
        /// The file initially selected in the dialog, relative to the current <see
        /// cref="FilePaths.UserFolder"/>.</param>
        /// <returns>
        /// A <see cref="RootedPath"/> wrapping the absolute file path selected by the user, or an
        /// empty path if the user cancelled the dialog.</returns>
        /// <remarks>
        /// The specified <paramref name="file"/> may be a null reference or an empty string to
        /// indicate that no file should be initially selected. The dialog initially shows the <see
        /// cref="FilePaths.SessionFolder"/>, unless overriden by an absolute <paramref
        /// name="file"/> path.</remarks>

        public static RootedPath SaveSessionDialog(string file)
        {
            return(SaveDialog(Strings.TitleGameSave, Strings.FilterGame, 2,
                              "xml.gz", FilePaths.CreateUserPath(file), FilePaths.SessionFolder));
        }
示例#6
0
        /// <summary>
        /// Shows an <see cref="OpenFileDialog"/> allowing the user to enter or select a session
        /// file to open.</summary>
        /// <returns>
        /// A <see cref="RootedPath"/> wrapping the absolute file path selected by the user, or an
        /// empty path if the user cancelled the dialog.</returns>
        /// <remarks>
        /// <b>OpenSessionDialog</b> only allows the selection of existing files. The dialog
        /// initially shows the <see cref="FilePaths.SessionFolder"/>.</remarks>

        public static RootedPath OpenSessionDialog()
        {
            return(OpenDialog(Strings.TitleGameOpen, Strings.FilterGame, "xml.gz",
                              FilePaths.CreateUserPath(), FilePaths.SessionFolder, false));
        }
示例#7
0
        /// <summary>
        /// Shows an <see cref="OpenFileDialog"/> allowing the user to enter or select a scenario
        /// file to open.</summary>
        /// <returns>
        /// A <see cref="RootedPath"/> wrapping the absolute file path selected by the user, or an
        /// empty path if the user cancelled the dialog.</returns>
        /// <remarks>
        /// <b>OpenScenarioDialog</b> only allows the selection of existing files. The dialog
        /// initially shows the <see cref="FilePaths.ScenarioFolder"/>.</remarks>

        public static RootedPath OpenScenarioDialog()
        {
            return(OpenDialog(Strings.TitleScenarioOpen, Strings.FilterScenario, "xml",
                              FilePaths.CreateCommonPath(), FilePaths.ScenarioFolder, false));
        }
示例#8
0
        /// <summary>
        /// Shows an <see cref="OpenFileDialog"/> allowing the user to select a rule script file to
        /// open.</summary>
        /// <param name="file">
        /// The file initially selected in the dialog, relative to the current <see
        /// cref="FilePaths.CommonFolder"/>.</param>
        /// <returns>
        /// A <see cref="RootedPath"/> wrapping the absolute file path selected by the user, or an
        /// empty path if the user cancelled the dialog.</returns>
        /// <remarks><para>
        /// <b>OpenRulesDialog</b> only allows the selection of existing files.
        /// </para><para>
        /// The specified <paramref name="file"/> may be a null reference or an empty string to
        /// indicate that no file should be initially selected. The dialog initially shows the <see
        /// cref="FilePaths.RulesFolder"/>, unless overriden by an absolute <paramref name="file"/>
        /// path.</para></remarks>

        public static RootedPath OpenRulesDialog(string file)
        {
            return(OpenDialog(Strings.TitleRulesOpen, Strings.FilterRules, "cs",
                              FilePaths.CreateCommonPath(file), FilePaths.RulesFolder, false));
        }