Skip to content

Commit 6cdcb21

Browse files
committed
Show appman download progress in taskbar, closes #641.
1 parent 69d9886 commit 6cdcb21

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

External/Tools/AppMan/AppMan.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<Compile Include="Properties\AssemblyInfo.cs" />
7575
<Compile Include="Utilities\ArgProcessor.cs" />
7676
<Compile Include="Utilities\PathHelper.cs" />
77+
<Compile Include="Utilities\TaskbarProgress.cs" />
7778
<Compile Include="Win32.cs" />
7879
<Compile Include="ZipLib\BZip2\BZip2.cs" />
7980
<Compile Include="ZipLib\BZip2\BZip2Constants.cs" />

External/Tools/AppMan/MainForm.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ private void EntriesDownloadCompleted(Object sender, AsyncCompletedEventArgs e)
10451045
this.PopulateListView();
10461046
}
10471047
else this.statusLabel.Text = this.localeData.ItemListDownloadFailed;
1048+
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress);
10481049
this.progressBar.Value = 0;
10491050
}
10501051
catch (Exception ex)
@@ -1105,6 +1106,7 @@ private void DownloadNextFromQueue()
11051106
this.isLoading = false;
11061107
this.progressBar.Value = 0;
11071108
this.cancelButton.Enabled = false;
1109+
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress);
11081110
this.statusLabel.Text = this.localeData.AllItemsCompleted;
11091111
this.NoneLinkLabelLinkClicked(null, null);
11101112
this.UpdateButtonLabels();
@@ -1138,6 +1140,7 @@ private void DownloadNextFromQueue()
11381140
private void DownloadProgressChanged(Object sender, DownloadProgressChangedEventArgs e)
11391141
{
11401142
this.progressBar.Value = e.ProgressPercentage;
1143+
TaskbarProgress.SetValue(this.Handle, e.ProgressPercentage, 100);
11411144
}
11421145

11431146
/// <summary>
@@ -1152,6 +1155,7 @@ private void DownloadFileCompleted(Object sender, AsyncCompletedEventArgs e)
11521155
this.isLoading = false;
11531156
this.cancelButton.Enabled = false;
11541157
this.statusLabel.Text = this.localeData.ItemListDownloadCancelled;
1158+
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress);
11551159
this.TryDeleteOldTempFiles();
11561160
this.progressBar.Value = 0;
11571161
this.UpdateButtonLabels();
@@ -1170,6 +1174,7 @@ private void DownloadFileCompleted(Object sender, AsyncCompletedEventArgs e)
11701174
this.isLoading = false;
11711175
this.progressBar.Value = 0;
11721176
this.cancelButton.Enabled = false;
1177+
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress);
11731178
this.statusLabel.Text = this.localeData.AllItemsCompleted;
11741179
this.NoneLinkLabelLinkClicked(null, null);
11751180
this.TryDeleteEntryDir(this.curEntry);
@@ -1195,6 +1200,7 @@ private void DownloadFileCompleted(Object sender, AsyncCompletedEventArgs e)
11951200
this.isLoading = false;
11961201
this.progressBar.Value = 0;
11971202
this.cancelButton.Enabled = false;
1203+
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress);
11981204
this.statusLabel.Text = this.localeData.AllItemsCompleted;
11991205
this.NoneLinkLabelLinkClicked(null, null);
12001206
this.TryDeleteEntryDir(this.curEntry);
@@ -1221,6 +1227,7 @@ private void ExtractFile(String file, String path)
12211227
this.bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.WorkerDoCompleted);
12221228
this.bgWorker.RunWorkerAsync(new BgArg(file, path));
12231229
this.statusLabel.Text = this.localeData.ExtractingFile + this.curFile;
1230+
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Indeterminate);
12241231
this.progressBar.Style = ProgressBarStyle.Marquee;
12251232
}
12261233
catch
@@ -1234,6 +1241,7 @@ private void ExtractFile(String file, String path)
12341241
this.isLoading = false;
12351242
this.progressBar.Value = 0;
12361243
this.cancelButton.Enabled = false;
1244+
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress);
12371245
this.statusLabel.Text = this.localeData.AllItemsCompleted;
12381246
this.NoneLinkLabelLinkClicked(null, null);
12391247
this.TryDeleteEntryDir(this.curEntry);
@@ -1272,6 +1280,7 @@ private void WorkerDoWork(Object sender, DoWorkEventArgs e)
12721280
this.isLoading = false;
12731281
this.progressBar.Value = 0;
12741282
this.cancelButton.Enabled = false;
1283+
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress);
12751284
this.statusLabel.Text = this.localeData.AllItemsCompleted;
12761285
this.NoneLinkLabelLinkClicked(null, null);
12771286
this.TryDeleteEntryDir(this.curEntry);
@@ -1288,7 +1297,9 @@ private void WorkerDoCompleted(Object sender, RunWorkerCompletedEventArgs e)
12881297
{
12891298
try
12901299
{
1300+
12911301
this.progressBar.Style = ProgressBarStyle.Continuous;
1302+
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Normal);
12921303
if (this.fileQueue.Count > 0)
12931304
{
12941305
this.curFile = this.fileQueue.Dequeue();
@@ -1335,6 +1346,7 @@ private void WorkerDoCompleted(Object sender, RunWorkerCompletedEventArgs e)
13351346
this.isLoading = false;
13361347
this.progressBar.Value = 0;
13371348
this.cancelButton.Enabled = false;
1349+
TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.NoProgress);
13381350
this.statusLabel.Text = this.localeData.AllItemsCompleted;
13391351
this.NoneLinkLabelLinkClicked(null, null);
13401352
this.UpdateButtonLabels();
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
// http://stackoverflow.com/questions/1295890/windows-7-progress-bar-in-taskbar-in-c
5+
6+
namespace AppMan.Utilities
7+
{
8+
public static class TaskbarProgress
9+
{
10+
public enum TaskbarStates
11+
{
12+
NoProgress = 0,
13+
Indeterminate = 0x1,
14+
Normal = 0x2,
15+
Error = 0x4,
16+
Paused = 0x8
17+
}
18+
19+
[ComImportAttribute()]
20+
[GuidAttribute("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
21+
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
22+
private interface ITaskbarList3
23+
{
24+
// ITaskbarList
25+
[PreserveSig]
26+
void HrInit();
27+
[PreserveSig]
28+
void AddTab(IntPtr hwnd);
29+
[PreserveSig]
30+
void DeleteTab(IntPtr hwnd);
31+
[PreserveSig]
32+
void ActivateTab(IntPtr hwnd);
33+
[PreserveSig]
34+
void SetActiveAlt(IntPtr hwnd);
35+
// ITaskbarList2
36+
[PreserveSig]
37+
void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen);
38+
// ITaskbarList3
39+
[PreserveSig]
40+
void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal);
41+
[PreserveSig]
42+
void SetProgressState(IntPtr hwnd, TaskbarStates state);
43+
}
44+
45+
[GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")]
46+
[ClassInterfaceAttribute(ClassInterfaceType.None)]
47+
[ComImportAttribute()]
48+
private class TaskbarInstance {}
49+
50+
private static ITaskbarList3 taskbarInstance = (ITaskbarList3)new TaskbarInstance();
51+
private static bool taskbarSupported = (Environment.OSVersion.Version >= new Version(6, 1)) && !Win32.IsRunningOnMono;
52+
53+
public static void SetState(IntPtr windowHandle, TaskbarStates taskbarState)
54+
{
55+
if (taskbarSupported) taskbarInstance.SetProgressState(windowHandle, taskbarState);
56+
}
57+
58+
public static void SetValue(IntPtr windowHandle, double progressValue, double progressMax)
59+
{
60+
if (taskbarSupported) taskbarInstance.SetProgressValue(windowHandle, (ulong)progressValue, (ulong)progressMax);
61+
}
62+
63+
}
64+
65+
}
1.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)