-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMachineIDUtilities.cpp
More file actions
67 lines (54 loc) · 1.74 KB
/
MachineIDUtilities.cpp
File metadata and controls
67 lines (54 loc) · 1.74 KB
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
58
59
60
61
62
63
64
65
66
67
/*
==============================================================================
MachineIDUtilities.cpp
Created: 23 Sep 2019 7:39:39pm
Author: Edwin Park
==============================================================================
*/
#include "MachineIDUtilities.h"
#include <juce_core/juce_core.h>
#include <juce_cryptography/juce_cryptography.h>
using juce::int64;
using juce::juce_wchar;
using juce::MACAddress;
using juce::MD5;
using juce::SystemStats;
char MachineIDUtilities::getPlatformPrefix() {
#if JUCE_MAC
return 'M';
#elif JUCE_WINDOWS
return 'W';
#elif JUCE_LINUX
return 'L';
#elif JUCE_IOS
return 'I';
#elif JUCE_ANDROID
return 'A';
#endif
}
String MachineIDUtilities::getEncodedIDString(const String &input) {
auto platform =
String::charToString(static_cast<juce_wchar>(getPlatformPrefix()));
return platform + MD5((input + "salt_1" + platform).toUTF8())
.toHexString()
.substring(0, 9)
.toUpperCase();
}
bool MachineIDUtilities::addFileIDToList(StringArray &ids, const File &f) {
if (auto num = f.getFileIdentifier()) {
ids.add(getEncodedIDString(String::toHexString((int64)num)));
return true;
}
return false;
}
void MachineIDUtilities::addMACAddressesToList(StringArray &ids) {
for (auto &address : MACAddress::getAllAddresses())
ids.add(getEncodedIDString(address.toString()));
}
StringArray MachineIDUtilities::getLocalMachineIDs() {
auto identifiers = juce::StringArray();
identifiers.add(juce::SystemStats::getUniqueDeviceID());
for (auto &identifier : identifiers)
identifier = getEncodedIDString(identifier);
return identifiers;
}