From 9b081b9d465147dfb2d004e1be27988417c3c704 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 16 Sep 2012 21:42:59 -0400 Subject: [PATCH] Change version.properties search slightly, allow access to found file from the preinit event --- .../cpw/mods/fml/common/FMLModContainer.java | 44 +++++++++++++------ .../event/FMLPreInitializationEvent.java | 14 ++++++ 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/fml/common/cpw/mods/fml/common/FMLModContainer.java b/fml/common/cpw/mods/fml/common/FMLModContainer.java index 042205c20..df97880aa 100644 --- a/fml/common/cpw/mods/fml/common/FMLModContainer.java +++ b/fml/common/cpw/mods/fml/common/FMLModContainer.java @@ -157,11 +157,17 @@ public class FMLModContainer implements ModContainer internalVersion = (String) descriptor.get("version"); if (Strings.isNullOrEmpty(internalVersion) && getSource().isFile()) { - internalVersion = searchForVersionProperties(); + Properties versionProps = searchForVersionProperties(); + if (versionProps != null) + { + internalVersion = versionProps.getProperty(getModId()+".version"); + FMLLog.fine("Found version %s for mod %s in version.properties", internalVersion, getModId()); + } + } if (Strings.isNullOrEmpty(internalVersion) && !Strings.isNullOrEmpty(modMetadata.version)) { - FMLLog.warning("Mod %s is missing the required element 'version'. Falling back to metadata version %s", getModId(), modMetadata.version); + FMLLog.warning("Mod %s is missing the required element 'version' and a version.properties file could not be found. Falling back to metadata version %s", getModId(), modMetadata.version); internalVersion = modMetadata.version; } if (Strings.isNullOrEmpty(internalVersion)) @@ -171,22 +177,34 @@ public class FMLModContainer implements ModContainer } } - private String searchForVersionProperties() + public Properties searchForVersionProperties() { try { - FMLLog.fine("Attempting to load the file version.properties and from %s locate a version", getSource().getName()); - String version = null; - ZipFile source = new ZipFile(getSource()); - ZipEntry versionFile = source.getEntry("version.properties"); - if (versionFile!=null) + FMLLog.fine("Attempting to load the file version.properties from %s to locate a version number for %s", getSource().getName(), getModId()); + Properties version = null; + if (getSource().isFile()) { - Properties versionProps = new Properties(); - versionProps.load(source.getInputStream(versionFile)); - version = versionProps.getProperty(getModId()+".version"); - FMLLog.fine("Found version %s for mod %s in version.properties", version, getModId()); + ZipFile source = new ZipFile(getSource()); + ZipEntry versionFile = source.getEntry("version.properties"); + if (versionFile!=null) + { + version = new Properties(); + version.load(source.getInputStream(versionFile)); + } + source.close(); + } + else if (getSource().isDirectory()) + { + File propsFile = new File(getSource(),"version.properties"); + if (propsFile.exists() && propsFile.isFile()) + { + version = new Properties(); + FileInputStream fis = new FileInputStream(propsFile); + version.load(fis); + fis.close(); + } } - source.close(); return version; } catch (Exception e) diff --git a/fml/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java b/fml/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java index ed356b04e..d2d01221e 100644 --- a/fml/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java +++ b/fml/common/cpw/mods/fml/common/event/FMLPreInitializationEvent.java @@ -1,8 +1,10 @@ package cpw.mods.fml.common.event; import java.io.File; +import java.util.Properties; import cpw.mods.fml.common.LoaderState.ModState; +import cpw.mods.fml.common.FMLModContainer; import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.discovery.ASMDataTable; @@ -14,6 +16,7 @@ public class FMLPreInitializationEvent extends FMLStateEvent private File configurationDir; private File suggestedConfigFile; private ASMDataTable asmData; + private ModContainer modContainer; public FMLPreInitializationEvent(Object... data) { @@ -31,6 +34,7 @@ public class FMLPreInitializationEvent extends FMLStateEvent @Override public void applyModContainer(ModContainer activeContainer) { + this.modContainer = activeContainer; this.modMetadata = activeContainer.getMetadata(); this.sourceFile = activeContainer.getSource(); this.suggestedConfigFile = new File(configurationDir, activeContainer.getModId()+".cfg"); @@ -60,4 +64,14 @@ public class FMLPreInitializationEvent extends FMLStateEvent { return asmData; } + + public Properties getVersionProperties() + { + if (this.modContainer instanceof FMLModContainer) + { + return ((FMLModContainer)(this.modContainer)).searchForVersionProperties(); + } + + return null; + } }