mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] Обнаружение HTTP Error Code, частичная скачка ZIP
This commit is contained in:
parent
ae34a06a5f
commit
9922479314
4 changed files with 20 additions and 5 deletions
|
@ -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<NewLauncherSettings.HashedStoreEntry> lastEn = new AtomicReference<>(null);
|
||||
|
|
|
@ -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()
|
||||
.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();
|
||||
|
|
|
@ -11,6 +11,8 @@ public class UpdateRequestEvent extends RequestEvent {
|
|||
public String url;
|
||||
@LauncherNetworkAPI
|
||||
public boolean zip;
|
||||
@LauncherNetworkAPI
|
||||
public boolean fullDownload;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue