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
12 changes: 10 additions & 2 deletions common/src/main/java/com/adamcalculator/dynamicpack/PackUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static String readString(Path path) throws IOException {
return Files.readString(path, StandardCharsets.UTF_8);
}

public static void openPackFileSystem(File pack, Consumer<Path> consumer) throws IOException {
public static void openPackFileSystem(File pack, Consumer<Path> consumer) throws Exception {
if (!pack.exists()) {
throw new FileNotFoundException(pack.getCanonicalPath());
}
Expand All @@ -52,8 +52,16 @@ public static void openPackFileSystem(File pack, Consumer<Path> consumer) throws
env.put("create", "true");

URI uri = URI.create("jar:" + pack.toPath().toUri());
Exception ex = null;
try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {
consumer.accept(fs.getPath(""));
try {
consumer.accept(fs.getPath(""));
} catch (Exception e) {
ex = e;
}
}
if (ex != null) {
throw ex;
}

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public String getCurrentPackContentHash(String id) {


@Override
public boolean sync(PackSyncProgress progress, boolean manually) throws IOException {
public boolean sync(PackSyncProgress progress, boolean manually) throws Exception {
AtomicBoolean returnValue = new AtomicBoolean(false);
PackUtil.openPackFileSystem(parent.getLocation(), path -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public boolean checkUpdateAvailable() throws IOException {
}

@Override
public boolean sync(PackSyncProgress progress, boolean manually) throws IOException {
public boolean sync(PackSyncProgress progress, boolean manually) throws Exception {
progress.textLog("getting latest version on modrinth...");
ModrinthRemote.LatestModrinthVersion latest = getLatest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ public void sync(PackSyncProgress progress, boolean manually) throws Exception {
setLatestException(null);
} catch (Exception e) {
isSyncing = false;
checkSafePackMinecraftMeta();
setLatestException(e);
try {
checkSafePackMinecraftMeta();
} catch (Exception e2) {
Out.error("Error while check safe pack meta", e);
}
throw e;
}
}
Expand Down Expand Up @@ -144,7 +148,7 @@ private void checkNetwork() {
}
}

private void checkSafePackMinecraftMeta() throws IOException {
private void checkSafePackMinecraftMeta() throws Exception {
PackUtil.openPackFileSystem(location, path -> {
Path mcmeta = path.resolve(DynamicPackModBase.MINECRAFT_META);
boolean safe = PackUtil.isPathFileExists(mcmeta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.json.JSONObject;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.function.Supplier;

Expand All @@ -28,5 +27,5 @@ public static void initRemoteTypes() {

public abstract boolean checkUpdateAvailable() throws IOException;

public abstract boolean sync(PackSyncProgress progress, boolean manually) throws IOException, NoSuchAlgorithmException;
public abstract boolean sync(PackSyncProgress progress, boolean manually) throws Exception;
}
2 changes: 1 addition & 1 deletion common/src/test/java/tests/PackUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class PackUtilTest {
@Test
public void test() throws IOException {
public void test() throws Exception {
PackUtil.openPackFileSystem(new File("tests_files/filedir"), new Consumer<Path>() {
@Override
public void accept(Path path) {
Expand Down