Beispiel #1
0
        /// <summary>
        /// Run the Player
        /// </summary>
        /// <param name="screenSaver"></param>
        private static void RunClient(bool screenSaver)
        {
            Trace.WriteLine(new LogMessage("Main", "Client Started"), LogType.Info.ToString());

            KeyInterceptor.SetHook();
            if (screenSaver)
            {
                MouseInterceptor.SetHook();
            }

            MainWindow windowMain = new MainWindow(screenSaver);

            windowMain.ShowDialog();

            KeyInterceptor.UnsetHook();
            if (screenSaver)
            {
                MouseInterceptor.UnsetHook();
            }
        }
        static int Main(string[] args)
        {
            NativeMethods.SetErrorMode(NativeMethods.SetErrorMode(0) |
                                       ErrorModes.SEM_NOGPFAULTERRORBOX |
                                       ErrorModes.SEM_FAILCRITICALERRORS |
                                       ErrorModes.SEM_NOOPENFILEERRORBOX);


            // Ensure our process has the highest priority
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;

            Application.SetCompatibleTextRenderingDefault(false);

#if !DEBUG
            // Catch unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.ThreadException           += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
#endif

            // Add the Xibo Tracelistener
            Trace.Listeners.Add(new XiboTraceListener());

            try
            {
                // Check for any passed arguments
                if (args.Length > 0)
                {
                    if (args[0].ToString() == "o")
                    {
                        RunSettings();
                    }
                    else
                    {
                        switch (args[0].ToLower().Trim().Substring(0, 2))
                        {
                        // Preview the screen saver
                        case "/p":
                            // args[1] is the handle to the preview window
                            KeyInterceptor.SetHook();
                            MouseInterceptor.SetHook();
                            RunClient(new IntPtr(long.Parse(args[1])));
                            KeyInterceptor.UnsetHook();
                            MouseInterceptor.UnsetHook();
                            break;

                        // Show the screen saver
                        case "/s":
                            KeyInterceptor.SetHook();
                            MouseInterceptor.SetHook();
                            RunClient(true);
                            KeyInterceptor.UnsetHook();
                            MouseInterceptor.UnsetHook();
                            break;

                        // Configure the screesaver's settings
                        case "/c":
                            // Show the settings form
                            RunSettings();
                            break;

                        // Show the screen saver
                        default:
                            KeyInterceptor.SetHook();
                            MouseInterceptor.SetHook();
                            RunClient(true);
                            KeyInterceptor.UnsetHook();
                            MouseInterceptor.UnsetHook();
                            break;
                        }
                    }
                }
                else
                {
                    // Add a message filter
                    Application.AddMessageFilter(KeyStore.Instance);

                    // No arguments were passed - we run the usual client
                    RunClient();
                }
            }
            catch (Exception ex)
            {
                HandleUnhandledException(ex);
            }

            // Always flush at the end
            Trace.WriteLine(new LogMessage("Main", "Application Finished"), LogType.Info.ToString());
            Trace.Flush();

            return(0);
        }
        static int Main(string[] args)
        {
            NativeMethods.SetErrorMode(NativeMethods.SetErrorMode(0) |
                                       ErrorModes.SEM_NOGPFAULTERRORBOX |
                                       ErrorModes.SEM_FAILCRITICALERRORS |
                                       ErrorModes.SEM_NOOPENFILEERRORBOX);

            // Do we need to initialise CEF?
            if (ApplicationSettings.Default.UseCefWebBrowser)
            {
                try
                {
                    CefRuntime.Load();
                }
                catch (DllNotFoundException ex)
                {
                    MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(1);
                }
                catch (CefRuntimeException ex)
                {
                    MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(2);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(3);
                }

                var settings = new CefSettings();
                settings.MultiThreadedMessageLoop = true;
                settings.SingleProcess            = false;
                settings.LogSeverity         = CefLogSeverity.Disable;
                settings.LogFile             = "cef.log";
                settings.ResourcesDirPath    = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);
                settings.RemoteDebuggingPort = 20480;

                CefRuntime.Initialize(new CefMainArgs(args), settings, null, IntPtr.Zero);
            }

            // Ensure our process has the highest priority
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;

            Application.SetCompatibleTextRenderingDefault(false);

#if !DEBUG
            // Catch unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.ThreadException           += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
#endif

            // Add the Xibo Tracelistener
            Trace.Listeners.Add(new XiboTraceListener());

            try
            {
                // Check for any passed arguments
                if (args.Length > 0)
                {
                    if (args[0].ToString() == "o")
                    {
                        RunSettings();
                    }
                    else
                    {
                        switch (args[0].ToLower().Trim().Substring(0, 2))
                        {
                        // Preview the screen saver
                        case "/p":
                            // args[1] is the handle to the preview window
                            KeyInterceptor.SetHook();
                            MouseInterceptor.SetHook();
                            RunClient(new IntPtr(long.Parse(args[1])));
                            KeyInterceptor.UnsetHook();
                            MouseInterceptor.UnsetHook();
                            break;

                        // Show the screen saver
                        case "/s":
                            KeyInterceptor.SetHook();
                            MouseInterceptor.SetHook();
                            RunClient(true);
                            KeyInterceptor.UnsetHook();
                            MouseInterceptor.UnsetHook();
                            break;

                        // Configure the screesaver's settings
                        case "/c":
                            // Show the settings form
                            RunSettings();
                            break;

                        // Show the screen saver
                        default:
                            KeyInterceptor.SetHook();
                            MouseInterceptor.SetHook();
                            RunClient(true);
                            KeyInterceptor.UnsetHook();
                            MouseInterceptor.UnsetHook();
                            break;
                        }
                    }
                }
                else
                {
                    // Add a message filter
                    Application.AddMessageFilter(KeyStore.Instance);

                    // No arguments were passed - we run the usual client
                    RunClient();
                }
            }
            catch (Exception ex)
            {
                HandleUnhandledException(ex);
            }

            // Always flush at the end
            Trace.WriteLine(new LogMessage("Main", "Application Finished"), LogType.Info.ToString());
            Trace.Flush();

            if (ApplicationSettings.Default.UseCefWebBrowser)
            {
                CefRuntime.Shutdown();
            }

            return(0);
        }