[FIX] IOHelper.move

This commit is contained in:
Zaxar163 2020-04-15 20:16:56 +03:00
parent 85400d968b
commit de01dda23d
6 changed files with 66 additions and 81 deletions

View file

@ -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;

View file

@ -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));
}

View file

@ -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();

View file

@ -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();

View file

@ -5,6 +5,7 @@
public class HardwareReportRequest extends Request<HardwareReportRequestEvent> {
public HardwareInfo hardware;
@Override
public String getType() {
return "hardwareReport";

View file

@ -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<Path> {
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,38 @@ public static void write(Path file, byte[] bytes) throws IOException {
Files.write(file, bytes, WRITE_OPTIONS);
}
private static class MoveFileVisitor implements FileVisitor<Path> {
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 {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
IOHelper.copy(file, to.resolve(from.relativize(file)));
Files.delete(file);
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;
}
}
private static final class DeleteDirVisitor extends SimpleFileVisitor<Path> {
private final Path dir;
private final boolean self;