diff --git a/Launcher/src/main/java/pro/gravit/launcher/runtime/backend/LauncherBackendImpl.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/backend/LauncherBackendImpl.java index 691a295b..e2c19626 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/runtime/backend/LauncherBackendImpl.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/backend/LauncherBackendImpl.java @@ -415,6 +415,9 @@ public Path initVfsDirectory() { } } } + if(LogHelper.isDevEnabled()) { + Vfs.get().debugPrint(LogHelper.Level.DEV); + } return defaultPath; } } diff --git a/Launcher/src/main/java/pro/gravit/launcher/runtime/backend/ResourceLayerImpl.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/backend/ResourceLayerImpl.java index 6aa50a16..751de58a 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/runtime/backend/ResourceLayerImpl.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/backend/ResourceLayerImpl.java @@ -4,11 +4,13 @@ import pro.gravit.launcher.base.vfs.VfsDirectory; import pro.gravit.launcher.base.vfs.directory.OverlayVfsDirectory; import pro.gravit.launcher.core.backend.LauncherBackendAPI; +import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; import java.io.IOException; import java.net.URL; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Stream; @@ -21,14 +23,23 @@ public ResourceLayerImpl(Path basePath, List overlayList) { vfsPath = basePath; return; } - List overlays = Stream.concat(overlayList.stream(), Stream.of(Path.of(""))) - .map(basePath::resolve) - .map(x -> (VfsDirectory) Vfs.get().resolve(x)) - .filter(Objects::nonNull) - .toList(); + List overlays = new ArrayList<>(); + overlays.add((VfsDirectory) Vfs.get().resolve(basePath)); + for(var e : overlayList) { + var dir = (VfsDirectory) Vfs.get().resolve(basePath.resolve(e)); + if(dir != null) { + overlays.add(dir); + } + } OverlayVfsDirectory directory = new OverlayVfsDirectory(overlays); String randomName = SecurityHelper.randomStringToken(); vfsPath = Path.of(randomName); + if(LogHelper.isDevEnabled()) { + LogHelper.dev("Make overlay %s from %s", vfsPath, basePath); + for(var e : overlays) { + LogHelper.dev("Layer %s", e.getClass().getSimpleName()); + } + } Vfs.get().put(vfsPath, directory); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/vfs/Vfs.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/vfs/Vfs.java index 992ca4fb..7c94e651 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/vfs/Vfs.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/vfs/Vfs.java @@ -3,6 +3,7 @@ import pro.gravit.launcher.base.vfs.directory.SimpleVfsDirectory; import pro.gravit.launcher.base.vfs.protocol.vfs.VfsURLStreamHandlerProvider; +import pro.gravit.utils.helper.LogHelper; import java.io.FileNotFoundException; import java.io.IOException; @@ -17,6 +18,7 @@ public class Vfs { private final VfsDirectory directory; + private volatile String name; private static final Map map = new HashMap<>(); private static final Vfs defaultImpl = new Vfs(); static { @@ -36,8 +38,33 @@ public VfsEntry resolve(Path path) { return directory.resolve(path); } + public VfsEntry createDirectories(Path path) { + VfsDirectory current = directory; + for(int i=0;i paths = List.of( + Path.of("test/testfile.txt"), + Path.of("test/dir/testfile2.txt") + ); + Map testPaths = new HashMap<>(); + for(var path : paths) { + var file = new UrlVfsFile(URI.create("https://example.com").toURL()); + Vfs.get().put(path, file); + testPaths.put(path, file); + } + for(var path : testPaths.entrySet()) { + Assertions.assertSame(Vfs.get().resolve(path.getKey()), path.getValue()); + } + } + + @Test + public void testVfsWithOverlay() throws Exception { + List paths = List.of( + Path.of("test/testfile.txt"), + Path.of("test/dir/testfile2.txt") + ); + Path prefix = Path.of("base"); + Map testPaths = new HashMap<>(); + for(var path : paths) { + var file = new UrlVfsFile(URI.create("https://example.com").toURL()); + Vfs.get().put(prefix.resolve(path), file); + testPaths.put(path, file); + } + Path overlayPrefix = Path.of("oveerlay"); + OverlayVfsDirectory vfsDirectory = new OverlayVfsDirectory(List.of((VfsDirectory) Vfs.get().resolve(prefix))); + Vfs.get().put(overlayPrefix, vfsDirectory); + for(var path : testPaths.entrySet()) { + Assertions.assertSame(Vfs.get().resolve(overlayPrefix.resolve(path.getKey())), path.getValue()); + } + } +}