Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                if (Settings.Default.UpdateRequired)
                {
                    Settings.Default.Upgrade();
                    Settings.Default.UpdateRequired = false;
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                MainWindow.SetDefaultSettings();

                Plugin.LoadPlugins();

                //only do it when there are args
                if (args.Length > 0)
                {
                    NativeMethods.InitConsoleHandles();
                }

                CommandOptions options = new CommandOptions();

                bool bOk = options.Parse(args);

                if (!bOk || options.help)
                {
                    string allFormats = string.Empty;

                    foreach (ExporterInfo info in Plugin.Exporters)
                    {
                        if (!string.IsNullOrEmpty(allFormats))
                        {
                            allFormats += "|";
                        }

                        allFormats += info.ID;
                    }

                    string usage = string.Format
                                       (@"
                                    Usage:
                                    BehaviacDesigner.exe <workspaceFile> <options>
                                    options:
                                    /bt=btFile
                                    /export=<{0}>
                                    /help", allFormats);

                    System.Console.WriteLine(usage);
                }

                if (options.export)
                {
                    if (bOk)
                    {
                        string msg = string.Format("Exporting: format '{0}' workspace '{1}' ...", options.format, options.workspace);
                        System.Console.WriteLine(msg);

                        if (!System.IO.File.Exists(options.workspace))
                        {
                            msg = string.Format("Workspace '{0}' does not exist! check the workspace path and name.", options.workspace);
                            System.Console.WriteLine(msg);

                            return;
                        }

                        try
                        {
                            new MainWindow(false);

                            MainWindow.Instance.Hide();

                            if (MainWindow.Instance.SetWorkspace(options.workspace, false))
                            {
                                MainWindow.Instance.ExportBehavior(true, options.format);
                            }
                            else
                            {
                                //msg = string.Format("Workspace '{0}' is not a valid workspace file!", options.workspace);
                                //System.Console.WriteLine(msg);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(options.workspace))
                        {
                            System.Console.WriteLine("No workspace is specified!");
                        }

                        if (string.IsNullOrEmpty(options.format))
                        {
                            System.Console.WriteLine("No format is specified!");
                        }
                    }

                    return;
                }

                using (MainWindow mainWindow = new MainWindow(true))
                {
                    if (!string.IsNullOrEmpty(options.workspace))
                    {
                        mainWindow.SetWorkspace(options.workspace, false);

                        if (!string.IsNullOrEmpty(options.bt))
                        {
                            UIUtilities.ShowBehaviorTree(options.bt);
                        }
                    }

                    Application.Run(mainWindow);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception is {0}", e);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            try
            {
                if (Settings.Default.UpdateRequired)
                {
                    Settings.Default.Upgrade();
                    Settings.Default.UpdateRequired = false;
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Plugin.LoadPlugins();

                //only do it when there are args
                if (args.Length > 0)
                {
                    NativeMethods.InitConsoleHandles();
                }

                CommandOptions options = new CommandOptions();

                bool bOk = options.Parse(args);

                if (!bOk || options.help)
                {
                    string allFormats = string.Empty;
                    foreach (ExporterInfo info in Plugin.Exporters)
                    {
                        if (!string.IsNullOrEmpty(allFormats))
                            allFormats += "|";

                        allFormats += info.ID;
                    }

                    string usage = string.Format
                        (@"
                            Usage:
                                BehaviacDesigner.exe <workspaceFile> <options>
                                    options:
                                        /bt=btFile
                                        /export=<{0}>
                                        /help", allFormats);

                    System.Console.WriteLine(usage);
                }

                if (options.export)
                {
                    if (bOk)
                    {
                        string msg = string.Format("Exporting: format '{0}' workspace '{1}' ...", options.format, options.workspace);
                        System.Console.WriteLine(msg);

                        if (!System.IO.File.Exists(options.workspace))
                        {
                            msg = string.Format("Workspace '{0}' does not exist! check the workspace path and name.", options.workspace);
                            System.Console.WriteLine(msg);

                            return;
                        }

                        new MainWindow(false);

                        if (MainWindow.Instance.SetWorkspace(options.workspace, false))
                        {
                            MainWindow.Instance.ExportBehavior(true, options.format);
                        }
                        else
                        {
                            //msg = string.Format("Workspace '{0}' is not a valid workspace file!", options.workspace);
                            //System.Console.WriteLine(msg);
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(options.workspace))
                        {
                            System.Console.WriteLine("No workspace is specified!");
                        }
                        if (string.IsNullOrEmpty(options.format))
                        {
                            System.Console.WriteLine("No format is specified!");
                        }
                    }

                    return;
                }

                MainWindow mainWindow = new MainWindow(true);
                if (!string.IsNullOrEmpty(options.workspace))
                {
                    mainWindow.SetWorkspace(options.workspace, false);

                    if (!string.IsNullOrEmpty(options.bt))
                    {
                        UIUtilities.ShowBehaviorTree(options.bt);
                    }
                }

                Application.Run(mainWindow);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception is {0}", e);
            }
        }