From 1b933b538e2b009d73dff2b1421536991db5f7ce Mon Sep 17 00:00:00 2001 From: fayer3 Date: Mon, 9 Sep 2024 22:28:19 +0200 Subject: [PATCH] fix error with path check of non base dir zips, and folders with symbolic links --- .../src/main/java/net/irisshaders/iris/Iris.java | 4 +++- .../irisshaders/iris/shaderpack/ShaderPack.java | 8 ++++---- .../iris/shaderpack/include/IncludeGraph.java | 14 ++++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/net/irisshaders/iris/Iris.java b/common/src/main/java/net/irisshaders/iris/Iris.java index b8e0a0e0bc..9f79df47a6 100644 --- a/common/src/main/java/net/irisshaders/iris/Iris.java +++ b/common/src/main/java/net/irisshaders/iris/Iris.java @@ -254,6 +254,7 @@ private static boolean loadExternalShaderpack(String name) { } Path shaderPackPath; + boolean isZip = false; if (!Files.isDirectory(shaderPackRoot) && shaderPackRoot.toString().endsWith(".zip")) { Optional optionalPath; @@ -281,6 +282,7 @@ private static boolean loadExternalShaderpack(String name) { logger.error("Could not load the shaderpack \"{}\" because it appears to lack a \"shaders\" directory", name); return false; } + isZip = true; } else { if (!Files.exists(shaderPackRoot)) { logger.error("Failed to load the shaderpack \"{}\" because it does not exist!", name); @@ -309,7 +311,7 @@ private static boolean loadExternalShaderpack(String name) { resetShaderPackOptions = false; try { - currentPack = new ShaderPack(shaderPackPath, changedConfigs, StandardMacros.createStandardEnvironmentDefines()); + currentPack = new ShaderPack(shaderPackPath, changedConfigs, StandardMacros.createStandardEnvironmentDefines(), isZip); MutableOptionValues changedConfigsValues = currentPack.getShaderPackOptions().getOptionValues().mutableCopy(); diff --git a/common/src/main/java/net/irisshaders/iris/shaderpack/ShaderPack.java b/common/src/main/java/net/irisshaders/iris/shaderpack/ShaderPack.java index 426d70d02b..559ae0e0d4 100644 --- a/common/src/main/java/net/irisshaders/iris/shaderpack/ShaderPack.java +++ b/common/src/main/java/net/irisshaders/iris/shaderpack/ShaderPack.java @@ -87,8 +87,8 @@ public class ShaderPack { private final List dimensionIds; private Map dimensionMap; - public ShaderPack(Path root, ImmutableList environmentDefines) throws IOException, IllegalStateException { - this(root, Collections.emptyMap(), environmentDefines); + public ShaderPack(Path root, ImmutableList environmentDefines, boolean isZip) throws IOException, IllegalStateException { + this(root, Collections.emptyMap(), environmentDefines, isZip); } /** @@ -99,7 +99,7 @@ public ShaderPack(Path root, ImmutableList environmentDefines) throw * have completed, and there is no need to hold on to the path for that reason. * @throws IOException if there are any IO errors during shader pack loading. */ - public ShaderPack(Path root, Map changedConfigs, ImmutableList environmentDefines) throws IOException, IllegalStateException { + public ShaderPack(Path root, Map changedConfigs, ImmutableList environmentDefines, boolean isZip) throws IOException, IllegalStateException { // A null path is not allowed. Objects.requireNonNull(root); @@ -149,7 +149,7 @@ public ShaderPack(Path root, Map changedConfigs, ImmutableList nodes, this.failures = failures; } - public IncludeGraph(Path root, ImmutableList startingPaths) { + public IncludeGraph(Path root, ImmutableList startingPaths, boolean isZip) { Map cameFrom = new HashMap<>(); Map lineNumberInclude = new HashMap<>(); @@ -81,9 +81,15 @@ public IncludeGraph(Path root, ImmutableList startingPaths) { try { Path p = next.resolved(root); - if (Iris.getIrisConfig().areDebugOptionsEnabled() && root.isAbsolute() && !p.toAbsolutePath().toString().equals(p.toFile().getCanonicalPath())) { - throw new FileIncludeException("'" + next.getPathString() + "' doesn't exist, did you mean '" + - root.relativize(p.toFile().getCanonicalFile().toPath()).toString().replace("\\", "/") + "'?"); + if (Iris.getIrisConfig().areDebugOptionsEnabled() && !isZip) { + String absolute = p.toAbsolutePath().toString().replace("\\", "/"); + absolute = absolute.substring(absolute.lastIndexOf("shaders/") + 8); + + String canonical = p.toFile().getCanonicalPath().replace("\\", "/"); + canonical = canonical.substring(canonical.lastIndexOf("shaders/") + 8); + if (!absolute.equals(canonical)) { + throw new FileIncludeException("'" + next.getPathString() + "' doesn't exist, did you mean '" + canonical + "'?"); + } } source = readFile(p); } catch (IOException e) {