mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FIX] Смена директории при помощи DirBridge.move (#374)
This commit is contained in:
parent
1abb66fcb8
commit
8a53e5a925
7 changed files with 76 additions and 89 deletions
|
@ -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<ModuleEntity> 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 {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
||||
public int getProcessorPhysicalCount() {
|
||||
return hardware.getProcessor().getPhysicalProcessorCount();
|
||||
}
|
||||
public int getProcessorLogicalCount()
|
||||
{
|
||||
|
||||
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();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
public class HardwareReportRequest extends Request<HardwareReportRequestEvent> {
|
||||
public HardwareInfo hardware;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "hardwareReport";
|
||||
|
|
|
@ -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,40 @@ 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 {
|
||||
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<Path> {
|
||||
private final Path dir;
|
||||
private final boolean self;
|
||||
|
|
Loading…
Reference in a new issue