• R/O
  • HTTP
  • SSH
  • HTTPS

MUtilities: Commit

MUtilities development repository


Commit MetaInfo

Revision9c3ab391729c232788cafbaef1878c69e77b4f80 (tree)
Time2019-08-08 04:47:20
AuthorLoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Added function to detect the OS architecture (x86 vs x64).

Change Summary

Incremental Difference

--- a/include/MUtils/OSSupport.h
+++ b/include/MUtils/OSSupport.h
@@ -101,6 +101,16 @@ namespace MUtils
101101 }
102102
103103 /**
104+ * \brief This enumeration specifies possible operating system architectures
105+ */
106+ typedef enum
107+ {
108+ ARCH_X86 = 1, ///< Intel x86 or compatible [32-bit]
109+ ARCH_X64 = 2 ///< x86-64, aka AMD64, aka Intel 64 [64-bit]
110+ }
111+ os_arch_t;
112+
113+ /**
104114 * \brief This enumeration specifies "known" folder identifiers
105115 */
106116 typedef enum
@@ -174,6 +184,7 @@ namespace MUtils
174184 MUTILS_API const Version::os_version_t &os_version(void);
175185 MUTILS_API const char *os_friendly_name(const MUtils::OS::Version::os_version_t &os_version);
176186 MUTILS_API const bool &running_on_wine(void);
187+ MUTILS_API const os_arch_t &os_architecture(void);
177188
178189 //Get known Folder
179190 MUTILS_API const QString &known_folder(const known_folder_t folder_id);
--- a/src/OSSupport_Win32.cpp
+++ b/src/OSSupport_Win32.cpp
@@ -328,7 +328,6 @@ static inline DWORD SAFE_ADD(const DWORD &a, const DWORD &b, const DWORD &limit
328328 return ((a >= limit) || (b >= limit) || ((limit - a) <= b)) ? limit : (a + b);
329329 }
330330
331-
332331 static void initialize_os_version(OSVERSIONINFOEXW *const osInfo)
333332 {
334333 memset(osInfo, 0, sizeof(OSVERSIONINFOEXW));
@@ -645,6 +644,60 @@ const char *MUtils::OS::os_friendly_name(const MUtils::OS::Version::os_version_t
645644 }
646645
647646 ///////////////////////////////////////////////////////////////////////////////
647+// OS ARCHITECTURE DETECTION
648+///////////////////////////////////////////////////////////////////////////////
649+
650+static bool g_os_arch_initialized = false;
651+static MUtils::OS::os_arch_t g_os_arch = MUtils::OS::os_arch_t(0);
652+static QReadWriteLock g_os_arch_lock;
653+
654+static MUtils::OS::os_arch_t detect_os_arch(void)
655+{
656+#if (!(defined(_M_X64) || defined(_M_IA64)))
657+ typedef BOOL(WINAPI * IsWow64ProcessFun)(__in HANDLE hProcess, __out PBOOL Wow64Process);
658+ const IsWow64ProcessFun isWow64ProcessPtr = MUtils::Win32Utils::resolve<IsWow64ProcessFun>(QLatin1String("kernel32"), QLatin1String("IsWow64Process"));
659+ if (isWow64ProcessPtr)
660+ {
661+ BOOL x64flag = FALSE;
662+ if (isWow64ProcessPtr(GetCurrentProcess(), &x64flag))
663+ {
664+ if (x64flag)
665+ {
666+ return MUtils::OS::ARCH_X64;
667+ }
668+ }
669+ }
670+ return MUtils::OS::ARCH_X86;
671+#else
672+ return MUtils::OS::ARCH_X64;
673+#endif
674+}
675+
676+const MUtils::OS::os_arch_t &MUtils::OS::os_architecture(void)
677+{
678+ QReadLocker readLock(&g_os_arch_lock);
679+
680+ //Already initialized?
681+ if (g_os_arch_initialized)
682+ {
683+ return g_os_arch;
684+ }
685+
686+ readLock.unlock();
687+ QWriteLocker writeLock(&g_os_arch_lock);
688+
689+ //Initialized now?
690+ if (g_os_arch_initialized)
691+ {
692+ return g_os_arch;
693+ }
694+
695+ g_os_arch = detect_os_arch();
696+ g_os_arch_initialized = MUTILS_BOOLIFY(g_os_arch);
697+ return g_os_arch;
698+}
699+
700+///////////////////////////////////////////////////////////////////////////////
648701 // WINE DETECTION
649702 ///////////////////////////////////////////////////////////////////////////////
650703
Show on old repository browser