Example #1
0
        static void Main(string[] args)
        {
            try
            {
                // Exception handling
                Application.ThreadException += Application_ThreadException;                         // UI thread exceptions
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);       // Force UI exceptions through our handler
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;     // non-UI thread exceptions

                // Run the application
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // Command-line options
                bool minimizeToTray = false;
                bool autoConnect = false;
                string portName = null;
                string oscHost = OscTransmitter.DEFAULT_RECEIVER;
                int oscPort = OscTransmitter.DEFAULT_PORT;
                string logFile = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + WaxMainForm.DEFAULT_LOG_FILE;
                bool oscReceive = false;

                int positional = 0;
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].ToLower() == "-service")
                    {
                        minimizeToTray = true;
                        autoConnect = true;
                        logFile = "";
                    }
                    else if (args[i].ToLower() == "-systray") { minimizeToTray = true; }
                    else if (args[i].ToLower() == "-connect") { autoConnect = true; }
                    else if (args[i].ToLower() == "-port") { portName = args[++i]; }
                    else if (args[i].ToLower() == "-oschost") { oscHost = args[++i]; }
                    else if (args[i].ToLower() == "-oscport") { oscPort = int.Parse(args[++i]); }
                    else if (args[i].ToLower() == "-oscrecv") { oscReceive = true; }
                    else if (args[i].ToLower() == "-log") { logFile = args[++i]; }
                    else if (args[i][0] == '-')
                    {
                        Console.Error.WriteLine("ERROR: Ignoring unknown option: " + args[i]);
                    }
                    else
                    {
                        if (positional == 0) { portName = args[i]; }
                        else if (positional == 1) { oscHost = args[i]; }
                        else if (positional == 2) { oscPort = int.Parse(args[i]); }
                        else if (positional == 3) { logFile = args[i]; }
                        else
                        {
                            Console.Error.WriteLine("ERROR: Ignoring positional parameter #" + (positional + 1) + ": " + args[i]);
                        }
                        positional++;
                    }
                }

                WaxMainForm mainForm = new WaxMainForm();
                mainForm.MinimizeToTray = minimizeToTray;
                mainForm.AutoConnect = autoConnect;
                mainForm.PortName = portName;
                mainForm.OscHost = oscHost;
                mainForm.OscPort = oscPort;
                mainForm.OscReceive = oscReceive;
                mainForm.LogFile = logFile;

                Application.Run(mainForm);
            }
            catch (Exception ex)
            {
                string error =
                    "Sorry, a fatal application error occurred (exception in main function).\r\n\r\n" +
                    "Exception: " + ex.ToString() + "\r\n\r\n" +
                    "Stack trace: " + ex.StackTrace + "";
                MessageBox.Show(error, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(-1);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            try
            {
                // Exception handling
                Application.ThreadException += Application_ThreadException;                         // UI thread exceptions
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);       // Force UI exceptions through our handler
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;     // non-UI thread exceptions

                // Run the application
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // Command-line options
                bool   minimizeToTray = false;
                bool   autoConnect    = false;
                string portName       = null;
                string oscHost        = OscTransmitter.DEFAULT_RECEIVER;
                int    oscPort        = OscTransmitter.DEFAULT_PORT;
                string logFile        = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + WaxMainForm.DEFAULT_LOG_FILE;
                bool   oscReceive     = false;

                int positional = 0;
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i].ToLower() == "-service")
                    {
                        minimizeToTray = true;
                        autoConnect    = true;
                        logFile        = "";
                    }
                    else if (args[i].ToLower() == "-systray")
                    {
                        minimizeToTray = true;
                    }
                    else if (args[i].ToLower() == "-connect")
                    {
                        autoConnect = true;
                    }
                    else if (args[i].ToLower() == "-port")
                    {
                        portName = args[++i];
                    }
                    else if (args[i].ToLower() == "-oschost")
                    {
                        oscHost = args[++i];
                    }
                    else if (args[i].ToLower() == "-oscport")
                    {
                        oscPort = int.Parse(args[++i]);
                    }
                    else if (args[i].ToLower() == "-oscrecv")
                    {
                        oscReceive = true;
                    }
                    else if (args[i].ToLower() == "-log")
                    {
                        logFile = args[++i];
                    }
                    else if (args[i][0] == '-')
                    {
                        Console.Error.WriteLine("ERROR: Ignoring unknown option: " + args[i]);
                    }
                    else
                    {
                        if (positional == 0)
                        {
                            portName = args[i];
                        }
                        else if (positional == 1)
                        {
                            oscHost = args[i];
                        }
                        else if (positional == 2)
                        {
                            oscPort = int.Parse(args[i]);
                        }
                        else if (positional == 3)
                        {
                            logFile = args[i];
                        }
                        else
                        {
                            Console.Error.WriteLine("ERROR: Ignoring positional parameter #" + (positional + 1) + ": " + args[i]);
                        }
                        positional++;
                    }
                }

                WaxMainForm mainForm = new WaxMainForm();
                mainForm.MinimizeToTray = minimizeToTray;
                mainForm.AutoConnect    = autoConnect;
                mainForm.PortName       = portName;
                mainForm.OscHost        = oscHost;
                mainForm.OscPort        = oscPort;
                mainForm.OscReceive     = oscReceive;
                mainForm.LogFile        = logFile;

                Application.Run(mainForm);
            }
            catch (Exception ex)
            {
                string error =
                    "Sorry, a fatal application error occurred (exception in main function).\r\n\r\n" +
                    "Exception: " + ex.ToString() + "\r\n\r\n" +
                    "Stack trace: " + ex.StackTrace + "";
                MessageBox.Show(error, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(-1);
            }
        }