[FEATURE] Упрощение добавления своего HWIDProvider

This commit is contained in:
Gravit 2019-08-25 12:10:31 +07:00
parent 6cc18ec1b8
commit 9fb3d44d6a
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -24,7 +24,7 @@ public class FunctionalBridge {
@LauncherAPI @LauncherAPI
public static ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(0); public static ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(0);
@LauncherAPI @LauncherAPI
public static OshiHWIDProvider hwidProvider = new OshiHWIDProvider(); public static OshiHWIDProvider hwidProvider;
@LauncherAPI @LauncherAPI
public static AtomicReference<HWID> hwid = new AtomicReference<>(); public static AtomicReference<HWID> hwid = new AtomicReference<>();
@LauncherAPI @LauncherAPI
@ -51,14 +51,18 @@ public static void startTask(Runnable task) {
@LauncherAPI @LauncherAPI
public static HWID getHWID() { public static HWID getHWID() {
HWID hhwid = hwid.get(); HWID hhwid = hwid.get();
if (hhwid == null) hwid.set(hwidProvider.getHWID()); if (hhwid == null) {
if(hwidProvider == null) hwidProvider = new OshiHWIDProvider();
hwid.set(hwidProvider.getHWID());
}
return hhwid; return hhwid;
} }
@LauncherAPI @LauncherAPI
public static int getTotalMemory() { public static long getTotalMemory() {
if (cachedMemorySize > 0) return (int) cachedMemorySize; if (cachedMemorySize > 0) return cachedMemorySize;
return (int) (cachedMemorySize = hwidProvider.getTotalMemory() >> 20); if(hwidProvider == null) hwidProvider = new OshiHWIDProvider();
return (cachedMemorySize = hwidProvider.getTotalMemory() >> 20);
} }
@LauncherAPI @LauncherAPI
@ -67,7 +71,7 @@ public static int getClientJVMBits() {
} }
@LauncherAPI @LauncherAPI
public static int getJVMTotalMemory() { public static long getJVMTotalMemory() {
if (getClientJVMBits() == 32) { if (getClientJVMBits() == 32) {
return Math.min(getTotalMemory(), 1536); return Math.min(getTotalMemory(), 1536);
} else { } else {