Skip to content

Commit deabd42

Browse files
committed
Add support for modpack zips
1 parent 33ee60f commit deabd42

File tree

3 files changed

+56
-17
lines changed

3 files changed

+56
-17
lines changed

build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group = "com.therandomlabs.changeloggenerator"
2-
version = "2.0.0-pre9"
2+
version = "2.0.0-pre10"
33

44
ext {
55
commonGradleBranch = "master"
@@ -24,12 +24,11 @@ dependencies {
2424
api "com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT"
2525
api "com.github.TheRandomLabs:CurseAPI-Minecraft:master-SNAPSHOT"
2626

27-
implementation "info.picocli:picocli:4.6.1"
28-
annotationProcessor "info.picocli:picocli-codegen:4.6.1"
29-
3027
implementation "org.commonmark:commonmark:0.17.1"
28+
implementation "com.github.TheRandomLabs:TRLUtils-IO:master-SNAPSHOT"
3129

32-
testImplementation "com.github.TheRandomLabs:TRLUtils-IO:master-SNAPSHOT"
30+
implementation "info.picocli:picocli:4.6.1"
31+
annotationProcessor "info.picocli:picocli-codegen:4.6.1"
3332
}
3433

3534
compileJava {

src/main/java/com/therandomlabs/changeloggenerator/ChangelogGeneratorOptions.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,20 @@ public final class ChangelogGeneratorOptions implements Callable<Integer> {
5858
boolean markdown;
5959

6060
@CommandLine.Option(
61-
names = {"-o", "--old-manifest"},
62-
description = "The old modpack manifest. \"old.json\" by default."
61+
names = {"-o", "--old"},
62+
description = "The old modpack or modpack manifest. " +
63+
"\"old.json\" or \"old.zip\" by default."
6364
)
6465
@Nullable
65-
Path oldManifest;
66+
Path oldModpack;
6667

6768
@CommandLine.Option(
68-
names = {"-n", "--new-manifest"},
69-
description = "The new modpack manifest. \"new.json\" by default."
69+
names = {"-n", "--new"},
70+
description = "The new modpack or modpack manifest. " +
71+
"\"new.json\" or \"new.zip\" by default."
7072
)
7173
@Nullable
72-
Path newManifest;
74+
Path newModpack;
7375

7476
@CommandLine.Option(
7577
names = {"-O", "--output"},

src/main/java/com/therandomlabs/changeloggenerator/Main.java

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323

2424
package com.therandomlabs.changeloggenerator;
2525

26+
import java.io.IOException;
27+
import java.nio.file.Files;
2628
import java.nio.file.Path;
2729
import java.nio.file.Paths;
2830

2931
import com.therandomlabs.curseapi.minecraft.modpack.CurseModpack;
32+
import com.therandomlabs.utils.io.ZipFile;
3033
import okio.BufferedSink;
3134
import okio.Okio;
3235
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -55,6 +58,7 @@ public static void main(String[] args) {
5558
System.exit(commandLine.execute(args));
5659
}
5760

61+
@SuppressWarnings({"ConstantConditions", "NullAway"})
5862
private static Integer run() throws Exception {
5963
if (options == null) {
6064
throw new IllegalStateException("options should not be null");
@@ -74,20 +78,54 @@ private static Integer run() throws Exception {
7478
return 1;
7579
}
7680

77-
if (options.oldManifest == null) {
78-
options.oldManifest = Paths.get("old.json");
81+
if (options.oldModpack == null) {
82+
options.oldModpack = Paths.get("old.json");
83+
84+
if (!Files.exists(options.oldModpack)) {
85+
final Path zip = Paths.get("old.zip");
86+
87+
if (Files.exists(zip)) {
88+
options.oldModpack = zip;
89+
}
90+
}
91+
}
92+
93+
if (options.oldModpack.getFileName().toString().endsWith(".zip")) {
94+
try {
95+
options.oldModpack = new ZipFile(options.oldModpack).getEntry("manifest.json");
96+
} catch (IOException ex) {
97+
System.err.println("Invalid zip file: " + options.oldModpack);
98+
return 1;
99+
}
100+
}
101+
102+
if (options.newModpack == null) {
103+
options.newModpack = Paths.get("new.json");
104+
105+
if (!Files.exists(options.newModpack)) {
106+
final Path zip = Paths.get("new.zip");
107+
108+
if (Files.exists(zip)) {
109+
options.newModpack = zip;
110+
}
111+
}
79112
}
80113

81-
if (options.newManifest == null) {
82-
options.newManifest = Paths.get("new.json");
114+
if (options.newModpack.getFileName().toString().endsWith(".zip")) {
115+
try {
116+
options.newModpack = new ZipFile(options.newModpack).getEntry("manifest.json");
117+
} catch (IOException ex) {
118+
System.err.println("Invalid zip file: " + options.newModpack);
119+
return 1;
120+
}
83121
}
84122

85123
if (options.output == null) {
86124
options.output = Paths.get(options.markdown ? "changelog.md" : "changelog.txt");
87125
}
88126

89-
final CurseModpack oldModpack = CurseModpack.fromJSON(options.oldManifest);
90-
final CurseModpack newModpack = CurseModpack.fromJSON(options.newManifest);
127+
final CurseModpack oldModpack = CurseModpack.fromJSON(options.oldModpack);
128+
final CurseModpack newModpack = CurseModpack.fromJSON(options.newModpack);
91129
final ChangelogGenerator generator = options.markdown ?
92130
new MarkdownChangelogGenerator(options) : new BasicChangelogGenerator(options);
93131
final String changelog = generator.generate(oldModpack, newModpack);

0 commit comments

Comments
 (0)