Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,23 @@ Download a file
### install-curseforge

```
Usage: mc-image-helper install-curseforge [-h] [--file-id=<fileId>]
[--filename-matcher=STR] [--modpack-page-url=URL]
[--output-directory=DIR] [--results-file=FILE] [--slug=<slug>]
[--exclude-mods=PROJECT_ID[Whitespace or commasPROJECT_ID...]]...
Usage: mc-image-helper install-curseforge [-h] [--force-synchronize]
[--file-id=<fileId>] [--filename-matcher=STR] [--modpack-page-url=URL]
[--output-directory=DIR] [--parallel-downloads=<parallelDownloads>]
[--results-file=FILE] [--slug=<slug>] [--exclude-mods=PROJECT_ID
[Whitespace or commasPROJECT_ID...]]... [--force-include-mods=PROJECT_ID
[Whitespace or commasPROJECT_ID...]]...
--exclude-mods=PROJECT_ID[Whitespace or commasPROJECT_ID...]
For mods that need to be excluded from server
deployments, such as those that don't label as
client
--file-id=<fileId>
--filename-matcher=STR
Substring to select specific modpack filename
--force-include-mods=PROJECT_ID[Whitespace or commasPROJECT_ID...]
Some mods incorrectly declare client-only support,
but still need to be included in a server deploy
--force-synchronize
-h, --help
--modpack-page-url=URL
URL of a modpack page such as https://www.
Expand All @@ -138,6 +144,8 @@ Usage: mc-image-helper install-curseforge [-h] [--file-id=<fileId>]
0
--output-directory=DIR

--parallel-downloads=<parallelDownloads>
Default: 4
--results-file=FILE A key=value file suitable for scripted environment
variables. Currently includes
SERVER: the entry point jar or script
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/me/itzg/helpers/curseforge/CurseForgeInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ public class CurseForgeInstaller {
@Setter
private boolean forceSynchronize;

public void install(String slug, String fileMatcher, Integer fileId, Set<Integer> excludedModIds) throws IOException {
@Getter
@Setter
private Set<Integer> forceIncludeMods = Collections.emptySet();

@Getter
@Setter
private Set<Integer> excludedModIds = Collections.emptySet();

public void install(String slug, String fileMatcher, Integer fileId) throws IOException {
requireNonNull(outputDir, "outputDir is required");
requireNonNull(slug, "slug is required");

Expand All @@ -79,16 +87,13 @@ else if (searchResponse.getData().size() > 1) {
throw new GenericException("More than one mod found with slug={}" + slug);
}
else {
processMod(preparedFetch, uriBuilder, searchResponse.getData().get(0), fileId, fileMatcher,
excludedModIds != null ? excludedModIds : Collections.emptySet()
);
processMod(preparedFetch, uriBuilder, searchResponse.getData().get(0), fileId, fileMatcher);
}
}
}

private void processMod(SharedFetch preparedFetch, UriBuilder uriBuilder, CurseForgeMod mod, Integer fileId,
String fileMatcher,
Set<Integer> excludedModIds
String fileMatcher
)
throws IOException {

Expand Down Expand Up @@ -123,8 +128,7 @@ else if (Manifests.allFilesPresent(outputDir, manifest)) {

log.info("Processing modpack {} @ {}:{}", modFile.getDisplayName(), modFile.getModId(), modFile.getId());
final List<Path> installedFiles = processModpackFile(preparedFetch, uriBuilder,
normalizeDownloadUrl(modFile.getDownloadUrl()),
excludedModIds
normalizeDownloadUrl(modFile.getDownloadUrl())
);

final CurseForgeManifest newManifest = CurseForgeManifest.builder()
Expand Down Expand Up @@ -176,8 +180,7 @@ private static URI normalizeDownloadUrl(String downloadUrl) {
);
}

private List<Path> processModpackFile(SharedFetch preparedFetch, UriBuilder uriBuilder, URI downloadUrl,
Set<Integer> excludedModIds
private List<Path> processModpackFile(SharedFetch preparedFetch, UriBuilder uriBuilder, URI downloadUrl
)
throws IOException {
final Path downloaded = Files.createTempFile("curseforge-modpack", "zip");
Expand Down Expand Up @@ -257,7 +260,7 @@ private Mono<Path> downloadModFile(SharedFetch preparedFetch, UriBuilder uriBuil
file.getFileName(),
projectID, fileID
);
if (!isServerMod(file)) {
if (!forceIncludeMods.contains(projectID) && !isServerMod(file)) {
log.debug("Skipping {} since it is a client mod", file.getFileName());
return Mono.empty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.itzg.helpers.curseforge;

import java.nio.file.Path;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -39,6 +40,12 @@ public class InstallCurseForgeCommand implements Callable<Integer> {
)
Set<Integer> excludedModIds;

@Option(names = "--force-include-mods", paramLabel = "PROJECT_ID",
split = "\\s+|,", splitSynopsisLabel = "Whitespace or commas",
description = "Some mods incorrectly declare client-only support, but still need to be included in a server deploy"
)
Set<Integer> forceIncludeMods;

@Option(names = "--filename-matcher", paramLabel = "STR",
description = "Substring to select specific modpack filename")
String filenameMatcher;
Expand Down Expand Up @@ -80,10 +87,16 @@ public Integer call() throws Exception {
}

final CurseForgeInstaller installer = new CurseForgeInstaller(outputDirectory, resultsFile)
.setExcludedModIds(nonNullSet(excludedModIds))
.setForceIncludeMods(nonNullSet(forceIncludeMods))
.setForceSynchronize(forceSynchronize)
.setParallelism(parallelDownloads);
installer.install(slug, filenameMatcher, fileId, excludedModIds);
installer.install(slug, filenameMatcher, fileId);

return ExitCode.OK;
}

private static <T> Set<T> nonNullSet(Set<T> in) {
return in != null ? in : Collections.emptySet();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void testManual() throws IOException {
final Path resultsFile = tempDir.resolve(".results.env");

final CurseForgeInstaller installer = new CurseForgeInstaller(tempDir, resultsFile);
installer.install("all-the-mods-8", "1.0.4", null, null);
installer.install("all-the-mods-8", "1.0.4", null);

assertThat(tempDir)
.isNotEmptyDirectory();
Expand Down