aboutsummaryrefslogtreecommitdiff
path: root/src/hardware_functions.cpp
diff options
context:
space:
mode:
authorstonedDiscord <stoned@derpymail.org>2020-02-21 16:39:32 +0100
committerGitHub <noreply@github.com>2020-02-21 16:39:32 +0100
commit7d55ff01f5f139aaa4a343e93429997418cfd8bb (patch)
tree21950571b4e933583101db6c7b2405f55c48c03e /src/hardware_functions.cpp
parentabbbb43c985271c6d66b94ee384c6a401e43de8d (diff)
parent6ccabdd568075dfcecc6190d8d41a50b8bd99b84 (diff)
Merge branch 'master' into 2.7
Diffstat (limited to 'src/hardware_functions.cpp')
-rw-r--r--src/hardware_functions.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/hardware_functions.cpp b/src/hardware_functions.cpp
index ebba6ab7..bd6a6c3c 100644
--- a/src/hardware_functions.cpp
+++ b/src/hardware_functions.cpp
@@ -5,12 +5,12 @@
#if (defined (_WIN32) || defined (_WIN64))
#include <windows.h>
-DWORD dwVolSerial;
-BOOL bIsRetrieved;
+static DWORD dwVolSerial;
+static BOOL bIsRetrieved;
QString get_hdid()
{
- bIsRetrieved = GetVolumeInformation(TEXT("C:\\"), NULL, NULL, &dwVolSerial, NULL, NULL, NULL, NULL);
+ bIsRetrieved = GetVolumeInformation(TEXT("C:\\"), nullptr, 0, &dwVolSerial, nullptr, nullptr, nullptr, 0);
if (bIsRetrieved)
return QString::number(dwVolSerial, 16);
@@ -18,7 +18,6 @@ QString get_hdid()
//a totally random string
//what could possibly go wrong
return "gxsps32sa9fnwic92mfbs0";
-
}
#elif (defined (LINUX) || defined (__linux__))
@@ -51,10 +50,31 @@ QString get_hdid()
}
#elif defined __APPLE__
+#include <CoreFoundation/CoreFoundation.h>
+#include <IOKit/IOKitLib.h>
+
QString get_hdid()
{
- //hdids are broken at this point anyways
- return "just a mac passing by";
+ CFStringRef serial;
+ char buffer[64] = {0};
+ QString hdid;
+ io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,
+ IOServiceMatching("IOPlatformExpertDevice"));
+ if (platformExpert)
+ {
+ CFTypeRef serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert,
+ CFSTR(kIOPlatformSerialNumberKey),
+ kCFAllocatorDefault, 0);
+ if (serialNumberAsCFString) {
+ serial = (CFStringRef)serialNumberAsCFString;
+ }
+ if (CFStringGetCString(serial, buffer, 64, kCFStringEncodingUTF8)) {
+ hdid = buffer;
+ }
+
+ IOObjectRelease(platformExpert);
+ }
+ return hdid;
}
#else