Ejemplo n.º 1
0
        /// <summary>
        /// Parses the command line arguments.
        /// </summary>
        /// <param name="tokens">The tokens of the command line.</param>
        public static void ParseCommandLine(string[] tokens)
        {
            List <string> args       = new List <string>();
            Type          switchType = null;

            foreach (string token in tokens)
            {
                string tokenStr = token.Trim();
                if (switchTypes.ContainsKey(tokenStr))
                {
                    /// Beginning of a new switch has been found.
                    if (switchType != null)
                    {
                        object[] constructorArgs = new object[1] {
                            args.ToArray()
                        };
                        CmdLineSwitch sw = (CmdLineSwitch)Activator.CreateInstance(switchType, constructorArgs);
                        switches.Add(sw);
                        args.Clear();
                    }
                    switchType = switchTypes[tokenStr];
                }
                else
                {
                    args.Add(tokenStr);
                }
            }

            /// End of last switch
            if (switchType != null)
            {
                object[] constructorArgs = new object[1] {
                    args.ToArray()
                };
                CmdLineSwitch sw = (CmdLineSwitch)Activator.CreateInstance(switchType, constructorArgs);
                switches.Add(sw);
                args.Clear();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the starting point of the RC application. Command line switches for RC.exe:
        /// /cfg filename --> Name of the root configuration file to initialize with (RC.root by default).
        /// /c --> Run RC.exe with console window (console is hidden by default). You can also toggle the console
        ///        window by pressing the CTRL + ALT + SHIFT + C combination during runtime.
        /// </summary>
        static void Main(string[] args)
        {
            try
            {
                /// Read and execute the command line switches
                ConsoleHelper.HideConsole();
                CmdLineSwitch.ParseCommandLine(args);
                CmdLineSwitch.ExecuteSwitches();

                /// Initialize the configuration sub-system
                if (!ConfigurationManager.IsInitialized)
                {
                    ConfigurationManager.Initialize(RCAppSetup.Mode == RCAppMode.Normal ? "RC.App.root" : "RC.MapEditor.root");
                }

                /// Start the components of the system
                StartComponents();

                /// Initialize the UI-core and install the XNA-plugin (TODO: make it configurable)
                UIRoot   root      = new UIRoot(RCAppSetup.ScreenIndex);
                Assembly xnaPlugin = Assembly.Load("RC.UI.XnaPlugin, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
                root.LoadPlugins(xnaPlugin);
                root.InstallPlugins();

                /// Create the UIWorkspace (TODO: make it configurable)
                UIWorkspace workspace = new UIWorkspace(new RCIntVector(1024, 768), RCAppSetup.Mode == RCAppMode.Normal ? new RCIntVector(320, 200) : new RCIntVector(1024, 768));

                if (RCAppSetup.Mode == RCAppMode.Normal)
                {
                    TraceManager.WriteAllTrace("NORMAL STARTUP...", TraceManager.GetTraceFilterID("RC.App.Info"));

                    /// Load the common resource group (TODO: make it configurable?)
                    UIResourceManager.LoadResourceGroup("RC.App.SplashScreen");

                    /// Initialize the pages of the RC application.
                    root.GraphicsPlatform.RenderLoop.FrameUpdate += InitPages;

                    /// Start and run the render loop
                    root.GraphicsPlatform.RenderLoop.Start(workspace.DisplaySize);
                }
                else
                {
                    ConsoleHelper.ShowConsole();
                    TraceManager.WriteAllTrace("STARTING MAP EDITOR...", TraceManager.GetTraceFilterID("RC.MapEditor.Info"));

                    /// Read the parameters from the command line
                    if (RCAppSetup.Mode == RCAppMode.NewMap)
                    {
                        Console.Write("Name of the new map file: ");
                        RCAppSetup.MapFile = Console.ReadLine();
                        if (File.Exists(RCAppSetup.MapFile))
                        {
                            throw new IOException(string.Format("The file '{0}' already exists!", RCAppSetup.MapFile));
                        }
                        Console.Write("Name of the new map: ");
                        RCAppSetup.MapName = Console.ReadLine();
                        Console.Write("Name of the tileset of the new map: ");
                        RCAppSetup.TilesetName = Console.ReadLine();
                        Console.Write("Name of the default terrain of the new map: ");
                        RCAppSetup.DefaultTerrain = Console.ReadLine();
                        Console.Write("Size of the new map: ");
                        RCAppSetup.MapSize = XmlHelper.LoadIntVector(Console.ReadLine());
                    }
                    else if (RCAppSetup.Mode == RCAppMode.LoadMap)
                    {
                        Console.Write("Name of the map file to load: ");
                        RCAppSetup.MapFile = Console.ReadLine();
                    }

                    TraceManager.WriteAllTrace(RCAppSetup.ToString(), TraceManager.GetTraceFilterID("RC.MapEditor.Info"));

                    /// Load the resources for the map editor.
                    UIResourceManager.LoadResourceGroup("RC.MapEditor.Resources");

                    /// Set the default mouse pointer.
                    workspace.SetDefaultMousePointer(UIResourceManager.GetResource <UIPointer>("RC.App.Pointers.NormalPointer"));

                    /// Initialize the page of the map editor.
                    root.GraphicsPlatform.RenderLoop.FrameUpdate += InitMapEditorPage;

                    /// Start and run the render loop
                    root.GraphicsPlatform.RenderLoop.Start(workspace.DisplaySize);
                }

                /// After the render loop has been stopped, release all resources of the UIRoot.
                root.Dispose();

                ComponentManager.StopComponents();
                ComponentManager.UnregisterComponentsAndPlugins();

                /// End of RC application
                if (ConsoleHelper.IsConsoleHidden)
                {
                    Console.Clear();
                    ConsoleHelper.ShowConsole();
                }
            }
            catch (Exception ex)
            {
                /// Catch any exception from the UI-thread, write it to the console and show a "sorry" message-box
                Exception currException = ex;
                Console.WriteLine(currException.ToString());
                while (currException.InnerException != null)
                {
                    currException = currException.InnerException;
                    Console.WriteLine(currException.ToString());
                }

                MessageBox.Show("An internal error happened and the application will be closed.\nSee the contents of installed traces for more information!", "Sorry");
            }
        }