Skip to content

Commit

Permalink
Added clearer error when mod zip is missing inner directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilka2 committed Dec 31, 2022
1 parent f5c9381 commit 7165867
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions FactorioDataWrapper/src/com/demod/factorio/ModLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,18 @@ public Optional<InputStream> getResource(String path) throws FileNotFoundExcepti
}
}
}

public static class ModZip implements Mod {
private static String stripDirectoryName(String name) throws RuntimeException {
int firstSlash = name.indexOf('/');
if (firstSlash == -1) {
return name;
}
return name.substring(firstSlash);
}

private final Map<String, byte[]> files = new LinkedHashMap<>();

private ModInfo info;

private volatile Optional<String> lastResourceFolder = Optional.empty();
Expand All @@ -66,6 +76,9 @@ public ModZip(File file) throws FileNotFoundException, IOException {
try (ZipFile zipFile = new ZipFile(file)) {
zipFile.stream().forEach(entry -> {
String name = stripDirectoryName(entry.getName());
if (name.equals(entry.getName())) {
throw new RuntimeException(file.getName() + " missing the inner directory for the mod files.");
}

try (InputStream inputStream = zipFile.getInputStream(entry)) {
files.put(name, ByteStreams.toByteArray(inputStream));
Expand All @@ -85,14 +98,6 @@ public ModZip(File file) throws FileNotFoundException, IOException {
}
}

private static String stripDirectoryName(String name) {
int firstSlash = name.indexOf('/');
if (firstSlash == -1) {
return name;
}
return name.substring(firstSlash);
}

@Override
public ModInfo getInfo() {
return info;
Expand Down

0 comments on commit 7165867

Please sign in to comment.