Skip to content

Commit

Permalink
Fix DanEngine. Everything works fine now
Browse files Browse the repository at this point in the history
  • Loading branch information
fgRuslan committed Jul 15, 2019
1 parent cedd207 commit b9a294d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions DanEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ private void downloadImage(string url, string tags, bool keepOriginalNames)
{
using (WebClient wc = new WebClient())
{
wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; " +
"Windows NT 5.2; .NET CLR 1.0.3705;)");
if (keepOriginalNames)
wc.DownloadFileAsync(new System.Uri(url), "./out/" + FnameFromURL(url));
else
Expand Down
5 changes: 4 additions & 1 deletion Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ private async void downloadButton_Click(object sender, EventArgs e)
{
statusLabel.ForeColor = Color.Blue;
statusLabel.Text = "Downloading...";
for (int i = 0; i < postCount; i++)
for (int i = 1; i < postCount; i++)
{
await Task.Run(() => engine.downloadPosts(domainBox.Text, tagsBox.Text, i, checkBox1.Checked));
statusLabel.Text = "Downloading..." + Convert.ToString(postCount - i);
}
statusLabel.ForeColor = Color.Green;
statusLabel.Text = "Ready.";
Expand All @@ -87,6 +88,7 @@ private async void downloadButton_Click(object sender, EventArgs e)

GelEngine engine = new GelEngine();
int postCount = engine.getPostCount(domainBox.Text, tagsBox.Text);
Console.WriteLine(postCount);
if (postCount == 0)
{
Console.WriteLine("No posts found by tag " + tagsBox.Text);
Expand All @@ -100,6 +102,7 @@ private async void downloadButton_Click(object sender, EventArgs e)
for (int i = 0; i < postCount; i++)
{
await Task.Run(() => engine.downloadPosts(domainBox.Text, tagsBox.Text, i, checkBox1.Checked));
statusLabel.Text = "Downloading..." + Convert.ToString(postCount - i);
}
statusLabel.ForeColor = Color.Green;
statusLabel.Text = "Ready.";
Expand Down
8 changes: 7 additions & 1 deletion GelEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class GelEngine
XmlElement root;
string url;

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool AllocConsole();

string ExtFromURL(string line)
{
var ext = "";
Expand All @@ -41,6 +44,8 @@ private void downloadImage(string url, string tags, bool keepOriginalNames)
{
using (WebClient wc = new WebClient())
{
wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; " +
"Windows NT 5.2; .NET CLR 1.0.3705;)");
if (keepOriginalNames)
wc.DownloadFileAsync(new System.Uri(url), "./out/" + FnameFromURL(url));
else
Expand All @@ -52,7 +57,7 @@ public int getPostCount(string domain, string tags)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(domain + "/index.php?page=dapi&s=post&q=index&limit=1&tags=" + tags);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//AllocConsole();
AllocConsole();
string result = "";
using (Stream stream = response.GetResponseStream())
{
Expand Down Expand Up @@ -85,6 +90,7 @@ public string downloadPosts(string domain, string tags, int page, bool keepOrigi

url = root.Attributes["file_url"].Value;
tags = root.Attributes["tags"].Value;
Console.WriteLine(url);
downloadImage(url, tags, keepOriginalNames);
}
return url;
Expand Down

0 comments on commit b9a294d

Please sign in to comment.