[FIX] Попытка реализации автообновления с вебсокетами

This commit is contained in:
Gravit 2019-02-10 17:18:37 +07:00
parent a83754e7f1
commit f750e8897a
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 20 additions and 4 deletions

View file

@ -185,6 +185,8 @@ public class NettyConfig
{ {
public String bindAddress; public String bindAddress;
public int port; public int port;
public String launcherURL;
public String launcherEXEURL;
} }
public class GuardLicenseConf public class GuardLicenseConf
{ {

View file

@ -17,8 +17,8 @@ public class LauncherResponse implements JsonResponseInterface {
public byte[] digest; public byte[] digest;
public int launcher_type; public int launcher_type;
//REPLACED TO REAL URL //REPLACED TO REAL URL
public static final String JAR_URL = "http://localhost:9752/Launcher.jar"; public static final String JAR_URL = LaunchServer.server.config.netty.launcherURL;
public static final String EXE_URL = "http://localhost:9752/Launcher.exe"; public static final String EXE_URL = LaunchServer.server.config.netty.launcherEXEURL;
@Override @Override
public String getType() { public String getType() {

View file

@ -17,6 +17,10 @@
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -46,7 +50,16 @@ public static void update(LauncherConfig config, LauncherRequestEvent result) th
builder.inheritIO(); builder.inheritIO();
// Rewrite and start new instance // Rewrite and start new instance
IOHelper.write(BINARY_PATH, result.binary); if(result.binary != null)
IOHelper.write(BINARY_PATH, result.binary);
else
{
URLConnection connection = IOHelper.newConnection(new URL(result.url));
connection.connect();
try(OutputStream stream = connection.getOutputStream()) {
IOHelper.transfer(BINARY_PATH, stream);
}
}
builder.start(); builder.start();
// Kill current instance // Kill current instance
@ -62,7 +75,8 @@ public LauncherRequest() {
@Override @Override
public LauncherRequestEvent requestWebSockets() throws Exception public LauncherRequestEvent requestWebSockets() throws Exception
{ {
return (LauncherRequestEvent) LegacyRequestBridge.sendRequest(this); LauncherRequestEvent result = (LauncherRequestEvent) LegacyRequestBridge.sendRequest(this);
return result;
} }
@LauncherAPI @LauncherAPI