From 8f9b54a97a5550e6bcd2d8cd0890ab84faaa2e8b Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 17 Aug 2013 11:40:15 -0400 Subject: [PATCH] Clean up a couple of resources. Also, don't parse jars just because they're in the mods dir --- .../mods/fml/common/asm/FMLSanityChecker.java | 18 +++++++++++++++++- .../fml/common/discovery/ModDiscoverer.java | 6 +++++- .../mods/fml/relauncher/CoreModManager.java | 17 +++++++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/fml/common/cpw/mods/fml/common/asm/FMLSanityChecker.java b/fml/common/cpw/mods/fml/common/asm/FMLSanityChecker.java index 3866e1be09..1e2f6ea1dc 100644 --- a/fml/common/cpw/mods/fml/common/asm/FMLSanityChecker.java +++ b/fml/common/cpw/mods/fml/common/asm/FMLSanityChecker.java @@ -14,6 +14,7 @@ package cpw.mods.fml.common.asm; import java.io.ByteArrayInputStream; import java.io.File; +import java.io.IOException; import java.io.InputStreamReader; import java.io.ObjectInputStream.GetField; import java.io.StringReader; @@ -135,6 +136,7 @@ public class FMLSanityChecker implements IFMLCallHook // Probably a development environment, or the server (the server is not signed) goodMC = true; } + JarFile mcJarFile = null; if (fmlIsJar && !goodMC && codeSource.getLocation().getProtocol().equals("jar")) { try @@ -142,7 +144,7 @@ public class FMLSanityChecker implements IFMLCallHook String mcPath = codeSource.getLocation().getPath().substring(5); mcPath = mcPath.substring(0, mcPath.lastIndexOf('!')); mcPath = URLDecoder.decode(mcPath, Charsets.UTF_8.name()); - JarFile mcJarFile = new JarFile(mcPath,true); + mcJarFile = new JarFile(mcPath,true); mcJarFile.getManifest(); JarEntry cbrEntry = mcJarFile.getJarEntry("net/minecraft/client/ClientBrandRetriever.class"); ByteStreams.toByteArray(mcJarFile.getInputStream(cbrEntry)); @@ -166,6 +168,20 @@ public class FMLSanityChecker implements IFMLCallHook { FMLRelaunchLog.log(Level.SEVERE, e, "A critical error occurred trying to read the minecraft jar file"); } + finally + { + if (mcJarFile != null) + { + try + { + mcJarFile.close(); + } + catch (IOException ioe) + { + // Noise + } + } + } } else { diff --git a/fml/common/cpw/mods/fml/common/discovery/ModDiscoverer.java b/fml/common/cpw/mods/fml/common/discovery/ModDiscoverer.java index 610bb3629f..8436aa109d 100644 --- a/fml/common/cpw/mods/fml/common/discovery/ModDiscoverer.java +++ b/fml/common/cpw/mods/fml/common/discovery/ModDiscoverer.java @@ -85,7 +85,11 @@ public class ModDiscoverer for (File modFile : modList) { - if (modFile.isDirectory()) + if (CoreModManager.getLoadedCoremods().contains(modFile.getName())) + { + FMLLog.finer("Skipping already parsed coremod or tweaker %s", modFile.getName()); + } + else if (modFile.isDirectory()) { FMLLog.fine("Found a candidate mod directory %s", modFile.getName()); candidates.add(new ModCandidate(modFile, modFile, ContainerType.DIR)); diff --git a/fml/common/cpw/mods/fml/relauncher/CoreModManager.java b/fml/common/cpw/mods/fml/relauncher/CoreModManager.java index 1491ef890b..2164b0d1bd 100644 --- a/fml/common/cpw/mods/fml/relauncher/CoreModManager.java +++ b/fml/common/cpw/mods/fml/relauncher/CoreModManager.java @@ -160,7 +160,7 @@ public class CoreModManager for (File coreMod : coreModList) { FMLRelaunchLog.fine("Examining for coremod candidacy %s", coreMod.getName()); - JarFile jar; + JarFile jar = null; Attributes mfAttributes; try { @@ -177,7 +177,20 @@ public class CoreModManager FMLRelaunchLog.log(Level.SEVERE, ioe, "Unable to read the jar file %s - ignoring", coreMod.getName()); continue; } - + finally + { + if (jar!=null) + { + try + { + jar.close(); + } + catch (IOException e) + { + // Noise + } + } + } String cascadedTweaker = mfAttributes.getValue("TweakClass"); if (cascadedTweaker != null) {