>From 6f1f09594cebff4382a890cf33621f672e5d4534 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81ngel=20Gonz=C3=A1lez?=
Date: Wed, 23 Sep 2015 00:53:49 +0200
Subject: [PATCH] Progress bar on Windows console title
Adaptation of patch https://eternallybored.org/misc/wget/src/taskbar-progress.patch
from C++ to C
---
configure.ac | 2 +-
src/Makefile.am | 5 ++-
src/mswindows.c | 3 ++
src/tbprogress.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/tbprogress.h | 6 +++
5 files changed, 130 insertions(+), 3 deletions(-)
create mode 100644 src/tbprogress.c
create mode 100644 src/tbprogress.h
diff --git a/configure.ac b/configure.ac
index eb128f3..278bd64 100644
--- a/configure.ac
+++ b/configure.ac
@@ -298,7 +298,7 @@ WGET_NSL_SOCKET
dnl Deal with specific hosts
case $host_os in
*mingw32* )
- LIBS+=' -lws2_32'
+ LIBS+=' -lws2_32 -lole32'
AC_LIBOBJ([mswindows])
;;
esac
diff --git a/src/Makefile.am b/src/Makefile.am
index 050f58e..f564e00 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,13 +51,14 @@ wget_SOURCES = connect.c convert.c cookies.c ftp.c \
ftp-basic.c ftp-ls.c hash.c host.c hsts.c html-parse.c html-url.c \
http.c init.c log.c main.c netrc.c progress.c ptimer.c \
recur.c res.c retr.c spider.c url.c warc.c \
- utils.c exits.c build_info.c $(IRI_OBJ) $(METALINK_OBJ) \
+ utils.c exits.c tbprogress.c build_info.c \
+ $(IRI_OBJ) $(METALINK_OBJ) \
css-url.h css-tokens.h connect.h convert.h cookies.h \
ftp.h hash.h host.h hsts.h html-parse.h html-url.h \
http.h http-ntlm.h init.h log.h mswindows.h netrc.h \
options.h progress.h ptimer.h recur.h res.h retr.h \
spider.h ssl.h sysdep.h url.h warc.h utils.h wget.h iri.h \
- exits.h version.h metalink.h
+ exits.h version.h metalink.h tbprogress.h
nodist_wget_SOURCES = version.c
EXTRA_wget_SOURCES = iri.c
LDADD = $(LIBOBJS) ../lib/libgnu.a
diff --git a/src/mswindows.c b/src/mswindows.c
index 1a43b51..a15f6b8 100644
--- a/src/mswindows.c
+++ b/src/mswindows.c
@@ -43,6 +43,7 @@ as that of the covered work. */
#include "utils.h"
#include "url.h"
#include "exits.h"
+#include "tbprogress.h"
#ifndef ES_SYSTEM_REQUIRED
#define ES_SYSTEM_REQUIRED 0x00000001
@@ -89,6 +90,7 @@ windows_main (char **exec_name)
static void
ws_cleanup (void)
{
+ SetTBProgress(-1);
xfree (exec_name);
WSACleanup ();
}
@@ -402,6 +404,7 @@ ws_percenttitle (double percentage_float)
sprintf (title_buf, "Wget [%d%%] %s", percentage, curr_url);
SetConsoleTitle (title_buf);
+ SetTBProgress((int)(percentage_float * 10.0));
}
/* Returns a pointer to the fully qualified name of the directory that
diff --git a/src/tbprogress.c b/src/tbprogress.c
new file mode 100644
index 0000000..5465b98
--- /dev/null
+++ b/src/tbprogress.c
@@ -0,0 +1,117 @@
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0500
+#endif
+
+#include
+#include
+#include
+#include
+#include
+#include "tbprogress.h"
+
+const CLSID CLSID_TaskbarList = {0x56FDF344,0xFD6D,0x11d0,{0x95,0x8A,0x00,0x60,0x97,0xC9,0xA0,0x90}};
+const IID IID_ITaskbarList1 = {0x56FDF342,0xFD6D,0x11d0,{0x95,0x8A,0x00,0x60,0x97,0xC9,0xA0,0x90}};
+const IID IID_ITaskbarList3 = {0xea1afb91,0x9e28,0x4b86,{0x90,0xe9,0x9e,0x9f,0x8a,0x5e,0xef,0xaf}};
+
+#ifndef __ITaskbarList3_INTERFACE_DEFINED__
+typedef enum {
+ TBPF_NOPROGRESS = 0, // Normal state / no progress bar
+ TBPF_INDETERMINATE = 1, // Marquee style progress bar
+ TBPF_NORMAL = 2, // Standard progress bar
+ TBPF_ERROR = 4, // Red taskbar button to indicate an error occurred
+ TBPF_PAUSED = 8 // Yellow taskbar button to indicate user attention
+} TBPFLAG;
+
+typedef void* LPTHUMBBUTTON;//dummy typedef!
+typedef enum {TBATF_DUMMY} TBATFLAG;
+
+#define INTERFACE ITaskbarList3
+DECLARE_INTERFACE_(ITaskbarList3,IUnknown)
+{
+ STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
+ STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+ STDMETHOD_(ULONG,Release)(THIS) PURE;
+
+ //ITaskbarList(1)
+ STDMETHOD(HrInit)(THIS) PURE;
+ STDMETHOD(AddTab)(THIS, HWND hwnd) PURE;
+ STDMETHOD(DeleteTab)(THIS, HWND hwnd) PURE;
+ STDMETHOD(ActivateTab)(THIS, HWND hwnd) PURE;
+ STDMETHOD(SetActiveAlt)(THIS, HWND hwnd) PURE;
+ //ITaskbarList2
+ STDMETHOD(MarkFullscreenWindow)(THIS, HWND hwnd, BOOL fFullscreen) PURE;
+ //ITaskbarList3
+ STDMETHOD(SetProgressValue)(THIS, HWND hwnd, ULONGLONG ullCompleted, ULONGLONG ullTotal) PURE;
+ STDMETHOD(SetProgressState)(THIS, HWND hwnd, TBPFLAG tbpFlags) PURE;
+ STDMETHOD(RegisterTab)(THIS, HWND hwndTab, HWND hwndMDI) PURE;
+ STDMETHOD(UnregisterTab)(THIS, HWND hwndTab) PURE;
+ STDMETHOD(SetTabOrder)(THIS, HWND hwndTab,HWND hwndInsertBefore) PURE;
+ STDMETHOD(SetTabActive)(THIS, HWND hwndTab,HWND hwndMDI, TBATFLAG tbatFlags) PURE;
+ STDMETHOD(ThumbBarAddButtons)(THIS, HWND hwnd,UINT cButtons, LPTHUMBBUTTON pButton) PURE;
+ STDMETHOD(ThumbBarUpdateButtons)(THIS, HWND hwnd,UINT cButtons, LPTHUMBBUTTON pButton) PURE;
+ STDMETHOD(ThumbBarSetImageList)(THIS, HWND hwnd, HIMAGELIST himl) PURE;
+ STDMETHOD(SetOverlayIcon)(THIS, HWND hwnd, HICON hIcon, LPCWSTR pszDescription) PURE;
+ STDMETHOD(SetThumbnailTooltip)(THIS, HWND hwnd, LPCWSTR pszTip);
+ STDMETHOD(SetThumbnailClip)(THIS, HWND hwnd, RECT *prcClip);
+
+ STDMETHOD(QueryContextMenu)(THIS_ HMENU,UINT,UINT,UINT,UINT) PURE;
+ STDMETHOD(InvokeCommand)(THIS_ LPCMINVOKECOMMANDINFO) PURE;
+ STDMETHOD(GetCommandString)(THIS_ UINT,UINT,PUINT,LPSTR,UINT) PURE;
+ STDMETHOD(HandleMenuMsg)(THIS_ UINT,WPARAM,LPARAM) PURE;
+};
+#undef INTERFACE
+#endif
+
+void SetTBProgress(int permille)
+{
+
+ static ITaskbarList3 *g_pTL = NULL;
+ static HWND g_hwndConsole = NULL;
+ static int TB_status = 0;
+
+ if (g_pTL == NULL && permille < 0) return;
+ if (TB_status != 0) return;
+ if (permille > 1000) permille = 1000;
+
+ if (g_pTL == NULL) {
+ HRESULT hr;
+
+ g_hwndConsole = GetConsoleWindow();
+ if (g_hwndConsole == NULL) {
+ TB_status = -1;
+ return;
+ }
+
+ hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+ if (!SUCCEEDED(hr)) {
+ CoUninitialize();
+ TB_status = -1;
+ return;
+ }
+
+ hr = CoCreateInstance(&CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskbarList3, (void**)&g_pTL);
+ if (!SUCCEEDED(hr) || g_pTL == NULL) {
+ CoUninitialize();
+ TB_status = -1;
+ return;
+ }
+
+ hr = g_pTL->lpVtbl->HrInit(g_pTL);
+ if (!SUCCEEDED(hr)) {
+ TB_status = -1;
+ g_pTL->lpVtbl->Release(g_pTL);
+ g_pTL = NULL;
+ CoUninitialize();
+ return;
+ }
+ }
+
+ if (permille >= 0) {
+ g_pTL->lpVtbl->SetProgressValue(g_pTL, g_hwndConsole, permille, 1000);
+ } else {
+ g_pTL->lpVtbl->SetProgressState(g_pTL, g_hwndConsole, TBPF_NOPROGRESS);
+ g_pTL->lpVtbl->Release(g_pTL);
+ g_pTL = NULL;
+ CoUninitialize();
+ }
+}
diff --git a/src/tbprogress.h b/src/tbprogress.h
new file mode 100644
index 0000000..a59ad6d
--- /dev/null
+++ b/src/tbprogress.h
@@ -0,0 +1,6 @@
+#ifndef tbprogress_h
+#define tbprogress_h
+
+extern void SetTBProgress(int permille); // 0 - 1000
+
+#endif
--
2.5.1