From c6e6dd672f13b8b7b8877992fe163459bda57fdd Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Wed, 18 Dec 2019 17:02:56 +0100 Subject: [PATCH] =?UTF-8?q?[FIX]=20=D0=95=D1=89=D1=91=201=20=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BE=D0=B1=20=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B5=20=D0=B3=D1=80=D1=83=D0=BF?= =?UTF-8?q?=D0=BF=D1=8B=20URL=20(=D0=B2=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=20=D0=B4=D0=BB=D1=8F=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D0=B5=D0=B9).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launcher/AsyncDownloader.java | 25 +++++++++++++++++++ modules | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java b/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java index 4a024f88..7cf0d447 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/AsyncDownloader.java @@ -79,6 +79,13 @@ public void downloadListInOneThread(List files, String baseURL, Path downloadFile(url, targetDir.resolve(currentFile.filePath), currentFile.size); } } + public void downloadListInOneThreadSimple(List files, String baseURL, Path targetDir) throws URISyntaxException, IOException { + + for(AsyncDownloader.SizedFile currentFile : files) + { + downloadFile(new URL(baseURL + currentFile.urlPath), targetDir.resolve(currentFile.filePath), currentFile.size); + } + } public List> sortFiles(List files, int threads) { files.sort(Comparator.comparingLong((f) -> -f.size)); @@ -116,6 +123,24 @@ public CompletableFuture[] runDownloadList(List> files, String b return futures; } + @SuppressWarnings("rawtypes") + public CompletableFuture[] runDownloadListSimple(List> files, String baseURL, Path targetDir, Executor executor) { + int threads = files.size(); + CompletableFuture[] futures = new CompletableFuture[threads]; + for(int i=0;i currentTasks = files.get(i); + futures[i] = CompletableFuture.runAsync(() -> { + try { + downloadListInOneThreadSimple(currentTasks, baseURL, targetDir); + } catch (URISyntaxException | IOException e) { + throw new CompletionException(e); + } + }, executor); + } + return futures; + } + public void transfer(InputStream input, Path file, long size) throws IOException { try (OutputStream fileOutput = IOHelper.newOutput(file)) { long downloaded = 0L; diff --git a/modules b/modules index a3c8661d..dd140777 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit a3c8661d7e6f2af4fc64748945aec73dc55e0a7b +Subproject commit dd140777b7b27989a9e40b31590ca5345a963970