Пример #1
0
        private async Task ScrapItem(FtpListItemModel item, int PlatformId, bool useDirectory, bool removeIfExist = false)
        {
            var name            = (useDirectory ? item.Name : System.IO.Path.GetFileNameWithoutExtension(item.Name)) + ".png";
            var filePathConsole = $@"{_vieModel.FtpListItem.FullName }/media/{name}";

            item.LastSearchParam = useDirectory ? item.ParentPath.Split('/').Last() : item.Name;
            var game = await TheGamesDbHandler.GetGame(item.LastSearchParam, PlatformId, useDirectory, data.ScrapGuid);

            if (game.Games == null || errorHandling(game.Error, 0))
            {
                try
                {
                    if (game.Error != null && game.Error.Code == 200)
                    {
                        data.ScrapGuid = game.UserInfo.NewGuid;
                        Debug.WriteLine($"game.Error.Message");

                        updateDownloadList(0, item.Name, "", item.mFullName, "", "", "", 0, "", "");
                    }
                    else
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                try
                {
                    data.ScrapGuid = game.UserInfo.NewGuid;
                    _countAll++;
                    foreach (var gme in game.Games)
                    {
                        var boxart = gme.BoxArts.FirstOrDefault();

                        if (boxart == null)
                        {
                            continue;
                        }
                        var filePath = boxart.Filename;//game.BaseUrls.FirstOrDefault(b => b.Name == "small").Path +
                        var path     = filePath;
                        Debug.WriteLine($"Found:{ item.Name} ({gme.GameTitle}) path: {path}");
                        updateDownloadList(gme.Id, useDirectory ? item.ParentPath.Split('/').Last() : item.Name,
                                           gme.GameTitle, item.mFullName, path, gme.overview, gme.release_date, int.Parse(gme.players), gme.publisher_to_be_removed, gme.rating, game.Games.Count > 1, useDirectory, removeIfExist);
                    }
                }
                catch (Exception ex)
                {
                    ErrorHandler.Error(ex);
                    return;
                }
            }
        }
Пример #2
0
 private FtpListItemModel FindFtpItem(FtpListItemModel item)
 {
     if (item == null)
     {
         return(null);
     }
     if (item.IsDirectory)
     {
         return(FindFtpItem(item.Items.FirstOrDefault(i => i.FullName.Contains(item.FullName))));
     }
     else
     {
         return(item);
     }
 }
Пример #3
0
        private async Task ScrapingSearch(FtpListItemModel ftpListItem, bool useDirectory, bool isChild = false)
        {
            await Task.Run(async() =>
            {
                try
                {
                    if (!isChild)
                    {
                        await updateDownloadImageList(false);
                    }
                    var PlatformId = _vieModel.SelectedPlatform.Id;
                    var itemsCount = 0;

                    if (ftpListItem.HasChild)
                    {
                        if (ftpListItem.Items.Any(i => i == null))
                        {
                            await ftpListItem.GetChild(true);
                        }
                        //itemsCount = ftpListItem.Items.Count;

                        foreach (var item in ftpListItem.Items.Where(f => !skipIfexists || (skipIfexists && !getExistingImages.Contains(Path.GetFileNameWithoutExtension(f.Name)))))
                        {
                            if (item == null)
                            {
                                return;              //ToDo;if null load list
                            }
                            if (item.IsFile && _vieModel.SelectedPlatform.Extensions.Contains(System.IO.Path.GetExtension(item.Name), StringComparer.OrdinalIgnoreCase))
                            {
                                if (skipIfexists && getExistingImages.Contains(Path.GetFileNameWithoutExtension(item.Name)))
                                {
                                    continue;
                                }
                                if (_cancelScrap)
                                {
                                    break;
                                }
                                await ScrapItem(item, PlatformId, useDirectory);
                            }
                            else if (item.IsDirectory)
                            {
                                await ScrapingSearch(item, useDirectory, true);
                            }

                            updateValues(ftpListItem.Items.Count, itemsCount++, item.Name);
                        }

                        if (!isChild)
                        {
                            var lst = _vieModel.DownloadList?.OrderBy(g => g.Name).Where(l => !string.IsNullOrWhiteSpace(l.Name) && _vieModel.HaveImages(l.Name)).ToList() ?? new List <DownloadImageModel>();
                            foreach (var item in lst)
                            {
                                if (item.IsSelected && lst.Any(l => l.IsSelected && l.Name == item.Name && l.GameTitle != item.GameTitle))
                                {
                                    item.IsSelected = false;
                                }
                                if (!item.IsSelected && lst.Count(g => g.Name == item.Name) == 1)
                                {
                                    item.IsSelected = true;
                                }
                            }

                            await updateDownloadImageList(true, await UpdateChar());
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorHandler.Error(ex);
                    Console.WriteLine(ex);
                    return;
                }
            });
        }