public static async Task <string> GetHttpAsync(string url, int count = 3) { while (true) { var client = new CookieClient(); var content = string.Empty; try { // If user is NOT authenticated (cookie got deleted in GetWebResponse()), return empty result if (String.IsNullOrEmpty(Settings.Default.sessionid)) { return(string.Empty); } content = await client.DownloadStringTaskAsync(url); } catch (Exception ex) { Logger.Exception(ex, "CookieClient -> GetHttpAsync, for url = " + url); } if (!string.IsNullOrWhiteSpace(content) || count == 0) { return(content); } count = count - 1; } }
public async Task <bool> CanCardDrops() { try { var document = new HtmlDocument(); var response = await CookieClient.GetHttpAsync(Settings.Default.myProfileURL + "/gamecards/" + StringId); // Response should be empty. User should be unauthorised. if (string.IsNullOrEmpty(response)) { return(false); } document.LoadHtml(response); var hoursNode = document.DocumentNode.SelectSingleNode("//div[@class=\"badge_title_stats_playtime\"]"); var hours = Regex.Match(hoursNode.InnerText, @"[0-9\.,]+").Value; var cardNode = hoursNode.ParentNode.SelectSingleNode(".//span[@class=\"progress_info_bold\"]"); var cards = cardNode == null ? string.Empty : Regex.Match(cardNode.InnerText, @"[0-9]+").Value; UpdateStats(cards, hours); return(RemainingCard != 0); } catch (Exception ex) { Logger.Exception(ex, "Badge -> CanCardDrops, for id = " + AppId); } return(false); }
public async Task <bool> CanCardDrops() { try { var document = new HtmlDocument(); var response = await CookieClient.GetHttpAsync(Settings.Default.myProfileURL + "/gamecards/" + StringId); document.LoadHtml(response); var hoursNode = document.DocumentNode.SelectSingleNode("//div[@class=\"badge_title_stats\"]").ChildNodes["br"].PreviousSibling; var hours = Regex.Match(hoursNode.InnerText, @"[0-9\.,]+").Value; var cardNode = hoursNode.ParentNode.SelectSingleNode(".//span[@class=\"progress_info_bold\"]"); var cards = cardNode == null ? string.Empty : Regex.Match(cardNode.InnerText, @"[0-9]+").Value; RemainingCard = string.IsNullOrWhiteSpace(cards) ? 0 : int.Parse(cards); HoursPlayed = string.IsNullOrWhiteSpace(hours) ? 0 : double.Parse(hours, new NumberFormatInfo()); return(RemainingCard != 0); } catch (Exception ex) { Logger.Exception(ex, "Badge -> CanCardDrops, for id = " + AppId); } return(false); }
public static async Task<string> GetHttpAsync(string url, int count = 3) { while (true) { var client = new CookieClient(); var content = string.Empty; try { // If user is NOT authenticated (cookie got deleted in GetWebResponse()), return empty result if (String.IsNullOrEmpty(Settings.Default.sessionid)) { return string.Empty; } content = await client.DownloadStringTaskAsync(url); } catch (Exception ex) { Logger.Exception(ex, "CookieClient -> GetHttpAsync, for url = " + url); } if (!string.IsNullOrWhiteSpace(content) || count == 0) return content; count = count - 1; } }
private async Task <string> GetAppNameByID(int AppID) { //Try get Name from Cached INI StringBuilder temp = new StringBuilder(1000); GetPrivateProfileString("SteamAppCachedName", AppID.ToString(), "", temp, 1000, "./SteamAppCached.ini"); string CachedName = temp.ToString(); if (CachedName != "") { return(CachedName); } //If this AppID has not been cached. TargetAwait++; this.pictureBox1.Visible = true; var DocStr = await CookieClient.GetHttpAsync("https://store.steampowered.com/api/appdetails?appids=" + AppID.ToString() + "&filters=basic", 3, true); CurAwait++; if (TargetAwait <= CurAwait) { this.pictureBox1.Visible = false; } JObject MainJson = JsonConvert.DeserializeObject <JObject>(DocStr); JObject jb = MainJson.GetValue(AppID.ToString()).ToObject <JObject>(); if (jb.GetValue("success").ToObject <bool>() == true) { string AppName = jb.GetValue("data").ToObject <JObject>().GetValue("name").ToString(); WritePrivateProfileString("SteamAppCachedName", AppID.ToString(), AppName, "./SteamAppCached.ini"); return(AppName); } else { TargetAwait++; this.pictureBox1.Visible = true; DocStr = await CookieClient.GetHttpAsync("https://store.steampowered.com/api/appdetails?appids=" + AppID.ToString() + "&cc=us&filters=basic", 3, true); CurAwait++; if (TargetAwait <= CurAwait) { this.pictureBox1.Visible = false; } JObject MainJson2 = JsonConvert.DeserializeObject <JObject>(DocStr); JObject jb2 = MainJson2.GetValue(AppID.ToString()).ToObject <JObject>(); if (jb2.GetValue("success").ToObject <bool>() == true) { string AppName = jb2.GetValue("data").ToObject <JObject>().GetValue("name").ToString(); WritePrivateProfileString("SteamAppCachedName", AppID.ToString(), AppName, "./SteamAppCached.ini"); return(AppName); } else { return("无效ID:" + AppID.ToString() + ",游戏可能锁区,请右键自行输入名称"); } } }
public static async Task<string> GetHttpAsync(string url, int count = 3) { while (true) { var client = new CookieClient(); var content = string.Empty; try { content = await client.DownloadStringTaskAsync(url); } catch (Exception ex) { Logger.Exception(ex, "CookieClient -> GetHttpAsync, for url = " + url); } if (!string.IsNullOrWhiteSpace(content) || count == 0) return content; count = count - 1; } }
private async Task CheckAndSave() { try { Settings.Default.sessionid = txtSessionID.Text.Trim(); Settings.Default.steamLogin = txtSteamLogin.Text.Trim(); Settings.Default.steamLoginSecure = txtSteamLoginSecure.Text.Trim(); Settings.Default.myProfileURL = SteamProfile.GetSteamUrl(); Settings.Default.steamparental = txtSteamParental.Text.Trim(); if (await CookieClient.IsLogined()) { Settings.Default.Save(); Close(); return; } } catch (Exception ex) { Logger.Exception(ex, "frmSettingsAdvanced -> CheckAndSave"); } // Invalid cookie data, reset the form btnUpdate.Text = localization.strings.update; txtSessionID.Text = ""; txtSteamLogin.Text = ""; txtSteamLoginSecure.Text = ""; txtSteamParental.Text = ""; txtSessionID.PasswordChar = '\0'; txtSteamLogin.PasswordChar = '\0'; txtSteamLoginSecure.PasswordChar = '\0'; txtSteamParental.PasswordChar = '\0'; txtSessionID.Enabled = true; txtSteamLogin.Enabled = true; txtSteamLoginSecure.Enabled = true; txtSteamParental.Enabled = true; txtSessionID.Focus(); MessageBox.Show(localization.strings.validate_failed); btnUpdate.Enabled = true; }
public static async Task <string> GetHttpAsync(string url, int count = 3, bool IgnoreCookieState = false) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; while (true) { var client = new CookieClient(); var content = string.Empty; try { // If user is NOT authenticated (cookie got deleted in GetWebResponse()), return empty result if (IgnoreCookieState == false && String.IsNullOrEmpty(Settings.Default.sessionid)) { return(string.Empty); } System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return(true); // **** Always accept }; System.Net.ServicePointManager.Expect100Continue = false; url = url.Replace("http://", "https://"); content = await client.DownloadStringTaskAsync(url); } catch (Exception ex) { Logger.Exception(ex, "CookieClient -> GetHttpAsync, for url = " + url); } if (!string.IsNullOrWhiteSpace(content) || count == 0) { return(content); } count = count - 1; } }
private async Task CheckAndSave() { try { Settings.Default.sessionid = txtSessionID.Text.Trim(); Settings.Default.steamLogin = txtSteamLogin.Text.Trim(); if (txtSteamLogin.Text.Length > 17) { Settings.Default.myProfileURL = "http://steamcommunity.com/profiles/" + txtSteamLogin.Text.Substring(0, 17); } Settings.Default.steamparental = txtSteamParental.Text.Trim(); if (await CookieClient.IsLogined()) { Settings.Default.Save(); Close(); } } catch (Exception ex) { Logger.Exception(ex, "frmSettingsAdvanced -> CheckAndSave"); } // Invalid cookie data, reset the form btnUpdate.Text = "Update"; txtSessionID.Text = ""; txtSteamLogin.Text = ""; txtSteamParental.Text = ""; txtSessionID.PasswordChar = '\0'; txtSteamLogin.PasswordChar = '\0'; txtSteamParental.PasswordChar = '\0'; txtSessionID.Enabled = true; txtSteamLogin.Enabled = true; txtSteamParental.Enabled = true; txtSessionID.Focus(); MessageBox.Show("The data you've entered isn't valid. Please try again."); btnUpdate.Enabled = true; }
public static async Task <string> GetHttpAsync(string url, int count = 3) { while (true) { var client = new CookieClient(); var content = string.Empty; try { content = await client.DownloadStringTaskAsync(url); } catch (Exception ex) { Logger.Exception(ex, "CookieClient -> GetHttpAsync, for url = " + url); } if (!string.IsNullOrWhiteSpace(content) || count == 0) { return(content); } count = count - 1; } }
public async Task LoadBadgesAsync() { // Settings.Default.myProfileURL = http://steamcommunity.com/id/USER var profileLink = Settings.Default.myProfileURL + "/badges"; var pages = new List <string>() { "?p=1" }; var document = new HtmlDocument(); int pagesCount = 1; try { // Load Page 1 and check how many pages there are var pageURL = string.Format("{0}/?p={1}", profileLink, 1); var response = await CookieClient.GetHttpAsync(pageURL); // Response should be empty. User should be unauthorised. if (string.IsNullOrEmpty(response)) { RetryCount++; if (RetryCount == 18) { ResetClientStatus(); return; } throw new Exception(""); } document.LoadHtml(response); // If user is authenticated, check page count. If user is not authenticated, pages are different. var pageNodes = document.DocumentNode.SelectNodes("//a[@class=\"pagelink\"]"); if (pageNodes != null) { pages.AddRange(pageNodes.Select(p => p.Attributes["href"].Value).Distinct()); pages = pages.Distinct().ToList(); } string lastpage = pages.Last().ToString().Replace("?p=", ""); pagesCount = Convert.ToInt32(lastpage); // Get all badges from current page ProcessBadgesOnPage(document); // Load other pages for (var i = 2; i <= pagesCount; i++) { lblDrops.Text = string.Format(localization.strings.reading_badge_page + " {0}/{1}, " + localization.strings.please_wait, i, pagesCount); // Load Page 2+ pageURL = string.Format("{0}/?p={1}", profileLink, i); response = await CookieClient.GetHttpAsync(pageURL); // Response should be empty. User should be unauthorised. if (string.IsNullOrEmpty(response)) { RetryCount++; if (RetryCount == 18) { ResetClientStatus(); return; } throw new Exception(""); } document.LoadHtml(response); // Get all badges from current page ProcessBadgesOnPage(document); } } catch (Exception ex) { Logger.Exception(ex, "Badge -> LoadBadgesAsync, for profile = " + Settings.Default.myProfileURL); // badge page didn't load picReadingPage.Image = null; picIdleStatus.Image = null; lblDrops.Text = localization.strings.badge_didnt_load.Replace("__num__", "10"); lblIdle.Text = ""; // Set the form height var graphics = CreateGraphics(); var scale = graphics.DpiY * 1.625; Height = Convert.ToInt32(scale); ssFooter.Visible = false; ReloadCount = 1; tmrBadgeReload.Enabled = true; return; } RetryCount = 0; SortBadges(Settings.Default.sort); picReadingPage.Visible = false; UpdateStateInfo(); if (CardsRemaining == 0) { IdleComplete(); } }
public async Task LoadBadgesAsync() { // Settings.Default.myProfileURL = http://steamcommunity.com/id/USER var profileLink = Settings.Default.myProfileURL + "/badges"; var document = new HtmlDocument(); int pagesCount = 1; try { // Load Page 1 and check how many pages there are var pageURL = string.Format("{0}/?p={1}", profileLink, 1); var response = await CookieClient.GetHttpAsync(pageURL); // Response should be empty. User should be unauthorised. if (string.IsNullOrEmpty(response)) { ResetClientStatus(); return; } document.LoadHtml(response); // If user is authenticated, check page count. If user is not authenticated, pages are different. var pageNodes = document.DocumentNode.SelectNodes("//a[@class=\"pagelink\"]"); if (pageNodes != null) { pagesCount = pageNodes.Count; } // Get all badges from current page ProcessBadgesOnPage(document); // Load other pages for (var i = 2; i <= pagesCount; i++) { lblDrops.Text = string.Format("Reading badge page {0}/{1}, please wait...", i, pagesCount); // Load Page 2+ pageURL = string.Format("{0}/?p={1}", profileLink, i); response = await CookieClient.GetHttpAsync(pageURL); // Response should be empty. User should be unauthorised. if (string.IsNullOrEmpty(response)) { ResetClientStatus(); return; } document.LoadHtml(response); // Get all badges from current page ProcessBadgesOnPage(document); } } catch (Exception ex) { Logger.Exception(ex, "Badge -> LoadBadgesAsync, for profile = " + Settings.Default.myProfileURL); // badge page didn't load picReadingPage.Image = null; lblDrops.Text = "Badge page didn't load, will retry in 10 seconds"; ReloadCount = 10; tmrBadgeReload.Enabled = true; return; } SortBadges(Settings.Default.sort); picReadingPage.Visible = false; UpdateStateInfo(); if (CardsRemaining == 0) { IdleComplete(); } }
public async Task LoadBadgesAsync() { // Settings.Default.myProfileURL = http://steamcommunity.com/id/USER var profileLink = Settings.Default.myProfileURL + "/badges"; var pages = new List <string>() { "?p=1" }; var document = new HtmlDocument(); int pagesCount = 1; try { // Load Page 1 and check how many pages there are var pageURL = string.Format("{0}/?p={1}", profileLink, 1); var response = await CookieClient.GetHttpAsync(pageURL); // Response should be empty. User should be unauthorised. if (string.IsNullOrEmpty(response)) { RetryCount++; if (RetryCount == 18) { return; } throw new Exception(""); } document.LoadHtml(response); // If user is authenticated, check page count. If user is not authenticated, pages are different. var pageNodes = document.DocumentNode.SelectNodes("//a[@class=\"pagelink\"]"); if (pageNodes != null) { pages.AddRange(pageNodes.Select(p => p.Attributes["href"].Value).Distinct()); pages = pages.Distinct().ToList(); } string lastpage = pages.Last().ToString().Replace("?p=", ""); pagesCount = Convert.ToInt32(lastpage); // Get all badges from current page ProcessBadgesOnPage(document); // Load other pages for (var i = 2; i <= pagesCount; i++) { // Load Page 2+ pageURL = string.Format("{0}/?p={1}", profileLink, i); response = await CookieClient.GetHttpAsync(pageURL); // Response should be empty. User should be unauthorised. if (string.IsNullOrEmpty(response)) { RetryCount++; if (RetryCount == 18) { return; } throw new Exception(""); } document.LoadHtml(response); // Get all badges from current page ProcessBadgesOnPage(document); } } catch (Exception ex) { Logger.Exception(ex, "Game -> LoadBadgesAsync, for profile = " + Settings.Default.myProfileURL); // badge page didn't load // Set the form height var graphics = CreateGraphics(); var scale = graphics.DpiY * 1.625; Height = Convert.ToInt32(scale); ReloadCount = 1; return; } RetryCount = 0; //UpdateStateInfo(); }
public async Task LoadBadgesAsync() { var profileLink = Settings.Default.myProfileURL + "/badges"; var document = new HtmlDocument(); var pages = new List <string>() { "?p=1" }; try { for (var i = 0; i < pages.Count; i++) { var response = await CookieClient.GetHttpAsync(profileLink + pages[i]); document.LoadHtml(response); var pageNodes = document.DocumentNode.SelectNodes("//a[@class=\"pagelink\"]"); if (pageNodes != null) { pages.AddRange(pageNodes.Select(p => p.Attributes["href"].Value).Distinct()); pages = pages.Distinct().ToList(); } foreach (var badge in document.DocumentNode.SelectNodes("//div[@class=\"badge_row is_link\"]")) { var appIdNode = badge.SelectSingleNode(".//a[@class=\"badge_row_overlay\"]").Attributes["href"].Value; var appid = Regex.Match(appIdNode, @"gamecards/(\d+)/").Groups[1].Value; if (string.IsNullOrWhiteSpace(appid) || Settings.Default.blacklist.Contains(appid) || appid == "368020" || appid == "335590") { continue; } var hoursNode = badge.SelectSingleNode(".//div[@class=\"badge_title_stats_playtime\"]"); var hours = hoursNode == null ? string.Empty : Regex.Match(hoursNode.InnerText, @"[0-9\.,]+").Value; var nameNode = badge.SelectSingleNode(".//div[@class=\"badge_title\"]"); var name = WebUtility.HtmlDecode(nameNode.FirstChild.InnerText).Trim(); var cardNode = badge.SelectSingleNode(".//span[@class=\"progress_info_bold\"]"); var cards = cardNode == null ? string.Empty : Regex.Match(cardNode.InnerText, @"[0-9]+").Value; var badgeInMemory = AllBadges.FirstOrDefault(b => b.StringId == appid); if (badgeInMemory != null) { badgeInMemory.UpdateStats(cards, hours); } else { AllBadges.Add(new Badge(appid, name, cards, hours)); } } } } catch (Exception ex) { Logger.Exception(ex, "Badge -> LoadBadgesAsync, for profile = " + Settings.Default.myProfileURL); // badge page didn't load picReadingPage.Image = null; lblDrops.Text = "Badge page didn't load, will retry in 10 seconds"; ReloadCount = 10; tmrBadgeReload.Enabled = true; return; } SortBadges(Settings.Default.sort); picReadingPage.Visible = false; UpdateStateInfo(); if (CardsRemaining == 0) { IdleComplete(); } }
public static string GetHttp(string url, int count = 3) { while (true) { var client = new CookieClient(); var content = string.Empty; try { // If user is NOT authenticated (cookie got deleted in GetWebResponse()), return empty result if (String.IsNullOrEmpty(Settings.Default.sessionid)) { return string.Empty; } content = client.DownloadString(url); } catch (Exception) { } if (!string.IsNullOrWhiteSpace(content) || count == 0) return content; count = count - 1; } }