aboutsummaryrefslogtreecommitdiff
path: root/hardware_functions.cpp
blob: 0b161c3db67787bc5ba1da874d2abd7d1aaab316 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "hardware_functions.h"

#include <QDebug>

#if (defined (_WIN32) || defined (_WIN64))
#include <windows.h>

DWORD dwVolSerial;
BOOL bIsRetrieved;

QString get_hdid()
{
    bIsRetrieved = GetVolumeInformation(TEXT("C:\\"), NULL, NULL, &dwVolSerial, NULL, NULL, NULL, NULL);

    if (bIsRetrieved)
        return QString::number(dwVolSerial, 16);
    else
        return "gxsps32sa9fnwic92mfbs0"; //what could possibly go wrong

}

#elif (defined (LINUX) || defined (__linux__))

#include <QFile>
#include <QTextStream>

QString get_hdid()
{
  QFile fstab_file("/etc/fstab");
  if (!fstab_file.open(QIODevice::ReadOnly))
    //literally a random string.... what else are we supposed to do?
    return "gxcps32sa9fnwic92mfbs0";

  QTextStream in(&fstab_file);

  while(!in.atEnd())
  {
    QString line = in.readLine();

    if (line.startsWith("UUID"))
    {
      QStringList line_elements = line.split("=");

      if (line_elements.size() > 1)
        return line_elements.at(1).left(23).trimmed();
    }
  }

  return "gxcpz32sa9fnwic92mfbs0";
}

#else

//throwing compile-time errors professionally
fhasdfuifhidfhasjkfasdkfahsdj

#endif