Skip to content

Commit

Permalink
taskbar progress
Browse files Browse the repository at this point in the history
  • Loading branch information
setsumi committed Apr 30, 2023
1 parent 4b400cb commit 22e3a3b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
68 changes: 34 additions & 34 deletions src/syosetuDownloader/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using CommandLine;
using HtmlAgilityPack;
using System.Security.Permissions;

namespace syosetuDownloader
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{

[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
protected override void OnStartup(StartupEventArgs e)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

base.OnStartup(e);
}

static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
MessageBox.Show(e.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using CommandLine;
using HtmlAgilityPack;
using System.Security.Permissions;

namespace syosetuDownloader
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{

[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
protected override void OnStartup(StartupEventArgs e)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

base.OnStartup(e);
}

static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
MessageBox.Show(e.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
2 changes: 1 addition & 1 deletion src/syosetuDownloader/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public partial class MainWindow : Window
Shell32.Shell _shell;
string _exe_dir;
string _dl_dir;
readonly string _version = "2.4.0 plus 13";
readonly string _version = "2.4.0 plus 14";

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

Expand Down
7 changes: 5 additions & 2 deletions src/syosetuDownloaderCore/Syousetsu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
using HtmlAgilityPack;
using System.Net;
using System.IO;
using System.Windows.Media;

namespace Syousetsu
{
public class Methods
{
public static CancellationTokenSource AddDownloadJob(Syousetsu.Constants details, ProgressBar pb, Label lb)
{
var taskbar = Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance;
taskbar.SetProgressState(Microsoft.WindowsAPICodePack.Taskbar.TaskbarProgressBarState.Normal);

int max = Convert.ToInt32(pb.Maximum);

int i = 0;
Expand Down Expand Up @@ -58,7 +60,7 @@ public static CancellationTokenSource AddDownloadJob(Syousetsu.Constants details
details.LastDownloaded = ctr;
History.SaveNovel(details);

pb.Dispatcher.Invoke((Action)(() => { pb.Value = ctr; }));
pb.Dispatcher.Invoke((Action)(() => { pb.Value = ctr; taskbar.SetProgressValue(ctr, max); }));
if (upTo != -1 && ctr > upTo)//stop loop if the specifed range is reached
{
break;
Expand All @@ -73,6 +75,7 @@ public static CancellationTokenSource AddDownloadJob(Syousetsu.Constants details
}
pb.Dispatcher.Invoke((Action)(() =>
{
taskbar.SetProgressState(Microsoft.WindowsAPICodePack.Taskbar.TaskbarProgressBarState.NoProgress);
//pb.Value = max;
pb.ToolTip = null;
pb.Tag = 1;
Expand Down
3 changes: 3 additions & 0 deletions src/syosetuDownloaderCore/syosetuDownloaderCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<HintPath>..\packages\HtmlAgilityPack.1.11.29\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.WindowsAPICodePack.Shell">
<HintPath>..\packages\WindowsAPICodePack-Shell.1.1.1\lib\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
Expand Down

0 comments on commit 22e3a3b

Please sign in to comment.