Exemplo n.º 1
0
        public void InitializeItems()
        {
            Items.Clear();

            if (Games != null)
            {
                // Set Favorites
                var favoriteItem = new MenuItem()
                {
                    Header = resources.FindString("FavoriteGame")
                };

                favoriteItem.Click += (s, e) =>
                {
                    editor.SetFavoriteGames(Games, true);
                };

                Items.Add(favoriteItem);

                var unFavoriteItem = new MenuItem()
                {
                    Header = resources.FindString("RemoveFavoriteGame")
                };

                unFavoriteItem.Click += (s, e) =>
                {
                    editor.SetFavoriteGames(Games, false);
                };

                Items.Add(unFavoriteItem);

                // Set Hide
                var hideItem = new MenuItem()
                {
                    Header = resources.FindString("HideGame")
                };

                hideItem.Click += (s, e) =>
                {
                    editor.SetHideGames(Games, true);
                };

                Items.Add(hideItem);

                var unHideItem = new MenuItem()
                {
                    Header = resources.FindString("UnHideGame")
                };

                unHideItem.Click += (s, e) =>
                {
                    editor.SetHideGames(Games, false);
                };

                Items.Add(unHideItem);

                // Edit
                var editItem = new MenuItem()
                {
                    Header = resources.FindString("EditGame")
                };

                editItem.Click += (s, e) =>
                {
                    editor.EditGames(Games);
                };

                Items.Add(editItem);

                // Set Category
                var categoryItem = new MenuItem()
                {
                    Header = resources.FindString("SetGameCategory")
                };

                categoryItem.Click += (s, e) =>
                {
                    editor.SetGamesCategories(Games);
                };

                Items.Add(categoryItem);
                Items.Add(new Separator());

                // Remove
                var removeItem = new MenuItem()
                {
                    Header = resources.FindString("RemoveGame")
                };

                removeItem.Click += (s, e) =>
                {
                    editor.RemoveGames(Games);
                };

                Items.Add(removeItem);
            }
            else if (Game != null)
            {
                // Play / Install
                if (ShowStartSection)
                {
                    bool added = false;
                    if (Game.IsInstalled)
                    {
                        var playItem = new MenuItem()
                        {
                            Header     = resources.FindString("PlayGame"),
                            FontWeight = FontWeights.Bold
                        };

                        playItem.Click += (s, e) =>
                        {
                            editor.PlayGame(Game);
                        };

                        Items.Add(playItem);
                        added = true;
                    }
                    else if (Game.Provider != Provider.Custom)
                    {
                        var installItem = new MenuItem()
                        {
                            Header     = resources.FindString("InstallGame"),
                            FontWeight = FontWeights.Bold
                        };

                        installItem.Click += (s, e) =>
                        {
                            editor.InstallGame(Game);
                        };

                        Items.Add(installItem);
                        added = true;
                    }

                    if (added)
                    {
                        Items.Add(new Separator());
                    }
                }

                // Custom Actions
                if (Game.OtherTasks != null && Game.OtherTasks.Count > 0)
                {
                    foreach (var task in Game.OtherTasks)
                    {
                        var taskItem = new MenuItem()
                        {
                            Header = task.Name
                        };

                        taskItem.Click += (s, e) =>
                        {
                            editor.ActivateAction(Game, task);
                        };

                        Items.Add(taskItem);
                    }

                    Items.Add(new Separator());
                }

                // Open Game Location
                if (Game.IsInstalled)
                {
                    var locationItem = new MenuItem()
                    {
                        Header = resources.FindString("OpenGameLocation")
                    };

                    locationItem.Click += (s, e) =>
                    {
                        editor.OpenGameLocation(Game);
                    };

                    Items.Add(locationItem);
                }

                // Create Desktop Shortcut
                var shortcutItem = new MenuItem()
                {
                    Header = resources.FindString("CreateDesktopShortcut")
                };

                shortcutItem.Click += (s, e) =>
                {
                    editor.CreateShortcut(Game);
                };

                Items.Add(shortcutItem);
                Items.Add(new Separator());

                // Toggle Favorites
                var favoriteItem = new MenuItem()
                {
                    Header = Game.Favorite ? resources.FindString("RemoveFavoriteGame") : resources.FindString("FavoriteGame")
                };

                favoriteItem.Click += (s, e) =>
                {
                    editor.ToggleFavoriteGame(Game);
                };

                Items.Add(favoriteItem);

                // Toggle Hide
                var hideItem = new MenuItem()
                {
                    Header = Game.Hidden ? resources.FindString("UnHideGame") : resources.FindString("HideGame")
                };

                hideItem.Click += (s, e) =>
                {
                    editor.ToggleHideGame(Game);
                };

                Items.Add(hideItem);

                // Edit
                var editItem = new MenuItem()
                {
                    Header = resources.FindString("EditGame")
                };

                editItem.Click += (s, e) =>
                {
                    editor.EditGame(Game);
                };

                Items.Add(editItem);

                // Set Category
                var categoryItem = new MenuItem()
                {
                    Header = resources.FindString("SetGameCategory")
                };

                categoryItem.Click += (s, e) =>
                {
                    editor.SetGameCategories(Game);
                };

                Items.Add(categoryItem);
                Items.Add(new Separator());

                // Remove
                var removeItem = new MenuItem()
                {
                    Header = resources.FindString("RemoveGame")
                };

                removeItem.Click += (s, e) =>
                {
                    editor.RemoveGame(Game);
                };

                Items.Add(removeItem);

                // Uninstall
                if (Game.Provider != Provider.Custom)
                {
                    var uninstallItem = new MenuItem()
                    {
                        Header = resources.FindString("UninstallGame")
                    };

                    uninstallItem.Click += (s, e) =>
                    {
                        editor.UnInstallGame(Game);
                    };

                    Items.Add(uninstallItem);
                }
            }
        }
Exemplo n.º 2
0
        public void InitializeItems()
        {
            Items.Clear();

            if (Games?.Count == 0 && Game == null)
            {
                return;
            }

            if (Games != null)
            {
                // Set Favorites
                var favoriteItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCFavoriteGame"),
                    Icon             = favoriteIcon,
                    Command          = model.SetAsFavoritesCommand,
                    CommandParameter = Games
                };

                Items.Add(favoriteItem);

                var unFavoriteItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCRemoveFavoriteGame"),
                    Icon             = unFavoriteIcon,
                    Command          = model.RemoveAsFavoritesCommand,
                    CommandParameter = Games
                };

                Items.Add(unFavoriteItem);

                // Set Hide
                var hideItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCHideGame"),
                    Icon             = hideIcon,
                    Command          = model.SetAsHiddensCommand,
                    CommandParameter = Games
                };

                Items.Add(hideItem);

                var unHideItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCUnHideGame"),
                    Icon             = unHideIcon,
                    Command          = model.RemoveAsHiddensCommand,
                    CommandParameter = Games
                };

                Items.Add(unHideItem);

                // Edit
                var editItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCEditGame"),
                    Icon             = editIcon,
                    Command          = model.EditGamesCommand,
                    CommandParameter = Games,
                    InputGestureText = model.EditSelectedGamesCommand.GestureText
                };

                Items.Add(editItem);

                // Set Category
                var categoryItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCSetGameCategory"),
                    Icon             = Images.GetEmptyImage(),
                    Command          = model.AssignGamesCategoryCommand,
                    CommandParameter = Games
                };

                Items.Add(categoryItem);
                Items.Add(new Separator());

                // Remove
                var removeItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCRemoveGame"),
                    Icon             = removeIcon,
                    Command          = model.RemoveGamesCommand,
                    CommandParameter = Games,
                    InputGestureText = model.RemoveSelectedGamesCommand.GestureText
                };

                Items.Add(removeItem);
            }
            else if (Game != null)
            {
                // Play / Install
                if (ShowStartSection)
                {
                    bool added = false;
                    if (Game.IsInstalled)
                    {
                        var playItem = new MenuItem()
                        {
                            Header           = resources.FindString("LOCPlayGame"),
                            Icon             = startIcon,
                            FontWeight       = FontWeights.Bold,
                            Command          = model.StartGameCommand,
                            CommandParameter = Game,
                            InputGestureText = model.StartSelectedGameCommand.GestureText
                        };

                        Items.Add(playItem);
                        added = true;
                    }
                    else if (Game.Provider != Provider.Custom)
                    {
                        var installItem = new MenuItem()
                        {
                            Header           = resources.FindString("LOCInstallGame"),
                            Icon             = installIcon,
                            FontWeight       = FontWeights.Bold,
                            Command          = model.InstallGameCommand,
                            CommandParameter = Game
                        };

                        Items.Add(installItem);
                        added = true;
                    }

                    if (added)
                    {
                        Items.Add(new Separator());
                    }
                }

                // Custom Actions
                if (Game.OtherTasks != null && Game.OtherTasks.Count > 0)
                {
                    foreach (var task in Game.OtherTasks)
                    {
                        var taskItem = new MenuItem()
                        {
                            Header = task.Name,
                            Icon   = Images.GetEmptyImage()
                        };

                        taskItem.Click += (s, e) =>
                        {
                            model.GamesEditor.ActivateAction(Game, task);
                        };

                        Items.Add(taskItem);
                    }

                    Items.Add(new Separator());
                }

                // Links
                if (Game.Links?.Any() == true)
                {
                    var linksItem = new MenuItem()
                    {
                        Header = resources.FindString("LOCLinksLabel"),
                        Icon   = linksIcon
                    };

                    foreach (var link in Game.Links)
                    {
                        linksItem.Items.Add(new MenuItem()
                        {
                            Header           = link.Name,
                            Command          = Commands.GeneralCommands.NavigateUrlCommand,
                            CommandParameter = link.Url
                        });
                    }

                    Items.Add(linksItem);
                    Items.Add(new Separator());
                }

                // Open Game Location
                if (Game.IsInstalled)
                {
                    var locationItem = new MenuItem()
                    {
                        Header           = resources.FindString("LOCOpenGameLocation"),
                        Icon             = browseIcon,
                        Command          = model.OpenGameLocationCommand,
                        CommandParameter = Game
                    };

                    Items.Add(locationItem);
                }

                // Create Desktop Shortcut
                var shortcutItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCCreateDesktopShortcut"),
                    Icon             = shortcutIcon,
                    Command          = model.CreateGameShortcutCommand,
                    CommandParameter = Game
                };

                Items.Add(shortcutItem);
                Items.Add(new Separator());

                // Toggle Favorites
                var favoriteItem = new MenuItem()
                {
                    Header           = Game.Favorite ? resources.FindString("LOCRemoveFavoriteGame") : resources.FindString("LOCFavoriteGame"),
                    Icon             = Game.Favorite ? unFavoriteIcon : favoriteIcon,
                    Command          = model.ToggleFavoritesCommand,
                    CommandParameter = Game
                };

                Items.Add(favoriteItem);

                // Toggle Hide
                var hideItem = new MenuItem()
                {
                    Header           = Game.Hidden ? resources.FindString("LOCUnHideGame") : resources.FindString("LOCHideGame"),
                    Icon             = Game.Hidden ? unHideIcon : hideIcon,
                    Command          = model.ToggleVisibilityCommand,
                    CommandParameter = Game
                };

                Items.Add(hideItem);

                // Edit
                var editItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCEditGame"),
                    Icon             = editIcon,
                    Command          = model.EditGameCommand,
                    CommandParameter = Game,
                    InputGestureText = model.EditSelectedGamesCommand.GestureText
                };

                Items.Add(editItem);

                // Set Category
                var categoryItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCSetGameCategory"),
                    Icon             = Images.GetEmptyImage(),
                    Command          = model.AssignGameCategoryCommand,
                    CommandParameter = Game
                };

                Items.Add(categoryItem);
                Items.Add(new Separator());

                // Remove
                var removeItem = new MenuItem()
                {
                    Header           = resources.FindString("LOCRemoveGame"),
                    Icon             = removeIcon,
                    Command          = model.RemoveGameCommand,
                    CommandParameter = Game,
                    InputGestureText = model.RemoveGameCommand.GestureText
                };

                Items.Add(removeItem);

                // Uninstall
                if (Game.Provider != Provider.Custom && Game.IsInstalled)
                {
                    var uninstallItem = new MenuItem()
                    {
                        Header           = resources.FindString("LOCUninstallGame"),
                        Icon             = Images.GetEmptyImage(),
                        Command          = model.UninstallGameCommand,
                        CommandParameter = Game
                    };

                    Items.Add(uninstallItem);
                }
            }
        }
Exemplo n.º 3
0
        public void PlayGame(Game game)
        {
            if (!game.IsInstalled)
            {
                InstallGame(game);
                return;
            }

            logger.Info($"Starting {game.GetIdentifierInfo()}");
            var dbGame = database.Games.Get(game.Id);

            if (dbGame == null)
            {
                dialogs.ShowMessage(
                    string.Format(resources.FindString("LOCGameStartErrorNoGame"), game.Name),
                    resources.FindString("LOCGameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
                UpdateJumpList();
                return;
            }

            IGameController controller = null;

            try
            {
                if (game.IsRunning)
                {
                    logger.Warn("Failed to start the game, game is already running.");
                    return;
                }

                if (game.PlayAction.IsHandledByPlugin)
                {
                    logger.Info("Using library plugin to start the game.");
                    controller = controllers.GetGameBasedController(game, extensions.LibraryPlugins.Select(a => a.Value.Plugin));
                }
                else
                {
                    logger.Info("Using generic controller start the game.");
                    controller = controllers.GetGenericGameController(game);
                }

                if (controller == null)
                {
                    dialogs.ShowErrorMessage(
                        resources.FindString("LOCErrorLibraryPluginNotFound"),
                        resources.FindString("LOCGameError"));
                    return;
                }

                controllers.RemoveController(game.Id);
                controllers.AddController(controller);
                UpdateGameState(game.Id, null, null, null, null, true);
                controller.Play();
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                if (controller != null)
                {
                    controllers.RemoveController(game.Id);
                    UpdateGameState(game.Id, null, null, null, null, false);
                }

                logger.Error(exc, "Cannot start game: ");
                dialogs.ShowMessage(
                    string.Format(resources.FindString("LOCGameStartError"), exc.Message),
                    resources.FindString("LOCGameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                UpdateJumpList();
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(exc, "Failed to set jump list data: ");
            }
        }
Exemplo n.º 4
0
        public void PlayGame(IGame game)
        {
            // Set parent for message boxes in this method
            // because this method can be invoked from tray icon which otherwise bugs the dialog
            if (database.GamesCollection.FindOne(a => a.ProviderId == game.ProviderId) == null)
            {
                PlayniteMessageBox.Show(
                    Application.Current.MainWindow,
                    string.Format(resources.FindString("GameStartErrorNoGame"), game.Name),
                    resources.FindString("GameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
                UpdateJumpList();
                return;
            }

            try
            {
                if (game.IsInstalled)
                {
                    game.PlayGame(database.EmulatorsCollection.FindAll().ToList());
                }
                else
                {
                    game.InstallGame();
                }

                database.UpdateGameInDatabase(game);
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(exc, "Cannot start game: ");
                PlayniteMessageBox.Show(
                    Application.Current.MainWindow,
                    string.Format(resources.FindString("GameStartError"), exc.Message),
                    resources.FindString("GameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                UpdateJumpList();
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(exc, "Failed to set jump list data: ");
            }

            if (Settings.Instance.MinimizeAfterLaunch)
            {
                Application.Current.MainWindow.WindowState = WindowState.Minimized;
            }
        }
Exemplo n.º 5
0
        public void PlayGame(Game game)
        {
            var dbGame = database.GetGame(game.Id);

            if (dbGame == null)
            {
                dialogs.ShowMessage(
                    string.Format(resources.FindString("LOCGameStartErrorNoGame"), game.Name),
                    resources.FindString("LOCGameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
                UpdateJumpList();
                return;
            }

            try
            {
                var controller = GameControllerFactory.GetGameBasedController(game, appSettings);
                Controllers.RemoveController(game.Id);
                Controllers.AddController(controller);

                if (game.IsInstalled)
                {
                    UpdateGameState(game.Id, null, null, null, null, true);
                    controller.Play(database.GetEmulators());
                }
                else
                {
                    InstallGame(game);
                    return;
                }
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(exc, "Cannot start game: ");
                dialogs.ShowMessage(
                    string.Format(resources.FindString("LOCGameStartError"), exc.Message),
                    resources.FindString("LOCGameError"),
                    MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            try
            {
                UpdateJumpList();
            }
            catch (Exception exc) when(!PlayniteEnvironment.ThrowAllErrors)
            {
                logger.Error(exc, "Failed to set jump list data: ");
            }
        }