diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 950302f..7e36caa 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -41,6 +41,8 @@ private void InitializeComponent() this.label4 = new System.Windows.Forms.Label(); this.ratingCheckBox = new System.Windows.Forms.CheckBox(); this.detectButton = new System.Windows.Forms.Button(); + this.label5 = new System.Windows.Forms.Label(); + this.limitBox = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // tagsBox @@ -159,11 +161,29 @@ private void InitializeComponent() this.detectButton.UseVisualStyleBackColor = true; this.detectButton.Click += new System.EventHandler(this.detectButton_Click); // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(413, 80); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(81, 13); + this.label5.TabIndex = 13; + this.label5.Text = "Download limit: "; + // + // limitBox + // + this.limitBox.Location = new System.Drawing.Point(500, 77); + this.limitBox.Name = "limitBox"; + this.limitBox.Size = new System.Drawing.Size(47, 20); + this.limitBox.TabIndex = 14; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(624, 137); + this.Controls.Add(this.limitBox); + this.Controls.Add(this.label5); this.Controls.Add(this.detectButton); this.Controls.Add(this.ratingCheckBox); this.Controls.Add(this.label4); @@ -199,6 +219,8 @@ private void InitializeComponent() private System.Windows.Forms.Label label4; private System.Windows.Forms.CheckBox ratingCheckBox; private System.Windows.Forms.Button detectButton; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox limitBox; } } diff --git a/Form1.cs b/Form1.cs index 64e5605..ce916a5 100644 --- a/Form1.cs +++ b/Form1.cs @@ -21,6 +21,8 @@ public partial class Form1 : Form { [DllImport("kernel32.dll", SetLastError = true)] static extern bool AllocConsole(); + + int alreadyDownloaded = 0; public Form1() { @@ -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); @@ -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."; @@ -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.";