From 992247931498789ead0a0fe21b08164d4f23f7fa Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 28 Jun 2019 14:50:22 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9E=D0=B1=D0=BD=D0=B0=D1=80?= =?UTF-8?q?=D1=83=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20HTTP=20Error=20Code,=20?= =?UTF-8?q?=D1=87=D0=B0=D1=81=D1=82=D0=B8=D1=87=D0=BD=D0=B0=D1=8F=20=D1=81?= =?UTF-8?q?=D0=BA=D0=B0=D1=87=D0=BA=D0=B0=20ZIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/LauncherUpdateController.java | 2 +- .../launcher/downloader/ListDownloader.java | 19 ++++++++++++++++--- .../events/request/UpdateRequestEvent.java | 2 ++ .../request/update/UpdateRequest.java | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java index 8bba2200..3e5333a4 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/LauncherUpdateController.java @@ -33,7 +33,7 @@ public void preDiff(UpdateRequest request, UpdateRequestEvent e) { @Override public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException { - if (e.zip) return; + if (e.zip && e.fullDownload) return; if (SettingsManager.settings.featureStore) { LogHelper.info("Enabled HStore feature. Find"); AtomicReference lastEn = new AtomicReference<>(null); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java index cf836ff9..5f795bc7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/downloader/ListDownloader.java @@ -64,7 +64,7 @@ public void download(String base, List applies, Path dstDirFile, D } } - public void downloadZip(String base, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException, URISyntaxException { + public void downloadZip(String base, List applies, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean fullDownload) throws IOException, URISyntaxException { /*try (CloseableHttpClient httpclient = HttpClients.custom() .setRedirectStrategy(new LaxRedirectStrategy()) .build()) { @@ -81,8 +81,11 @@ public void downloadZip(String base, Path dstDirFile, DownloadCallback callback, // Unpack entry String name = entry.getName(); LogHelper.subInfo("Downloading file: '%s'", name); - Path fileName = IOHelper.toPath(name); - transfer(input, dstDirFile.resolve(fileName), fileName.toString(), entry.getSize(), callback, totalCallback); + if(fullDownload || applies.stream().anyMatch((t) -> t.apply.equals(name))) + { + Path fileName = IOHelper.toPath(name); + transfer(input, dstDirFile.resolve(fileName), fileName.toString(), entry.getSize(), callback, totalCallback); + } } } } @@ -134,6 +137,16 @@ public FileDownloadResponseHandler(Path target, DownloadCallback callback, Downl @Override public Path handleResponse(HttpResponse response) throws IOException { InputStream source = response.getEntity().getContent(); + int returnCode = response.getStatusLine().getStatusCode(); + if(returnCode != 200) + { + throw new IllegalStateException(String.format("Request download file %s return code %d", target.toString(), returnCode)); + } + long contentLength = response.getEntity().getContentLength(); + if (task != null && contentLength != task.size) + { + LogHelper.warning("Missing content length: expected %d | found %d", task.size, contentLength); + } if (zip) { try (ZipInputStream input = IOHelper.newZipInput(source)) { ZipEntry entry = input.getNextEntry(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java index 06663771..5f997795 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java @@ -11,6 +11,8 @@ public class UpdateRequestEvent extends RequestEvent { public String url; @LauncherNetworkAPI public boolean zip; + @LauncherNetworkAPI + public boolean fullDownload; @Override public String getType() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java index 8d77f7cf..bc372234 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java @@ -219,7 +219,7 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro ListDownloader listDownloader = new ListDownloader(); LogHelper.info("Download %s to %s", dirName, dir.toAbsolutePath().toString()); if (e.zip && !adds.isEmpty()) { - listDownloader.downloadZip(e.url, dir, this::updateState, (add) -> totalDownloaded += add); + listDownloader.downloadZip(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add, e.fullDownload); } else { listDownloader.download(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add); }