diff --git a/src/main/java/com/terraformersmc/modmenu/ModMenu.java b/src/main/java/com/terraformersmc/modmenu/ModMenu.java index c60ce0fb6..196a5f7e6 100644 --- a/src/main/java/com/terraformersmc/modmenu/ModMenu.java +++ b/src/main/java/com/terraformersmc/modmenu/ModMenu.java @@ -50,6 +50,7 @@ public class ModMenu implements ClientModInitializer { private static List>>> dynamicScreenFactories = new ArrayList<>(); private static int cachedDisplayedModCount = -1; + public static boolean runningQuilt = false; public static Screen getConfigScreen(String modid, Screen menuScreen) { if (ModMenuConfig.HIDDEN_CONFIGS.getValue().contains(modid)) { @@ -71,6 +72,7 @@ public static Screen getConfigScreen(String modid, Screen menuScreen) { @Override public void onInitializeClient() { ModMenuConfigManager.initializeConfig(); + runningQuilt = FabricLoader.getInstance().isModLoaded("quilt_loader"); Map> factories = new HashMap<>(); Set modpackMods = new HashSet<>(); FabricLoader.getInstance().getEntrypointContainers("modmenu", ModMenuApi.class).forEach(entrypoint -> { @@ -91,7 +93,7 @@ public void onInitializeClient() { // Fill mods map for (ModContainer modContainer : FabricLoader.getInstance().getAllMods()) { if (!ModMenuConfig.HIDDEN_MODS.getValue().contains(modContainer.getMetadata().getId())) { - if (FabricLoader.getInstance().isModLoaded("quilt_loader")) { + if (ModMenu.runningQuilt) { QuiltMod mod = new QuiltMod(modContainer, modpackMods); MODS.put(mod.getId(), mod); ModrinthUtil.checkForUpdates(mod); diff --git a/src/main/java/com/terraformersmc/modmenu/util/ModrinthUtil.java b/src/main/java/com/terraformersmc/modmenu/util/ModrinthUtil.java index ad1a248c2..bb6e37eb4 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/ModrinthUtil.java +++ b/src/main/java/com/terraformersmc/modmenu/util/ModrinthUtil.java @@ -69,7 +69,7 @@ public class ModrinthUtil { .header("User-Agent", userAgent) .uri(URI.create("https://api.modrinth.com/v2/project/%s/version?loaders=%s&game_versions=%s".formatted( projectId, - URLEncoder.encode("[\"%s\"]".formatted(FabricLoader.getInstance().isModLoaded("quilt_loader") ? "quilt" : "fabric"), StandardCharsets.UTF_8), + URLEncoder.encode("[\"%s\"]".formatted(ModMenu.runningQuilt ? "quilt" : "fabric"), StandardCharsets.UTF_8), URLEncoder.encode("[\"%s\"]".formatted(SharedConstants.getGameVersion().getName()), StandardCharsets.UTF_8) ))) .build(); @@ -80,17 +80,23 @@ public class ModrinthUtil { } else if (latestRsp.statusCode() == 200) { LOGGER.debug("Getting latest version from Modrinth."); var versions = JsonParser.parseString(latestRsp.body()).getAsJsonArray(); - var latestObj = versions.get(0).getAsJsonObject(); - var latestVersion = latestObj.get("version_number").getAsString(); - var latestId = latestObj.get("id").getAsString(); - var latestHash = latestObj.get("files").getAsJsonArray().asList() - .stream().filter(file -> file.getAsJsonObject().get("primary").getAsBoolean()).findFirst() - .get().getAsJsonObject().get("hashes").getAsJsonObject().get("sha512").getAsString(); - if (!Objects.equals(latestHash, localHash)) { - // hashes different, there's an update. - LOGGER.info("Update available for '{}@{}', ({} -> {})", mod.getId(), mod.getVersion(), modrinthVersion, latestVersion); - mod.setModrinthData(new ModrinthData(projectId, latestId, latestVersion)); - ModMenu.modUpdateAvailable = true; + String currentLoader = ModMenu.runningQuilt ? "Quilt" : "Fabric"; + LOGGER.debug("Versions of {} for {}: {}", mod.getId(), currentLoader, versions); + if (versions.isEmpty()) { + LOGGER.debug("No versions of {} for {} found on Modrinth.", mod.getId(), currentLoader); + } else { + var latestObj = versions.get(0).getAsJsonObject(); + var latestVersion = latestObj.get("version_number").getAsString(); + var latestId = latestObj.get("id").getAsString(); + var latestHash = latestObj.get("files").getAsJsonArray().asList() + .stream().filter(file -> file.getAsJsonObject().get("primary").getAsBoolean()).findFirst() + .get().getAsJsonObject().get("hashes").getAsJsonObject().get("sha512").getAsString(); + if (!Objects.equals(latestHash, localHash)) { + // hashes different, there's an update. + LOGGER.info("Update available for '{}@{}', ({} -> {})", mod.getId(), mod.getVersion(), modrinthVersion, latestVersion); + mod.setModrinthData(new ModrinthData(projectId, latestId, latestVersion)); + ModMenu.modUpdateAvailable = true; + } } } } diff --git a/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java b/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java index a23760cf9..d9ea5f874 100644 --- a/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java +++ b/src/main/java/com/terraformersmc/modmenu/util/mod/quilt/QuiltMod.java @@ -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; @@ -12,6 +13,7 @@ import org.quiltmc.loader.api.QuiltLoader; import java.io.IOException; +import java.nio.file.FileSystems; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -66,13 +68,15 @@ public QuiltMod(net.fabricmc.loader.api.ModContainer fabricModContainer, Set 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()) { + if (path.isPresent() && path.get().getFileSystem() == FileSystems.getDefault()) { var file = path.get().toFile(); if (file.isFile()) { + ModrinthUtil.LOGGER.debug(" Found {} hash", getId()); return Files.asByteSource(file).hash(Hashing.sha512()).toString(); } }