Skip to content

Commit

Permalink
Add limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
fgRuslan committed Jun 14, 2021
1 parent d803bd9 commit 28b1d7d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
22 changes: 22 additions & 0 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 37 additions & 4 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public partial class Form1 : Form
{
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool AllocConsole();

int alreadyDownloaded = 0;

public Form1()
{
Expand Down Expand Up @@ -71,6 +73,7 @@ public void TagsLostFocus(object sender, EventArgs e)

private async void downloadButton_Click(object sender, EventArgs e)
{
alreadyDownloaded = 0;
if (isDanbooruSite.Checked){//If it's a danbooru site
DanEngine engine = new DanEngine();
int postCount = engine.getPostCount(domainBox.Text, tagsBox.Text);
Expand All @@ -85,10 +88,25 @@ private async void downloadButton_Click(object sender, EventArgs e)
{
statusLabel.ForeColor = Color.Blue;
statusLabel.Text = "Downloading...";

int limitBoxText;
try
{
limitBoxText = int.Parse(limitBox.Text);
}
catch (Exception e1)
{
limitBox.Text = "999";
limitBoxText = 999;
}
for (int i = 1; i < postCount; i++)
{
await Task.Run(() => engine.downloadPosts(domainBox.Text, tagsBox.Text, i, checkBox1.Checked, ratingCheckBox.Checked));
label4.Text = Convert.ToString(postCount - i) + " left";
if (alreadyDownloaded <= limitBoxText)
{
await Task.Run(() => engine.downloadPosts(domainBox.Text, tagsBox.Text, i, checkBox1.Checked, ratingCheckBox.Checked));
label4.Text = Convert.ToString(postCount - i) + " left";
alreadyDownloaded++;
}
}
statusLabel.ForeColor = Color.Green;
statusLabel.Text = "Ready.";
Expand All @@ -112,10 +130,25 @@ private async void downloadButton_Click(object sender, EventArgs e)
{
statusLabel.ForeColor = Color.Blue;
statusLabel.Text = "Downloading...";

int limitBoxText;
try
{
limitBoxText = int.Parse(limitBox.Text);
}
catch (Exception e1)
{
limitBox.Text = "999";
limitBoxText = 999;
}
for (int i = 0; i < postCount; i++)
{
await Task.Run(() => engine.downloadPosts(domainBox.Text, tagsBox.Text, i, checkBox1.Checked, ratingCheckBox.Checked));
label4.Text = Convert.ToString(postCount - i) + " left";
if (alreadyDownloaded <= limitBoxText)
{
await Task.Run(() => engine.downloadPosts(domainBox.Text, tagsBox.Text, i, checkBox1.Checked, ratingCheckBox.Checked));
label4.Text = Convert.ToString(postCount - i) + " left";
alreadyDownloaded++;
}
}
statusLabel.ForeColor = Color.Green;
statusLabel.Text = "Ready.";
Expand Down

0 comments on commit 28b1d7d

Please sign in to comment.