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