Кеширование HardwareAbstractionLayer

This commit is contained in:
Gravit 2018-12-29 17:39:04 +07:00
parent 22763f3439
commit 49c53d4b35
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -9,6 +9,7 @@
public class OshiHWIDProvider implements LauncherHWIDInterface { public class OshiHWIDProvider implements LauncherHWIDInterface {
public SystemInfo systemInfo; public SystemInfo systemInfo;
public HardwareAbstractionLayer hardware;
public boolean noHWID; public boolean noHWID;
public OshiHWIDProvider() public OshiHWIDProvider()
{ {
@ -24,7 +25,8 @@ public OshiHWIDProvider()
public String getSerial() { public String getSerial() {
try { try {
return systemInfo.getHardware().getComputerSystem().getSerialNumber(); if(hardware == null) hardware = systemInfo.getHardware();
return hardware.getComputerSystem().getSerialNumber();
} catch (Exception e) { } catch (Exception e) {
LogHelper.error(e); LogHelper.error(e);
return ""; return "";
@ -34,7 +36,8 @@ public String getSerial() {
public String getProcessorID() { public String getProcessorID() {
try { try {
return systemInfo.getHardware().getProcessor().getProcessorID(); if(hardware == null) hardware = systemInfo.getHardware();
return hardware.getProcessor().getProcessorID();
} catch (Exception e) { } catch (Exception e) {
LogHelper.error(e); LogHelper.error(e);
return ""; return "";
@ -44,9 +47,10 @@ public String getProcessorID() {
public String getHWDisk() { public String getHWDisk() {
try { try {
if(hardware == null) hardware = systemInfo.getHardware();
HWDiskStore store = null; HWDiskStore store = null;
long size = 0; long size = 0;
for (HWDiskStore s : systemInfo.getHardware().getDiskStores()) { for (HWDiskStore s : hardware.getDiskStores()) {
if (size < s.getSize()) { if (size < s.getSize()) {
store = s; store = s;
size = s.getSize(); size = s.getSize();
@ -61,24 +65,26 @@ public String getHWDisk() {
public long getTotalMemory() { public long getTotalMemory() {
if(noHWID) return -1; if(noHWID) return -1;
return systemInfo.getHardware().getMemory().getTotal(); if(hardware == null) hardware = systemInfo.getHardware();
return hardware.getMemory().getTotal();
} }
public long getAvailableMemory() { public long getAvailableMemory() {
if(noHWID) return -1; if(noHWID) return -1;
return systemInfo.getHardware().getMemory().getAvailable(); if(hardware == null) hardware = systemInfo.getHardware();
return hardware.getMemory().getAvailable();
} }
public void printHardwareInformation() { public void printHardwareInformation() {
try try
{ {
HardwareAbstractionLayer hardware = systemInfo.getHardware(); if(hardware == null) hardware = systemInfo.getHardware();
ComputerSystem computerSystem = hardware.getComputerSystem(); ComputerSystem computerSystem = hardware.getComputerSystem();
LogHelper.debug("ComputerSystem Model: %s Serial: %s", computerSystem.getModel(), computerSystem.getSerialNumber()); LogHelper.debug("ComputerSystem Model: %s Serial: %s", computerSystem.getModel(), computerSystem.getSerialNumber());
for (HWDiskStore s : systemInfo.getHardware().getDiskStores()) { for (HWDiskStore s : hardware.getDiskStores()) {
LogHelper.debug("HWDiskStore Serial: %s Model: %s Size: %d", s.getSerial(), s.getModel(), s.getSize()); LogHelper.debug("HWDiskStore Serial: %s Model: %s Size: %d", s.getSerial(), s.getModel(), s.getSize());
} }
for (UsbDevice s : systemInfo.getHardware().getUsbDevices(true)) { for (UsbDevice s : hardware.getUsbDevices(true)) {
LogHelper.debug("USBDevice Serial: %s Name: %s", s.getSerialNumber(), s.getName()); LogHelper.debug("USBDevice Serial: %s Name: %s", s.getSerialNumber(), s.getName());
} }
CentralProcessor processor = hardware.getProcessor(); CentralProcessor processor = hardware.getProcessor();