diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java index 732e3878..ec571b65 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java @@ -1,16 +1,9 @@ package pro.gravit.launchserver.launchermodules; import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.MainBuildTask; -import pro.gravit.launchserver.modules.events.LaunchServerInitPhase; -import pro.gravit.launchserver.modules.events.LaunchServerPostInitPhase; -import pro.gravit.utils.Version; import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JarHelper; import pro.gravit.utils.helper.LogHelper; import java.io.IOException; @@ -34,18 +27,17 @@ public class LauncherModuleLoader { public final List launcherModules = new ArrayList<>(); - public Path modules_dir; - private transient LaunchServer server; + public final Path modulesDir; + private final LaunchServer server; public LauncherModuleLoader(LaunchServer server) { - this.server = server; + this.server = server; modulesDir = server.dir.resolve("launcher-modules"); } public void init() { - modules_dir = server.dir.resolve("launcher-modules"); - if (!IOHelper.isDir(modules_dir)) { + if (!IOHelper.isDir(modulesDir)) { try { - Files.createDirectories(modules_dir); + Files.createDirectories(modulesDir); } catch (IOException e) { LogHelper.error(e); } @@ -74,7 +66,7 @@ public void init() { public void syncModules() throws IOException { launcherModules.clear(); - IOHelper.walk(modules_dir, new ModulesVisitor(), false); + IOHelper.walk(modulesDir, new ModulesVisitor(), false); } static class ModuleEntity { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java index a10dd91d..d56975ea 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -105,12 +105,9 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { processArgs.add(executeFile.toString()); processArgs.addAll(jvmArgs); //ADD CLASSPATH - if(useLegacyJavaClassPathProperty) - { + if (useLegacyJavaClassPathProperty) { processArgs.add("-Djava.class.path=".concat(String.join(getPathSeparator(), systemClassPath))); - } - else - { + } else { processArgs.add("-cp"); processArgs.add(String.join(getPathSeparator(), systemClassPath)); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java index dc6fb4b5..8cd5b337 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java @@ -52,9 +52,10 @@ public static void move(Path newDir) throws IOException { LogHelper.dev(LogHelper.toString(new Throwable("Check stack of call DirBridge with null path..."))); return; } + Path oldUpdates = dirUpdates; dirUpdates = newDir; LogHelper.dev(newDir.toString()); - IOHelper.move(dirUpdates, newDir); + IOHelper.move(oldUpdates, dirUpdates); } public static Path getAppDataDir() throws IOException { diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java index 2d7a879e..624c249c 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java @@ -28,7 +28,7 @@ public void invoke(String... args) throws Exception { long totalMemory = provider.getTotalMemory(); boolean isBattery = provider.isBattery(); currentTime = System.currentTimeMillis(); - LogHelper.info("Bitness: %d, totalMemory: %d(%.3f GB), battery %s, TIME: %d ms", bitness, totalMemory, (double)totalMemory / (1024.0*1024.0*1024.0), Boolean.toString(isBattery), currentTime - startTime); + LogHelper.info("Bitness: %d, totalMemory: %d(%.3f GB), battery %s, TIME: %d ms", bitness, totalMemory, (double) totalMemory / (1024.0 * 1024.0 * 1024.0), Boolean.toString(isBattery), currentTime - startTime); startTime = System.currentTimeMillis(); int logicalProcessors = provider.getProcessorLogicalCount(); int physicalProcessors = provider.getProcessorPhysicalCount(); diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java b/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java index bdf41d46..f7b53b10 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java @@ -12,74 +12,70 @@ public class HWIDProvider { public SystemInfo systemInfo; public OperatingSystem system; public HardwareAbstractionLayer hardware; - public HWIDProvider() - { + + public HWIDProvider() { systemInfo = new SystemInfo(); system = systemInfo.getOperatingSystem(); hardware = systemInfo.getHardware(); } + //Statistic information - public int getBitness() - { + public int getBitness() { return system.getBitness(); } - public long getTotalMemory() - { + + public long getTotalMemory() { return hardware.getMemory().getTotal(); } - public long getProcessorMaxFreq() - { + + public long getProcessorMaxFreq() { return hardware.getProcessor().getMaxFreq(); } - public int getProcessorPhysicalCount() - { - return hardware.getProcessor().getPhysicalProcessorCount(); + + public int getProcessorPhysicalCount() { + return hardware.getProcessor().getPhysicalProcessorCount(); } - public int getProcessorLogicalCount() - { - return hardware.getProcessor().getLogicalProcessorCount(); + + public int getProcessorLogicalCount() { + return hardware.getProcessor().getLogicalProcessorCount(); } - public boolean isBattery() - { + + public boolean isBattery() { PowerSource[] powerSources = hardware.getPowerSources(); return powerSources != null && powerSources.length != 0; } + //Hardware Information - public String getHWDiskID() - { + public String getHWDiskID() { HWDiskStore[] hwDiskStore = hardware.getDiskStores(); long size = 0; HWDiskStore maxStore = null; - for(HWDiskStore store : hwDiskStore) - { - if(store.getSize() > size) - { + for (HWDiskStore store : hwDiskStore) { + if (store.getSize() > size) { maxStore = store; size = store.getSize(); } } - if(maxStore != null) - { + if (maxStore != null) { return maxStore.getSerial(); } return null; } - public byte[] getDisplayID() - { + + public byte[] getDisplayID() { Display[] displays = hardware.getDisplays(); - if(displays == null || displays.length == 0) return null; - for(Display display : displays) - { + if (displays == null || displays.length == 0) return null; + for (Display display : displays) { return display.getEdid(); } return null; } - public String getBaseboardSerialNumber() - { + + public String getBaseboardSerialNumber() { return hardware.getComputerSystem().getBaseboard().getSerialNumber(); } - public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial) - { + + public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial) { HardwareReportRequest.HardwareInfo info = new HardwareReportRequest.HardwareInfo(); info.bitness = getBitness(); info.logicalProcessors = getProcessorLogicalCount(); @@ -87,8 +83,7 @@ public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial) info.processorMaxFreq = getProcessorMaxFreq(); info.totalMemory = getTotalMemory(); info.battery = isBattery(); - if(needSerial) - { + if (needSerial) { info.hwDiskId = getHWDiskID(); info.displayId = getDisplayID(); info.baseboardSerialNumber = getBaseboardSerialNumber(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java index 2f7fd075..6e41781f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java @@ -5,6 +5,7 @@ public class HardwareReportRequest extends Request { public HardwareInfo hardware; + @Override public String getType() { return "hardwareReport"; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index 51c7ba40..f3b0387f 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -189,39 +189,6 @@ public static void move(Path source, Path target) throws IOException { IOHelper.walk(source, new MoveFileVisitor(source, target), true); } - private static class MoveFileVisitor implements FileVisitor { - private final Path from, to; - - private MoveFileVisitor(Path from, Path to) { - this.from = from; - this.to = to; - } - - @Override - public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { - Path toDir = to.resolve(from.relativize(dir)); - if (!IOHelper.isDir(toDir)) Files.createDirectories(toDir); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - Files.move(file, to.resolve(from.relativize(file)), COPY_OPTIONS); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { - throw exc; - } - - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { - Files.delete(dir); - return FileVisitResult.CONTINUE; - } - } - public static byte[] newBuffer() { return new byte[BUFFER_SIZE]; } @@ -608,6 +575,40 @@ public static void write(Path file, byte[] bytes) throws IOException { Files.write(file, bytes, WRITE_OPTIONS); } + private static class MoveFileVisitor implements FileVisitor { + private final Path from, to; + + private MoveFileVisitor(Path from, Path to) { + this.from = from; + this.to = to; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + if (!isDir(dir)) + Files.createDirectories(dir); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.move(file, to.resolve(from.relativize(file)), COPY_OPTIONS); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + throw exc; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (exc != null) throw exc; + if (!this.from.equals(dir)) Files.delete(dir); + return FileVisitResult.CONTINUE; + } + } + private static final class DeleteDirVisitor extends SimpleFileVisitor { private final Path dir; private final boolean self;