Beispiel #1
0
        private void ExecuteSelectGameCommand(Game param)
        {
            var game = Games.FirstOrDefault(p => p.gameId == param.gameId);

            if (game != null)
            {
                if (!game.selected)
                {
                    game.selected        = true;
                    game.colorBackground = "#333E3A";
                    game.colorText       = "#FFFFFF";

                    SelectedGames.Add(game);
                }
                else
                {
                    game.selected        = false;
                    game.colorBackground = "#FFFFFF";
                    game.colorText       = "#000000";

                    SelectedGames.Remove(game);
                }

                CountItems    = SelectedGames.Count.ToString();
                IsVisibleSort = SelectedGames.Count > 0;
            }
        }
Beispiel #2
0
        public async Task DeleteSelectedGames()
        {
            if (SelectedGames.Count == 0)
            {
                return;
            }

            if (MessageBox.Show(string.Format("Delete {0} games?", SelectedGames.Count), "Delete games?", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
            {
                return;
            }

            var selectedGames = SelectedGames.ToList();

            foreach (var game in selectedGames)
            {
                await gameManager.DeleteGame(game.Id);
            }
        }
Beispiel #3
0
        private void ExecuteSortGamesCommand(string param)
        {
            bool orderByAZ = param.Contains(FontIcons.SortAZ);

            IconOrderBy = orderByAZ ? FontIcons.SortZA : FontIcons.SortAZ;
            IEnumerable <Game> items;

            if (orderByAZ)
            {
                items = SelectedGames.OrderBy(p => p.name).ToList();
            }
            else
            {
                items = SelectedGames.OrderByDescending(p => p.name).ToList();
            }

            SelectedGames.Clear();
            foreach (var item in items)
            {
                SelectedGames.Add(item);
            }
        }
Beispiel #4
0
        private void InitializeCommands()
        {
            OpenSearchCommand = new RelayCommand <object>((game) =>
            {
                if (SearchOpened)
                {
                    // The binding sometimes breaks when main window is restored from minimized state.
                    // This fixes it.
                    SearchOpened = false;
                }

                SearchOpened = true;
            }, new KeyGesture(Key.F, ModifierKeys.Control));

            ToggleExplorerPanelCommand = new RelayCommand <object>((game) =>
            {
                AppSettings.ExplorerPanelVisible = !AppSettings.ExplorerPanelVisible;
            }, new KeyGesture(Key.E, ModifierKeys.Control));

            ToggleFilterPanelCommand = new RelayCommand <object>((game) =>
            {
                AppSettings.FilterPanelVisible = !AppSettings.FilterPanelVisible;
            }, new KeyGesture(Key.G, ModifierKeys.Control));

            OpenFilterPanelCommand = new RelayCommand <object>((game) =>
            {
                AppSettings.FilterPanelVisible = true;
            });

            CloseFilterPanelCommand = new RelayCommand <object>((game) =>
            {
                AppSettings.FilterPanelVisible = false;
            });

            CloseNotificationPanelCommand = new RelayCommand <object>((game) =>
            {
                AppSettings.NotificationPanelVisible = false;
            });

            ThirdPartyToolOpenCommand = new RelayCommand <ThirdPartyTool>((tool) =>
            {
                StartThirdPartyTool(tool);
            });

            UpdateGamesCommand = new RelayCommand <object>((a) =>
            {
#pragma warning disable CS4014
                UpdateLibrary(AppSettings.DownloadMetadataOnImport, true);
#pragma warning restore CS4014
            }, (a) => GameAdditionAllowed,
                                                           new KeyGesture(Key.F5));

            OpenSteamFriendsCommand = new RelayCommand <object>((a) =>
            {
                OpenSteamFriends();
            });

            ReportIssueCommand = new RelayCommand <object>((a) =>
            {
                ReportIssue();
            });

            ShutdownCommand = new RelayCommand <object>((a) =>
            {
                if (GlobalTaskHandler.IsActive)
                {
                    if (Dialogs.ShowMessage(
                            Resources.GetString("LOCBackgroundProgressCancelAskExit"),
                            Resources.GetString("LOCCrashClosePlaynite"),
                            MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                    {
                        return;
                    }
                }

                ignoreCloseActions = true;
                ShutdownApp();
            }, new KeyGesture(Key.Q, ModifierKeys.Alt));

            ShowWindowCommand = new RelayCommand <object>((a) =>
            {
                RestoreWindow();
            });

            WindowClosingCommand = new RelayCommand <CancelEventArgs>((args) =>
            {
                OnClosing(args);
            });

            FileDroppedCommand = new RelayCommand <DragEventArgs>((args) =>
            {
                OnFileDropped(args);
            });

            OpenAboutCommand = new RelayCommand <object>((a) =>
            {
                OpenAboutWindow(new AboutViewModel(new AboutWindowFactory(), Dialogs, Resources, App.ServicesClient));
            }, new KeyGesture(Key.F1));

            OpenEmulatorsCommand = new RelayCommand <object>((a) =>
            {
                ConfigureEmulators(
                    new EmulatorsViewModel(Database,
                                           new EmulatorsWindowFactory(),
                                           Dialogs,
                                           Resources));
            }, (a) => Database?.IsOpen == true,
                                                             new KeyGesture(Key.T, ModifierKeys.Control));

            OpenSoftwareToolsCommand = new RelayCommand <object>((a) =>
            {
                ConfigureSoftwareTools(new ToolsConfigViewModel(
                                           Database,
                                           new ToolsConfigWindowFactory(),
                                           Dialogs,
                                           Resources));
            }, (a) => Database?.IsOpen == true);

            AddCustomGameCommand = new RelayCommand <object>((a) =>
            {
                AddCustomGame(new GameEditWindowFactory());
            }, (a) => Database?.IsOpen == true,
                                                             new KeyGesture(Key.Insert));

            AddInstalledGamesCommand = new RelayCommand <object>((a) =>
            {
                ImportInstalledGames(
                    new InstalledGamesViewModel(
                        new InstalledGamesWindowFactory(),
                        Dialogs), null);
            }, (a) => Database?.IsOpen == true);

            AddEmulatedGamesCommand = new RelayCommand <object>((a) =>
            {
                ImportEmulatedGames(
                    new EmulatedGamesImportViewModel(
                        Database,
                        new EmulatedGameImportWindowFactory(),
                        Dialogs,
                        Resources));
            }, (a) => Database?.IsOpen == true,
                                                                new KeyGesture(Key.Q, ModifierKeys.Control));

            AddWindowsStoreGamesCommand = new RelayCommand <object>((a) =>
            {
                ImportWindowsStoreGames(
                    new InstalledGamesViewModel(
                        new InstalledGamesWindowFactory(),
                        Dialogs));
            }, (a) => Database?.IsOpen == true);

            OpenFullScreenCommand = new RelayCommand <object>((a) =>
            {
                SwitchToFullscreenMode();
            }, new KeyGesture(Key.F11));

            OpenFullScreenFromControllerCommand = new RelayCommand <object>((a) =>
            {
                if (AppSettings.GuideButtonOpensFullscreen)
                {
                    SwitchToFullscreenMode();
                }
            }, new KeyGesture(Key.F11));

            ClearMessagesCommand = new RelayCommand <object>((a) =>
            {
                ClearMessages();
            }, (a) => PlayniteApi?.Notifications?.Count > 0);

            DownloadMetadataCommand = new RelayCommand <object>((a) =>
            {
                DownloadMetadata(new MetadataDownloadViewModel(new MetadataDownloadWindowFactory()));
            }, (a) => GameAdditionAllowed,
                                                                new KeyGesture(Key.D, ModifierKeys.Control));

            ClearFiltersCommand = new RelayCommand <object>((a) =>
            {
                ClearFilters();
            });

            CheckForUpdateCommand = new RelayCommand <object>((a) =>
            {
                CheckForUpdate();
            });

            OpenDbFieldsManagerCommand = new RelayCommand <object>((a) =>
            {
                ConfigureDatabaseFields(
                    new DatabaseFieldsManagerViewModel(
                        Database,
                        new DatabaseFieldsManagerWindowFactory(),
                        Dialogs,
                        Resources));
            }, (a) => GameAdditionAllowed,
                                                                   new KeyGesture(Key.W, ModifierKeys.Control));

            OpenLibraryIntegrationsConfigCommand = new RelayCommand <object>((a) =>
            {
                OpenIntegrationSettings(
                    new LibraryIntegrationsViewModel(
                        new LibraryIntegrationsWindowFactory(),
                        Dialogs,
                        Resources,
                        Extensions));
            });

            UpdateLibraryCommand = new RelayCommand <LibraryPlugin>((a) =>
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                UpdateLibrary(a);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }, (a) => GameAdditionAllowed);

            RemoveGameSelectionCommand = new RelayCommand <object>((a) =>
            {
                RemoveGameSelection();
            });

            InvokeExtensionFunctionCommand = new RelayCommand <ExtensionFunction>((f) =>
            {
                if (!Extensions.InvokeExtension(f, out var error))
                {
                    Dialogs.ShowMessage(
                        error.Message,
                        Resources.GetString("LOCScriptError"),
                        MessageBoxButton.OK, MessageBoxImage.Error);
                }
            });

            ReloadScriptsCommand = new RelayCommand <object>((f) =>
            {
                Extensions.LoadScripts(PlayniteApi, AppSettings.DisabledPlugins, App.CmdLine.SafeStartup, AppSettings.DevelExtenions.Where(a => a.Selected == true).Select(a => a.Item).ToList());
            }, new KeyGesture(Key.F12));

            ShowGameSideBarCommand = new RelayCommand <GamesCollectionViewEntry>((f) =>
            {
                AppSettings.GridViewSideBarVisible = true;
                SelectedGame = f;
            });

            CloseGameSideBarCommand = new RelayCommand <object>((f) =>
            {
                AppSettings.GridViewSideBarVisible = false;
            });

            OpenSettingsCommand = new RelayCommand <object>((a) =>
            {
                OpenSettings(
                    new SettingsViewModel(Database,
                                          AppSettings,
                                          new SettingsWindowFactory(),
                                          Dialogs,
                                          Resources,
                                          Extensions,
                                          App));
            }, new KeyGesture(Key.F4));

            OpenAddonsCommand = new RelayCommand <object>((a) =>
            {
                new AddonsViewModel(
                    new AddonsWindowFactory(),
                    PlayniteApi,
                    Dialogs,
                    Resources,
                    App.ServicesClient,
                    Extensions,
                    AppSettings,
                    App).OpenView();
            }, new KeyGesture(Key.F9));

            StartGameCommand = new RelayCommand <Game>((game) =>
            {
                if (game != null)
                {
                    GamesEditor.PlayGame(game);
                }
                else if (SelectedGame != null)
                {
                    GamesEditor.PlayGame(SelectedGame.Game);
                }
            });

            StartSoftwareToolCommand = new RelayCommand <AppSoftware>((app) =>
            {
                StartSoftwareTool(app);
            });

            InstallGameCommand = new RelayCommand <Game>((game) =>
            {
                if (game != null)
                {
                    GamesEditor.InstallGame(game);
                }
                else if (SelectedGame != null)
                {
                    GamesEditor.InstallGame(SelectedGame.Game);
                }
            });

            UninstallGameCommand = new RelayCommand <Game>((game) =>
            {
                if (game != null)
                {
                    GamesEditor.UnInstallGame(game);
                }
                else if (SelectedGame != null)
                {
                    GamesEditor.UnInstallGame(SelectedGame.Game);
                }
            });

            EditSelectedGamesCommand = new RelayCommand <object>((a) =>
            {
                if (SelectedGames?.Count() > 1)
                {
                    ignoreSelectionChanges = true;
                    try
                    {
                        GamesEditor.EditGames(SelectedGames.Select(g => g.Game).ToList());
                    }
                    finally
                    {
                        ignoreSelectionChanges = false;
                    }
                }
                else
                {
                    GamesEditor.EditGame(SelectedGame.Game);
                }
            },
                                                                 (a) => SelectedGame != null,
                                                                 new KeyGesture(Key.F3));

            StartSelectedGameCommand = new RelayCommand <object>((a) =>
            {
                GamesEditor.PlayGame(SelectedGame.Game);
            },
                                                                 (a) => SelectedGames?.Count() == 1,
                                                                 new KeyGesture(Key.Enter));

            RemoveSelectedGamesCommand = new RelayCommand <object>((a) =>
            {
                if (SelectedGames?.Count() > 1)
                {
                    GamesEditor.RemoveGames(SelectedGames.Select(g => g.Game).Distinct().ToList());
                }
                else
                {
                    GamesEditor.RemoveGame(SelectedGame.Game);
                }
            },
                                                                   (a) => SelectedGame != null,
                                                                   new KeyGesture(Key.Delete));

            EditGameCommand = new RelayCommand <Game>((a) =>
            {
                if (GamesEditor.EditGame(a) == true)
                {
                    SelectedGame = GamesView.Items.FirstOrDefault(g => g.Id == a.Id);
                }
            });

            EditGamesCommand = new RelayCommand <IEnumerable <Game> >((a) =>
            {
                ignoreSelectionChanges = true;
                try
                {
                    GamesEditor.EditGames(a.ToList());
                }
                finally
                {
                    ignoreSelectionChanges = false;
                }
            });

            OpenGameLocationCommand = new RelayCommand <Game>((a) =>
            {
                GamesEditor.OpenGameLocation(a);
            });

            CreateDesktopShortcutCommand = new RelayCommand <Game>((a) =>
            {
                GamesEditor.CreateDesktopShortcut(a);
            });

            CreateDesktopShortcutsCommand = new RelayCommand <List <Game> >((a) =>
            {
                GamesEditor.CreateDesktopShortcut(a);
            });

            OpenManualCommand = new RelayCommand <Game>((a) =>
            {
                GamesEditor.OpenManual(a);
            });

            ToggleFavoritesCommand = new RelayCommand <Game>((a) =>
            {
                GamesEditor.ToggleFavoriteGame(a);
            });

            ToggleVisibilityCommand = new RelayCommand <Game>((a) =>
            {
                GamesEditor.ToggleHideGame(a);
            });

            AssignGameCategoryCommand = new RelayCommand <Game>((a) =>
            {
                if (GamesEditor.SetGameCategories(a) == true)
                {
                    SelectedGame = GamesView.Items.FirstOrDefault(g => g.Id == a.Id);
                }
            });

            AssignGamesCategoryCommand = new RelayCommand <IEnumerable <Game> >((a) =>
            {
                GamesEditor.SetGamesCategories(a.ToList());
            });

            SetGameCompletionStatusCommand = new RelayCommand <Tuple <Game, CompletionStatus> >((a) =>
            {
                GamesEditor.SetCompletionStatus(a.Item1, a.Item2);
            });

            SetGamesCompletionStatusCommand = new RelayCommand <Tuple <IEnumerable <Game>, CompletionStatus> >((a) =>
            {
                GamesEditor.SetCompletionStatus(a.Item1.ToList(), a.Item2);
            });

            RemoveGameCommand = new RelayCommand <Game>((a) =>
            {
                GamesEditor.RemoveGame(a);
            },
                                                        new KeyGesture(Key.Delete));

            RemoveGamesCommand = new RelayCommand <IEnumerable <Game> >((a) =>
            {
                GamesEditor.RemoveGames(a.Distinct().ToList());
            },
                                                                        new KeyGesture(Key.Delete));

            SetAsFavoritesCommand = new RelayCommand <IEnumerable <Game> >((a) =>
            {
                GamesEditor.SetFavoriteGames(a.ToList(), true);
            });

            RemoveAsFavoritesCommand = new RelayCommand <IEnumerable <Game> >((a) =>
            {
                GamesEditor.SetFavoriteGames(a.ToList(), false);
            });

            SetAsHiddensCommand = new RelayCommand <IEnumerable <Game> >((a) =>
            {
                GamesEditor.SetHideGames(a.ToList(), true);
            });

            RemoveAsHiddensCommand = new RelayCommand <IEnumerable <Game> >((a) =>
            {
                GamesEditor.SetHideGames(a.ToList(), false);
            });

            SelectRandomGameCommand = new RelayCommand <object>((a) =>
            {
                PlayRandomGame();
            }, (a) => Database?.IsOpen == true,
                                                                new KeyGesture(Key.F6));

            RestartInSafeMode = new RelayCommand <object>((a) =>
            {
                RestartAppSafe();
            });

            SelectSidebarViewCommand = new RelayCommand <SidebarWrapperItem>((a) =>
            {
                a.Command.Execute(null);
            });

            SwitchDetailsViewCommand = new RelayCommand <object>((_) => AppSettings.ViewSettings.GamesViewType = ViewType.Details);
            SwitchGridViewCommand    = new RelayCommand <object>((_) => AppSettings.ViewSettings.GamesViewType = ViewType.Grid);
            SwitchListViewCommand    = new RelayCommand <object>((_) => AppSettings.ViewSettings.GamesViewType = ViewType.List);

            UpdateEmulationDirCommand = new RelayCommand <GameScannerConfig>((a) =>
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                UpdateEmulationLibrary(a);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }, (a) => GameAdditionAllowed);

            UpdateEmulationDirsCommand = new RelayCommand(() =>
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                UpdateEmulationLibrary();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }, () => GameAdditionAllowed);
        }
 private async void ButtonMultiDelete_OnClick(object sender, RoutedEventArgs e)
 => await GameStatsHelper.DeleteGamesWithDialog(this, SelectedGames.ToArray());
 private void ButtonMultiMove_OnClick(object sender, RoutedEventArgs e)
 => GameStatsHelper.MoveGamesToOtherDeckWithDialog(this, SelectedGames.ToArray());