Exemple #1
0
        /// <summary>
        /// Shows the export dialogue for the behaviors to be exported.
        /// </summary>
        /// <param name="node">The behavior you want to export. Use null to export all behaviors.</param>
        /// <returns>Returns true if the user did not abort and all behaviors could be exported.</returns>
        internal bool ExportBehavior(BehaviorNode node, string format = "", bool ignoreErrors = false, TreeNode selectedTreeRoot = null)
        {
            // get the exporter index
            int formatIndex = Plugin.GetExporterIndex(format);

            // create export dialogue
            using (ExportDialog dialog = new ExportDialog(this, node, ignoreErrors, selectedTreeRoot, formatIndex))
            {
                //when format is not empty, it is for the command line exporting, don't show the gui
                if (string.IsNullOrEmpty(format))
                {
                    // show the dialogue
                    if (dialog.ShowDialog() == DialogResult.Cancel)
                        return false;
                }

                try
                {
                    string exportedPath = Workspace.Current.DefaultExportFolder;
                    if (!Directory.Exists(exportedPath))
                        Directory.CreateDirectory(exportedPath);

                    if (exportedPath.StartsWith(_behaviorFolder, StringComparison.CurrentCultureIgnoreCase))
                        throw new Exception("Behaviors cannot be exported into the behaviors source folder.");

                    if (this.UpdateExportedSettting(exportedPath))
                    {
                        Debug.Check(Workspace.Current != null);

                        for (int i = 0; i < Plugin.Exporters.Count; ++i)
                        {
                            ExporterInfo info = Plugin.Exporters[i];
                            if (Workspace.Current.ShouldBeExported(info.ID))
                            {
                                bool aborted = false;
                                exportBehavior(i, exportedPath, dialog.treeView.Nodes, ref aborted);
                                if (aborted)
                                    break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Resources.ExportError, MessageBoxButtons.OK);
                    return false;
                }
            }

            return true;
        }
Exemple #2
0
        /// <summary>
        /// Shows the export dialogue for the behaviors to be exported.
        /// </summary>
        /// <param name="node">The behavior you want to export. Use null to export all behaviors.</param>
        /// <returns>Returns true if the user did not abort and all behaviors could be exported.</returns>
        internal bool ExportBehavior(BehaviorNode node, string format = "", bool ignoreErrors = false, TreeNode selectedTreeRoot = null)
        {
            // save modified behaviors
            if (node != null)
            {
                this.SaveBehavior(node, false, false);
            }
            else
            {
                this.SaveAll();
            }

            // get the exporter index
            int formatIndex = Plugin.GetExporterIndex(format);

            // create export dialogue
            using (ExportDialog dialog = new ExportDialog(this, node, ignoreErrors, selectedTreeRoot, formatIndex))
            {
                //when format is not empty, it is for the command line exporting, don't show the gui
                if (string.IsNullOrEmpty(format))
                {
                    // show the dialogue
                    if (dialog.ShowDialog() == DialogResult.Cancel)
                    {
                        return false;
                    }

                    if (!string.IsNullOrEmpty(Plugin.SourceLanguage) && Plugin.SourceLanguage != "cpp" && !Workspace.Current.IsSetExportFolder(Plugin.SourceLanguage))
                    {
                        if (DialogResult.OK == MessageBox.Show(Resources.InvalidExportedTypePath, Resources.ExportError, MessageBoxButtons.OK))
                        {
                            MetaStoreDock.Inspect(null);

                            return false;
                        }
                    }
                }

                try
                {
                    string exportedPath = Workspace.Current.DefaultExportFolder;

                    if (!Directory.Exists(exportedPath))
                    {
                        Directory.CreateDirectory(exportedPath);
                    }

                    if (exportedPath.StartsWith(_behaviorFolder, StringComparison.CurrentCultureIgnoreCase))
                    {
                        throw new Exception("Behaviors cannot be exported into the behaviors source folder.");
                    }

                    bool aborted = false;
                    bool exportXML = false;
                    bool exportBson = false;

                    //if (this.UpdateExportedSettting(exportedPath))
                    {
                        Debug.Check(Workspace.Current != null);

                        for (int i = 0; i < Plugin.Exporters.Count; ++i)
                        {
                            ExporterInfo info = Plugin.Exporters[i];

                            if ((string.IsNullOrEmpty(format) && (Workspace.Current.ShouldBeExported(info.ID) || (info.ID == Plugin.SourceLanguage))) || (info.ID == format))
                            {
                                exportXML |= (info.ID == "xml");
                                exportBson |= (info.ID == "bson");

                                bool bExportBehaviors = dialog.ExportBehaviors;
                                if (info.ID == Plugin.SourceLanguage && !Workspace.Current.ShouldBeExported(info.ID))
                                    bExportBehaviors = false;

                                exportBehavior(bExportBehaviors, i, exportedPath, dialog.treeView.Nodes, ref aborted);

                                if (aborted)
                                {
                                    break;
                                }
                            }
                        }

                        if (!aborted)
                        {
                            if (Plugin.SourceLanguage == "cpp")
                            {
                                Workspace.ExportCustomMembers(Workspace.Current, exportXML, exportBson);
                            }

                            Utilities.ReportExportBehavior();
                        }
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Resources.ExportError, MessageBoxButtons.OK);
                    return false;
                }
            }

            return true;
        }