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 6bda4b15..56293bd2 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/downloader/ListDownloader.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/downloader/ListDownloader.java @@ -37,6 +37,25 @@ public void download(String base, List applies, Path dstDirFile) throws } } } + + public static void downloadOne(String url, Path target) throws IOException, URISyntaxException + { + try (CloseableHttpClient httpclient = HttpClients.custom() + .setRedirectStrategy(new LaxRedirectStrategy()) + .build()) { + + HttpGet get = null; + URI u = new URL(url).toURI(); + LogHelper.debug("Download URL: %s", u.toString()); + if (get == null) get = new HttpGet(u); + else { + get.reset(); + get.setURI(u); + } + httpclient.execute(get, new FileDownloadResponseHandler(target)); + } + } + public String escapeURL(String apply) { return apply.replaceAll(" ", "%20"); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java index 5eee3381..52113387 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/LauncherRequest.java @@ -4,6 +4,7 @@ import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.LauncherNetworkAPI; +import ru.gravit.launcher.downloader.ListDownloader; import ru.gravit.launcher.events.request.LauncherRequestEvent; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.RequestType; @@ -17,9 +18,7 @@ import ru.gravit.utils.helper.SecurityHelper; import java.io.IOException; -import java.io.OutputStream; -import java.net.URL; -import java.net.URLConnection; +import java.net.URISyntaxException; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -50,10 +49,16 @@ public static void update(LauncherConfig config, LauncherRequestEvent result) th if (result.binary != null) IOHelper.write(BINARY_PATH, result.binary); else { - URLConnection connection = IOHelper.newConnection(new URL(result.url)); + /*URLConnection connection = IOHelper.newConnection(new URL(result.url)); + connection.setDoOutput(true); connection.connect(); try (OutputStream stream = connection.getOutputStream()) { IOHelper.transfer(BINARY_PATH, stream); + }*/ + try { + ListDownloader.downloadOne(result.url, BINARY_PATH); + } catch (URISyntaxException e) { + throw new SecurityException(e); } } builder.start();