Minor change

This commit is contained in:
CreepyCrafter24 2019-12-30 15:09:16 +01:00
parent 53a9bc5fe0
commit 40f88649f1
3 changed files with 16 additions and 14 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
CREPLSETUP.creplscript
# Created by https://www.gitignore.io/api/csharp,visualstudio
# Edit at https://www.gitignore.io/?templates=csharp,visualstudio

View File

@ -41,10 +41,8 @@ namespace CC_Functions.Misc
func();
}
public static T ParseToEnum<T>(string value)
{
return (T) Enum.Parse(typeof(T), Enum.GetNames(typeof(T)).First(s => s.ToLower() == value.ToLower()));
}
public static T ParseToEnum<T>(string value) => (T) Enum.Parse(typeof(T),
Enum.GetNames(typeof(T)).First(s => s.ToLower() == value.ToLower()));
public static bool? ParseBool(string value) =>
string.IsNullOrWhiteSpace(value) || value.ToLower() == "Indeterminate"
@ -62,5 +60,8 @@ namespace CC_Functions.Misc
public static bool FALSE(this bool? self) => self == false;
public static bool NULL(this bool? self) => self == null;
public static void RemoveAt<T, G>(this Dictionary<T, G> dict, int index) =>
dict.Remove(dict.Keys.OfType<T>().ToArray()[index]);
}
}

View File

@ -9,8 +9,8 @@ namespace CC_Functions.Misc
{
public static class HID
{
public static bool forceWindows = false;
private static byte[] _fingerPrint;
private static readonly string HIDClasses = @"Win32_Processor:UniqueId
Win32_Processor:ProcessorId
Win32_Processor:Name
@ -25,7 +25,7 @@ Win32_BaseBoard:Model
Win32_BaseBoard:Manufacturer
Win32_BaseBoard:Name
Win32_BaseBoard:SerialNumber
Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled";
Win32_NetworkAdapterConfiguration:MACAddress";
public static byte[] Value
{
@ -34,9 +34,9 @@ Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled";
if (_fingerPrint == null)
{
string fingerprintTmp = "";
if (Type.GetType("Mono.Runtime") == null)
if (forceWindows || Type.GetType("Mono.Runtime") == null)
{
HIDClasses.Split('\r').Select(s =>
HIDClasses.Split(new[] {"\r\n"}, StringSplitOptions.None).Select(s =>
{
if (s.StartsWith("\n"))
s = s.Remove(0, 1);
@ -48,8 +48,6 @@ Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled";
{
ManagementBaseObject[] array = moc.OfType<ManagementBaseObject>().ToArray();
for (int j = 0; j < array.Length; j++)
{
if (s.Length > 2 && array[j][s[2]].ToString() != "True") continue;
try
{
fingerprintTmp += array[j][s[1]].ToString();
@ -59,11 +57,10 @@ Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled";
{
Console.WriteLine("Failed to read property");
}
}
}
});
}
else //Linux implementation. This will not work if you are using Mono on windows or do not have uname and lscpu available
else //Linux implementation. This will not work if you are using Mono on windows or do not have "uname", "lscpu" and "id" available
{
Process p = new Process
{
@ -83,8 +80,12 @@ Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled";
p.Start();
fingerprintTmp += p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.StartInfo.FileName = "ip";
p.StartInfo.Arguments = "link";
p.Start();
fingerprintTmp += p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
using (MD5 sec = new MD5CryptoServiceProvider())
{
byte[] bt = Encoding.ASCII.GetBytes(fingerprintTmp);