diff --git a/Form1.cs b/Form1.cs index b188a43..ffdf016 100644 --- a/Form1.cs +++ b/Form1.cs @@ -19,7 +19,7 @@ namespace Omnibus public partial class Form1 : Form { - private String version = "1.4.2"; + private String version = "1.4.2.1"; private String url = "https://getcomics.info/?s="; private int cancelled = 0; private int complete; @@ -132,113 +132,120 @@ private void btnDownload_Click(object sender, EventArgs e) if (lbComics.Items.Count > 0) { - HtmlNode n = nodes.ElementAt(lbComics.SelectedIndex); - string node = n.InnerHtml; - string[] a = node.Split('"'); - - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(a[1]); - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - - if (response.StatusCode == HttpStatusCode.OK) + if (lbComics.SelectedItems.Count == 0) { - Stream receiveStream = response.GetResponseStream(); - StreamReader readStream = null; + MessageBox.Show("You must select a comic before downloading."); + } + else + { + HtmlNode n = nodes.ElementAt(lbComics.SelectedIndex); + string node = n.InnerHtml; + string[] a = node.Split('"'); - if (response.CharacterSet == null) - { - readStream = new StreamReader(receiveStream); - } - else + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(a[1]); + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + + if (response.StatusCode == HttpStatusCode.OK) { - readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet)); - } + Stream receiveStream = response.GetResponseStream(); + StreamReader readStream = null; - string data = readStream.ReadToEnd(); + if (response.CharacterSet == null) + { + readStream = new StreamReader(receiveStream); + } + else + { + readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet)); + } - response.Close(); - readStream.Close(); + string data = readStream.ReadToEnd(); - HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); - doc.LoadHtml(data); + response.Close(); + readStream.Close(); - //Regex regex = new Regex("(?<=go.php-url=)(.*)Mega", RegexOptions.IgnoreCase); //old regex string - Regex regex = new Regex("(?<=go.php-urls/)(.*)Mega", RegexOptions.IgnoreCase); //updated regex string to match new paths - Match match; + HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); + doc.LoadHtml(data); - if (regex.Match(data).Success != false) - { - for (match = regex.Match(data); match.Success; match = match.NextMatch()) - { - string lastEV = ""; - List EVs = new List(); + //Regex regex = new Regex("(?<=go.php-url=)(.*)Mega", RegexOptions.IgnoreCase); //old regex string + Regex regex = new Regex("(?<=go.php-urls/)(.*)Mega", RegexOptions.IgnoreCase); //updated regex string to match new paths + Match match; - foreach (Group group in match.Groups) + if (regex.Match(data).Success != false) + { + for (match = regex.Match(data); match.Success; match = match.NextMatch()) { - string[] g1 = group.ToString().Split(new string[] { " EVs = new List(); - for(int i = 0; i < g1.Count(); i++) + foreach (Group group in match.Groups) { - if(g1[i].Contains("aio-purple")) + string[] g1 = group.ToString().Split(new string[] { "= 4) - { - encodedValue = gcURLArray[4]; //first hash location - } - else - { - gcURL = g3[0]; - encodedValue = gcURL; //second hash location - } - - if (IsBase64(encodedValue) != true) - { - MessageBox.Show("No downloads available, go to the comic's page to download."); - } + if (gcURLArray.Length >= 4) + { + encodedValue = gcURLArray[4]; //first hash location + } + else + { + gcURL = g3[0]; + encodedValue = gcURL; //second hash location + } - if (lastEV != encodedValue) - { - byte[] urlData = Convert.FromBase64String(encodedValue); - string decodedURL = Encoding.UTF8.GetString(urlData); + if (IsBase64(encodedValue) != true) + { + MessageBox.Show("No downloads available, go to the comic's page to download."); + } + + if (lastEV != encodedValue) + { + byte[] urlData = Convert.FromBase64String(encodedValue); + string decodedURL = Encoding.UTF8.GetString(urlData); - downloadList.Add(decodedURL); + downloadList.Add(decodedURL); - HtmlNode tn = nodes.ElementAt(lbComics.SelectedIndex); - string tnode = n.InnerHtml; - string[] ta = node.Split('"'); + HtmlNode tn = nodes.ElementAt(lbComics.SelectedIndex); + string tnode = n.InnerHtml; + string[] ta = node.Split('"'); - string title = replaceASCII(ta[5]); + string title = replaceASCII(ta[5]); - //add item to listview - AddLVItem("0", title); + //add item to listview + AddLVItem("0", title); - titleList.Add(title); + titleList.Add(title); - lastEV = encodedValue; + lastEV = encodedValue; + } + break; } - break; } } + break; } - break; } - } - else - MessageBox.Show("No download link available. Go to comic's page and download manually."); - + else + MessageBox.Show("No download link available. Go to comic's page and download manually."); - if (downloadList.Count > 0) - { - DownloadComic(idCount); + + if (downloadList.Count > 0) + { + DownloadComic(idCount); + } } } }