-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorWindow.cs
475 lines (406 loc) · 15.9 KB
/
ErrorWindow.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlServerCe;
namespace CSL
{
public partial class ErrorWindow : Form
{
static DirectoryHandler DirectoryHandler = new DirectoryHandler(); //Prevent infinite loop between DirectoryHandler & ErrorWindow
int s_index;
int e_index;
bool okButtonSelected;
bool discard = false;
static string applyToAll = "";
public ErrorWindow()
{
InitializeComponent();
}
public void ClearApplyToAll()
{
applyToAll = "";
}
private void OkButton_MouseHover(object sender, EventArgs e)
{
OkButton.BackColor = Color.Aquamarine;
}
private void OkButton_MouseLeave(object sender, EventArgs e)
{
OkButton.BackColor = Control.DefaultBackColor;
}
private void ErrorWindow_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar.Equals(Keys.Escape))
{
DiscardButton.PerformClick();
}
}
public string IssueYearError(FileInfo file)
{
if (applyToAll.Contains("CSL::YEAR|"))
{
s_index = applyToAll.IndexOf("CSL::YEAR|") + 10;
e_index = applyToAll.IndexOf("***", s_index);
return applyToAll.Substring(s_index, e_index - s_index);
}
InstructionalLabel.Text = "Please provide a year below";
ErrorLabel.Text = "CSL was unable to parse out a year";
SelectionTextBox.Show();
OkButton.Enabled = false; //Will enable when key is pressed
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
{
if (ApplyToAllCheck.Checked)
applyToAll += "CSL::YEAR|" + SelectionTextBox.Text + "***";
ApplyToAllCheck.Checked = false;
return SelectionTextBox.Text;
}
}
public string IssueArtistError(FileInfo file)
{
if (applyToAll.Contains("CSL::ARTIST|"))
{
s_index = applyToAll.IndexOf("CSL::ARTIST|") + 12;
e_index = applyToAll.IndexOf("***", s_index);
return applyToAll.Substring(s_index, e_index - s_index);
}
InstructionalLabel.Text = "Please provide an artist below";
ErrorLabel.Text = "CSL was unable to parse out an artist";
SelectionTextBox.Show();
OkButton.Enabled = false; //Will enable when key is pressed
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
{
if (ApplyToAllCheck.Checked)
applyToAll += "CSL::ARTIST|" + SelectionTextBox.Text + "***";
ApplyToAllCheck.Checked = false;
return SelectionTextBox.Text;
}
}
public string IssueAlbumError(FileInfo file)
{
if (applyToAll.Contains("CSL::ALBUM|"))
{
s_index = applyToAll.IndexOf("CSL::ALBUM|") + 11;
e_index = applyToAll.IndexOf("***", s_index);
return applyToAll.Substring(s_index, e_index - s_index);
}
ErrorLabel.Text = "CSL was unable to parse out an album";
InstructionalLabel.Text = "Please provide an album below";
SelectionTextBox.Show();
OkButton.Enabled = false; //Will enable when key is pressed
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
{
if (ApplyToAllCheck.Checked)
applyToAll += "CSL::ALBUM|" + SelectionTextBox.Text + "***";
ApplyToAllCheck.Checked = false;
return SelectionTextBox.Text;
}
}
public string IssueReleaseFormatError(FileInfo file)
{
if (applyToAll.Contains("CSL::RELEASEF|"))
{
s_index = applyToAll.IndexOf("CSL::RELEASEF|") + 14;
e_index = applyToAll.IndexOf("***", s_index);
return applyToAll.Substring(s_index, e_index - s_index);
}
ErrorLabel.Text = "CSL was unable to parse out a release format";
InstructionalLabel.Text = "Please select a release format below";
ReleaseSelectionComboBox.Show();
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
{
if (ApplyToAllCheck.Checked)
applyToAll += "CSL::RELEASEF|" + ReleaseSelectionComboBox.Text + "***";
ApplyToAllCheck.Checked = false;
return ReleaseSelectionComboBox.Text;
}
}
public string IssuePhysicalFormatError(FileInfo file)
{
if (applyToAll.Contains("CSL::PHYSICALF|"))
{
s_index = applyToAll.IndexOf("CSL::PHYSICALF|") + 15;
e_index = applyToAll.IndexOf("***", s_index);
return applyToAll.Substring(s_index, e_index - s_index);
}
ErrorLabel.Text = "CSL was unable to parse out a physical format";
InstructionalLabel.Text = "Please select a physical format below";
PhysicalFormatSelectionComboBox.Show();
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
{
if (ApplyToAllCheck.Checked)
applyToAll += "CSL::PHYSICALF|" + PhysicalFormatSelectionComboBox.Text + "***";
ApplyToAllCheck.Checked = false;
return PhysicalFormatSelectionComboBox.Text;
}
}
public string IssueBitformatError(FileInfo file)
{
if (applyToAll.Contains("CSL::BITF|"))
{
s_index = applyToAll.IndexOf("CSL::BITF|") + 10;
e_index = applyToAll.IndexOf("***", s_index);
return applyToAll.Substring(s_index, e_index - s_index);
}
ErrorLabel.Text = "CSL was unable to parse out a bit format";
InstructionalLabel.Text = "Please select a bit format below";
BitformatSelectionComboBox.Show();
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
{
if (ApplyToAllCheck.Checked)
applyToAll += "CSL::BITF|" + BitformatSelectionComboBox.Text + "***";
ApplyToAllCheck.Checked = false;
return BitformatSelectionComboBox.Text;
}
}
public string IssueBitrateError(FileInfo file)
{
if (applyToAll.Contains("CSL::BITR|"))
{
s_index = applyToAll.IndexOf("CSL::BITR|") + 10;
e_index = applyToAll.IndexOf("***", s_index);
return applyToAll.Substring(s_index, e_index - s_index);
}
ErrorLabel.Text = "CSL was unable to parse out a bitrate";
InstructionalLabel.Text = "Please select a bitrate below";
BitrateSelectionComboBox.Show();
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
{
if (ApplyToAllCheck.Checked)
applyToAll += "CSL::BITR|" + BitrateSelectionComboBox.Text + "***";
return BitrateSelectionComboBox.Text;
}
}
public string IssueBirthError(FileInfo file)
{
if (applyToAll.Contains("CSL::BIRTH|"))
{
s_index = applyToAll.IndexOf("CSL::BIRTH|") + 11;
e_index = applyToAll.IndexOf("***", s_index);
return applyToAll.Substring(s_index, e_index - s_index);
}
ErrorLabel.Text = "CSL doesn't know which site this torrent came from";
InstructionalLabel.Text = "Please select a torrent site below";
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
BirthSelectionComboBox.Show();
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
{
if (ApplyToAllCheck.Checked)
applyToAll += "CSL::BIRTH|" + BirthSelectionComboBox.Text + "***";
return BirthSelectionComboBox.Text;
}
}
public string IssueIllegalCharactersError(FileInfo file, string destPath)
{
ErrorLabel.Text = "There's illegal characters in destination path: \"" + destPath + "\"";
InstructionalLabel.Text = "Please correct the path below";
SelectionTextBox.Show();
SelectionTextBox.Text = destPath;
OkButton.Enabled = false; //Will enable when key is pressed
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Activate();
this.ShowDialog();
return SelectionTextBox.Text;
}
public string IssueArtistWarning(FileInfo file, string artist)
{
InstructionalLabel.Text = "Validate and change if necessary";
ErrorLabel.Text = "MusicBrainz doesn't recognize this artist: \"" + artist + "\"";
SelectionTextBox.Show();
SelectionTextBox.Text = artist;
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Text = "[CSL] -- Warning";
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
return SelectionTextBox.Text;
}
public string IssueAlbumWarning(FileInfo file, string album)
{
InstructionalLabel.Text = "Validate and change if necessary";
ErrorLabel.Text = "MusicBrainz doesn't recognize this album: \"" + album + "\"";
SelectionTextBox.Show();
SelectionTextBox.Text = album;
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Text = "[CSL] -- Warning";
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
return SelectionTextBox.Text;
}
public string IssueYearWarning(FileInfo file, string year)
{
InstructionalLabel.Text = "Please provide the correct year";
ErrorLabel.Text = "This year is unrealistic: \"" + year + "\"";
SelectionTextBox.Show();
SelectionTextBox.Text = year;
FileNameLabel.Text = file.Name;
FilePathRichTextBox.Text = file.FullName;
this.Text = "[CSL] -- Warning";
this.Activate();
this.ShowDialog();
if (discard)
{
discard = false; //To ensure future Issues aren't discarded
return null;
}
else
return SelectionTextBox.Text;
}
public void IssueFileMoveWarning(FileInfo file, bool handled)
{
InstructionalLabel.Text = "The file could not be moved";
ErrorLabel.Text = "Please manually delete or move it";
FilePathRichTextBox.Text = file.FullName;
FileNameLabel.Text = file.Name;
this.Text = "[CSL] -- Warning";
this.Activate();
this.ShowDialog();
}
public void IssueGeneralWarning(string message, string submessage, string file)
{
InstructionalLabel.Text = message;
ErrorLabel.Text = submessage;
DiscardButton.Visible = false;
if (file != null)
{
FilePathRichTextBox.Text = file;
}
this.Text = "[CSL] -- Warning";
this.Activate();
this.ShowDialog();
}
public bool IssueCreateEmptyDirectoriesWarning(string message, string submessage)
{
InstructionalLabel.Text = message;
ErrorLabel.Text = submessage;
DiscardButton.Visible = false;
this.Text = "[CSL] -- Warning";
this.Activate();
this.ShowDialog();
return this.okButtonSelected;
}
private void DiscardButton_Click(object sender, EventArgs e)
{
discard = true;
//Reset all to hidden -- the issues choose which one to show
SelectionTextBox.Visible = false;
ReleaseSelectionComboBox.Visible = false;
BitformatSelectionComboBox.Visible = false;
BitrateSelectionComboBox.Visible = false;
BirthSelectionComboBox.Visible = false;
PhysicalFormatSelectionComboBox.Visible = false;
this.Hide();
}
private void OkButton_Click(object sender, EventArgs e)
{
DiscardButton.Visible = true;
//Reset all to hidden -- the issues choose which one to show
SelectionTextBox.Visible = false;
ReleaseSelectionComboBox.Visible = false;
BitformatSelectionComboBox.Visible = false;
BitrateSelectionComboBox.Visible = false;
BirthSelectionComboBox.Visible = false;
PhysicalFormatSelectionComboBox.Visible = false;
this.okButtonSelected = true;
this.Hide();
}
private void SelectionTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter || e.KeyData == Keys.Return)
OkButton.PerformClick();
else
OkButton.Enabled = true;
}
}
}