1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-31 01:27:55 +00:00

Improve UX when a resource mount cannot be found

- Add a full example of the docs. Hopefully is a little more explicit.
 - Print a warning when the mount is empty.

Closes #762
This commit is contained in:
Jonathan Coates
2021-04-13 13:01:28 +01:00
committed by Jummit
parent d955443b21
commit 46846a4fde
3 changed files with 28 additions and 8 deletions

View File

@@ -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
```

View File

@@ -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".

View File

@@ -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) {