diff --git a/patchwork.md b/patchwork.md index aead31369..40372bb64 100644 --- a/patchwork.md +++ b/patchwork.md @@ -619,3 +619,9 @@ b90611b4b4c176ec1c80df002cc4ac36aa0c4dc8 Preserve registration order of upgrades ``` Again, a huge diff because of code style changes. + +``` +8494ba8ce29cd8d7b9105eef497fe3fe3f89d350 + +Improve UX when a resource mount cannot be found +``` diff --git a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java index 7a7de9cb7..4868de353 100644 --- a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java +++ b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java @@ -108,7 +108,10 @@ public final class ComputerCraftAPI { * Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a resource folder onto a computer's file * system. * - * The files in this mount will be a combination of files in all mod jar, and data packs that contain resources with the same domain and path. + * The files in this mount will be a combination of files in all mod jar, and data packs that contain + * resources with the same domain and path. For instance, ComputerCraft's resources are stored in + * "/data/computercraft/lua/rom". We construct a mount for that with + * {@code createResourceMount("computercraft", "lua/rom")}. * * @param domain The domain under which to look for resources. eg: "mymod". * @param subPath The subPath under which to look for resources. eg: "lua/myfiles". diff --git a/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java b/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java index a9f2b243c..e767525b6 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java @@ -90,19 +90,30 @@ public final class ResourceMount implements IMount { private void load() { boolean hasAny = false; - FileEntry newRoot = new FileEntry(new Identifier(this.namespace, this.subPath)); - for (Identifier file : this.manager.findResources(this.subPath, s -> true)) { - if (!file.getNamespace() - .equals(this.namespace)) { - continue; - } + String existingNamespace = null; + + FileEntry newRoot = new FileEntry( new Identifier( namespace, subPath ) ); + for( Identifier file : manager.findResources( subPath, s -> true ) ) + { + existingNamespace = file.getNamespace(); + + if( !file.getNamespace().equals( namespace ) ) continue; String localPath = FileSystem.toLocal(file.getPath(), this.subPath); this.create(newRoot, localPath); hasAny = true; } - this.root = hasAny ? newRoot : null; + root = hasAny ? newRoot : null; + + if( !hasAny ) + { + ComputerCraft.log.warn("Cannot find any files under /data/{}/{} for resource mount.", namespace, subPath); + if( newRoot != null ) + { + ComputerCraft.log.warn("There are files under /data/{}/{} though. Did you get the wrong namespace?", existingNamespace, subPath); + } + } } private void create(FileEntry lastEntry, String path) {