Пример #1
0
        /// <summary>
        /// Shows a <see cref="FileDialogs.SaveSectionDialog"/> allowing the user to enter or select
        /// an <see cref="AreaSection"/> file to save the current <see cref="WorldState"/> to.
        /// </summary>
        /// <param name="file">
        /// The file initially selected in the dialog.</param>
        /// <remarks><para>
        /// The specified <paramref name="file"/> may be a null reference or an empty string to
        /// indicate that no file should be initially selected. Otherwise, any directory prefix it
        /// contains overrides the specified <paramref name="file"/>. Files without an absolute path
        /// are interpreted as relative to the <see cref="ScenarioSection.Areas"/> section folder.
        /// </para><para>
        /// <b>SaveAreas</b> attempts to create a new <see cref="AreaSection"/> object from the <see
        /// cref="WorldState"/> of the current session, using the latter's <see
        /// cref="WorldState.CreateAreaSection"/> method, and then invokes <see
        /// cref="ScenarioElement.Save"/> on the new <see cref="AreaSection"/> object. If either
        /// operation fails, an error message is shown but no exception is thrown.</para></remarks>

        public static void SaveAreas(string file)
        {
            // abort if no world state to save
            if (Session.Instance == null)
            {
                return;
            }

            // let user select file path for Areas section
            RootedPath path = FilePaths.GetSectionFile(ScenarioSection.Areas, file);

            path = FileDialogs.SaveSectionDialog(ScenarioSection.Areas, path.AbsolutePath);
            if (path.IsEmpty)
            {
                return;
            }

            try {
                // create Areas section from world state
                AreaSection areas = Session.Instance.WorldState.CreateAreaSection(0, 0, 0, 0);
                areas.Save(path.AbsolutePath);
            }
            catch (Exception e) {
                string message = String.Format(ApplicationInfo.Culture,
                                               Global.Strings.DialogSectionSaveError, path.AbsolutePath);

                MessageDialog.Show(MainWindow.Instance, message,
                                   Global.Strings.TitleSectionError, e, MessageBoxButton.OK, Images.Error);
            }
        }