I have an aqward question
How to redesign my code?
I change my mind about the structure of the program.
I want to do what its doing already, but in a different way.
What is doing right now: When [I select a user from list], its going and read the Online page and decrypt it and solving the directives, for every user i click in list.
What I want is a single time button click that will resolve the existing tasks but for ALL users in list. After resolving everything, save ALL (images,bio,etc) to my hard drive, and then load it from there.
So, this is my structure change. I hope I was clear enough.
Before looking at the code, I must specify is not about the code itself. Its working perfectly. Also, I can add by myself anything is needed when the structure of the code is changed.
But its about the order of things. I really hope to be explicit enough.
I know how to reorganize with "cut and paste". Its not such a big deal.
I will in the end, add [
everything] in a BIG Method, and the most obvious one will be the button1_Click one.
I am conscientious that will be a MASSIVE method. I dont mind, I did it before and worked perfectly.
What I ask from you, are
ideas about reorganizing (more structural perhaps, or logical) than I am already used to do it by myself, which is working great by the way. Maybe you know something that i missed in organizing and planning my structural code thinking, I want something that will actually help me, not confuse me.
Thanks for your understanding.
And here is the code(a part), but is not actually too relevant(I put it anyway).
For the fun of it.
private void button1_Click(object sender, EventArgs e)
{
streamx = ""; file = ""; listBox1.Items.Clear();
DirectoryInfo di = new DirectoryInfo(Application.StartupPath);
foreach (var item in di.GetFiles())
{
if (item.Extension == ".htm")
{
StreamReader sr = new StreamReader(item.FullName);
file += sr.ReadToEnd();
sr.Close();
}
}
string cod = "username=\".*?\"";
Regex rx = new Regex(cod);
foreach (var item in rx.Matches(file)) listBox1.Items.Add(item.ToString().Replace("username=", "").Replace("\"", ""));
label1.Text = listBox1.Items.Count.ToString();
listBox1.SelectedIndex = 0;
StreamWriter sw = new StreamWriter("Artists\\0.txt");
foreach (var item in listBox1.Items) sw.Write(item + "\r\n");
sw.Close();
}
List<string> URLs;
string urlx = "", text3564 = "", codRX = "", extrpage = ""; int i7 = 0, i8972 = 0, pagesDeviants = 1;
bool nextpag = false;
public void userBio()
{
streamx = ""; urlx = "";
urlx = "http://" + listBox1.SelectedItem.ToString().ToLower() + ".deviantart.com";
linkLabel1.Text = urlx;
HttpWebRequest request;
HttpWebResponse response = null;
Stream stream = null;
request = (HttpWebRequest)WebRequest.Create(urlx);
request.UserAgent = "Foo";
request.Accept = "*/*";
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream, System.Text.Encoding.Default);
streamx = sr.ReadToEnd();
if (stream != null) stream.Close();
if (response != null) response.Close();
RichTextBox1.Text = listBox1.SelectedItem.ToString() + " ";
text3564 = streamx;
if (text3564.Contains("aboutme-personal-info"))
{
string cod01 = "aboutme-personal-info\">.*\n.*";
text3564 = Regex.Match(streamx, cod01).ToString().Replace("aboutme-personal-info\">", "").TrimStart().Replace("</div>", "").TrimEnd();
RichTextBox1.Text += "[" + text3564 + "]\r\n";
}
if (text3564.Contains("aboutme-realname"))
{
string cod02 = "aboutme-realname\">.*\n.*";
text3564 = Regex.Match(streamx, cod02).ToString().Replace("aboutme-realname\">", "").TrimStart().Replace("</div>", "").TrimEnd();
RichTextBox1.Text += "Real Name= [" + text3564 + "]\r\n";
}
text3564 = streamx;
if (text3564.Contains("START BIO"))
{
i7 = text3564.IndexOf("START BIO"); text3564 = text3564.Remove(0, i7);
if (text3564.Contains("END BIO"))
{
i7 = text3564.IndexOf("END BIO"); text3564 = "<" + text3564.Remove(i7, text3564.Length - i7) + ">";
}
text3564 = text3564.Replace("<br />", "\r\n").Replace(""", "\"");
string cod03 = "<.*?>";
text3564 = Regex.Replace(text3564, cod03, "");
text3564 = text3564.TrimStart().TrimEnd();
RichTextBox1.Text += "\r\n Bio= [ " + text3564 + "\r\n]\r\n";
}
text3564 = streamx;
if (text3564.Contains("<img class=\"avatar float-left\" src=\""))
{
i7 = text3564.IndexOf("<img class=\"avatar float-left\" src=\""); text3564 = text3564.Remove(0, i7);
string cod05 = "src=\".*?\"";
text3564 = Regex.Match(text3564, cod05).ToString().Replace("src=", "").Replace("\"", "");
pictureBox2.ImageLocation = text3564;
}
text3564 = streamx;
if (text3564.Contains("id=\"aboutme-profile-pic"))
{
i7 = text3564.IndexOf("id=\"aboutme-profile-pic"); text3564 = text3564.Remove(0, i7);
if (text3564.Contains("<div id=\"aboutme-info\">"))
{
i7 = text3564.IndexOf("<div id=\"aboutme-info\">"); text3564 = text3564.Remove(i7, text3564.Length - i7);
}
string cod04 = "src=\".*?\"";
text3564 = Regex.Match(text3564, cod04).ToString().Replace("src=", "").Replace("\"", "");
pictureBox1.ImageLocation = text3564;
}
else
{
pictureBox1.Image = null;
}
}
public void userGallery()
{
pagesDeviants = 1;
streamx = ""; urlx = "";
urlx = "http://" + listBox1.SelectedItem.ToString().ToLower() + ".deviantart.com/gallery/";
linkLabel1.Text = urlx;
URLs = new List<string>();
start:
HttpWebRequest request;
HttpWebResponse response = null;
Stream stream = null;
request = (HttpWebRequest)WebRequest.Create(urlx);
request.UserAgent = "Foo";
request.Accept = "*/*";
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream, System.Text.Encoding.Default);
streamx = sr.ReadToEnd();
extrpage = streamx;
if (stream != null) stream.Close();
if (response != null) response.Close();
text3564 = streamx; codRX = urlx = ""; i7 = 0;
i7 = text3564.IndexOf("<div class=\"folderview-art\">"); text3564 = text3564.Remove(0, i7);
string st0 = "data-super-img=";
if (text3564.Contains(st0))
{
while (text3564.Contains(st0))
{
i7 = text3564.IndexOf(st0); text3564 = text3564.Remove(0, i7);
codRX = st0 + ".*?(\" )";
urlx = Regex.Match(text3564, codRX).ToString().Replace(st0, "").Replace("\"", "");
i7 = text3564.IndexOf(urlx); text3564 = text3564.Remove(0, i7 + urlx.Length);
URLs.Add(urlx);
}
}
if (extrpage.Contains("<li class=\"next\">"))
{
if (extrpage.Contains("class=\"next\"><a class=\"disabled\">")) goto end;
i8972 = extrpage.IndexOf("<li class=\"next\">");
extrpage = extrpage.Remove(0, i8972);
i8972 = extrpage.IndexOf("offset=\"");
extrpage = extrpage.Remove(0, i8972 + "offset=\"".Length);
i8972 = extrpage.IndexOf("\"");
extrpage = extrpage.Remove(i8972, extrpage.Length - i8972);
urlx = "http://" + listBox1.SelectedItem.ToString().ToLower() + ".deviantart.com/gallery/?offset=" + extrpage;
pagesDeviants++;
goto start;
}
end: ;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label2.Text = "Loading"; listBox1.Update();
this.Refresh();
userBio();
userGallery();
AutoArrange();
label2.Text = "Done";
}