Example #1
0
 public GameViewEntry(Game game, string category, GamesCollectionView view, ILibraryPlugin plugin)
 {
     this.plugin           = plugin;
     this.view             = view;
     Category              = new CategoryView(category);
     Game                  = game;
     Game.PropertyChanged += Game_PropertyChanged;
     Platform              = new PlatformView(game.PlatformId, view.Database.Platforms[game.PlatformId]);
 }
Example #2
0
        public static List <Game> ImportGames(ILibraryPlugin library, GameDatabase database, bool forcePlayTimeSync)
        {
            var addedGames = new List <Game>();

            foreach (var newGame in library.GetGames())
            {
                var existingGame = database.Games.FirstOrDefault(a => a.GameId == newGame.GameId && a.PluginId == library.Id);
                if (existingGame == null)
                {
                    logger.Info(string.Format("Adding new game {0} from {1} plugin", newGame.GameId, library.Name));
                    if (!string.IsNullOrEmpty(newGame.Icon))
                    {
                        newGame.Icon = AddNewGameFile(newGame.Icon, newGame.Id, database);
                    }

                    if (!string.IsNullOrEmpty(newGame.CoverImage))
                    {
                        newGame.CoverImage = AddNewGameFile(newGame.CoverImage, newGame.Id, database);
                    }

                    if (!string.IsNullOrEmpty(newGame.BackgroundImage))
                    {
                        if (!newGame.BackgroundImage.IsHttpUrl())
                        {
                            newGame.BackgroundImage = AddNewGameFile(newGame.BackgroundImage, newGame.Id, database);
                        }
                    }

                    database.AssignPcPlatform(newGame);
                    database.Games.Add(newGame);
                    addedGames.Add(newGame);
                }
                else
                {
                    existingGame.IsInstalled      = newGame.IsInstalled;
                    existingGame.InstallDirectory = newGame.InstallDirectory;
                    if (existingGame.PlayAction == null || existingGame.PlayAction.IsHandledByPlugin)
                    {
                        existingGame.PlayAction = newGame.PlayAction;
                    }

                    if ((existingGame.Playtime == 0 && newGame.Playtime > 0) ||
                        (newGame.Playtime > 0 && forcePlayTimeSync))
                    {
                        existingGame.Playtime = newGame.Playtime;
                        if (existingGame.CompletionStatus == CompletionStatus.NotPlayed)
                        {
                            existingGame.CompletionStatus = CompletionStatus.Played;
                        }

                        if (existingGame.LastActivity == null && newGame.LastActivity != null)
                        {
                            existingGame.LastActivity = newGame.LastActivity;
                        }
                    }

                    if (existingGame.OtherActions?.Any() != true && newGame.OtherActions?.Any() == true)
                    {
                        existingGame.OtherActions = newGame.OtherActions;
                    }

                    database.Games.Update(existingGame);
                }
            }

            return(addedGames);
        }
Example #3
0
        public static IEnumerable <Game> ImportGames(ILibraryPlugin library, GameDatabase database)
        {
            foreach (var newGame in library.GetGames())
            {
                var existingGame = database.GamesCollection.FindOne(a => a.GameId == newGame.GameId && a.PluginId == library.Id);
                if (existingGame == null)
                {
                    logger.Info(string.Format("Adding new game {0} from {1} plugin", newGame.GameId, library.Name));
                    if (!string.IsNullOrEmpty(newGame.Icon))
                    {
                        newGame.Icon = AddNewFile(newGame.Icon, library.Id, database);
                    }

                    if (!string.IsNullOrEmpty(newGame.CoverImage))
                    {
                        newGame.CoverImage = AddNewFile(newGame.CoverImage, library.Id, database);
                    }

                    if (!string.IsNullOrEmpty(newGame.BackgroundImage))
                    {
                        if (!newGame.BackgroundImage.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                        {
                            newGame.BackgroundImage = AddNewFile(newGame.BackgroundImage, library.Id, database);
                        }
                    }

                    database.AssignPcPlatform(newGame);
                    database.AddGame(newGame);
                    yield return(newGame);
                }
                else
                {
                    existingGame.State.Installed  = newGame.State.Installed;
                    existingGame.InstallDirectory = newGame.InstallDirectory;
                    if (existingGame.PlayAction == null || existingGame.PlayAction.IsHandledByPlugin)
                    {
                        existingGame.PlayAction = newGame.PlayAction;
                    }

                    if (existingGame.Playtime == 0 && newGame.Playtime > 0)
                    {
                        existingGame.Playtime = newGame.Playtime;
                        if (existingGame.CompletionStatus == CompletionStatus.NotPlayed)
                        {
                            existingGame.CompletionStatus = CompletionStatus.Played;
                        }

                        if (existingGame.LastActivity == null && newGame.LastActivity != null)
                        {
                            existingGame.LastActivity = newGame.LastActivity;
                        }
                    }

                    if (existingGame.OtherActions?.Any() != true && newGame.OtherActions?.Any() == true)
                    {
                        existingGame.OtherActions = newGame.OtherActions;
                    }

                    database.UpdateGameInDatabase(existingGame);
                }
            }
        }
Example #4
0
 public LoadedLibraryPlugin(ILibraryPlugin plugin, ExtensionDescription description)
 {
     Plugin      = plugin;
     Description = description;
 }