private async void btnTest_Click(object sender, RoutedEventArgs e) { TimeOnline.GameRoot game = null; try { game = await TheGamesDbHandler.GetGame(txbName.Text, _platformId, false, _dataModel.ScrapGuid); if (game == null || game.Games == null) { searchResult.ItemsSource = new string[0]; MessageBox.Show("Found no games"); return; } searchResult.ItemsSource = game.Games.Select(g => g.GameTitle); } catch (Exception) { } finally { if (game != null) { _dataModel.ScrapGuid = game.UserInfo.NewGuid; LiteDBHelper.Save(_dataModel); } } }
private async void btnTest_Click(object sender, RoutedEventArgs e) { TimeOnline.GameRoot game = null; if (GeneralFunctions.IsFilenameInvalid(txbName.Text)) { MessageBox.Show("Sorry Name Contains Invalid Chars!", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } try { game = await TheGamesDbHandler.GetGame(txbName.Text, _platformId, false, _dataModel.ScrapGuid); if (game == null || game.Games == null) { MessageBox.Show("Found no games"); return; } var listGames = game.Games.Select(g => g.GameTitle); MessageBox.Show($"Found {game.Games.Count()} games.\n[{string.Join("],\n[", listGames.Take(5))}]{(listGames.Count() > 5 ? "\n...\nThe result is large, please improve the game name" : "")}", "Result", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception) { } finally { if (game != null) { _dataModel.ScrapGuid = game.UserInfo.NewGuid; LiteDBHelper.Save(_dataModel); } } }
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; } } }
private async void btnScrap_Click(object sender, RoutedEventArgs e) { try { spPbScraping.Visibility = Visibility.Visible; btnScrap.IsEnabled = false; spUploadSettings.IsEnabled = false; _vieModel.DownloadList.Clear(); _countAll = 0; data = LiteDBHelper.Load <DataModel>().FirstOrDefault() ?? new DataModel() { Id = 1, ScrapGuid = "", ScrapEmail = "" }; var burl = await TheGamesDbHandler.GetGame("timeonlin9022", 1, false, data.ScrapGuid); if (errorHandling(burl.Error, 0)) { spPbScraping.Visibility = Visibility.Collapsed; status.Text = ""; percent.Text = ""; btnScrap.IsEnabled = true; spUploadSettings.IsEnabled = true; return; } else { data.ScrapGuid = burl.UserInfo.NewGuid; TheGamesDbHandler.BaseUrls = burl.BaseUrls; } // _cancelScrap = false; getExistingImages = FtpHandler.Instance.List(_vieModel.FtpListItem.mFullName + "/media").Where(f => f.Name.EndsWith(".png")).Select(f => Path.GetFileNameWithoutExtension(f.Name)); skipIfexists = cbSkipExist.IsChecked.Value; //_ = Dispatcher.BeginInvoke((Action)(() => skipIfexists = cbSkipExist.IsChecked.Value)); await ScrapingSearch(_vieModel.FtpListItem, cbUseDirectory.IsChecked.Value); spPbScraping.Visibility = Visibility.Collapsed; status.Text = ""; percent.Text = ""; btnScrap.IsEnabled = true; spUploadSettings.IsEnabled = true; } catch (Exception ex) { ErrorHandler.Error(ex); Debug.WriteLine(ex); } finally { LiteDBHelper.Save(data); } }
private bool Login(int count = 0) { try { if (count >= 3) { return(false); } var login = new LoginView(); login.ShowDialog(); if (!login.DialogResult.Value) { return(false); } Dispatcher.BeginInvoke((Action)(() => { data = LiteDBHelper.Load <DataModel>().FirstOrDefault() ?? new DataModel() { Id = 1, ScrapGuid = "", ScrapEmail = "" }; var burl = new GameRoot(); var task = Task.Run(async() => { burl = await TheGamesDbHandler.GetGame("¤", 1, false, data.ScrapGuid); }); task.Wait(); _ = errorHandling(burl.Error, count); data.ScrapGuid = burl.UserInfo.NewGuid; LiteDBHelper.Save(data); TheGamesDbHandler.BaseUrls = burl.BaseUrls; })); return(true); } catch (Exception ex) { ErrorHandler.Error(ex); return(false); } }