[FEATURE] Обнаружение HTTP Error Code, частичная скачка ZIP

This commit is contained in:
Gravit 2019-06-28 14:50:22 +07:00
parent ae34a06a5f
commit 9922479314
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 20 additions and 5 deletions

View file

@ -33,7 +33,7 @@ public void preDiff(UpdateRequest request, UpdateRequestEvent e) {
@Override @Override
public void postDiff(UpdateRequest request, UpdateRequestEvent e, HashedDir.Diff diff) throws IOException { 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) { if (SettingsManager.settings.featureStore) {
LogHelper.info("Enabled HStore feature. Find"); LogHelper.info("Enabled HStore feature. Find");
AtomicReference<NewLauncherSettings.HashedStoreEntry> lastEn = new AtomicReference<>(null); AtomicReference<NewLauncherSettings.HashedStoreEntry> lastEn = new AtomicReference<>(null);

View file

@ -64,7 +64,7 @@ public void download(String base, List<DownloadTask> applies, Path dstDirFile, D
} }
} }
public void downloadZip(String base, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback) throws IOException, URISyntaxException { public void downloadZip(String base, List<DownloadTask> applies, Path dstDirFile, DownloadCallback callback, DownloadTotalCallback totalCallback, boolean fullDownload) throws IOException, URISyntaxException {
/*try (CloseableHttpClient httpclient = HttpClients.custom() /*try (CloseableHttpClient httpclient = HttpClients.custom()
.setRedirectStrategy(new LaxRedirectStrategy()) .setRedirectStrategy(new LaxRedirectStrategy())
.build()) { .build()) {
@ -81,8 +81,11 @@ public void downloadZip(String base, Path dstDirFile, DownloadCallback callback,
// Unpack entry // Unpack entry
String name = entry.getName(); String name = entry.getName();
LogHelper.subInfo("Downloading file: '%s'", name); LogHelper.subInfo("Downloading file: '%s'", name);
Path fileName = IOHelper.toPath(name); if(fullDownload || applies.stream().anyMatch((t) -> t.apply.equals(name)))
transfer(input, dstDirFile.resolve(fileName), fileName.toString(), entry.getSize(), callback, totalCallback); {
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 @Override
public Path handleResponse(HttpResponse response) throws IOException { public Path handleResponse(HttpResponse response) throws IOException {
InputStream source = response.getEntity().getContent(); 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) { if (zip) {
try (ZipInputStream input = IOHelper.newZipInput(source)) { try (ZipInputStream input = IOHelper.newZipInput(source)) {
ZipEntry entry = input.getNextEntry(); ZipEntry entry = input.getNextEntry();

View file

@ -11,6 +11,8 @@ public class UpdateRequestEvent extends RequestEvent {
public String url; public String url;
@LauncherNetworkAPI @LauncherNetworkAPI
public boolean zip; public boolean zip;
@LauncherNetworkAPI
public boolean fullDownload;
@Override @Override
public String getType() { public String getType() {

View file

@ -219,7 +219,7 @@ public UpdateRequestEvent requestDo(StandartClientWebSocketService service) thro
ListDownloader listDownloader = new ListDownloader(); ListDownloader listDownloader = new ListDownloader();
LogHelper.info("Download %s to %s", dirName, dir.toAbsolutePath().toString()); LogHelper.info("Download %s to %s", dirName, dir.toAbsolutePath().toString());
if (e.zip && !adds.isEmpty()) { 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 { } else {
listDownloader.download(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add); listDownloader.download(e.url, adds, dir, this::updateState, (add) -> totalDownloaded += add);
} }