diff --git a/DEIFR/Form1.cs b/DEIFR/Form1.cs index ded0b55..e540c8e 100644 --- a/DEIFR/Form1.cs +++ b/DEIFR/Form1.cs @@ -19,6 +19,16 @@ namespace DEIFR checkBox1.Checked = Program.KeepImages; Program.Progress = progressBar1; Program.AllProgress = progressBar2; + this.FormClosing += Form1_FormClosing; + } + + private void Form1_FormClosing(object sender, FormClosingEventArgs e) + { + if (!ImageDownloader.Stop) + { + ImageDownloader.Stop = true; + e.Cancel = true; + } } private void checkBox1_CheckedChanged(object sender, EventArgs e) diff --git a/DEIFR/ImageDownloader.cs b/DEIFR/ImageDownloader.cs index a7ba20d..f0e8df6 100644 --- a/DEIFR/ImageDownloader.cs +++ b/DEIFR/ImageDownloader.cs @@ -96,6 +96,14 @@ namespace DEIFR private static bool Next() { + if (Stop) + { + Program.Form.Invoke(new Action(delegate + { + Program.Form.Close(); + })); + return true; + } if (enumerator.MoveNext()) { JToken result = enumerator.Current; @@ -113,7 +121,6 @@ namespace DEIFR else return false; //Otherwise we don't know what is there } - //Image.FromStream(respstr).Save(i + "." + s.Split('/').Last().Split('.')[1]); string path = id + "." + s.Split('/').Last().Split('.')[1].Split('?')[0]; //?: FB and similar sites using (WebClient client = new WebClient()) { @@ -140,5 +147,7 @@ namespace DEIFR } return true; } + + public static bool Stop { get; set; } } } diff --git a/DEIFR/Program.cs b/DEIFR/Program.cs index be2fe6e..2f78dea 100644 --- a/DEIFR/Program.cs +++ b/DEIFR/Program.cs @@ -29,6 +29,7 @@ namespace DEIFR return; } AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + if (File.Exists("DEIFRSettings.ini")) { string[] ss = File.ReadAllLines("DEIFRSettings.ini");