From 486d6535867d35e801e9f0b11423783e5b6caadc Mon Sep 17 00:00:00 2001
From: Petr Mrázek <peterix@gmail.com>
Date: Thu, 24 Nov 2016 23:28:55 +0100
Subject: NOISSUE Better Windows version detection and user agent

---
 libraries/ganalytics/src/sys_win32.cpp | 88 ++++++++++++++++------------------
 1 file changed, 41 insertions(+), 47 deletions(-)

(limited to 'libraries/ganalytics/src/sys_win32.cpp')

diff --git a/libraries/ganalytics/src/sys_win32.cpp b/libraries/ganalytics/src/sys_win32.cpp
index 4c4e35a9..d5e33172 100644
--- a/libraries/ganalytics/src/sys_win32.cpp
+++ b/libraries/ganalytics/src/sys_win32.cpp
@@ -1,56 +1,51 @@
 #include "sys.h"
 
-// FIXME: replace with our version...
+#include <windows.h>
+
 QString Sys::getSystemInfo()
 {
-	QSysInfo::WinVersion version = QSysInfo::windowsVersion();
-	QString os("Windows; ");
-	switch (version)
+	static QString cached;
+	if(!cached.isNull())
 	{
-	case QSysInfo::WV_95:
-		os += "Win 95";
-		break;
-	case QSysInfo::WV_98:
-		os += "Win 98";
-		break;
-	case QSysInfo::WV_Me:
-		os += "Win ME";
-		break;
-	case QSysInfo::WV_NT:
-		os += "Win NT";
-		break;
-	case QSysInfo::WV_2000:
-		os += "Win 2000";
-		break;
-	case QSysInfo::WV_2003:
-		os += "Win Server 2003";
-		break;
-	case QSysInfo::WV_VISTA:
-		os += "Win Vista";
-		break;
-	case QSysInfo::WV_WINDOWS7:
-		os += "Win 7";
-		break;
-	case QSysInfo::WV_WINDOWS8:
-		os += "Win 8";
-		break;
-	case QSysInfo::WV_WINDOWS8_1:
-		os += "Win 8.1";
-		break;
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
-	case QSysInfo::WV_WINDOWS10:
-		os += "Win 10";
-		break;
+		return cached;
+	}
+	else
+	{
+		// We support only Windows NT (XP and up) - everything else is not interesting.
+		OSVERSIONINFO osvi;
+		ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+		GetVersionExW(&osvi);
+		QString os = QString("Windows NT %1.%2").arg(osvi.dwMajorVersion).arg(osvi.dwMinorVersion);
+
+#if defined(_WIN64)
+		// 64-bit programs run only on Win64
+		os.append("; Win64");
+		// determine CPU type
+		SYSTEM_INFO info;
+		ZeroMemory(&info, sizeof(SYSTEM_INFO));
+		GetNativeSystemInfo(&info);
+		auto arch = info.wProcessorArchitecture;
+		if(arch == PROCESSOR_ARCHITECTURE_AMD64)
+		{
+			os.append("; x64");
+		}
+		else if (arch == PROCESSOR_ARCHITECTURE_IA64)
+		{
+			os.append("; IA64");
+		}
+#elif defined(_WIN32)
+		// 32-bit programs run on both 32-bit and 64-bit Windows
+		// so must sniff
+		BOOL f64 = false;
+		if(IsWow64Process(GetCurrentProcess(), &f64) && f64)
+		{
+			os.append("; WOW64");
+		}
 #endif
-	default:
-		os = "Windows; unknown";
-		break;
+		return os;
 	}
-	return os;
 }
 
-#include <windows.h>
-
 uint64_t Sys::getSystemRam()
 {
 	MEMORYSTATUSEX status;
@@ -63,10 +58,8 @@ uint64_t Sys::getSystemRam()
 bool Sys::isSystem64bit()
 {
 #if defined(_WIN64)
-	return true;  // 64-bit programs run only on Win64
+	return true;
 #elif defined(_WIN32)
-	// 32-bit programs run on both 32-bit and 64-bit Windows
-	// so must sniff
 	BOOL f64 = false;
 	return IsWow64Process(GetCurrentProcess(), &f64) && f64;
 #else
@@ -78,6 +71,7 @@ bool Sys::isSystem64bit()
 bool Sys::isCPU64bit()
 {
 	SYSTEM_INFO info;
+	ZeroMemory(&info, sizeof(SYSTEM_INFO));
 	GetNativeSystemInfo(&info);
 	auto arch = info.wProcessorArchitecture;
 	return arch == PROCESSOR_ARCHITECTURE_AMD64 || arch == PROCESSOR_ARCHITECTURE_IA64;
-- 
cgit