示例#1
0
文件: Program.cs 项目: clayne/x360ce
        static void StartApp(string[] args)
        {
            if (!RuntimePolicyHelper.LegacyV2RuntimeEnabledSuccessfully)
            {
                // Failed to enable useLegacyV2RuntimeActivationPolicy at runtime.
            }
            // Requires System.Configuration.Installl reference.
            var ic = new System.Configuration.Install.InstallContext(null, args);
            // ------------------------------------------------
            // Administrator commands.
            // ------------------------------------------------
            var executed = ProcessAdminCommands(args);

            // If valid command was executed then...
            if (executed)
            {
                return;
            }
            // ------------------------------------------------
            // If must open all setting folders then...
            if (ic.Parameters.ContainsKey("Settings"))
            {
                OpenSettingsFolder(ApplicationDataPath);
                OpenSettingsFolder(CommonApplicationDataPath);
                OpenSettingsFolder(LocalApplicationDataPath);
                return;
            }
            // If default application settings failed to load then...
            if (!CheckDefaultSettings())
            {
                return;
            }
            // Load all settings.
            SettingsManager.Load();
            var o = SettingsManager.Options;

            // DPI aware property must be set before application window is created.
            if (Environment.OSVersion.Version.Major >= 6 && o.IsProcessDPIAware)
            {
                NativeMethods.SetProcessDPIAware();
            }
            Global.InitializeServices();
            Global.InitializeCloudClient();
            // Initialize DInput Helper.
            Global.DHelper = new DInput.DInputHelper();
            if (ic.Parameters.ContainsKey("Exit"))
            {
                // Close all x360ce apps.
                StartHelper.BroadcastMessage(StartHelper.wParam_Close);
                return;
            }
            // Allow to run if multiple copies allowed or allow to restore window.
            var allowToRun = !o.AllowOnlyOneCopy || !StartHelper.BroadcastMessage(StartHelper.wParam_Restore);

            // If one copy is already opened then...
            if (allowToRun)
            {
                InitializeServices();
                InitializeTrayIcon();
                app = new App();
                //app.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
                app.Startup += App_Startup;
                app.InitializeComponent();
                app.Run();
            }
            Global.DisposeCloudClient();
            Global.DisposeServices();
        }
示例#2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (ControlsHelper.IsDesignMode(this))
            {
                return;
            }
            StartHelper.OnClose += (sender1, e1)
                                   => Close();
            StartHelper.OnRestore += (sender1, e1)
                                     => Global._TrayManager.RestoreFromTray(true);
            AppHelper.InitializeHidGuardian();
            System.Threading.Thread.CurrentThread.Name = "MainFormThread";
            Global.InitDHelperHelper();
            Global.DHelper.DevicesUpdated                         += DHelper_DevicesUpdated;
            Global.DHelper.UpdateCompleted                        += DHelper_UpdateCompleted;
            Global.DHelper.FrequencyUpdated                       += DHelper_FrequencyUpdated;
            Global.DHelper.StatesRetrieved                        += DHelper_StatesRetrieved;
            Global.DHelper.XInputReloaded                         += DHelper_XInputReloaded;
            MainBodyPanel.SettingsPanel._ParentControl             = MainPanel._bwm;
            MainBodyPanel.SettingsPanel.MainDataGrid.SelectionMode = System.Windows.Controls.DataGridSelectionMode.Extended;
            MainBodyPanel.SettingsPanel.InitPanel();
            // NotifySettingsChange will be called on event suspension and resume.
            SettingsManager.Current.NotifySettingsStatus = NotifySettingsStatus;
            // NotifySettingsChange will be called on setting changes.
            var scheduler = ControlsHelper.MainTaskScheduler;

            SettingsManager.Current.SettingChanged += Current_SettingChanged;
            SettingsManager.Load(scheduler);
            SettingsManager.Summaries.Items.ListChanged += Summaries_ListChanged;
            XInputMaskScanner.FileInfoCache.Load();
            UpdateTimer = new System.Timers.Timer
            {
                AutoReset = false,
                Interval  = DefaultPoolingInterval
            };
            UpdateTimer.Elapsed += UpdateTimer_Elapsed;
            SettingsTimer        = new System.Timers.Timer
            {
                AutoReset = false,
                Interval  = 500
            };
            SettingsTimer.Elapsed += SettingsTimer_Elapsed;
            CleanStatusTimer       = new System.Timers.Timer
            {
                AutoReset = false,
                Interval  = 3000
            };
            CleanStatusTimer.Elapsed += CleanStatusTimer_Elapsed;
            Title = EngineHelper.GetProductFullName();
            MainBodyPanel.ShowProgramsTab(SettingsManager.Options.ShowProgramsTab);
            MainBodyPanel.ShowSettingsTab(SettingsManager.Options.ShowSettingsTab);
            MainBodyPanel.ShowDevicesTab(SettingsManager.Options.ShowDevicesTab);
            // Start Timers.
            UpdateTimer.Start();
            JocysCom.ClassLibrary.Win32.NativeMethods.CleanSystemTray();
            // If enabling first time and application version changed then...
            ErrorsHelper.InitErrorsHelper(AppVersionChanged, MainPanel.StatusErrorsLabel, MainPanel.StatusErrorsIcon, MainPanel);
            var game = SettingsManager.CurrentGame;

            if (SettingsManager.Options.HidGuardianConfigureAutomatically)
            {
                // Enable Reconfigure HID Guardian.
                var changed             = SettingsManager.AutoHideShowMappedDevices(game);
                var mappedInstanceGuids = SettingsManager.GetMappedDevices(game?.FileName, true)
                                          .Select(x => x.InstanceGuid).ToArray();
                AppHelper.SynchronizeToHidGuardian(mappedInstanceGuids);
            }
        }