Fix crash introduced in previous zip related changes.

This commit is contained in:
modmuss50
2022-06-20 20:13:03 +01:00
parent e422dab784
commit 0460f0d618
3 changed files with 13 additions and 4 deletions

View File

@@ -72,15 +72,15 @@ public final class FileSystemUtil {
}
public static Delegate getJarFileSystem(File file, boolean create) throws IOException {
return getJarFileSystem(file.toURI(), create);
return new Delegate(FileSystemReference.openJar(file.toPath(), create));
}
public static Delegate getJarFileSystem(Path path, boolean create) throws IOException {
return getJarFileSystem(path.toUri(), create);
return new Delegate(FileSystemReference.openJar(path, create));
}
public static Delegate getJarFileSystem(Path path) throws IOException {
return getJarFileSystem(path, false);
return new Delegate(FileSystemReference.openJar(path));
}
public static Delegate getJarFileSystem(URI uri, boolean create) throws IOException {

View File

@@ -47,7 +47,7 @@ public final class ModUtils {
@Nullable
public static JsonObject getFabricModJson(Path path) {
try {
return ZipUtils.unpackGson(path, "fabric.mod.json", JsonObject.class);
return ZipUtils.unpackGsonNullable(path, "fabric.mod.json", JsonObject.class);
} catch (IOException e) {
throw new UncheckedIOException("Failed to extract fabric.mod.json from " + path, e);
}

View File

@@ -112,6 +112,15 @@ public class ZipUtils {
return LoomGradlePlugin.GSON.fromJson(new String(bytes, StandardCharsets.UTF_8), clazz);
}
@Nullable
public static <T> T unpackGsonNullable(Path zip, String path, Class<T> clazz) throws IOException {
try {
return unpackGson(zip, path, clazz);
} catch (NoSuchFileException e) {
return null;
}
}
public static <T> T unpackJackson(Path zip, String path, Class<T> clazz) throws IOException {
final byte[] bytes = unpack(zip, path);
return LoomGradlePlugin.OBJECT_MAPPER.readValue(new String(bytes, StandardCharsets.UTF_8), clazz);