From 9ba9987d1fae9de120ee19ac93655efe9ed6566b Mon Sep 17 00:00:00 2001 From: David Skoland Date: Mon, 23 Jan 2017 12:21:58 +0100 Subject: [PATCH] added cleaner frame for cross-platform hdid implementation --- Attorney_Online_remake.pro | 4 +-- hardware_functions.cpp | 34 +++++++++++++++++++++++ win32_functions.h => hardware_functions.h | 3 ++ packet_distribution.cpp | 6 +--- win32_functions.cpp | 15 ---------- 5 files changed, 40 insertions(+), 22 deletions(-) create mode 100644 hardware_functions.cpp rename win32_functions.h => hardware_functions.h (80%) delete mode 100644 win32_functions.cpp diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index fe41bc2..1b2a1a2 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -30,7 +30,7 @@ SOURCES += main.cpp\ encryption_functions.cpp \ courtroom.cpp \ aocharbutton.cpp \ - win32_functions.cpp + hardware_functions.cpp HEADERS += lobby.h \ text_file_functions.h \ @@ -48,4 +48,4 @@ HEADERS += lobby.h \ encryption_functions.h \ courtroom.h \ aocharbutton.h \ - win32_functions.h + hardware_functions.h diff --git a/hardware_functions.cpp b/hardware_functions.cpp new file mode 100644 index 0000000..ce6e35a --- /dev/null +++ b/hardware_functions.cpp @@ -0,0 +1,34 @@ +#include "hardware_functions.h" + +#if (defined (_WIN32) || defined (_WIN64)) +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 "invalid_windows_hd"; //what could possibly go wrong + +} + +#elif (defined (LINUX) || defined (__linux__)) + +QString get_hdid() +{ + //T0D0: add linux implementation + return "linux_os_hdid"; +} + +#else + +QString get_hdid() +{ + //T0D0: find a sane way to handle this + return "unknown_os_hdid"; +} + +#endif diff --git a/win32_functions.h b/hardware_functions.h similarity index 80% rename from win32_functions.h rename to hardware_functions.h index a095b88..7508a5a 100644 --- a/win32_functions.h +++ b/hardware_functions.h @@ -3,7 +3,10 @@ #include +#ifdef Q_OS_WIN32 #include +#endif // Q_OS_WIN32 + #include QString get_hdid(); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 114f01b..852afaf 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -3,7 +3,7 @@ #include "lobby.h" #include "networkmanager.h" #include "encryption_functions.h" -#include "win32_functions.h" +#include "hardware_functions.h" #include @@ -87,11 +87,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) s_decryptor = fanta_decrypt(f_contents.at(0), 322).toUInt(); QString f_hdid; -#ifdef Q_OS_WIN32 f_hdid = get_hdid(); -#else - f_hdid = "ao2testinginprogress"; -#endif AOPacket *hi_packet = new AOPacket("HI#" + f_hdid + "#%"); send_server_packet(hi_packet); diff --git a/win32_functions.cpp b/win32_functions.cpp deleted file mode 100644 index 76ca18a..0000000 --- a/win32_functions.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "win32_functions.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 "invalidhd"; //what could possibly go wrong - -}