Beispiel #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (Process.GetProcessesByName("GW2PAO").Count() > 1)
            {
                // Application is already running
                Application.Current.Shutdown();
                return;
            }

            // Log application information
            var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly();

            System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(executingAssembly.Location);
            logger.Info("Application starting - " + executingAssembly.GetName().Name + " - " + executingAssembly.GetName().Version + " - " + fvi.FileVersion + " - " + fvi.ProductVersion);

            // Software only mode provides improved performance when using transparent windows and hardware acceleration is not available
            if ((System.Windows.Media.RenderCapability.Tier >> 16) == 0)
            {
                logger.Info("Hardware acceleration unavailable - setting ProcessRenderMode to SoftwareOnly");
                System.Windows.Media.RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
            }
            else
            {
                logger.Info("Hardware acceleration available - leaving ProcessRenderMode");
            }

            base.OnStartup(e);

            this.InitializeSettings();
            this.InitializeLogging();

            // Initialize the last chance exception handlers
            logger.Debug("Registering last chance exception handlers");
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            this.InitializeInternationalization();

            if (GW2PAO.Properties.Settings.Default.CheckForUpdates)
            {
                UpdateChecker.CheckForUpdateAndNotify();
            }

            ApplicationBootstrapper ab = new ApplicationBootstrapper();

            ab.Run();

            Commands.ApplicationShutdownCommand.RegisterCommand(new DelegateCommand(this.DoShutdown));

            GW2PAO.Properties.Settings.Default.FirstTimeRun = false;
            GW2PAO.Properties.Settings.Default.Save();

            // Disable client-side connection throttling
            ServicePointManager.DefaultConnectionLimit = int.MaxValue;
        }
Beispiel #2
0
        /// <summary>
        /// Application startup
        /// </summary>
        public void AppStartup(object sender, StartupEventArgs e)
        {
            // We save this so that if we perform an upgrade of settings,
            //  we still treat this startup as a first-time run of the application
            bool firstTimeUse = GW2PAO.Properties.Settings.Default.FirstTimeRun;

            // Update settings if neccessary
            if (GW2PAO.Properties.Settings.Default.UpgradeRequired)
            {
                GW2PAO.Properties.Settings.Default.Upgrade();
                GW2PAO.Properties.Settings.Default.UpgradeRequired = false;
                GW2PAO.Properties.Settings.Default.FirstTimeRun    = firstTimeUse;
                GW2PAO.Properties.Settings.Default.Save();
            }

#if DEBUG
            // Enable logging if running in debug
            LogManager.GlobalThreshold = NLog.LogLevel.Trace;
#else
            // Set up logging configuration
            if (!GW2PAO.Properties.Settings.Default.IsLoggingEnabled)
            {
                LogManager.GlobalThreshold = NLog.LogLevel.Fatal;
            }
#endif

            // Disable the debug assert windows that pop-up from NLog
            System.Diagnostics.Trace.Listeners.OfType <System.Diagnostics.DefaultTraceListener>().First().AssertUiEnabled = false;

            // Log application information
            var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
            System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(executingAssembly.Location);
            logger.Info("Application starting - " + executingAssembly.GetName().Name + " - " + executingAssembly.GetName().Version + " - " + fvi.FileVersion + " - " + fvi.ProductVersion);

            // Initialize the last chance exception handlers
            logger.Debug("Registering last chance exception handlers");
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

#if !NO_BROWSER
            // Initialize the WebCore for the web browser
            logger.Debug("Initializing Awesomium WebCore");
            if (!WebCore.IsInitialized)
            {
                WebCore.Initialize(new WebConfig()
                {
                    HomeURL = "http://wiki.guildwars2.com/".ToUri(),
                });
            }
#endif

            // Create dummy window so that the only way to exit the app is by using the tray icon
            Window dummyWindow = new Window()
            {
                WindowStyle        = System.Windows.WindowStyle.None,
                AllowsTransparency = true,
                Background         = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent),
                ShowInTaskbar      = false,
                Title = "GW2 Personal Assistant Overlay"
            };
            dummyWindow.Show();
            GW2PAO.Views.OverlayWindow.OwnerWindow = dummyWindow;

            // Create the tray icon
            logger.Debug("Creating tray icon");
            TaskbarIcon                         = (TaskbarIcon)this.FindResource("TrayIcon");
            TrayIconVm                          = new TrayIconViewModel();
            TaskbarIcon.DataContext             = TrayIconVm;
            TaskbarIcon.ContextMenu.DataContext = TrayIconVm;
            TaskbarIcon.ContextMenu.ItemsSource = TrayIconVm.MenuItems;
            App.TrayIcon                        = new ApplicationTrayIcon(TaskbarIcon);
            logger.Debug("Tray icon created");

            // Initialize the application controller
            AppController = new ApplicationController();

            // Initialize the process monitor
            ProcessMonitor = new ProcessMonitor(AppController.SystemService);
            GW2PAO.Views.OverlayWindow.ProcessMonitor = ProcessMonitor;

            // Initialize the OverlayMenuIcon
            ApplicationOverlayMenuIcon = new OverlayMenuIcon(TrayIconVm);

            // Set up the menu items
            logger.Debug("Initializing menu items");
            if (TrayIconVm != null)
            {
                foreach (var item in AppController.GetMenuItems())
                {
                    TrayIconVm.MenuItems.Add(item);
                }

                TrayIconVm.MenuItems.Add(null); // Null is treated as a seperator

                var settingsMenu = new MenuItemViewModel("Settings", null);

                settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Non-Interactive Windows", null, true,
                                                                    () => { return(GW2PAO.Properties.Settings.Default.IsClickthroughEnabled); },
                                                                    (enabled) => {
                    GW2PAO.Properties.Settings.Default.IsClickthroughEnabled = enabled;
                    GW2PAO.Properties.Settings.Default.Save();
                },
                                                                    GW2PAO.Properties.Settings.Default, "IsClickthroughEnabled"));

                settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Sticky Windows", null, true,
                                                                    () => { return(GW2PAO.Properties.Settings.Default.AreWindowsSticky); },
                                                                    (enabled) =>
                {
                    GW2PAO.Properties.Settings.Default.AreWindowsSticky = enabled;
                    GW2PAO.Properties.Settings.Default.Save();
                },
                                                                    GW2PAO.Properties.Settings.Default, "AreWindowsSticky"));

                settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Overlay Menu Icon", null, true,
                                                                    () => { return(ApplicationOverlayMenuIcon.IsVisible); },
                                                                    (show) => { ApplicationOverlayMenuIcon.IsVisible = show; },
                                                                    ApplicationOverlayMenuIcon, "IsVisible"));

                settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Check for Updates at Startup", null, true,
                                                                    () => { return(GW2PAO.Properties.Settings.Default.CheckForUpdates); },
                                                                    (enabled) =>
                {
                    GW2PAO.Properties.Settings.Default.CheckForUpdates = enabled;
                    GW2PAO.Properties.Settings.Default.Save();
                },
                                                                    GW2PAO.Properties.Settings.Default, "CheckForUpdates"));

                TrayIconVm.MenuItems.Add(settingsMenu);
                TrayIconVm.MenuItems.Add(new MenuItemViewModel("About", () => new GW2PAO.Views.AboutView().Show()));
                TrayIconVm.MenuItems.Add(new MenuItemViewModel("Exit", this.ExitAndCleanup));
            }

            logger.Info("Program startup complete");

            // Reopen windows based on user settings
            AppController.ReopenWindowsFromSettings();

            GW2PAO.Properties.Settings.Default.FirstTimeRun = false;
            GW2PAO.Properties.Settings.Default.Save();

            // Perform a check for new updates
            if (GW2PAO.Properties.Settings.Default.CheckForUpdates)
            {
                UpdateChecker.CheckForUpdateAndNotify();
            }
        }