From 6fd1b4f7212c80b3812ebfd5347a9e54fade671b Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 26 Dec 2014 00:46:39 +0100 Subject: [PATCH] Don't try to initialize ITaskbarList3 on systems prior to Windows 7. --- include/MUtils/OSSupport.h | 31 +++++++++++++++---------------- src/OSSupport_Win32.cpp | 31 +++++++++++++++++++++++++++++++ src/Taskbar7_Win32.cpp | 24 +++++++++++++++++++----- 3 files changed, 65 insertions(+), 21 deletions(-) diff --git a/include/MUtils/OSSupport.h b/include/MUtils/OSSupport.h index 7db9988..9dbb359 100644 --- a/include/MUtils/OSSupport.h +++ b/include/MUtils/OSSupport.h @@ -52,28 +52,27 @@ namespace MUtils unsigned int versionMinor; bool overrideFlag; - //comparision operators - inline bool operator== (const _os_info_t &rhs) const { return (type == rhs.type) && (versionMajor == rhs.versionMajor) && ((versionMinor == rhs.versionMinor)); } - inline bool operator!= (const _os_info_t &rhs) const { return (type != rhs.type) || (versionMajor != rhs.versionMajor) || ((versionMinor != rhs.versionMinor)); } - inline bool operator> (const _os_info_t &rhs) const { return (type == rhs.type) && ((versionMajor > rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor > rhs.versionMinor))); } - inline bool operator>= (const _os_info_t &rhs) const { return (type == rhs.type) && ((versionMajor > rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor >= rhs.versionMinor))); } - inline bool operator< (const _os_info_t &rhs) const { return (type == rhs.type) && ((versionMajor < rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor < rhs.versionMinor))); } - inline bool operator<= (const _os_info_t &rhs) const { return (type == rhs.type) && ((versionMajor < rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor <= rhs.versionMinor))); } + MUTILS_API bool operator== (const _os_info_t &rhs) const; + MUTILS_API bool operator!= (const _os_info_t &rhs) const; + MUTILS_API bool operator> (const _os_info_t &rhs) const; + MUTILS_API bool operator>= (const _os_info_t &rhs) const; + MUTILS_API bool operator< (const _os_info_t &rhs) const; + MUTILS_API bool operator<= (const _os_info_t &rhs) const; } os_version_t; //Known Windows NT versions - static const os_version_t WINDOWS_WIN2K = { OS_WINDOWS, 5, 0 }; // 2000 - static const os_version_t WINDOWS_WINXP = { OS_WINDOWS, 5, 1 }; // XP - static const os_version_t WINDOWS_XPX64 = { OS_WINDOWS, 5, 2 }; // XP_x64 - static const os_version_t WINDOWS_VISTA = { OS_WINDOWS, 6, 0 }; // Vista - static const os_version_t WINDOWS_WIN70 = { OS_WINDOWS, 6, 1 }; // 7 - static const os_version_t WINDOWS_WIN80 = { OS_WINDOWS, 6, 2 }; // 8 - static const os_version_t WINDOWS_WIN81 = { OS_WINDOWS, 6, 3 }; // 8.1 - static const os_version_t WINDOWS_WN100 = { OS_WINDOWS, 6, 4 }; // 10 + MUTILS_API extern const os_version_t WINDOWS_WIN2K; // 2000 + MUTILS_API extern const os_version_t WINDOWS_WINXP; // XP + MUTILS_API extern const os_version_t WINDOWS_XPX64; // XP_x64 + MUTILS_API extern const os_version_t WINDOWS_VISTA; // Vista + MUTILS_API extern const os_version_t WINDOWS_WIN70; // 7 + MUTILS_API extern const os_version_t WINDOWS_WIN80; // 8 + MUTILS_API extern const os_version_t WINDOWS_WIN81; // 8.1 + MUTILS_API extern const os_version_t WINDOWS_WN100; // 10 //Unknown OS - static const os_version_t UNKNOWN_OPSYS = { OS_UNKNOWN, 0, 0 }; // N/A + MUTILS_API extern const os_version_t UNKNOWN_OPSYS; // N/A } //Known Folders IDs diff --git a/src/OSSupport_Win32.cpp b/src/OSSupport_Win32.cpp index f47590d..d67ba16 100644 --- a/src/OSSupport_Win32.cpp +++ b/src/OSSupport_Win32.cpp @@ -140,6 +140,37 @@ g_os_version_lut[] = { MUtils::OS::Version::UNKNOWN_OPSYS, "N/A" } }; +//OS version data dtructures +namespace MUtils +{ + namespace OS + { + namespace Version + { + //Comparision operators for os_version_t + bool os_version_t::operator== (const os_version_t &rhs) const { return (type == rhs.type) && (versionMajor == rhs.versionMajor) && ((versionMinor == rhs.versionMinor)); } + bool os_version_t::operator!= (const os_version_t &rhs) const { return (type != rhs.type) || (versionMajor != rhs.versionMajor) || ((versionMinor != rhs.versionMinor)); } + bool os_version_t::operator> (const os_version_t &rhs) const { return (type == rhs.type) && ((versionMajor > rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor > rhs.versionMinor))); } + bool os_version_t::operator>= (const os_version_t &rhs) const { return (type == rhs.type) && ((versionMajor > rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor >= rhs.versionMinor))); } + bool os_version_t::operator< (const os_version_t &rhs) const { return (type == rhs.type) && ((versionMajor < rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor < rhs.versionMinor))); } + bool os_version_t::operator<= (const os_version_t &rhs) const { return (type == rhs.type) && ((versionMajor < rhs.versionMajor) || ((versionMajor == rhs.versionMajor) && (versionMinor <= rhs.versionMinor))); } + + //Known Windows NT versions + const os_version_t WINDOWS_WIN2K = { OS_WINDOWS, 5, 0 }; // 2000 + const os_version_t WINDOWS_WINXP = { OS_WINDOWS, 5, 1 }; // XP + const os_version_t WINDOWS_XPX64 = { OS_WINDOWS, 5, 2 }; // XP_x64 + const os_version_t WINDOWS_VISTA = { OS_WINDOWS, 6, 0 }; // Vista + const os_version_t WINDOWS_WIN70 = { OS_WINDOWS, 6, 1 }; // 7 + const os_version_t WINDOWS_WIN80 = { OS_WINDOWS, 6, 2 }; // 8 + const os_version_t WINDOWS_WIN81 = { OS_WINDOWS, 6, 3 }; // 8.1 + const os_version_t WINDOWS_WN100 = { OS_WINDOWS, 6, 4 }; // 10 + + //Unknown OS + const os_version_t UNKNOWN_OPSYS = { OS_UNKNOWN, 0, 0 }; // N/A + } + } +} + static bool verify_os_version(const DWORD major, const DWORD minor) { OSVERSIONINFOEXW osvi; diff --git a/src/Taskbar7_Win32.cpp b/src/Taskbar7_Win32.cpp index d86bd53..9b8501d 100644 --- a/src/Taskbar7_Win32.cpp +++ b/src/Taskbar7_Win32.cpp @@ -20,8 +20,9 @@ // http://www.gnu.org/licenses/gpl-2.0.txt /////////////////////////////////////////////////////////////////////////////// -//Internal +//MUtils #include +#include #include //Qt @@ -40,7 +41,11 @@ #define INITIALIZE_TASKBAR() do \ { \ - if(!initialize()) \ + if(!p->supported) \ + { \ + return false; \ + } \ + if(!(p->initialized || initialize())) \ { \ qWarning("Taskbar initialization failed!"); \ return false; \ @@ -59,7 +64,15 @@ namespace MUtils friend class Taskbar7; protected: + Taskbar7_Private(void) + { + taskbarList = NULL; + supported = false; + initialized = false; + } + ITaskbarList3 *taskbarList; + volatile bool supported; volatile bool initialized; }; } @@ -73,13 +86,14 @@ MUtils::Taskbar7::Taskbar7(QWidget *const window) p(new Taskbar7_Private()), m_window(window) { - p->taskbarList = NULL; - p->initialized = false; - if(!m_window) { MUTILS_THROW("Taskbar7: Window pointer must not be NULL!"); } + if(!(p->supported = (OS::os_version() >= OS::Version::WINDOWS_WIN70))) + { + qWarning("Taskbar7: Taskbar progress not supported on this platform."); + } } MUtils::Taskbar7::~Taskbar7(void)