public MyAbandonGameInfo RetrieveGameData(string GameURI) { string queryResult = string.Empty; string queryUri = GameURI; request = (HttpWebRequest)WebRequest.Create(queryUri); response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { Stream receiveStream = response.GetResponseStream(); StreamReader readStream = null; readStream = new StreamReader(receiveStream, Encoding.UTF8); queryResult = readStream.ReadToEnd(); response.Close(); readStream.Close(); } MyAbandonGameInfo result = ParseGamePage(queryResult); if (result != null) { result.GameURI = GameURI; } return(result); }
private void btnGetGameData_Click(object sender, EventArgs e) { if (_selectedGame != null) { if (_game == null || _game.GameURI != _selectedGame.Uri) { _game = _scraper.RetrieveGameData(_selectedGame.Uri); if (_game == null) { return; } //Retrieving first available screenshot if (_game.Screenshots != null && _game.Screenshots.Count > 0) { _scraper.DownloadFileCompleted += _scraper_DownloadFileCompleted; _scraper.DownloadMedia(_game.Screenshots[0], Application.StartupPath + "\\tmp.img"); } } else if (_game != null) { CustomMessageBox cmb = new CustomMessageBox(_manager.Translator.GetTranslatedMessage(_manager.AppSettings.Language, 77, "Download Completed!!!"), _manager.Translator.GetTranslatedMessage(_manager.AppSettings.Language, 59, "Information"), MessageBoxDialogButtons.Ok, MessageBoxDialogIcon.Information, false, false); cmb.ShowDialog(); cmb.Dispose(); } } }
private void btnInfo_Click(object sender, EventArgs e) { MyAbandonwareSearchDialog msd = new MyAbandonwareSearchDialog(_manager, _game.Title); if (msd.ShowDialog() == DialogResult.OK) { MyAbandonGameInfo gameData = msd.GameData; if (gameData != null) { if (_cats.ContainsKey(gameData.Genre.Trim().ToLower())) { //Category existing _game.CategoryID = _cats[gameData.Genre.Trim().ToLower()].ID; CompileCategoriesCombo(_game.CategoryID); } else if (gameData.Genre.Trim() != string.Empty) { //Category not existing _cats.Add(gameData.Genre.Trim().ToLower(), new Category(-1, gameData.Genre.Trim(), string.Empty, false, false)); CompileCategoriesCombo(-1); } _game.Title = gameData.Title; _game.Description = gameData.Description; _game.Developer = gameData.Developer; _game.Perspectives = (gameData.Perspectives == null) ? string.Empty : string.Join(",", gameData.Perspectives); _game.Platform = gameData.Platform; _game.Publisher = gameData.Publisher; _game.ReleasedIn = gameData.ReleasedIn; _game.Themes = (gameData.Themes == null) ? string.Empty : string.Join(",", gameData.Themes); _game.Vote = gameData.Vote.ToString(); _game.Year = Convert.ToInt32(gameData.Year); UpdatePanel(); _game.ImagePath = msd.GameScreenshot; ShowCoverImage(); //RenderTemporaryCover(msd.GameScreenshot); } } msd.Dispose(); }
public MyAbandonwareGameDialog(AppManager Manager, MyAbandonGameInfo game, MyAbandonware helper, bool ShowDownload) { InitializeComponent(); _manager = Manager; _game = game; _helper = helper; //I allow the creation of a new game if the connection is up //btnCommit.Visible = (_manager.DB.ConnectionStatus == ConnectionState.Open); gameDownloader.Visible = ShowDownload; if (!ShowDownload) { screenshotsList.Height = 502; } _manager.Translator.TranslateUI(_manager.AppSettings.Language, this.Name, this.Controls); CompileUI(); }
private void LoadGameData(bool noDownload) { _game = _scraper.RetrieveGameData(_selectedGame.Uri); if (_game != null) { MyAbandonwareGameDialog gameData = new MyAbandonwareGameDialog(_manager, _game, _scraper, noDownload); gameData.ShowDialog(); if (gameData.Screenshot != null) { _gameScreenshot = Application.StartupPath + "\\tmp.img"; Bitmap bmp = new Bitmap(gameData.Screenshot); bmp.Save(_gameScreenshot); bmp.Dispose(); } else { _gameScreenshot = string.Empty; } gameData.Dispose(); } }
private MyAbandonGameInfo ParseGamePage(string queryResult) { MyAbandonGameInfo result = null; if (queryResult != string.Empty) { htmlDoc.LoadHtml(queryResult); if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0) { // Handle any parse errors as required string errorMessage = string.Empty; foreach (HtmlParseError error in htmlDoc.ParseErrors) { errorMessage += error.Reason + "\n"; } CustomMessageBox cmb = new CustomMessageBox(errorMessage, _manager.Translator.GetTranslatedMessage(_manager.AppSettings.Language, 28, "Error"), MessageBoxDialogButtons.Ok, MessageBoxDialogIcon.Error, false, false); cmb.ShowDialog(); cmb.Dispose(); } else { if (htmlDoc.DocumentNode != null) { HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body//div[@class='box']"); if (bodyNode != null) { result = new MyAbandonGameInfo(); //Game Name HtmlNode nameNode = bodyNode.SelectSingleNode("//h2[@itemprop='name']"); if (nameNode != null) { result.Title = nameNode.InnerText.Trim(); } //Game Data HtmlNode gameDataNode = bodyNode.SelectSingleNode("//div[@class='gameData']/dl"); if (gameDataNode != null) { foreach (HtmlNode itemNode in gameDataNode.ChildNodes) { if (itemNode.Name.ToLower() == "dt") { if (itemNode.InnerText.Trim().ToLower() == "year") { flags.SetFlags(true, false, false, false, false, false, false, false, false); } if (itemNode.InnerText.Trim().ToLower() == "platform") { flags.SetFlags(false, true, false, false, false, false, false, false, false); } if (itemNode.InnerText.Trim().ToLower() == "released in") { flags.SetFlags(false, false, true, false, false, false, false, false, false); } if (itemNode.InnerText.Trim().ToLower() == "genre") { flags.SetFlags(false, false, false, true, false, false, false, false, false); } if (itemNode.InnerText.Trim().ToLower() == "theme") { flags.SetFlags(false, false, false, false, true, false, false, false, false); } if (itemNode.InnerText.Trim().ToLower() == "publisher") { flags.SetFlags(false, false, false, false, false, true, false, false, false); } if (itemNode.InnerText.Trim().ToLower() == "developer") { flags.SetFlags(false, false, false, false, false, false, true, false, false); } if (itemNode.InnerText.Trim().ToLower() == "perspectives") { flags.SetFlags(false, false, false, false, false, false, false, true, false); } if (itemNode.InnerText.Trim().ToLower() == "dosbox support") { flags.SetFlags(false, false, false, false, false, false, false, false, true); } } if (itemNode.Name.ToLower() == "dd") { if (flags.IsYear) { result.Year = WebUtility.HtmlDecode(itemNode.InnerText.Trim()); } if (flags.IsPlatform) { result.Platform = WebUtility.HtmlDecode(itemNode.InnerText.Trim()); } if (flags.IsReleasedIn) { result.ReleasedIn = WebUtility.HtmlDecode(itemNode.InnerText.Trim()); } if (flags.IsGenre) { result.Genre = WebUtility.HtmlDecode(itemNode.InnerText.Trim()); } if (flags.IsTheme) { string themeString = WebUtility.HtmlDecode(itemNode.InnerText.Trim()); if (themeString != string.Empty) { result.Themes = themeString.Replace(", ", ",").Split(',').ToList(); } } if (flags.IsPublisher) { result.Publisher = WebUtility.HtmlDecode(itemNode.InnerText.Trim()); } if (flags.IsDeveloper) { result.Developer = WebUtility.HtmlDecode(itemNode.InnerText.Trim()); } if (flags.IsPerspectives) { string perspectiveString = WebUtility.HtmlDecode(itemNode.InnerText.Trim()); if (perspectiveString != string.Empty) { result.Perspectives = perspectiveString.Replace(", ", ",").Split(',', ' ').ToList(); } } if (flags.IsDosBox) { result.DosBoxVersion = WebUtility.HtmlDecode(itemNode.InnerText.Trim()); } } } } //Game Vote HtmlNode voteNode = bodyNode.SelectSingleNode("//span[@itemprop='ratingValue']"); if (voteNode != null) { result.Vote = voteNode.InnerText; } //Game Descritpion //First I check if exists the proper node HtmlNode descriptionNode = bodyNode.SelectSingleNode("//div[@class='gameDescription dscr']"); if (descriptionNode != null) { result.Description = WebUtility.HtmlDecode(descriptionNode.InnerText); } else { //As it seems missing I try the other one descriptionNode = bodyNode.SelectSingleNode("//div[@class='box']/h3[@class='cBoth']"); if (descriptionNode != null) { HtmlNode descNone = descriptionNode.ParentNode.SelectSingleNode("p"); if (descNone != null) { result.Description = WebUtility.HtmlDecode(descNone.InnerText); } } } //Game Screenshots HtmlNodeCollection screenshotsNodes = bodyNode.SelectNodes("//body//div[@class='thumb']/a[@class='lb']/img"); if (screenshotsNodes != null) { foreach (HtmlNode screen in screenshotsNodes) { if (screen.Name.ToLower().Trim() == "img") { if (result.Screenshots == null) { result.Screenshots = new List <string>(); } result.Screenshots.Add(GetMediaURI(screen.Attributes["src"].Value)); } } } //Game Download & Size HtmlNode downloadNode = bodyNode.SelectSingleNode("//a[@class='button download']"); if (downloadNode != null) { result.DownloadLink = downloadNode.Attributes["href"].Value; HtmlNode downloadSize = downloadNode.SelectSingleNode("//a[@class='button download']/span"); if (downloadSize != null) { result.DownloadSize = downloadSize.InnerText.Trim(); } } } } } } return(result); }