-
Notifications
You must be signed in to change notification settings - Fork 35
Generate valid machine id #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
2b5a348
7a3d5b7
c16c6f7
c5effc0
37d5ad7
8ab10c0
758824c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Backtrace.Unity.Tests.Runtime")] | ||
namespace Backtrace.Unity.Model.DataProvider | ||
{ | ||
internal interface IMachineIdentifierDataProvider | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only provides the machine identifier. Why not name this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
string Get(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Backtrace.Unity.Tests.Runtime")] | ||
namespace Backtrace.Unity.Model.DataProvider | ||
{ | ||
internal interface ISessionStorageDataProvider | ||
{ | ||
void SetString(string key, string value); | ||
string GetString(string key); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Backtrace.Unity.Extensions; | ||
using System; | ||
using System.Linq; | ||
using System.Net.NetworkInformation; | ||
|
||
namespace Backtrace.Unity.Model.DataProvider | ||
{ | ||
internal class NetworkIdentifierDataProvider : IMachineIdentifierDataProvider | ||
{ | ||
public string Get() | ||
{ | ||
var interfaces = NetworkInterface.GetAllNetworkInterfaces() | ||
.Where(n => n.OperationalStatus == OperationalStatus.Up); | ||
|
||
foreach (var @interface in interfaces) | ||
{ | ||
var physicalAddress = @interface.GetPhysicalAddress(); | ||
if (physicalAddress == null) | ||
{ | ||
continue; | ||
} | ||
var macAddress = physicalAddress.ToString(); | ||
if (string.IsNullOrEmpty(macAddress)) | ||
{ | ||
continue; | ||
} | ||
string hex = macAddress.Replace(":", string.Empty); | ||
var value = Convert.ToInt64(hex, 16); | ||
return GuidHelper.FromLong(value).ToString(); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using UnityEngine; | ||
|
||
namespace Backtrace.Unity.Model.DataProvider | ||
{ | ||
internal class SessionStorageDataProvider : ISessionStorageDataProvider | ||
{ | ||
public string GetString(string key) | ||
{ | ||
return PlayerPrefs.GetString(key); | ||
} | ||
|
||
public void SetString(string key, string value) | ||
{ | ||
PlayerPrefs.SetString(key, value); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Backtrace.Unity.Extensions; | ||
using System; | ||
using System.Linq; | ||
using System.Net.NetworkInformation; | ||
using UnityEngine; | ||
|
||
namespace Backtrace.Unity.Model.DataProvider | ||
{ | ||
internal class UnityMachineIdentifierProvider : IMachineIdentifierDataProvider | ||
{ | ||
private readonly string _deviceUniqueIdentifier; | ||
internal UnityMachineIdentifierProvider() : this(SystemInfo.deviceUniqueIdentifier) { } | ||
|
||
internal UnityMachineIdentifierProvider(string machineIdentifier) | ||
{ | ||
_deviceUniqueIdentifier = machineIdentifier; | ||
} | ||
public string Get() | ||
{ | ||
if (!IsValidIdentifier()) | ||
{ | ||
return null; | ||
} | ||
|
||
if (Guid.TryParse(_deviceUniqueIdentifier, out Guid unityUuidGuid)) | ||
{ | ||
return unityUuidGuid.ToString(); | ||
} | ||
return GuidHelper.FromString(_deviceUniqueIdentifier).ToString(); | ||
Comment on lines
+23
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How often the ID will be generated? Maybe it's a good idea to generate this in the constructor, or cache the value somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see that in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to confirm - yes. we're doing it only once. |
||
} | ||
|
||
private bool IsValidIdentifier() | ||
{ | ||
return _deviceUniqueIdentifier != SystemInfo.unsupportedIdentifier && !string.IsNullOrEmpty(_deviceUniqueIdentifier); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this to
FromMD5String
?FromString
suggests that a GUID string can be provided here.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MD5 is an algorithm behind the scene that we're using to convert string into bytes that later we can use to generate GUID. It doesn't make sense to include MD5 in the name in my opinion. It's string and md5 is an implementation detail.