Ejemplo n.º 1
0
        private async void codeList_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (codeList.SelectedItem == null)
            {
                return;
            }

            CheatText cheatText = (CheatText)codeList.SelectedItem;

            codeList.SelectedItem = null;


            if (cheatText.Url != null && cheatText.Url != "") //need to go to the link to obtain the code
            {
                GZipWebClient webClient = new GZipWebClient();
                string        response  = null;
                SystemTray.GetProgressIndicator(this).IsIndeterminate = true;

                try
                {
                    //USE THIRD-PARTY GZIPWEBCLIENT
                    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.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";

                    response = await webClient.DownloadStringTaskAsync(new Uri(cheatText.Url, UriKind.Absolute));


                    if (response == null)
                    {
                        SystemTray.GetProgressIndicator(this).IsIndeterminate = false;
                        return;
                    }

                    Match  contentMatch = Regex.Match(response, "(?<=<div id='sub).*?(?=</div>)", RegexOptions.Singleline);
                    string content      = contentMatch.Value;
                    int    index        = content.IndexOf(">"); //get the position of the closing bracket
                    content = content.Substring(index + 1);     //get rid of the closing bracket

                    cheatText.TextHtml += "<p style=\"font-size:22px\">" + content + "</p></body></html>";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                SystemTray.GetProgressIndicator(this).IsIndeterminate = false;
            }

            cheatTextStackpanel.DataContext = cheatText;
            cheatTextBox.NavigateToString(cheatText.TextHtml);

            gameList.Visibility            = Visibility.Collapsed;
            codeList.Visibility            = Visibility.Collapsed;
            cheatTextStackpanel.Visibility = Visibility.Visible;
        }
Ejemplo n.º 2
0
        private async void DisplayCheats(string url, int cheatType)
        {
            //cheatType: 0 for GS, 1 for AR

            //navigate to the cheat link and download cheat text
            GZipWebClient webClient = new GZipWebClient();
            string        response  = null;

            SystemTray.GetProgressIndicator(this).IsIndeterminate = true;

            try
            {
                //USE THIRD-PARTY GZIPWEBCLIENT
                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.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";

                response = await webClient.DownloadStringTaskAsync(new Uri(url, UriKind.Absolute));


                if (response == null)
                {
                    SystemTray.GetProgressIndicator(this).IsIndeterminate = false;
                    return;
                }


                MatchCollection headers = Regex.Matches(response, "(?<=<h5 class=\"fleft\">).*?(?=</h5>)", RegexOptions.Singleline);


                List <CheatText> CheatTextList = new List <CheatText>();


                for (int i = 0; i < headers.Count; i++)
                {
                    string htmlstring = "<html><head><meta name='viewport' content='width=456, user-scalable=yes' /></head><body>";

                    CheatText cheatText = new CheatText();

                    //get the title
                    if (headers[i].Value == "")
                    {
                        cheatText.Title = "No description";
                    }
                    else
                    {
                        cheatText.Title = headers[i].Value;
                    }

                    //get the text content
                    string content = "";
                    if (cheatType == 0) //GS cheats
                    {
                        Match contentMatch = Regex.Match(response, "(?<=<div class=\"body\").*?(?=</div>)", RegexOptions.Singleline);
                        content = contentMatch.Value;
                    }
                    else if (cheatType == 1)
                    {
                        Match contentMatch = Regex.Match(response, "(?<=<div class=\"body\").*?(?=</span></div>)", RegexOptions.Singleline);
                        content = contentMatch.Value;
                    }



                    int index = content.IndexOf(">");       //get the position of the closing bracket
                    content = content.Substring(index + 1); //get rid of the closing bracket

                    //get the text in html format
                    if (cheatType == 0)
                    {
                        htmlstring        += "<p style=\"font-size:22px\">" + content + "</p>" + "</body></html>"; //html string does not need to replace <br/> by \n
                        cheatText.TextHtml = htmlstring;
                    }
                    else if (cheatType == 1)
                    {
                        int index2 = content.IndexOf("<div");                                                        //find the end of the title

                        htmlstring        += "<p style=\"font-size:22px\">" + content.Substring(0, index2) + "</p>"; //html string does not need to replace <br/> by \n
                        cheatText.TextHtml = htmlstring;
                    }

                    index    = response.IndexOf("<div class=\"body\"");
                    response = response.Substring(index + 10); //just any number to make it go pass the <div


                    //get the text in plain text format
                    content = content.Replace("<br/>", "\n");
                    content = content.Replace("<br />", "\n");
                    content = content.Replace("<BR>", "\n");
                    content.Replace("\n\n\n", "\n\n");
                    content = content.Trim();


                    if (cheatType == 1)
                    {
                        //get the link to the full cheat text
                        Match linkMatch = Regex.Match(content, "(?<=<a href=\").*?(?=\")", RegexOptions.Singleline);
                        cheatText.Url = linkMatch.Value;

                        //get the text part
                        int index2 = content.IndexOf("<div"); //find the end of the text

                        if (index2 > 0)
                        {
                            content = content.Substring(0, index2 - 1); //there is a \t at the end so get rid of it.
                        }
                        else
                        {
                            content = "";
                        }
                    }

                    //get only the first few lines
                    int count = 0;
                    index          = 0;
                    cheatText.Text = "";
                    while (count <= 4 && index != -1)
                    {
                        index = content.IndexOf("\n");

                        if (index != -1)
                        {
                            count++;
                            cheatText.Text += content.Substring(0, index + 1); //copy the first line to cheatText

                            content = content.Substring(index + 1);            //remove the first line
                            content = content.Trim();
                        }
                        else
                        {
                            cheatText.Text += content;
                        }
                    }

                    if (cheatText.Text.Length > 0 && cheatText.Text[cheatText.Text.Length - 1] != '\n')
                    {
                        cheatText.Text += "\n";
                    }

                    cheatText.Text += "..............";

                    //add to list
                    CheatTextList.Add(cheatText);
                }


                codeList.DataContext = CheatTextList;



                gameList.Visibility            = Visibility.Collapsed;
                codeList.Visibility            = Visibility.Visible;
                cheatTextStackpanel.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            SystemTray.GetProgressIndicator(this).IsIndeterminate = false;
        }