diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 51743f7d..962b2f4b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -263,6 +263,11 @@ public static class ExeConf { public String txtFileVersion; public String txtProductVersion; } + public static class NettyUpdatesBind + { + public String url; + public boolean zip; + } public class LauncherConf { public String guardType; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/ru/gravit/launcher/downloader/ListDownloader.java index b5350d8d..935bcd3b 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/downloader/ListDownloader.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/downloader/ListDownloader.java @@ -18,6 +18,8 @@ import java.net.URL; import java.nio.file.Path; import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; public class ListDownloader { @FunctionalInterface @@ -55,10 +57,21 @@ public void download(String base, List applies, Path dstDirFile, D get.reset(); get.setURI(u); } - httpclient.execute(get, new FileDownloadResponseHandler(dstDirFile.resolve(apply.apply), apply, callback, totalCallback)); + httpclient.execute(get, new FileDownloadResponseHandler(dstDirFile.resolve(apply.apply), apply, callback, totalCallback, false)); } } } + public void downloadZip(String base, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException, URISyntaxException { + try (CloseableHttpClient httpclient = HttpClients.custom() + .setRedirectStrategy(new LaxRedirectStrategy()) + .build()) { + HttpGet get; + URI u = new URL(base).toURI(); + LogHelper.debug("Download ZIP URL: %s", u.toString()); + get = new HttpGet(u); + httpclient.execute(get, new FileDownloadResponseHandler(dstDirFile, callback, totalCallback, true)); + } + } public void downloadOne(String url, Path target) throws IOException, URISyntaxException { try (CloseableHttpClient httpclient = HttpClients.custom() @@ -78,24 +91,48 @@ static class FileDownloadResponseHandler implements ResponseHandler { private final DownloadTask task; private final DownloadCallback callback; private final DownloadTotalCallback totalCallback; + private final boolean zip; public FileDownloadResponseHandler(Path target) { this.target = target; this.task = null; + this.zip = false; callback = null; totalCallback = null; } - public FileDownloadResponseHandler(Path target, DownloadTask task, DownloadCallback callback, DownloadTotalCallback totalCallback) { + public FileDownloadResponseHandler(Path target, DownloadTask task, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean zip) { this.target = target; this.task = task; this.callback = callback; this.totalCallback = totalCallback; + this.zip = zip; + } + + public FileDownloadResponseHandler(Path target, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean zip) { + this.target = target; + this.task = null; + this.callback = callback; + this.totalCallback = totalCallback; + this.zip = zip; } @Override public Path handleResponse(HttpResponse response) throws IOException { InputStream source = response.getEntity().getContent(); + if(zip) + { + try(ZipInputStream input = IOHelper.newZipInput(source)) + { + ZipEntry entry = input.getNextEntry(); + long size = entry.getSize(); + String filename = entry.getName(); + Path target = this.target.resolve(filename); + LogHelper.dev("Resolved filename %s to %s", filename, target.toAbsolutePath().toString()); + transfer(source, target, filename, size, callback, totalCallback); + } + return null; + } if (callback != null && task != null) { callback.stateChanged(task.apply, 0, task.size); transfer(source, this.target, task.apply, task.size, callback, totalCallback); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/events/request/UpdateRequestEvent.java b/LauncherAPI/src/main/java/ru/gravit/launcher/events/request/UpdateRequestEvent.java index 6f49c758..ddcaa6c6 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/events/request/UpdateRequestEvent.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/events/request/UpdateRequestEvent.java @@ -9,6 +9,8 @@ public class UpdateRequestEvent extends RequestEvent { public HashedDir hdir; @LauncherNetworkAPI public String url; + @LauncherNetworkAPI + public boolean zip; @Override public String getType() { @@ -17,10 +19,18 @@ public String getType() { public UpdateRequestEvent(HashedDir hdir) { this.hdir = hdir; + this.zip = false; } public UpdateRequestEvent(HashedDir hdir, String url) { this.hdir = hdir; this.url = url; + this.zip = false; + } + + public UpdateRequestEvent(HashedDir hdir, String url, boolean zip) { + this.hdir = hdir; + this.url = url; + this.zip = zip; } } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java index f7eb00f4..aafa0b55 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java @@ -191,7 +191,14 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro startTime = Instant.now(); updateState("UnknownFile", 0L, 100); ListDownloader listDownloader = new ListDownloader(); - listDownloader.download(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add); + if(e.zip) + { + listDownloader.downloadZip(e.url, dir, this::updateState, (add) -> totalDownloaded += add); + } + else + { + listDownloader.download(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add); + } deleteExtraDir(dir, diff.extra, diff.extra.flag); LogHelper.debug("Update success"); return e;