[FIX] Фикс LauncherRequest

This commit is contained in:
Gravit 2019-04-03 22:59:56 +07:00
parent 468ff01f9f
commit 04cdfcb360
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 28 additions and 4 deletions

View file

@ -37,6 +37,25 @@ public void download(String base, List<String> 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) public String escapeURL(String apply)
{ {
return apply.replaceAll(" ", "%20"); return apply.replaceAll(" ", "%20");

View file

@ -4,6 +4,7 @@
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.LauncherNetworkAPI; import ru.gravit.launcher.LauncherNetworkAPI;
import ru.gravit.launcher.downloader.ListDownloader;
import ru.gravit.launcher.events.request.LauncherRequestEvent; import ru.gravit.launcher.events.request.LauncherRequestEvent;
import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.RequestType; import ru.gravit.launcher.request.RequestType;
@ -17,9 +18,7 @@
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.net.URISyntaxException;
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;
@ -50,10 +49,16 @@ public static void update(LauncherConfig config, LauncherRequestEvent result) th
if (result.binary != null) if (result.binary != null)
IOHelper.write(BINARY_PATH, result.binary); IOHelper.write(BINARY_PATH, result.binary);
else { else {
URLConnection connection = IOHelper.newConnection(new URL(result.url)); /*URLConnection connection = IOHelper.newConnection(new URL(result.url));
connection.setDoOutput(true);
connection.connect(); connection.connect();
try (OutputStream stream = connection.getOutputStream()) { try (OutputStream stream = connection.getOutputStream()) {
IOHelper.transfer(BINARY_PATH, stream); IOHelper.transfer(BINARY_PATH, stream);
}*/
try {
ListDownloader.downloadOne(result.url, BINARY_PATH);
} catch (URISyntaxException e) {
throw new SecurityException(e);
} }
} }
builder.start(); builder.start();