2018-11-28 13:52:20 +03:00
|
|
|
package ru.gravit.launcher;
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
2019-03-28 13:13:27 +03:00
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.StringJoiner;
|
|
|
|
|
2018-11-28 13:52:20 +03:00
|
|
|
public class OshiHWID implements HWID {
|
|
|
|
public static Gson gson = new Gson();
|
2018-12-03 13:44:23 +03:00
|
|
|
@LauncherAPI
|
2018-11-28 13:52:20 +03:00
|
|
|
public long totalMemory = 0;
|
2018-12-03 13:44:23 +03:00
|
|
|
@LauncherAPI
|
2018-11-28 13:52:20 +03:00
|
|
|
public String serialNumber;
|
2018-12-03 13:44:23 +03:00
|
|
|
@LauncherAPI
|
2018-11-28 13:52:20 +03:00
|
|
|
public String HWDiskSerial;
|
2018-12-03 13:44:23 +03:00
|
|
|
@LauncherAPI
|
|
|
|
public String processorID;
|
2019-03-09 18:52:24 +03:00
|
|
|
@LauncherAPI
|
|
|
|
public String macAddr;
|
2018-11-28 13:52:20 +03:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getSerializeString() {
|
|
|
|
return gson.toJson(this);
|
|
|
|
}
|
2018-12-20 18:45:01 +03:00
|
|
|
|
2018-12-03 13:44:23 +03:00
|
|
|
@Override
|
2018-11-28 13:52:20 +03:00
|
|
|
public int getLevel() //Уровень доверия, насколько уникальные значения
|
|
|
|
{
|
|
|
|
int result = 0;
|
2019-03-09 18:52:24 +03:00
|
|
|
if (totalMemory != 0) result+=8;
|
|
|
|
if (serialNumber != null && !serialNumber.equals("unknown")) result += 12;
|
|
|
|
if (HWDiskSerial != null && !HWDiskSerial.equals("unknown")) result += 30;
|
|
|
|
if (processorID != null && !processorID.equals("unknown")) result += 10;
|
|
|
|
if (macAddr != null && !macAddr.equals("00:00:00:00:00:00")) result += 15;
|
2018-11-28 13:52:20 +03:00
|
|
|
return result;
|
|
|
|
}
|
2018-12-20 18:45:01 +03:00
|
|
|
|
2019-03-08 14:02:54 +03:00
|
|
|
@Override
|
|
|
|
public int compare(HWID hwid) {
|
|
|
|
if(hwid instanceof OshiHWID)
|
|
|
|
{
|
|
|
|
int rate = 0;
|
|
|
|
OshiHWID oshi = (OshiHWID) hwid;
|
2019-03-09 18:52:24 +03:00
|
|
|
if(Math.abs(oshi.totalMemory - totalMemory) < 1024*1024) rate+=5;
|
|
|
|
if(oshi.totalMemory == totalMemory) rate+=15;
|
|
|
|
if(oshi.HWDiskSerial.equals(HWDiskSerial)) rate+=45;
|
|
|
|
if(oshi.processorID.equals(processorID)) rate+=18;
|
2019-03-08 14:02:54 +03:00
|
|
|
if(oshi.serialNumber.equals(serialNumber)) rate+=15;
|
2019-03-12 13:38:22 +03:00
|
|
|
if(!oshi.macAddr.isEmpty() && oshi.macAddr.equals(macAddr)) rate+=19;
|
2019-03-08 14:02:54 +03:00
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-28 13:52:20 +03:00
|
|
|
@Override
|
|
|
|
public boolean isNull() {
|
2019-03-09 18:52:24 +03:00
|
|
|
return getLevel() < 15;
|
2018-11-28 13:52:20 +03:00
|
|
|
}
|
2019-03-28 13:13:27 +03:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o) return true;
|
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
OshiHWID oshiHWID = (OshiHWID) o;
|
|
|
|
return totalMemory == oshiHWID.totalMemory &&
|
|
|
|
Objects.equals(serialNumber, oshiHWID.serialNumber) &&
|
|
|
|
Objects.equals(HWDiskSerial, oshiHWID.HWDiskSerial) &&
|
|
|
|
Objects.equals(processorID, oshiHWID.processorID) &&
|
|
|
|
Objects.equals(macAddr, oshiHWID.macAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return Objects.hash(totalMemory, serialNumber, HWDiskSerial, processorID, macAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return new StringJoiner(", ", OshiHWID.class.getSimpleName() + "[", "]")
|
|
|
|
.add("totalMemory=" + totalMemory)
|
|
|
|
.add("serialNumber='" + serialNumber + "'")
|
|
|
|
.add("HWDiskSerial='" + HWDiskSerial + "'")
|
|
|
|
.add("processorID='" + processorID + "'")
|
|
|
|
.add("macAddr='" + macAddr + "'")
|
|
|
|
.toString();
|
|
|
|
}
|
2018-11-28 13:52:20 +03:00
|
|
|
}
|