Skip to content

Commit

Permalink
Merge pull request #2457 from fayer3/file-capitalization-check-2
Browse files Browse the repository at this point in the history
fix capitalization check for zipped shaders
  • Loading branch information
IMS212 authored Sep 9, 2024
2 parents 162de47 + 1b933b5 commit 747b9b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 3 additions & 1 deletion common/src/main/java/net/irisshaders/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ private static boolean loadExternalShaderpack(String name) {
}

Path shaderPackPath;
boolean isZip = false;

if (!Files.isDirectory(shaderPackRoot) && shaderPackRoot.toString().endsWith(".zip")) {
Optional<Path> optionalPath;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public class ShaderPack {
private final List<String> dimensionIds;
private Map<NamespacedId, String> dimensionMap;

public ShaderPack(Path root, ImmutableList<StringPair> environmentDefines) throws IOException, IllegalStateException {
this(root, Collections.emptyMap(), environmentDefines);
public ShaderPack(Path root, ImmutableList<StringPair> environmentDefines, boolean isZip) throws IOException, IllegalStateException {
this(root, Collections.emptyMap(), environmentDefines, isZip);
}

/**
Expand All @@ -99,7 +99,7 @@ public ShaderPack(Path root, ImmutableList<StringPair> 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<String, String> changedConfigs, ImmutableList<StringPair> environmentDefines) throws IOException, IllegalStateException {
public ShaderPack(Path root, Map<String, String> changedConfigs, ImmutableList<StringPair> environmentDefines, boolean isZip) throws IOException, IllegalStateException {
// A null path is not allowed.
Objects.requireNonNull(root);

Expand Down Expand Up @@ -149,7 +149,7 @@ public ShaderPack(Path root, Map<String, String> changedConfigs, ImmutableList<S
}

// Read all files and included files recursively
IncludeGraph graph = new IncludeGraph(root, starts.build());
IncludeGraph graph = new IncludeGraph(root, starts.build(), isZip);

if (!graph.getFailures().isEmpty()) {
throw new IOException(String.join("\n", graph.getFailures().values().stream().map(RusticError::toString).toArray(String[]::new)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private IncludeGraph(ImmutableMap<AbsolutePackPath, FileNode> nodes,
this.failures = failures;
}

public IncludeGraph(Path root, ImmutableList<AbsolutePackPath> startingPaths) {
public IncludeGraph(Path root, ImmutableList<AbsolutePackPath> startingPaths, boolean isZip) {
Map<AbsolutePackPath, AbsolutePackPath> cameFrom = new HashMap<>();
Map<AbsolutePackPath, Integer> lineNumberInclude = new HashMap<>();

Expand All @@ -81,9 +81,15 @@ public IncludeGraph(Path root, ImmutableList<AbsolutePackPath> 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) {
Expand Down

0 comments on commit 747b9b8

Please sign in to comment.