From 10a83bb245769389510ecfc7ddc741ddd09978da Mon Sep 17 00:00:00 2001 From: koldo Date: Fri, 12 May 2017 07:59:42 +0000 Subject: [PATCH] SysInfo: Better serial disk detection in Windows git-svn-id: svn://ultimatepp.org/upp/trunk@11073 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/SysInfo/SysInfo.cpp | 43 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/bazaar/SysInfo/SysInfo.cpp b/bazaar/SysInfo/SysInfo.cpp index f08d10252..e8ea072a5 100644 --- a/bazaar/SysInfo/SysInfo.cpp +++ b/bazaar/SysInfo/SysInfo.cpp @@ -1993,6 +1993,36 @@ void SystemSignature::Load() { netAdapters = GetAdapterInfo(); } + +String Serial_ReorderInPairs(String input) { + String ret; + for (int i = 0; i < input.GetCount(); i += 2) + ret << char(input[i + 1]) << char(input[i]); + return ret; +} + +String Serial_HexToStr(String input) { + return TrimBoth(HexDecode(input)); +} + +bool Serial_Check(String hdSerial, String other_hdSerial) { + Vector list, otherList; + String toStr = Serial_HexToStr(hdSerial); + list << hdSerial << Serial_ReorderInPairs(hdSerial) << toStr << Serial_ReorderInPairs(toStr); + String toStrOther = Serial_HexToStr(other_hdSerial); + otherList << other_hdSerial << Serial_ReorderInPairs(other_hdSerial) << toStrOther << Serial_ReorderInPairs(toStrOther); + + // Check them all + bool hdSerialMatch = false; + for (int i = 0; i < list.GetCount(); ++i) { + for (int j = 0; j < otherList.GetCount(); ++j) + if (list[i] == otherList[j]) + return true; + } + return false; +} + + bool SystemSignature::operator==(const SystemSignature &other) const { // if (!(manufacturer == other.manufacturer && productName == other.productName)) // return false; // Manufacturers do change manufacturer name and product name... @@ -2002,15 +2032,12 @@ bool SystemSignature::operator==(const SystemSignature &other) const { userName == other.userName)) return false; - if (hdSerial != other.hdSerial) { // Check error reported in at least Windows Vista and 7 - if (Odd(hdSerial.GetCount())) + // hdSerial check + if (Odd(hdSerial.GetCount())) return false; - String reOrderedHdSerial; - for (int i = 0; i < hdSerial.GetCount(); i += 2) - reOrderedHdSerial << char(hdSerial[i + 1]) << char(hdSerial[i]); - if (reOrderedHdSerial != other.hdSerial) - return false; - } + + if (!Serial_Check(hdSerial, other.hdSerial)) + return false; for (int i = 0; i < netAdapters.GetCount(); ++i) { if (TrimBoth(netAdapters[i].mac).IsEmpty())