mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +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;
|
package pro.gravit.launchserver.launchermodules;
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
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.LaunchServer;
|
||||||
import pro.gravit.launchserver.binary.tasks.MainBuildTask;
|
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.IOHelper;
|
||||||
import pro.gravit.utils.helper.JarHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -34,18 +27,17 @@
|
||||||
|
|
||||||
public class LauncherModuleLoader {
|
public class LauncherModuleLoader {
|
||||||
public final List<ModuleEntity> launcherModules = new ArrayList<>();
|
public final List<ModuleEntity> launcherModules = new ArrayList<>();
|
||||||
public Path modules_dir;
|
public final Path modulesDir;
|
||||||
private transient LaunchServer server;
|
private final LaunchServer server;
|
||||||
|
|
||||||
public LauncherModuleLoader(LaunchServer server) {
|
public LauncherModuleLoader(LaunchServer server) {
|
||||||
this.server = server;
|
this.server = server; modulesDir = server.dir.resolve("launcher-modules");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
modules_dir = server.dir.resolve("launcher-modules");
|
if (!IOHelper.isDir(modulesDir)) {
|
||||||
if (!IOHelper.isDir(modules_dir)) {
|
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(modules_dir);
|
Files.createDirectories(modulesDir);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +66,7 @@ public void init() {
|
||||||
|
|
||||||
public void syncModules() throws IOException {
|
public void syncModules() throws IOException {
|
||||||
launcherModules.clear();
|
launcherModules.clear();
|
||||||
IOHelper.walk(modules_dir, new ModulesVisitor(), false);
|
IOHelper.walk(modulesDir, new ModulesVisitor(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ModuleEntity {
|
static class ModuleEntity {
|
||||||
|
|
|
@ -105,12 +105,9 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException {
|
||||||
processArgs.add(executeFile.toString());
|
processArgs.add(executeFile.toString());
|
||||||
processArgs.addAll(jvmArgs);
|
processArgs.addAll(jvmArgs);
|
||||||
//ADD CLASSPATH
|
//ADD CLASSPATH
|
||||||
if(useLegacyJavaClassPathProperty)
|
if (useLegacyJavaClassPathProperty) {
|
||||||
{
|
|
||||||
processArgs.add("-Djava.class.path=".concat(String.join(getPathSeparator(), systemClassPath)));
|
processArgs.add("-Djava.class.path=".concat(String.join(getPathSeparator(), systemClassPath)));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
processArgs.add("-cp");
|
processArgs.add("-cp");
|
||||||
processArgs.add(String.join(getPathSeparator(), systemClassPath));
|
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...")));
|
LogHelper.dev(LogHelper.toString(new Throwable("Check stack of call DirBridge with null path...")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Path oldUpdates = dirUpdates;
|
||||||
dirUpdates = newDir;
|
dirUpdates = newDir;
|
||||||
LogHelper.dev(newDir.toString());
|
LogHelper.dev(newDir.toString());
|
||||||
IOHelper.move(dirUpdates, newDir);
|
IOHelper.move(oldUpdates, dirUpdates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Path getAppDataDir() throws IOException {
|
public static Path getAppDataDir() throws IOException {
|
||||||
|
|
|
@ -28,7 +28,7 @@ public void invoke(String... args) throws Exception {
|
||||||
long totalMemory = provider.getTotalMemory();
|
long totalMemory = provider.getTotalMemory();
|
||||||
boolean isBattery = provider.isBattery();
|
boolean isBattery = provider.isBattery();
|
||||||
currentTime = System.currentTimeMillis();
|
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();
|
startTime = System.currentTimeMillis();
|
||||||
int logicalProcessors = provider.getProcessorLogicalCount();
|
int logicalProcessors = provider.getProcessorLogicalCount();
|
||||||
int physicalProcessors = provider.getProcessorPhysicalCount();
|
int physicalProcessors = provider.getProcessorPhysicalCount();
|
||||||
|
|
|
@ -12,74 +12,70 @@ public class HWIDProvider {
|
||||||
public SystemInfo systemInfo;
|
public SystemInfo systemInfo;
|
||||||
public OperatingSystem system;
|
public OperatingSystem system;
|
||||||
public HardwareAbstractionLayer hardware;
|
public HardwareAbstractionLayer hardware;
|
||||||
public HWIDProvider()
|
|
||||||
{
|
public HWIDProvider() {
|
||||||
systemInfo = new SystemInfo();
|
systemInfo = new SystemInfo();
|
||||||
system = systemInfo.getOperatingSystem();
|
system = systemInfo.getOperatingSystem();
|
||||||
hardware = systemInfo.getHardware();
|
hardware = systemInfo.getHardware();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Statistic information
|
//Statistic information
|
||||||
public int getBitness()
|
public int getBitness() {
|
||||||
{
|
|
||||||
return system.getBitness();
|
return system.getBitness();
|
||||||
}
|
}
|
||||||
public long getTotalMemory()
|
|
||||||
{
|
public long getTotalMemory() {
|
||||||
return hardware.getMemory().getTotal();
|
return hardware.getMemory().getTotal();
|
||||||
}
|
}
|
||||||
public long getProcessorMaxFreq()
|
|
||||||
{
|
public long getProcessorMaxFreq() {
|
||||||
return hardware.getProcessor().getMaxFreq();
|
return hardware.getProcessor().getMaxFreq();
|
||||||
}
|
}
|
||||||
public int getProcessorPhysicalCount()
|
|
||||||
{
|
public int getProcessorPhysicalCount() {
|
||||||
return hardware.getProcessor().getPhysicalProcessorCount();
|
return hardware.getProcessor().getPhysicalProcessorCount();
|
||||||
}
|
}
|
||||||
public int getProcessorLogicalCount()
|
|
||||||
{
|
public int getProcessorLogicalCount() {
|
||||||
return hardware.getProcessor().getLogicalProcessorCount();
|
return hardware.getProcessor().getLogicalProcessorCount();
|
||||||
}
|
}
|
||||||
public boolean isBattery()
|
|
||||||
{
|
public boolean isBattery() {
|
||||||
PowerSource[] powerSources = hardware.getPowerSources();
|
PowerSource[] powerSources = hardware.getPowerSources();
|
||||||
return powerSources != null && powerSources.length != 0;
|
return powerSources != null && powerSources.length != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Hardware Information
|
//Hardware Information
|
||||||
public String getHWDiskID()
|
public String getHWDiskID() {
|
||||||
{
|
|
||||||
HWDiskStore[] hwDiskStore = hardware.getDiskStores();
|
HWDiskStore[] hwDiskStore = hardware.getDiskStores();
|
||||||
long size = 0;
|
long size = 0;
|
||||||
HWDiskStore maxStore = null;
|
HWDiskStore maxStore = null;
|
||||||
for(HWDiskStore store : hwDiskStore)
|
for (HWDiskStore store : hwDiskStore) {
|
||||||
{
|
if (store.getSize() > size) {
|
||||||
if(store.getSize() > size)
|
|
||||||
{
|
|
||||||
maxStore = store;
|
maxStore = store;
|
||||||
size = store.getSize();
|
size = store.getSize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(maxStore != null)
|
if (maxStore != null) {
|
||||||
{
|
|
||||||
return maxStore.getSerial();
|
return maxStore.getSerial();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public byte[] getDisplayID()
|
|
||||||
{
|
public byte[] getDisplayID() {
|
||||||
Display[] displays = hardware.getDisplays();
|
Display[] displays = hardware.getDisplays();
|
||||||
if(displays == null || displays.length == 0) return null;
|
if (displays == null || displays.length == 0) return null;
|
||||||
for(Display display : displays)
|
for (Display display : displays) {
|
||||||
{
|
|
||||||
return display.getEdid();
|
return display.getEdid();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public String getBaseboardSerialNumber()
|
|
||||||
{
|
public String getBaseboardSerialNumber() {
|
||||||
return hardware.getComputerSystem().getBaseboard().getSerialNumber();
|
return hardware.getComputerSystem().getBaseboard().getSerialNumber();
|
||||||
}
|
}
|
||||||
public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial)
|
|
||||||
{
|
public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial) {
|
||||||
HardwareReportRequest.HardwareInfo info = new HardwareReportRequest.HardwareInfo();
|
HardwareReportRequest.HardwareInfo info = new HardwareReportRequest.HardwareInfo();
|
||||||
info.bitness = getBitness();
|
info.bitness = getBitness();
|
||||||
info.logicalProcessors = getProcessorLogicalCount();
|
info.logicalProcessors = getProcessorLogicalCount();
|
||||||
|
@ -87,8 +83,7 @@ public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial)
|
||||||
info.processorMaxFreq = getProcessorMaxFreq();
|
info.processorMaxFreq = getProcessorMaxFreq();
|
||||||
info.totalMemory = getTotalMemory();
|
info.totalMemory = getTotalMemory();
|
||||||
info.battery = isBattery();
|
info.battery = isBattery();
|
||||||
if(needSerial)
|
if (needSerial) {
|
||||||
{
|
|
||||||
info.hwDiskId = getHWDiskID();
|
info.hwDiskId = getHWDiskID();
|
||||||
info.displayId = getDisplayID();
|
info.displayId = getDisplayID();
|
||||||
info.baseboardSerialNumber = getBaseboardSerialNumber();
|
info.baseboardSerialNumber = getBaseboardSerialNumber();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
public class HardwareReportRequest extends Request<HardwareReportRequestEvent> {
|
public class HardwareReportRequest extends Request<HardwareReportRequestEvent> {
|
||||||
public HardwareInfo hardware;
|
public HardwareInfo hardware;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return "hardwareReport";
|
return "hardwareReport";
|
||||||
|
|
|
@ -189,39 +189,6 @@ public static void move(Path source, Path target) throws IOException {
|
||||||
IOHelper.walk(source, new MoveFileVisitor(source, target), true);
|
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() {
|
public static byte[] newBuffer() {
|
||||||
return new byte[BUFFER_SIZE];
|
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);
|
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 static final class DeleteDirVisitor extends SimpleFileVisitor<Path> {
|
||||||
private final Path dir;
|
private final Path dir;
|
||||||
private final boolean self;
|
private final boolean self;
|
||||||
|
|
Loading…
Reference in a new issue