Пример #1
0
        public Game GetLibraryGameFromGamePassGameAnySource(GamePassGame gamePassGame)
        {
            var game = PlayniteApi.Database.Games.
                       Where(g => g.PluginId.Equals(pluginId)).
                       Where(g => g.GameId.Equals(gamePassGame.GameId)).
                       FirstOrDefault();

            return(game);
        }
Пример #2
0
        public void AddExpiredTag(GamePassGame gamePassGame)
        {
            var game = GetLibraryGameFromGamePassGame(gamePassGame);

            if (game != null)
            {
                AddTagToGame(game, gameExpiredTag);
                game.SourceId = sourceXbox.Id;
                PlayniteApi.Database.Games.Update(game);
            }
        }
Пример #3
0
        public GamePassGame RestoreMediaPaths(GamePassGame game)
        {
            game.CoverImageLowRes = Path.GetFileName(game.CoverImageLowRes);
            game.CoverImage       = Path.GetFileName(game.CoverImage);
            if (game.Icon != null)
            {
                game.Icon = Path.GetFileName(game.Icon);
            }

            return(game);
        }
Пример #4
0
        public void DownloadGamePassGameCache(GamePassGame game)
        {
            game.CoverImageLowRes = Path.Combine(imageCachePath, game.CoverImageLowRes);
            DownloadFile(string.Format("{0}?mode=scale&q=90&h=300&w=200", game.CoverImageUrl), game.CoverImageLowRes).GetAwaiter().GetResult();

            game.CoverImage = Path.Combine(imageCachePath, game.CoverImage);
            DownloadFile(string.Format("{0}?mode=scale&q=90&h=900&w=600", game.CoverImageUrl), game.CoverImage).GetAwaiter().GetResult();

            if (game.Icon != null)
            {
                game.Icon = Path.Combine(imageCachePath, game.Icon);
                DownloadFile(string.Format("{0}?mode=scale&q=90&h=128&w=128", game.IconUrl), game.Icon).GetAwaiter().GetResult();
            }
        }
 public bool GetAddButtonStatus(GamePassGame game)
 {
     if (game == null)
     {
         return(false);
     }
     if (xboxLibraryHelper.GameIdsInLibrary.Contains(game.GameId))
     {
         return(false);
     }
     if (game.ProductType == ProductType.Collection)
     {
         return(false);
     }
     if (game.ProductType == ProductType.EaGame)
     {
         return(false);
     }
     return(true);
 }
Пример #6
0
        public bool RemoveGamePassGame(GamePassGame gamePassGame)
        {
            var game = GetLibraryGameFromGamePassGame(gamePassGame);

            if (game != null)
            {
                if (game.Playtime > 0)
                {
                    game.SourceId = sourceXbox.Id;
                    PlayniteApi.Database.Games.Update(game);
                    return(false);
                }
                else
                {
                    PlayniteApi.Database.Games.Remove(game.Id);
                    GameIdsInLibrary.Remove(game.GameId);
                    return(true);
                }
            }
            return(false);
        }
Пример #7
0
        public bool AddGameToLibrary(GamePassGame game, bool showGameAddDialog)
        {
            if (game == null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(game.GameId))
            {
                return(false);
            }

            if (game.ProductType != ProductType.Game)
            {
                return(false);
            }

            var existingGame = GetLibraryGameFromGamePassGameAnySource(game);

            if (existingGame != null)
            {
                return(false);
            }

            var newGame = new Game
            {
                Name         = game.Name,
                GameId       = game.GameId,
                DeveloperIds = arrayToCompanyGuids(game.Developers),
                PublisherIds = arrayToCompanyGuids(game.Publishers),
                PluginId     = pluginId,
                PlatformIds  = platformsList,
                Description  = StringToHtml(game.Description, true),
                SourceId     = source.Id,
                ReleaseDate  = new ReleaseDate(game.ReleaseDate)
            };

            AddTagToGame(newGame, gameAddedTag);

            PlayniteApi.Database.Games.Add(newGame);

            if (File.Exists(game.CoverImage))
            {
                var copiedImage = PlayniteApi.Database.AddFile(game.CoverImage, newGame.Id);
                newGame.CoverImage = copiedImage;
            }

            if (File.Exists(game.Icon))
            {
                var copiedImage = PlayniteApi.Database.AddFile(game.Icon, newGame.Id);
                newGame.Icon = copiedImage;
            }

            if (string.IsNullOrEmpty(game.BackgroundImageUrl) == false)
            {
                var fileName     = string.Format("{0}.jpg", Guid.NewGuid().ToString());
                var downloadPath = Path.Combine(PlayniteApi.Database.GetFileStoragePath(newGame.Id), fileName);
                DownloadFile(string.Format("{0}?mode=scale&q=90&h=1080&w=1920", game.BackgroundImageUrl), downloadPath).GetAwaiter().GetResult();
                if (File.Exists(downloadPath))
                {
                    newGame.BackgroundImage = string.Format("{0}/{1}", newGame.Id.ToString(), fileName);
                }
            }

            PlayniteApi.Database.Games.Update(newGame);
            GameIdsInLibrary.Add(game.GameId);

            if (showGameAddDialog == true)
            {
                PlayniteApi.Dialogs.ShowMessage(string.Format(ResourceProvider.GetString("LOCGamePass_Catalog_Browser_AddGameResultsMessage"), game.Name));
            }
            return(true);
        }
        public CatalogBrowserViewModel(List <GamePassGame> list, IPlayniteAPI api)
        {
            PlayniteApi = api;

            xboxLibraryHelper = new XboxLibraryHelper(api);

            IList <GamePassGame> gamePassGames = list;

            _gamePassGamesView = CollectionViewSource.GetDefaultView(gamePassGames);

            _gamePassGamesView.CurrentChanged += GamePassGameSelectionChanged;

            void GamePassGameSelectionChanged(object sender, EventArgs e)
            {
                // Not implemented
            }

            _gamePassGamesView.Filter = GamePassGameFilter;


            bool IsGameInGenre(GamePassGame game)
            {
                if (_categoriesFilterString == "All")
                {
                    return(true);
                }
                else if (string.IsNullOrEmpty(game.Category))
                {
                    return(false);
                }
                else if (game.Category == _categoriesFilterString)
                {
                    return(true);
                }

                return(false);
            }

            bool GameContainsString(GamePassGame game)
            {
                if (string.IsNullOrEmpty(_searchString))
                {
                    return(IsGameInGenre(game));
                }
                else if (game.Name.ToLower().Contains(_searchString.ToLower()))
                {
                    return(IsGameInGenre(game));
                }
                else
                {
                    return(false);
                }
            }

            bool GamePassGameFilter(object item)
            {
                GamePassGame game = item as GamePassGame;

                switch (game.ProductType)
                {
                case ProductType.Game:
                    if (_collectionsFilterString != "Games")
                    {
                        return(false);
                    }
                    break;

                case ProductType.Collection:
                    if (_collectionsFilterString != "Collections")
                    {
                        return(false);
                    }
                    break;

                case ProductType.EaGame:
                    if (_collectionsFilterString != "EA Games")
                    {
                        return(false);
                    }
                    break;

                default:
                    break;
                }

                if (showGamesOnLibrary == false)
                {
                    if (xboxLibraryHelper.GameIdsInLibrary.Contains(game.GameId))
                    {
                        return(false);
                    }
                    else
                    {
                        return(GameContainsString(game));
                    }
                }

                return(GameContainsString(game));
            }

            IList <string> collections = GetCollectionsList();

            _collectionsView = CollectionViewSource.GetDefaultView(collections);

            _collectionsView.CurrentChanged += CollectionSelectionChanged;

            void CollectionSelectionChanged(object sender, EventArgs e)
            {
                CollectionsFilterString = Collections.CurrentItem.ToString();
            }

            List <string> GetCollectionsList()
            {
                return(new List <string>()
                {
                    { "Games" },
                    { "EA Games" },
                    { "Collections" }
                });
            }

            IList <string> categories = GetCategoriesList(list);

            _categoriesView = CollectionViewSource.GetDefaultView(categories);

            _categoriesView.CurrentChanged += CategoriesSelectionChanged;

            void CategoriesSelectionChanged(object sender, EventArgs e)
            {
                CategoriesFilterString = Categories.CurrentItem.ToString();
            }

            List <string> GetCategoriesList(List <GamePassGame> collection)
            {
                var categoriesList = new List <string>()
                {
                    { "All" }
                };
                var categoriesTempList = collection.Select(x => x.Category).
                                         Where(a => a != null).Distinct().
                                         OrderBy(c => c).ToList();

                foreach (string category in categoriesTempList)
                {
                    categoriesList.Add(category);
                }
                return(categoriesList);
            }
        }
Пример #9
0
        public void addGamesFromCatalogData(CatalogData catalogData, bool addChildProducts, ProductType gameProductType, bool isChildProduct, string parentProductId)
        {
            foreach (CatalogProduct product in catalogData.Products)
            {
                if (product.ProductBSchema == "ProductAddOn;3")
                {
                    continue;
                }

                if (gamePassGamesList.Any(g => g.ProductId.Equals(product.ProductId)))
                {
                    continue;
                }

                var childSubproductsList = new List <string>();
                if (string.IsNullOrEmpty(product.Properties.PackageFamilyName))
                {
                    if (addChildProducts == true)
                    {
                        var marketProperties = product.MarketProperties.FirstOrDefault();
                        if (marketProperties != null)
                        {
                            var idsForDataRequest = new List <string>();

                            foreach (RelatedProduct relatedProduct in marketProperties.RelatedProducts)
                            {
                                if (relatedProduct.RelationshipType == "Bundle" || relatedProduct.RelationshipType == "Parent")
                                {
                                    childSubproductsList.Add(relatedProduct.RelatedProductId);
                                    if (gamePassGamesList.Any(g => g.ProductId.Equals(relatedProduct.RelatedProductId)) == false)
                                    {
                                        idsForDataRequest.Add(relatedProduct.RelatedProductId);
                                    }
                                }
                            }

                            if (idsForDataRequest.Count > 0)
                            {
                                var    bigIdsParam       = string.Join(",", idsForDataRequest);
                                string catalogDataApiUrl = string.Format(catalogDataApiBaseUrl, bigIdsParam, countryCode, languageCode);
                                try
                                {
                                    var response = client.GetAsync(string.Format(catalogDataApiUrl));
                                    var contents = response.Result.Content.ReadAsStringAsync();
                                    if (response.Status == TaskStatus.RanToCompletion)
                                    {
                                        addGamesFromCatalogData(JsonConvert.DeserializeObject <CatalogData>(contents.Result), false, gameProductType, true, product.ProductId);
                                    }
                                    else
                                    {
                                        logger.Info($"Request {catalogDataApiUrl} not completed");
                                    }
                                }
                                catch (Exception e)
                                {
                                    logger.Error(e, $"Error in ApiRequest {catalogDataApiUrl}");
                                }
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                var gamePassGame = new GamePassGame
                {
                    BackgroundImage    = string.Format("{0}.jpg", Guid.NewGuid().ToString()),
                    BackgroundImageUrl = string.Format("https:{0}", product.LocalizedProperties[0].Images.Where(x => x.ImagePurpose == ImagePurpose.SuperHeroArt)?.FirstOrDefault()?.Uri),
                    Category           = product.Properties.Category,
                    Categories         = product.Properties.Categories,
                    CoverImage         = string.Format("{0}.jpg", Guid.NewGuid().ToString()),
                    CoverImageUrl      = string.Format("https:{0}", product.LocalizedProperties[0].Images.Where(x => x.ImagePurpose == ImagePurpose.Poster)?.FirstOrDefault()?.Uri),
                    CoverImageLowRes   = string.Format("{0}.jpg", Guid.NewGuid().ToString()),
                    Description        = product.LocalizedProperties[0].ProductDescription,
                    Name            = NormalizeGameName(product.LocalizedProperties[0].ProductTitle),
                    ProductId       = product.ProductId,
                    Publishers      = companiesStringToArray(product.LocalizedProperties[0].PublisherName),
                    ReleaseDate     = product.MarketProperties.FirstOrDefault().OriginalReleaseDate.UtcDateTime,
                    ChildProducts   = childSubproductsList,
                    IsChildProduct  = isChildProduct,
                    ParentProductId = parentProductId
                };

                if (string.IsNullOrEmpty(product.Properties.PackageFamilyName))
                {
                    gamePassGame.ProductType = ProductType.Collection;
                }
                else
                {
                    gamePassGame.GameId      = product.Properties.PackageFamilyName;
                    gamePassGame.ProductType = gameProductType;
                }

                if (string.IsNullOrEmpty(product.LocalizedProperties[0].DeveloperName))
                {
                    gamePassGame.Developers = gamePassGame.Publishers;
                }
                else
                {
                    gamePassGame.Developers = companiesStringToArray(product.LocalizedProperties[0].DeveloperName);
                }

                if (product.LocalizedProperties[0].Images.Any(x => x.ImagePurpose == ImagePurpose.BoxArt) == true)
                {
                    gamePassGame.Icon    = string.Format("{0}.jpg", Guid.NewGuid().ToString());
                    gamePassGame.IconUrl = string.Format("https:{0}", product.LocalizedProperties[0].Images.Where(x => x.ImagePurpose == ImagePurpose.BoxArt)?.FirstOrDefault()?.Uri);
                }
                else if (product.LocalizedProperties[0].Images.Any(x => x.ImagePurpose == ImagePurpose.Logo) == true)
                {
                    gamePassGame.Icon    = string.Format("{0}.jpg", Guid.NewGuid().ToString());
                    gamePassGame.IconUrl = string.Format("https:{0}", product.LocalizedProperties[0].Images.Where(x => x.ImagePurpose == ImagePurpose.Logo)?.FirstOrDefault()?.Uri);
                }

                gamePassGamesList.Add(gamePassGame);
                DownloadGamePassGameCache(gamePassGame);

                var gameAdded = false;
                if (addNewGames == true && gamePassGame.ProductType == ProductType.Game)
                {
                    xboxLibraryHelper.AddGameToLibrary(gamePassGame, false);
                    if (gameAdded == true)
                    {
                        playniteApi.Notifications.Add(new NotificationMessage(
                                                          Guid.NewGuid().ToString(),
                                                          $"{gamePassGame.Name} has been added to the Game Pass catalog and Playnite library",
                                                          NotificationType.Info));
                    }
                }

                // Notify user that game has been added
                if (notifyCatalogUpdates == true && gameAdded == false)
                {
                    playniteApi.Notifications.Add(new NotificationMessage(
                                                      Guid.NewGuid().ToString(),
                                                      $"{gamePassGame.Name} has been added to the Game Pass catalog",
                                                      NotificationType.Info));
                }

                RestoreMediaPaths(gamePassGame);
            }
        }