vendredi 30 septembre 2016

Int not incrementing or being checked properly

I am new to coding and am having a hard time trying to figure this out. I have an if/else loop that if matched will do things as well as increment the variable bbb. Then at the end it checks what the number of bbb is and acts on it depending on the if/else statement. The code is strange when I have the if(bbb==0) statement in, it will always resolve as true even when I know it shouldn't be. If the if(bbb == 0) statement is commented out it resolves with the correct number for count. Here is my full set of code. If I am not asking the correct questions please let me know. Thanks for your help.

        protected void jotti()
    {
        string input = TextBox1.Text;
        string file;
        file = "/C \"curl http://ift.tt/2dx1hPr" + input + " -o C:\\Windows\\Temp\\jotti.txt";
        System.Diagnostics.Process CMDprocess = new System.Diagnostics.Process();
        var StartProcessInfo = new System.Diagnostics.ProcessStartInfo();
        StartProcessInfo.FileName = "cmd.exe";
        StartProcessInfo.UseShellExecute = false;
        StartProcessInfo.CreateNoWindow = false;
        StartProcessInfo.Verb = "runas";
        StartProcessInfo.Arguments = file;
        CMDprocess.StartInfo = StartProcessInfo;
        CMDprocess.Start();
        CMDprocess.WaitForExit();
        jotti_Parser();
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    protected void jotti_Parser()
    {
        StringBuilder sb = new StringBuilder();
        string input = TextBox1.Text;
        int bbb = 0;
        var filename = @"C:\Windows\Temp\jotti.txt";
        var text = File.ReadAllText(filename);
        text = text.Replace("dataType:", "");
        File.WriteAllText(filename, text);
        string a = "<a href=http://ift.tt/2dx1hPr" + input + "> Hash Results </a> <br/> ";
        sb.Append(a);
        foreach (string line in File.ReadAllLines(filename))
        {
            if (line.Contains("Name:"))
            {
                string t = line.ToString() + " <br/> ";
                sb.Append(t);
                bbb++;
            }
            if (line.Contains("Size:"))
            {
                string y = line.ToString() + " <br/> ";
                sb.Append(y);
                bbb++;
            }
            if (line.Contains("Type:"))
            {
                string s = line.ToString() + " <br/> ";
                sb.Append(s);
                bbb++;
            }
            if (line.Contains("MD5:"))
            {
                string q = line.ToString() + " <br/> ";
                sb.Append(q);
                bbb++;
            }
            if (line.Contains("Status:"))
            {
                string u = line.ToString() + " <br/> ";
                sb.Append(u);
                bbb++;
            }
            File.WriteAllText(filename, sb.ToString());
            string text2 = File.ReadAllText(filename);
            text2 = text2.Replace("<td>", "");
            text2 = text2.Replace("</td>", "");
            text2 = text2.Replace("Status:<td id=\"statusText[hl5p2789za]\"", "Status:");
            text2 = text2.Replace("class=\"statusText\">Scan", "Scan");
            text2 = text2.Replace("Scan finished.", "Scan finished. <br/> ");
            text2 = text2.Replace(" <br/> ", " <br/> " + Environment.NewLine);
            File.WriteAllText(filename, text2);
            if (bbb == 0)
            {
                Label6.Visible = true;
                Label6.Text = text2.ToString() + bbb;
            }
            else
            {
                string v = "This hash has not been seen by this resource. <br/>";
                sb.Clear();
                Label6.Visible = true;
                Label6.Text = v + bbb;
                bbb++;
                return;
            }
        }
   }

Aucun commentaire:

Enregistrer un commentaire