コード例 #1
0
        public static void Main()
        {
            application = new App();
            application.InitializeComponent();
            ToolTipService.ShowDurationProperty.OverrideMetadata(
                typeof(DependencyObject), new FrameworkPropertyMetadata(Int32.MaxValue));
            ToolTipService.InitialShowDelayProperty.OverrideMetadata(
                typeof(DependencyObject), new FrameworkPropertyMetadata(0));

            if (!Directory.Exists(Helpers.UserDataFolder))
            {
                Directory.CreateDirectory(Helpers.UserDataFolder);
            }

            // Tray icon initialization
            {
                System.Windows.Forms.ContextMenuStrip context_menu_strip = new System.Windows.Forms.ContextMenuStrip {
                    Visible = true
                };

                context_menu_strip.SuspendLayout();

                System.Windows.Forms.ToolStripMenuItem settings = new System.Windows.Forms.ToolStripMenuItem {
                    Text = "Settings", Visible = true
                };
                settings.Click += OpenSettings;

                System.Windows.Forms.ToolStripMenuItem reset_calibration = new System.Windows.Forms.ToolStripMenuItem {
                    Text = "Reset calibration", Visible = true
                };
                reset_calibration.Click += ResetCalibration;

                System.Windows.Forms.ToolStripMenuItem exit = new System.Windows.Forms.ToolStripMenuItem {
                    Text = "Exit", Visible = true
                };
                exit.Click += Shutdown;

                context_menu_strip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { settings, reset_calibration, exit });

                context_menu_strip.ResumeLayout(false);
                Helpers.tray_icon.ContextMenuStrip = context_menu_strip;
                Helpers.tray_icon.MouseClick      += Tray_icon_Click;
            }

            eye_tracking_mouse = new EyeTrackingMouse();
            input_manager      = new InputManager(eye_tracking_mouse);

            SquirrelAwareApp.HandleEvents(
                onAppUninstall: v =>
            {
                Helpers.RemoveShortcuts();
                lock (Helpers.locker)
                {
                    if (Options.Instance.key_bindings.is_driver_installed)
                    {
                        string interception_installer = System.IO.Path.Combine(
                            Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).FullName,
                            "install-interception.exe");

                        var process = System.Diagnostics.Process.Start(
                            interception_installer, " /uninstall");
                    }
                }

                Helpers.DeleteAppFiles();
            },
                onAppUpdate: (Version version) =>
            {
                lock (Helpers.locker)
                {
                    Helpers.ShowBaloonNotification("EyeTrackingMouse has updated. It is now faster and more accurate. \n Double press " + Options.Instance.key_bindings[Key.Modifier] + " to toggle Always On mode. \n" +
                                                   "This is the last automatic update over the network. I removed auto-update for better security. EyeTrackingMouse is completely offline now.");
                }
            },
                onFirstRun: () =>
            {
                Helpers.CreateShortcuts();
            });

            lock (Helpers.locker)
            {
                if (!Options.Instance.user_consent_given)
                {
                    new ConsentWindow(() =>
                    {
                        Autostart.Enable();
                        OpenSettings(null, null);
                    }, () => {
                        Shutdown(null, null);
                    }).Show();
                }
            }

            application.Run();

            eye_tracking_mouse.Dispose();
            Helpers.tray_icon.Visible = false;
        }