Skip to content

Commit

Permalink
fix(serializer-minecraft): make unknown file paths relative to the co…
Browse files Browse the repository at this point in the history
…ntainer's path when deserializing
  • Loading branch information
yusshu committed Oct 7, 2023
1 parent b651ff7 commit 739db5f
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public ResourcePack read(FileTreeReader reader) {
// but it may change if the file is inside an overlay folder
@Subst("dir")
@Nullable String overlayDir = null;

// the file path, relative to the container
String containerPath = path;
ResourceContainer container = resourcePack;

// if there are two or more tokens, it means the
Expand All @@ -127,7 +130,7 @@ public ResourcePack read(FileTreeReader reader) {
if (tokens.isEmpty()) {
// this means that there is a file directly
// inside the "overlays" folder, this is illegal
resourcePack.unknownFile(path, writableFromInputStreamCopy(input));
resourcePack.unknownFile(containerPath, writableFromInputStreamCopy(input));
continue;
}

Expand All @@ -140,12 +143,13 @@ public ResourcePack read(FileTreeReader reader) {

container = overlay;
folder = tokens.poll();
containerPath = path.substring((OVERLAYS_FOLDER + '/' + overlayDir + '/').length());
}

// null check to make ide happy
if (folder == null || !folder.equals(ASSETS_FOLDER) || tokens.isEmpty()) {
// not assets! this is an unknown file
container.unknownFile(path, writableFromInputStreamCopy(input));
container.unknownFile(containerPath, writableFromInputStreamCopy(input));
continue;
}

Expand All @@ -155,14 +159,14 @@ public ResourcePack read(FileTreeReader reader) {

if (!Keys.isValidNamespace(namespace)) {
// invalid namespace found
container.unknownFile(path, writableFromInputStreamCopy(input));
container.unknownFile(containerPath, writableFromInputStreamCopy(input));
continue;
}

if (tokens.isEmpty()) {
// found a file directly inside "assets", like
// assets/<file>, it is not allowed
container.unknownFile(path, writableFromInputStreamCopy(input));
container.unknownFile(containerPath, writableFromInputStreamCopy(input));
continue;
}

Expand All @@ -184,7 +188,7 @@ public ResourcePack read(FileTreeReader reader) {
continue;
} else {
// TODO: gpu_warnlist.json?
container.unknownFile(path, writableFromInputStreamCopy(input));
container.unknownFile(containerPath, writableFromInputStreamCopy(input));
continue;
}
}
Expand Down Expand Up @@ -254,7 +258,7 @@ public ResourcePack read(FileTreeReader reader) {

// unknown category or
// file inside category had a wrong extension
container.unknownFile(path, writableFromInputStreamCopy(input));
container.unknownFile(containerPath, writableFromInputStreamCopy(input));
}

for (Map.Entry<String, Map<Key, Texture>> entry : incompleteTextures.entrySet()) {
Expand Down

0 comments on commit 739db5f

Please sign in to comment.