Skip to content

Commit

Permalink
Fix quilt mod discarding hash from superclass, checking bundled mods (#…
Browse files Browse the repository at this point in the history
…552)

- Fix hash checking sometimes disregarded on Quilt
  • Loading branch information
LostLuma authored and Prospector committed Feb 17, 2023
1 parent 8d0d20f commit b008e08
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.Lists;
import com.google.common.hash.Hashing;
import com.google.common.io.Files;
import com.terraformersmc.modmenu.util.ModrinthUtil;
import com.terraformersmc.modmenu.util.mod.fabric.FabricMod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -12,6 +13,8 @@
import org.quiltmc.loader.api.QuiltLoader;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -66,18 +69,22 @@ public QuiltMod(net.fabricmc.loader.api.ModContainer fabricModContainer, Set<Str
public @Nullable String getSha512Hash() throws IOException {
var fabricResult = super.getSha512Hash();
if (fabricResult == null) {
if (container.getSourceType().equals(ModContainer.BasicSourceType.NORMAL_QUILT)) {
var path = container.getSourcePaths().stream()
.filter(p -> p.stream().anyMatch(p2 -> p2.toString().toLowerCase(Locale.ROOT).endsWith(".jar"))).findFirst().orElse(Collections.emptyList())
.stream().filter(p -> p.toString().toLowerCase(Locale.ROOT).endsWith(".jar")).findFirst();
if (path.isPresent()) {
var file = path.get().toFile();
if (file.isFile()) {
return Files.asByteSource(file).hash(Hashing.sha512()).toString();
ModrinthUtil.LOGGER.debug("Checking {}", getId());
if (container.getSourceType().equals(ModContainer.BasicSourceType.NORMAL_QUILT) || container.getSourceType().equals(ModContainer.BasicSourceType.NORMAL_FABRIC)) {
for (var paths : container.getSourcePaths()) {
List<Path> jars = paths.stream().filter(p -> p.toString().toLowerCase(Locale.ROOT).endsWith(".jar")).toList();

if (jars.size() == 1 && jars.get(0).getFileSystem() == FileSystems.getDefault()) {
var file = jars.get(0).toFile();

if (file.exists()) {
ModrinthUtil.LOGGER.debug("Found {} hash", getId());
return Files.asByteSource(file).hash(Hashing.sha512()).toString();
}
}
}
}
}
return null;
return fabricResult;
}
}

0 comments on commit b008e08

Please sign in to comment.