示例#1
0
文件: Global.cs 项目: x360ce/x360ce
        public static void FindAndSetOpenGame()
        {
            // Get selected process.
            var activeProcess = ForegroundWindowHook.GetActiveProcess();
            var activePath    = ForegroundWindowHook.GetProcessFileName(activeProcess);
            var allPaths      = System.Diagnostics.Process.GetProcesses().Select(x => ForegroundWindowHook.GetProcessFileName(x))
                                .Distinct()
                                .ToArray();
            // Get list of all configured user games.
            var userGames  = SettingsManager.UserGames.ItemsToArraySynchronized().ToList();
            var currentApp = userGames.FirstOrDefault(x => x.IsCurrentApp());

            if (currentApp != null)
            {
                userGames.Remove(currentApp);
            }
            // Select all games which are running (except current app).
            var runningGames = userGames
                               .Where(x => allPaths.Any(a => string.Equals(x.FullPath, a, StringComparison.OrdinalIgnoreCase)))
                               .ToArray();

            // If game was selected and still running then...
            if (!string.IsNullOrEmpty(LastActivePath) && runningGames.Any(x => x.FullPath == LastActivePath))
            {
                // Do nothing, because user could be trying to adjust mapping on the running game.
                return;
            }
            // Try to get game by active window (except current app).
            var game = runningGames
                       .FirstOrDefault(x => string.Equals(x.FullPath, activePath, StringComparison.OrdinalIgnoreCase));

            // If not found then...
            if (game == null)
            {
                // Try to get first currently running game (except current app).
                game = runningGames.FirstOrDefault(x => !x.IsCurrentApp());
            }
            // If not found then...
            if (game == null)
            {
                // Select current app.
                game = currentApp;
            }
            LastActivePath = game?.FullPath;
            SettingsManager.UpdateCurrentGame(game);
        }
示例#2
0
        private void GameToCustomizeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var game = (UserGame)GameToCustomizeComboBox.SelectedItem;

            SettingsManager.UpdateCurrentGame(game);
        }