Skip to content

Commit

Permalink
[FIX] Update loop(incorrect configuration)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gravit committed Apr 13, 2020
1 parent b2269ee commit 41845ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import javafx.application.Platform;

public class RuntimeSecurityService {
private final JavaFXApplication application;
Expand Down Expand Up @@ -95,29 +96,28 @@ public void update(LauncherRequestEvent result) throws IOException {
try (OutputStream stream = connection.getOutputStream()) {
IOHelper.transfer(BINARY_PATH, stream);
}*/
try {
Files.deleteIfExists(C_BINARY_PATH);
URL url = new URL(result.url);
URLConnection connection = url.openConnection();
try (InputStream in = connection.getInputStream()) {
IOHelper.transfer(in, C_BINARY_PATH);
}
try (InputStream in = IOHelper.newInput(C_BINARY_PATH)) {
IOHelper.transfer(in, BINARY_PATH);
}
Files.deleteIfExists(C_BINARY_PATH);
} catch (Throwable e) {
LogHelper.error(e);
Files.deleteIfExists(C_BINARY_PATH);
URL url = new URL(result.url);
URLConnection connection = url.openConnection();
try (InputStream in = connection.getInputStream()) {
IOHelper.transfer(in, C_BINARY_PATH);
}
try (InputStream in = IOHelper.newInput(C_BINARY_PATH)) {
IOHelper.transfer(in, BINARY_PATH);
}
Files.deleteIfExists(C_BINARY_PATH);
}
LogHelper.info("Create new process");
builder.start();

// Kill current instance
LogHelper.info("Close current instances");
try {
LauncherEngine.exitLauncher(0);
Platform.exit();
} catch (Throwable e) {
System.exit(0);
LauncherEngine.exitLauncher(0);
}
LauncherEngine.exitLauncher(0);
throw new AssertionError("Why Launcher wasn't restarted?!");
}

Expand Down
19 changes: 11 additions & 8 deletions src/main/java/pro/gravit/launcher/client/gui/scene/LoginScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.scene.control.*;
import javafx.util.StringConverter;
import pro.gravit.launcher.LauncherEngine;
import pro.gravit.launcher.client.events.ClientExitPhase;
import pro.gravit.launcher.client.gui.JavaFXApplication;
import pro.gravit.launcher.client.gui.helper.LookupHelper;
import pro.gravit.launcher.client.gui.raw.AbstractScene;
Expand Down Expand Up @@ -77,15 +78,17 @@ public void doInit() {
if (result.needUpdate) {
try {
application.securityService.update(result);
} catch (IOException e) {
LogHelper.error(e);
} catch (Throwable ignored) {

}
try {
LauncherEngine.exitLauncher(0);
} catch (Throwable e) {
Platform.exit();
contextHelper.runInFxThread(() -> {
getCurrentOverlay().errorHandle(e);
});
try {
Thread.sleep(1500);
LauncherEngine.modulesManager.invokeEvent(new ClientExitPhase(0));
Platform.exit();
} catch (Throwable ex) {
LauncherEngine.exitLauncher(0);
}
}
}
LogHelper.dev("Launcher update processed");
Expand Down

0 comments on commit 41845ff

Please sign in to comment.