diff --git a/src/syosetuDownloader/MainWindow.xaml.cs b/src/syosetuDownloader/MainWindow.xaml.cs index c491a11..f3800da 100644 --- a/src/syosetuDownloader/MainWindow.xaml.cs +++ b/src/syosetuDownloader/MainWindow.xaml.cs @@ -32,6 +32,21 @@ public partial class MainWindow : Window public MainWindow() { InitializeComponent(); + + this.Closed += new EventHandler(MainWindow_Closed); + + txtLink.Text = Properties.Settings.Default.Link; + txtLink.SelectAll(); + txtLink.Focus(); + } + + void MainWindow_Closed(object sender, EventArgs e) + { + if (Syousetsu.Methods.IsValidLink(txtLink.Text)) + { + Properties.Settings.Default.Link = txtLink.Text; + Properties.Settings.Default.Save(); + } } public void GetFilenameFormat() @@ -82,6 +97,7 @@ private void btnDownload_Click(object sender, RoutedEventArgs e) pb.Maximum = (_end == String.Empty) ? Syousetsu.Methods.GetTotalChapters(toc) : Convert.ToDouble(_end); pb.ToolTip = "Click to stop download"; pb.Height = 10; + pb.Tag = 0; Separator s = new Separator(); s.Height = 5; @@ -103,7 +119,7 @@ private void btnDownload_Click(object sender, RoutedEventArgs e) Syousetsu.Create.GenerateTableOfContents(sc, toc); } - System.Threading.CancellationTokenSource ct = Syousetsu.Methods.AddDownloadJob(sc, pb); + System.Threading.CancellationTokenSource ct = Syousetsu.Methods.AddDownloadJob(sc, pb, lb); pb.MouseDown += (snt, evt) => { ct.Cancel(); @@ -152,7 +168,7 @@ private void rbHtml_Checked(object sender, RoutedEventArgs e) private void btnDelete_Click(object sender, RoutedEventArgs e) { - _controls.Where((c) => c.ProgressBar.Value == c.ProgressBar.Maximum).ToList().ForEach((c) => + _controls.Where((c) => (int)c.ProgressBar.Tag != 0).ToList().ForEach((c) => { stackPanel1.Children.Remove(c.Label); stackPanel1.Children.Remove(c.ProgressBar); @@ -160,7 +176,7 @@ private void btnDelete_Click(object sender, RoutedEventArgs e) }); _controls = (from c in _controls - where c.ProgressBar.Value != c.ProgressBar.Maximum + where (int)c.ProgressBar.Tag == 0 select c).ToList(); } } diff --git a/src/syosetuDownloader/Properties/Settings.Designer.cs b/src/syosetuDownloader/Properties/Settings.Designer.cs index 68c44c8..5e0bb1e 100644 --- a/src/syosetuDownloader/Properties/Settings.Designer.cs +++ b/src/syosetuDownloader/Properties/Settings.Designer.cs @@ -1,30 +1,38 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.34209 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace syosetuDownloader.Properties -{ - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.1022 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace syosetuDownloader.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string Link { + get { + return ((string)(this["Link"])); + } + set { + this["Link"] = value; + } + } + } +} diff --git a/src/syosetuDownloader/Properties/Settings.settings b/src/syosetuDownloader/Properties/Settings.settings index 033d7a5..a0f15ed 100644 --- a/src/syosetuDownloader/Properties/Settings.settings +++ b/src/syosetuDownloader/Properties/Settings.settings @@ -1,7 +1,9 @@ - - - - - - + + + + + + + + \ No newline at end of file diff --git a/src/syosetuDownloader/Settings.cs b/src/syosetuDownloader/Settings.cs new file mode 100644 index 0000000..4d54b34 --- /dev/null +++ b/src/syosetuDownloader/Settings.cs @@ -0,0 +1,28 @@ +namespace syosetuDownloader.Properties { + + + // This class allows you to handle specific events on the settings class: + // The SettingChanging event is raised before a setting's value is changed. + // The PropertyChanged event is raised after a setting's value is changed. + // The SettingsLoaded event is raised after the setting values are loaded. + // The SettingsSaving event is raised before the setting values are saved. + internal sealed partial class Settings { + + public Settings() { + // // To add event handlers for saving and changing settings, uncomment the lines below: + // + // this.SettingChanging += this.SettingChangingEventHandler; + // + // this.SettingsSaving += this.SettingsSavingEventHandler; + // + } + + private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) { + // Add code to handle the SettingChangingEvent event here. + } + + private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) { + // Add code to handle the SettingsSaving event here. + } + } +} diff --git a/src/syosetuDownloader/Syousetsu.cs b/src/syosetuDownloader/Syousetsu.cs index 6b5909d..c436648 100644 --- a/src/syosetuDownloader/Syousetsu.cs +++ b/src/syosetuDownloader/Syousetsu.cs @@ -14,7 +14,7 @@ namespace Syousetsu { public class Methods { - public static CancellationTokenSource AddDownloadJob(Syousetsu.Constants details, ProgressBar pb) + public static CancellationTokenSource AddDownloadJob(Syousetsu.Constants details, ProgressBar pb, Label lb) { int max = Convert.ToInt32(pb.Maximum); @@ -42,6 +42,7 @@ public static CancellationTokenSource AddDownloadJob(Syousetsu.Constants details CancellationTokenSource ct = new CancellationTokenSource(); Task.Factory.StartNew(() => { + bool cancelled = false; for (int ctr = i; ctr <= max; ctr++) { string subLink = details.Link + ctr; @@ -57,13 +58,22 @@ public static CancellationTokenSource AddDownloadJob(Syousetsu.Constants details if (ct.IsCancellationRequested) { // another thread decided to cancel + cancelled = true; break; } } pb.Dispatcher.Invoke((Action)(() => { - pb.Value = max; pb.ToolTip = null; + pb.Tag = 1; + + if (cancelled) + lb.Content = lb.Content + " download cancelled"; + else + { + pb.Value = max; + lb.Content = lb.Content + " finished"; + } })); }, ct.Token); diff --git a/src/syosetuDownloader/app.config b/src/syosetuDownloader/app.config new file mode 100644 index 0000000..1f294c6 --- /dev/null +++ b/src/syosetuDownloader/app.config @@ -0,0 +1,15 @@ + + + + +
+ + + + + + + + + + \ No newline at end of file diff --git a/src/syosetuDownloader/syosetuDownloader.csproj b/src/syosetuDownloader/syosetuDownloader.csproj index 54bfa10..8b8f626 100644 --- a/src/syosetuDownloader/syosetuDownloader.csproj +++ b/src/syosetuDownloader/syosetuDownloader.csproj @@ -1,149 +1,156 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {3D9382A0-5AC7-4D1C-B108-E5DF390151DD} - WinExe - Properties - syosetuDownloader - syosetuDownloader - v4.0 - Client - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - x86 - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - x86 - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\DLL\CommandLine.dll - - - .\HtmlAgilityPack.dll - - - - - - - - - - - - 4.0 - - - - - - - - MSBuild:Compile - Designer - - - - - MSBuild:Compile - Designer - - - App.xaml - Code - - - MainWindow.xaml - Code - - - - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - Always - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - - - - False - Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 - false - - - False - Windows Installer 4.5 - true - - - + + + + Debug + x86 + 8.0.30703 + 2.0 + {3D9382A0-5AC7-4D1C-B108-E5DF390151DD} + WinExe + Properties + syosetuDownloader + syosetuDownloader + v4.0 + Client + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + false + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\DLL\CommandLine.dll + + + .\HtmlAgilityPack.dll + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + Always + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + False + Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 4.5 + true + + + + --> \ No newline at end of file