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); } }
public MainWindow() { InitializeComponent(); ControllImages.Init(); LiteDBHelper.init(); TheGamesDbHandler.init(); // Assembly.GetEntryAssembly().GetName().Version.ToString() + "-beta"; RGHSettings.init(); VersionText.Text = RGHSettings.Version; PageHandler.AddPage(new firstPage()); PageHandler.AddPage(new RetroResorcesView()); PageHandler.AddPage(new StartView()); PageHandler.AddPage(new FtpSettingsView()); PageHandler.AddPage(new OptionsView()); PageHandler.AddPage(new ScrapFolderView()); PageHandler.AddPage(new NotePad()); PageHandler.AddPage(new LogView()); PageHandler.AddPage(new AboutView()); this.DataContext = PageHandler.Instance; PageHandler.SelectedPage <firstPage>(); //PageHandler.SelectedPage<LogView>(); ConsoleIconHelper.Init(); ConsoleIconHelper.Close += (s, e) => { this.Close(); }; ConsoleIconHelper.OpenConsole += (s, e) => { this.WindowState = WindowState.Normal; }; //PageHandler.ThePageChanged += (s, e) => //{ // ContentControl.Content = PageHandler.Instans.Page; //}; //PageHandler.SelectedPage<FtpSettingsView>(); }
public DownloadImageModel(int Id, string Name, string GameTitle, string FullName, string Url, bool MultiImages, bool useDirectory, string overview, string releseDate, int players, string publisher, string rating) { this.Id = Id; this.Name = Name; this.GameTitle = GameTitle; this.FullName = FullName; this.MultiImages = MultiImages; this.IsDirectoryName = useDirectory; this.Overview = overview; this.ReleseDate = releseDate; Players = players; Publisher = publisher; Rating = rating; DownloadPath = Url; var tmpName = TheGamesDbHandler.CleanGameName(Name, true) .Replace("&", string.Empty) .Replace("-", string.Empty) .Replace("/", string.Empty) .Replace(":", string.Empty) .Replace(";", string.Empty) .Replace("*", string.Empty) .Replace("_", string.Empty) .Replace(" ", string.Empty) .Replace("'", string.Empty) .Replace(".", string.Empty) .Replace(",", string.Empty) .Replace("%", string.Empty) .Replace("The", string.Empty) .Replace("!", string.Empty) .Replace("é", "e"); var tmpGameTitle = GameTitle .Replace("&", string.Empty) .Replace("-", string.Empty) .Replace("/", string.Empty) .Replace(":", string.Empty) .Replace(";", string.Empty) .Replace("*", string.Empty) .Replace("_", string.Empty) .Replace(" ", string.Empty) .Replace("'", string.Empty) .Replace(".", string.Empty) .Replace(",", string.Empty) .Replace("%", string.Empty) .Replace("!", string.Empty) .Replace("The", string.Empty) .Replace("é", "e");; IsSelected = tmpName.Trim().ToLower() == tmpGameTitle.Trim().ToLower(); //if (!IsSelected) IsSelected = tmpGameTitle.Trim().ToLower().Contains(tmpName.Trim().ToLower()); //if (!string.IsNullOrWhiteSpace(Url)) //{ // using (WebClient client = new WebClient()) // { // ImageStream = client.DownloadData(Url); // } // HasImage = true; //} //else //{ // var bm = new BitmapImage(new Uri("pack://application:,,,/Images/image-not-found.png")); // Stream stream = bm.StreamSource; // byte[] buffer = null; // if (stream != null && stream.Length > 0) // { // using (BinaryReader br = new BinaryReader(stream)) // { // buffer = br.ReadBytes((Int32)stream.Length); // } // } // ImageStream = buffer; // //Image = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Images/image-not-found.png"))); // HasImage = false; //} }