-
Notifications
You must be signed in to change notification settings - Fork 2
/
Form1.cs
151 lines (133 loc) · 5.06 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BooruDownloader
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool AllocConsole();
int alreadyDownloaded = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
bool exists = System.IO.Directory.Exists("./out/");
if (!exists)
System.IO.Directory.CreateDirectory("./out/");
tagsBox.GotFocus += new EventHandler(this.TagsGotFocus);
tagsBox.LostFocus += new EventHandler(this.TagsLostFocus);
label4.Text = "";
this.MaximizeBox = false;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
ToolTip toolTip1 = new ToolTip();
toolTip1.AutoPopDelay = 99999;
toolTip1.InitialDelay = 250;
toolTip1.ReshowDelay = 250;
// Force the ToolTip text to be displayed whether or not the form is active.
toolTip1.ShowAlways = true;
toolTip1.SetToolTip(this.detectButton, "Click here if you don't know what engine does the selected website uses. Keep in mind that engine detection feature is experimental.");
#if DEBUG
AllocConsole();
#endif
}
public void TagsGotFocus(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
if (tb.Text == "tags separated by whitespace")
{
tb.Text = "";
tb.ForeColor = Color.Black;
}
}
public void TagsLostFocus(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
if (tb.Text == "")
{
tb.Text = "tags separated by whitespace";
tb.ForeColor = Color.DarkGray;
}
}
private async void downloadButton_Click(object sender, EventArgs e)
{
EngineBase engine = Detector.detectEngine(domainBox.Text);
if (engine == null)
{
if (isDanbooruSite.Checked == true)
engine = new DanEngine();
else
engine = new GelEngine();
}
engine.SetApiKey(apiKeyTextBox.Text);
engine.SetLogin(loginTextBox.Text);
int postCount = engine.GetPostCount(domainBox.Text, tagsBox.Text);
alreadyDownloaded = 0;
Console.WriteLine(postCount);
if (postCount == 0)
{
Console.WriteLine("No posts found by tag " + tagsBox.Text);
statusLabel.ForeColor = Color.Red;
statusLabel.Text = "No posts found.";
}
else
{
statusLabel.ForeColor = Color.Blue;
statusLabel.Text = "Downloading...";
int limitBoxText;
try
{
limitBoxText = int.Parse(limitBox.Text);
}
catch (Exception)
{
limitBox.Text = "999";
limitBoxText = 999;
}
int offset;
try
{
offset = int.Parse(offsetTextBox.Text);
}
catch (Exception)
{
offsetTextBox.Text = "0";
offset = 0;
}
for (int i = offset; i < postCount; i++)
{
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.";
label4.Text = "";
MessageBox.Show("Download compelete!", "BooruDownloader", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void detectButton_Click(object sender, EventArgs e)
{
EngineBase.type engine = Detector.detectEngine(domainBox.Text).getType();
switch (engine)
{
case EngineBase.type.DAN:
isDanbooruSite.Checked = true;
break;
case EngineBase.type.GEL:
isDanbooruSite.Checked = false;
break;
}
}
}
}