2323
2424package com .therandomlabs .changeloggenerator ;
2525
26+ import java .io .IOException ;
27+ import java .nio .file .Files ;
2628import java .nio .file .Path ;
2729import java .nio .file .Paths ;
2830
2931import com .therandomlabs .curseapi .minecraft .modpack .CurseModpack ;
32+ import com .therandomlabs .utils .io .ZipFile ;
3033import okio .BufferedSink ;
3134import okio .Okio ;
3235import 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