Skip to content

Commit 4063515

Browse files
authored
Limit/config concurrent downloads for CF and Modrinth (#610)
1 parent 2fb4ac6 commit 4063515

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/main/java/me/itzg/helpers/curseforge/CurseForgeInstaller.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ public class CurseForgeInstaller {
133133
@Getter @Setter
134134
private ForgeUrlArgs forgeUrlArgs;
135135

136+
@Getter @Setter
137+
int maxConcurrentDownloads;
138+
136139
/**
137140
*/
138141
public void installFromModpackZip(Path modpackZip, String slug) {
@@ -546,6 +549,8 @@ private ModPackResults processModpack(InstallContext context,
546549
final ExcludeIncludeIds excludeIncludeIds = resolveExcludeIncludes(context);
547550
log.debug("Using {}", excludeIncludeIds);
548551

552+
log.debug("Max concurrent downloads is {}", maxConcurrentDownloads);
553+
549554
// Go through all the files listed in modpack (given project ID + file ID)
550555
final List<PathWithInfo> modFiles = Flux.fromIterable(modpackManifest.getFiles())
551556
// ...does the modpack even say it's required?
@@ -577,7 +582,8 @@ private ModPackResults processModpack(InstallContext context,
577582
processFileWithIds(context, outputSubdirResolver,
578583
excludeIncludeIds.getForceIncludeIds(), fileRef.getProjectID(), fileRef.getFileID()
579584
)
580-
.checkpoint()
585+
.checkpoint(),
586+
maxConcurrentDownloads > 0 ? maxConcurrentDownloads : 10
581587
)
582588
.collectList()
583589
.block();

src/main/java/me/itzg/helpers/curseforge/InstallCurseForgeCommand.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ static class Listed {
171171
@ArgGroup(exclusive = false)
172172
ForgeUrlArgs forgeUrlArgs = new ForgeUrlArgs();
173173

174+
@Option(names = {"--max-concurrent-downloads"}, defaultValue = "${env:CF_MAX_CONCURRENT_DOWNLOADS:-10}",
175+
description = "Default is ${DEFAULT-VALUE}"
176+
)
177+
int maxConcurrentDownloads;
178+
174179
@Override
175180
public Integer call() throws Exception {
176181
// https://www.curseforge.com/minecraft/modpacks/all-the-mods-8/files
@@ -208,7 +213,8 @@ public Integer call() throws Exception {
208213
.setDownloadsRepo(downloadsRepo)
209214
.setDisableApiCaching(disableApiCaching)
210215
.setCacheArgs(cacheArgs)
211-
.setForgeUrlArgs(forgeUrlArgs);
216+
.setForgeUrlArgs(forgeUrlArgs)
217+
.setMaxConcurrentDownloads(maxConcurrentDownloads);
212218

213219
if (apiBaseUrl != null) {
214220
installer.setApiBaseUrl(apiBaseUrl);

src/main/java/me/itzg/helpers/modrinth/InstallModrinthModpackCommand.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ public class InstallModrinthModpackCommand implements Callable<Integer> {
121121
@ArgGroup(exclusive = false)
122122
ForgeUrlArgs forgeUrlArgs = new ForgeUrlArgs();
123123

124+
@Option(names = {"--max-concurrent-downloads"}, defaultValue = "${env:MODRINTH_MAX_CONCURRENT_DOWNLOADS:-10}",
125+
description = "Can also set env var MODRINTH_MAX_CONCURRENT_DOWNLOADS%n"
126+
+ "Default is ${DEFAULT-VALUE}"
127+
)
128+
int maxConcurrentDownloads = 1;
129+
124130
@Override
125131
public Integer call() throws IOException {
126132

@@ -154,6 +160,7 @@ public Integer call() throws IOException {
154160
)
155161
)
156162
.setOverridesExclusions(overridesExclusions)
163+
.setMaxConcurrentDownloads(maxConcurrentDownloads)
157164
.processModpack(sharedFetch)
158165
.flatMap(installation -> {
159166
if (resultsFile != null) {

src/main/java/me/itzg/helpers/modrinth/ModrinthPackInstaller.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.stream.Collectors;
1414
import java.util.stream.Stream;
1515
import java.util.zip.ZipFile;
16+
import lombok.Getter;
1617
import lombok.Setter;
1718
import lombok.extern.slf4j.Slf4j;
1819
import me.itzg.helpers.errors.GenericException;
@@ -46,8 +47,10 @@ public class ModrinthPackInstaller {
4647
private final boolean forceModloaderReinstall;
4748
private final FileInclusionCalculator fileInclusionCalculator;
4849
private final Options sharedFetchOpts;
49-
@Setter
50+
@Setter @Getter
5051
private ForgeUrlArgs forgeUrlArgs = new ForgeUrlArgs();
52+
@Setter @Getter
53+
private int maxConcurrentDownloads = 1;
5154

5255
private AntPathMatcher overridesExclusions;
5356

@@ -169,7 +172,7 @@ private Flux<Path> processModFiles(ModpackIndex modpackIndex) {
169172
(uri, file, contentSizeBytes) ->
170173
log.info("Downloaded {}", modpackFilePath)
171174
);
172-
});
175+
}, maxConcurrentDownloads);
173176
}
174177

175178
@SuppressWarnings("SameParameterValue")

0 commit comments

Comments
 (0)