Skip to content

Commit

Permalink
initial fork
Browse files Browse the repository at this point in the history
- restore last url
- download complete/cancelled indicator
  • Loading branch information
setsumi committed Sep 4, 2018
1 parent 13c0853 commit e43a40d
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 183 deletions.
22 changes: 19 additions & 3 deletions src/syosetuDownloader/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -152,15 +168,15 @@ 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);
stackPanel1.Children.Remove(c.Separator);
});

_controls = (from c in _controls
where c.ProgressBar.Value != c.ProgressBar.Maximum
where (int)c.ProgressBar.Tag == 0
select c).ToList();
}
}
Expand Down
68 changes: 38 additions & 30 deletions src/syosetuDownloader/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions src/syosetuDownloader/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="syosetuDownloader.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="Link" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
28 changes: 28 additions & 0 deletions src/syosetuDownloader/Settings.cs
Original file line number Diff line number Diff line change
@@ -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.
}
}
}
14 changes: 12 additions & 2 deletions src/syosetuDownloader/Syousetsu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
15 changes: 15 additions & 0 deletions src/syosetuDownloader/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="syosetuDownloader.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<syosetuDownloader.Properties.Settings>
<setting name="Link" serializeAs="String">
<value />
</setting>
</syosetuDownloader.Properties.Settings>
</userSettings>
</configuration>
Loading

0 comments on commit e43a40d

Please sign in to comment.