1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Stats: Unique Machine ID

This commit is contained in:
chroma 2022-08-31 15:16:20 +01:00
parent 4418376335
commit 6bd1582b47
9 changed files with 201 additions and 14 deletions

View file

@ -314,6 +314,14 @@ void OnlineUnlockStatus::MachineIDUtilities::addMACAddressesToList (StringArray&
ids.add (getEncodedIDString (address.toString()));
}
String OnlineUnlockStatus::MachineIDUtilities::getUniqueMachineID()
{
return getEncodedIDString (SystemStats::getUniqueDeviceID());
}
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations")
JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4996)
StringArray OnlineUnlockStatus::MachineIDUtilities::getLocalMachineIDs()
{
auto identifiers = SystemStats::getDeviceIdentifiers();
@ -329,6 +337,9 @@ StringArray OnlineUnlockStatus::getLocalMachineIDs()
return MachineIDUtilities::getLocalMachineIDs();
}
JUCE_END_IGNORE_WARNINGS_GCC_LIKE
JUCE_END_IGNORE_WARNINGS_MSVC
void OnlineUnlockStatus::userCancelled()
{
}
@ -378,22 +389,19 @@ bool OnlineUnlockStatus::applyKeyFile (String keyFileContent)
return false;
}
static bool canConnectToWebsite (const URL& url)
{
return url.createInputStream (URL::InputStreamOptions (URL::ParameterHandling::inAddress)
.withConnectionTimeoutMs (2000)) != nullptr;
}
static bool areMajorWebsitesAvailable()
{
const char* urlsToTry[] = { "http://google.com", "http://bing.com", "http://amazon.com",
"https://google.com", "https://bing.com", "https://amazon.com", nullptr};
static constexpr const char* const urlsToTry[] = { "http://google.com", "http://bing.com", "http://amazon.com",
"https://google.com", "https://bing.com", "https://amazon.com" };
const auto canConnectToWebsite = [] (auto url)
{
return URL (url).createInputStream (URL::InputStreamOptions (URL::ParameterHandling::inAddress)
.withConnectionTimeoutMs (2000)) != nullptr;
};
for (const char** url = urlsToTry; *url != nullptr; ++url)
if (canConnectToWebsite (URL (*url)))
return true;
return false;
return std::any_of (std::begin (urlsToTry),
std::end (urlsToTry),
canConnectToWebsite);
}
OnlineUnlockStatus::UnlockResult OnlineUnlockStatus::handleXmlReply (XmlElement xml)

View file

@ -242,6 +242,7 @@ public:
/** Utility function that you may want to use in your machine-ID generation code.
This adds some ID strings to the given array which represent each MAC address of the machine.
*/
[[deprecated ("MAC addresses are no longer reliable methods of ID generation. You should use getUniqueMachineID() instead, You can still get a list of this device's MAC addresses with MACAddress::findAllAddresses().")]]
static void addMACAddressesToList (StringArray& result);
/** This method calculates some machine IDs based on things like network
@ -259,7 +260,14 @@ public:
registration on machines which have had hardware added/removed
since the product was first registered.
*/
[[deprecated ("The identifiers generated by this function are no longer reliable. Use getUniqueMachineID() instead.")]]
static StringArray getLocalMachineIDs();
/** Returns an encoded unique machine ID.
@see SystemStats::getUniqueDeviceID
*/
static String getUniqueMachineID();
};
private: