private void partialMatches_Tap(object sender, System.Windows.Input.GestureEventArgs e) { CheatInfo entry = (CheatInfo)partialMatches.SelectedItem; partialMatches.SelectedItem = null; txtSearchString.Text = entry.Title; searchButton_Click(null, null); }
private void ARButton_Tap(object sender, System.Windows.Input.GestureEventArgs e) { CheatInfo cheatInfo = (sender as Button).DataContext as CheatInfo; DisplayCheats(cheatInfo.ARLink, 1); }
private async void searchButton_Click(object sender, RoutedEventArgs e) { string body = "search=" + this.txtSearchString.Text; GZipWebClient webClient = new GZipWebClient(); string response = null; SystemTray.GetProgressIndicator(this).IsIndeterminate = true; try { //==WINDOWS PHONE DOES NOT SUPPORT GZIP STREAM DECOMPRESSION, SO CANNOT USE HTTPWEBREQUEST //// Create a new HttpWebRequest object. //HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.supercheats.com/search.php"); //request.Accept = "text/html, application/xhtml+xml, */*"; //request.Headers[HttpRequestHeader.Referer] = "http://www.supercheats.com/search.php"; //request.Headers[HttpRequestHeader.AcceptLanguage] = "en-US"; //request.ContentType = "application/x-www-form-urlencoded"; //request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"; //request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate"; //request.Headers[HttpRequestHeader.Connection] = "Keep-Alive"; //request.Headers[HttpRequestHeader.Host] = "www.supercheats.com"; //request.Headers[HttpRequestHeader.Pragma] = "no-cache"; //request.ContentLength = str.Length; //// Set the Method property to 'POST' to post data to the URI. //request.Method = "POST"; //// start the asynchronous operation //request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request); //USE THIRD-PARTY GZIPWEBCLIENT INSTEAD webClient.Headers[HttpRequestHeader.Accept] = "text/html, application/xhtml+xml, */*"; webClient.Headers[HttpRequestHeader.Referer] = "http://www.supercheats.com/search.php"; webClient.Headers[HttpRequestHeader.AcceptLanguage] = "en-US"; webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; webClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"; webClient.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate"; webClient.Headers[HttpRequestHeader.Connection] = "Keep-Alive"; webClient.Headers[HttpRequestHeader.Host] = "www.supercheats.com"; webClient.Headers[HttpRequestHeader.Pragma] = "no-cache"; webClient.Headers[HttpRequestHeader.ContentLength] = body.Length.ToString(); response = await webClient.UploadStringTaskAsync(new Uri("http://www.supercheats.com/search.php", UriKind.Absolute), body); } catch (Exception ex) { MessageBox.Show(ex.Message); } if (response == null) { SystemTray.GetProgressIndicator(this).IsIndeterminate = false; return; } List <CheatInfo> PartialMatchList = new List <CheatInfo>(); List <CheatInfo> CheatInfoList = new List <CheatInfo>(); //=========get the partial matches MatchCollection partialMatches = Regex.Matches(response, "(?<=<div class=\"search_otherresult\">).*?(?=</div>)", RegexOptions.Singleline); //look for the string between <tr class=\"table_sub\"> and </tr> for (int i = 0; i < partialMatches.Count; i++) { CheatInfo cheatInfo = new CheatInfo(); //get the title Match partialMatch = partialMatches[i]; Match matchTitle = Regex.Match(partialMatch.Value, "(?<=<b>).*?(?=</b>)", RegexOptions.Singleline); cheatInfo.Title = matchTitle.Value; //===get the platform Match matchPlatform = Regex.Match(partialMatch.Value, "(?<=<a href=.*?>).*?(?=</a>)", RegexOptions.Singleline); //====add title to list PartialMatchList.Add(cheatInfo); } //get rid of the bold tag response = response.Replace("<b>", ""); response = response.Replace("</b>", ""); //string test = "hhh\n <tr class=\"table_head_01\">\n\t<td align=\"left\" valign=\"middle\">Cheats</td><td align=\"left\" valign=\"middle\">Hints</td><td align=\"left\" valign=\"middle\">Q&A</td><td align=\"left\" valign=\"middle\">Walkthroughs</td><td align=\"left\" valign=\"middle\">Screens</td><td align=\"left\" valign=\"middle\">Walls</td><td align=\"left\" valign=\"middle\">Videos</td></tr>"; //MatchCollection tests = Regex.Matches(test, "(?<=<tr class=\"table_head_01\">).*?(?=</tr>)", RegexOptions.Singleline); //=====get the exact match MatchCollection headers = Regex.Matches(response, "(?<=<tr class=\"table_sub\">).*?(?=</tr>)", RegexOptions.Singleline); //look for the string between <tr class=\"table_sub\"> and </tr> MatchCollection contents = Regex.Matches(response, "(?<=<tr class=\"table_head_01\">).*?(?=</tr>)"); //look for the string between <tr class=\"table_head_01\"> and </tr> //don't use Singleline to avoid 2 unncessearies results for (int i = 0; i < headers.Count; i++) { CheatInfo cheatInfo = new CheatInfo(); //get the title Match matchHeader = headers[i]; Match matchTitle = Regex.Match(matchHeader.Value, "(?<=<a href=.*?>).*?(?=</a>)", RegexOptions.Singleline); cheatInfo.Title = matchTitle.Value; //===get the links to cheat code Match matchContent = contents[i]; MatchCollection matchTDs = Regex.Matches(matchContent.Value, "(?<=<td align=center class=\"platform_table\">).*?(?=</td>)", RegexOptions.Singleline); //check each <td> cheatInfo.HasAR = false; cheatInfo.HasGS = false; foreach (Match matchtd in matchTDs) { if (matchtd.Value.Contains("YES")) { if (matchtd.Value.Contains("codes.htm")) //GS { cheatInfo.HasGS = true; Match matchhref = Regex.Match(matchtd.Value, "(?<=<a href=\").*?(?=\")", RegexOptions.Singleline); cheatInfo.GSLink = "http://www.supercheats.com" + matchhref.Value; } else if (matchtd.Value.Contains("codes2.htm")) //AR { cheatInfo.HasAR = true; Match matchhref = Regex.Match(matchtd.Value, "(?<=<a href=\").*?(?=\")", RegexOptions.Singleline); cheatInfo.ARLink = "http://www.supercheats.com" + matchhref.Value; } } } CheatInfoList.Add(cheatInfo); // if (!value.StartsWith("/roms/")) // { // continue; // } // value = string.Concat("http://m.coolrom.com.au", value); // Uri uri = new Uri(value, UriKind.Absolute); // if (uri.Segments.Count() < 4) // { // continue; // } // string str4 = uri.Segments[2].Substring(0, uri.Segments[2].Length - 1); // string str5 = uri.Segments[3].Substring(0, uri.Segments[3].Length - 1); // string lower = str4.ToLower(); // string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(uri.LocalPath); // string str6 = fileNameWithoutExtension.Replace("_", " "); // string str7 = string.Concat(fileNameWithoutExtension, ".zip"); } this.exactMatches.DataContext = CheatInfoList; this.partialMatches.DataContext = PartialMatchList; gameList.Visibility = Visibility.Visible; codeList.Visibility = Visibility.Collapsed; cheatTextStackpanel.Visibility = Visibility.Collapsed; SystemTray.GetProgressIndicator(this).IsIndeterminate = false; //try //{ // webClient.Headers["user-agent"] = "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 520)"; // string str3 = await webClient.DownloadStringTaskAsync(new Uri(string.Concat("http://m.coolrom.com.au/search?q=", str1), UriKind.Absolute)); // str2 = str3; //} //catch //{ //} //foreach (Match match in Regex.Matches(str2, "(?<=\\bhref=\")[^\"]*")) //first look for href=", then look for " // // \\b got translated to \b which is the boundary anchor // //use @ if does not want to use double \ in \\b but then we cannot escape " //{ // string value = match.Value; // if (!value.StartsWith("/roms/")) // { // continue; // } // value = string.Concat("http://m.coolrom.com.au", value); // Uri uri = new Uri(value, UriKind.Absolute); // if (uri.Segments.Count() < 4) // { // continue; // } // string str4 = uri.Segments[2].Substring(0, uri.Segments[2].Length - 1); // string str5 = uri.Segments[3].Substring(0, uri.Segments[3].Length - 1); // string lower = str4.ToLower(); // string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(uri.LocalPath); // string str6 = fileNameWithoutExtension.Replace("_", " "); // string str7 = string.Concat(fileNameWithoutExtension, ".zip"); //} }