Skip to content

Commit

Permalink
download progress details
Browse files Browse the repository at this point in the history
  • Loading branch information
setsumi committed May 30, 2023
1 parent f4cd937 commit 72984d7
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions src/syosetuDownloader/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public partial class MainWindow : Window
Shell32.Shell _shell;
string _exe_dir;
string _dl_dir;
readonly string _version = "2.4.0 plus 17";
readonly string _version = "2.4.0 plus 18";

public Util.GridViewTool.SortInfo sortInfo = new Util.GridViewTool.SortInfo();

Expand Down Expand Up @@ -81,11 +81,11 @@ void PopulateNovelsURLs(ComboBox cb)
string[] fileEntries = Directory.GetFiles(_dl_dir);
foreach (string file in fileEntries)
{
if (System.IO.Path.GetExtension(file).Equals(".url", StringComparison.OrdinalIgnoreCase))
if (Path.GetExtension(file).Equals(".url", StringComparison.OrdinalIgnoreCase))
{
//Get the shortcut's file.
Shell32.FolderItem folder_item =
shortcut_folder.Items().Item(System.IO.Path.GetFileName(file));
shortcut_folder.Items().Item(Path.GetFileName(file));
// Get shortcut's information.
Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)folder_item.GetLink;
items.Add(new NovelDrop() { Novel = folder_item.Name, Link = lnk.Path });
Expand Down Expand Up @@ -141,6 +141,19 @@ public void GetFilenameFormat()
}
}

private class ProgressMultiValueConverter : System.Windows.Data.IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((double)values[0] == 0) values[0] = "";
return $"{values[0]} {values[1]}";
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
private static Action EmptyDelegate = delegate () { };
private void btnDownload_Click(object sender, RoutedEventArgs e)
{
Expand All @@ -152,9 +165,22 @@ private void btnDownload_Click(object sender, RoutedEventArgs e)
Label lb = new Label();
lb.Content = "Preparing...";
lb.Background = Brushes.Gold;

ProgressBar pb = new ProgressBar();
pb.Height = 10;
pb.Height = 15;
pb.Tag = 0;

TextBlock tb = new TextBlock();
var binding = new System.Windows.Data.MultiBinding();
binding.Bindings.Add(new System.Windows.Data.Binding("Value") { Source = pb });
binding.Bindings.Add(new System.Windows.Data.Binding("ToolTip") { Source = pb });
binding.Converter = new ProgressMultiValueConverter();
tb.SetBinding(TextBlock.TextProperty, binding);
tb.HorizontalAlignment = HorizontalAlignment.Center;
tb.VerticalAlignment = VerticalAlignment.Center;
tb.Margin = new Thickness(0, -pb.Height, 0, 0);
tb.IsHitTestVisible = false;

Separator s = new Separator();
s.Height = 5;

Expand All @@ -163,6 +189,7 @@ private void btnDownload_Click(object sender, RoutedEventArgs e)

stackPanel1.Children.Add(lb);
stackPanel1.Children.Add(pb);
stackPanel1.Children.Add(tb);
stackPanel1.Children.Add(s);
scrollViewer1.ScrollToLeftEnd();
scrollViewer1.ScrollToBottom();
Expand Down Expand Up @@ -248,7 +275,7 @@ private void Download()
};
lb.MouseDown += (snt, evt) =>
{
_shell.Explore(System.IO.Path.Combine(_dl_dir, sc.SeriesTitle));
_shell.Explore(Path.Combine(_dl_dir, sc.SeriesTitle));
};

scrollViewer1.ScrollToLeftEnd();
Expand Down Expand Up @@ -345,7 +372,7 @@ private void cbSite_PreviewKeyDown(object sender, KeyEventArgs e)

public void LoadConfig()
{
string file = _exe_dir + System.IO.Path.DirectorySeparatorChar + "config.xml";
string file = _exe_dir + Path.DirectorySeparatorChar + "config.xml";
if (!File.Exists(file)) return;

XElement fileElem = XElement.Load(file);
Expand All @@ -365,7 +392,7 @@ public void LoadConfig()

public void SaveConfig()
{
string file = _exe_dir + System.IO.Path.DirectorySeparatorChar + "config.xml";
string file = _exe_dir + Path.DirectorySeparatorChar + "config.xml";

XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
Expand Down

0 comments on commit 72984d7

Please sign in to comment.