Skip to content

Instantly share code, notes, and snippets.

@pgp
Created January 14, 2020 17:20
Show Gist options
  • Save pgp/3232e47afa67ea9a9cd72b4e7acc78bf to your computer and use it in GitHub Desktop.
Save pgp/3232e47afa67ea9a9cd72b4e7acc78bf to your computer and use it in GitHub Desktop.
#ifndef __RH_PROGRESS_HOOK__
#define __RH_PROGRESS_HOOK__
#include "unifiedlogging.h"
#ifdef _WIN32
#include <shobjidl.h>
#endif
class ProgressHook {
public:
const uint64_t totalSize;
uint64_t currentSize;
explicit ProgressHook(uint64_t totalSize_) : totalSize(totalSize_), currentSize(0) {}
virtual void publish(uint64_t current) = 0;
virtual void publishDelta(uint64_t delta) = 0;
};
class ConsoleProgressHook : public ProgressHook {
public:
explicit ConsoleProgressHook(uint64_t totalSize_) : ProgressHook(totalSize_) {
PRINTUNIFIED("###Total size: %" PRIu64 "\n",totalSize_);
}
void publish(uint64_t current) override {
currentSize = current;
PRINTUNIFIED("###Progress: %" PRIu64 "\n",currentSize);
}
void publishDelta(uint64_t delta) override {
currentSize += delta;
PRINTUNIFIED("###Progress: %" PRIu64 "\n",currentSize);
}
};
#ifdef _WIN32
class MfcProgressHook : public ProgressHook {
public:
ITaskbarList3 *g_pTaskbarList;
HWND hWnd;
MfcProgressHook(uint64_t totalSize_) : ProgressHook(totalSize_) {
PRINTUNIFIED("Total size: %" PRIu64 "\n",totalSize_);
// TODO CoCreateInstance (here or externally?)
}
void publish(uint64_t current) override {
currentSize = current;
PRINTUNIFIED("Progress: %" PRIu64 "\n",currentSize);
g_pTaskbarList->SetProgressValue(hWnd, currentSize, totalSize);
}
void publishDelta(uint64_t delta) override {
currentSize += delta;
PRINTUNIFIED("Progress: %" PRIu64 "\n",currentSize);
g_pTaskbarList->SetProgressValue(hWnd, currentSize, totalSize);
}
};
#endif
#endif /* __RH_PROGRESS_HOOK__ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment