mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-15 17:45:06 +00:00
Change version.properties search slightly, allow access to found file from the preinit event
This commit is contained in:
1 parent
1513b369d3
commit
aacbfeb66e
2 files changed
+45
-13
No files matched your search
@@ -157,11 +157,17 @@ public class FMLModContainer implements ModContainer
|
|||||||
internalVersion = (String) descriptor.get("version");
|
internalVersion = (String) descriptor.get("version");
|
||||||
if (Strings.isNullOrEmpty(internalVersion) && getSource().isFile())
|
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))
|
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;
|
internalVersion = modMetadata.version;
|
||||||
}
|
}
|
||||||
if (Strings.isNullOrEmpty(internalVersion))
|
if (Strings.isNullOrEmpty(internalVersion))
|
||||||
@@ -171,22 +177,34 @@ public class FMLModContainer implements ModContainer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String searchForVersionProperties()
|
public Properties searchForVersionProperties()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FMLLog.fine("Attempting to load the file version.properties and from %s locate a version", getSource().getName());
|
FMLLog.fine("Attempting to load the file version.properties from %s to locate a version number for %s", getSource().getName(), getModId());
|
||||||
String version = null;
|
Properties version = null;
|
||||||
ZipFile source = new ZipFile(getSource());
|
if (getSource().isFile())
|
||||||
ZipEntry versionFile = source.getEntry("version.properties");
|
|
||||||
if (versionFile!=null)
|
|
||||||
{
|
{
|
||||||
Properties versionProps = new Properties();
|
ZipFile source = new ZipFile(getSource());
|
||||||
versionProps.load(source.getInputStream(versionFile));
|
ZipEntry versionFile = source.getEntry("version.properties");
|
||||||
version = versionProps.getProperty(getModId()+".version");
|
if (versionFile!=null)
|
||||||
FMLLog.fine("Found version %s for mod %s in version.properties", version, getModId());
|
{
|
||||||
|
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;
|
return version;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package cpw.mods.fml.common.event;
|
package cpw.mods.fml.common.event;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import cpw.mods.fml.common.LoaderState.ModState;
|
import cpw.mods.fml.common.LoaderState.ModState;
|
||||||
|
import cpw.mods.fml.common.FMLModContainer;
|
||||||
import cpw.mods.fml.common.ModContainer;
|
import cpw.mods.fml.common.ModContainer;
|
||||||
import cpw.mods.fml.common.ModMetadata;
|
import cpw.mods.fml.common.ModMetadata;
|
||||||
import cpw.mods.fml.common.discovery.ASMDataTable;
|
import cpw.mods.fml.common.discovery.ASMDataTable;
|
||||||
@@ -14,6 +16,7 @@ public class FMLPreInitializationEvent extends FMLStateEvent
|
|||||||
private File configurationDir;
|
private File configurationDir;
|
||||||
private File suggestedConfigFile;
|
private File suggestedConfigFile;
|
||||||
private ASMDataTable asmData;
|
private ASMDataTable asmData;
|
||||||
|
private ModContainer modContainer;
|
||||||
|
|
||||||
public FMLPreInitializationEvent(Object... data)
|
public FMLPreInitializationEvent(Object... data)
|
||||||
{
|
{
|
||||||
@@ -31,6 +34,7 @@ public class FMLPreInitializationEvent extends FMLStateEvent
|
|||||||
@Override
|
@Override
|
||||||
public void applyModContainer(ModContainer activeContainer)
|
public void applyModContainer(ModContainer activeContainer)
|
||||||
{
|
{
|
||||||
|
this.modContainer = activeContainer;
|
||||||
this.modMetadata = activeContainer.getMetadata();
|
this.modMetadata = activeContainer.getMetadata();
|
||||||
this.sourceFile = activeContainer.getSource();
|
this.sourceFile = activeContainer.getSource();
|
||||||
this.suggestedConfigFile = new File(configurationDir, activeContainer.getModId()+".cfg");
|
this.suggestedConfigFile = new File(configurationDir, activeContainer.getModId()+".cfg");
|
||||||
@@ -60,4 +64,14 @@ public class FMLPreInitializationEvent extends FMLStateEvent
|
|||||||
{
|
{
|
||||||
return asmData;
|
return asmData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Properties getVersionProperties()
|
||||||
|
{
|
||||||
|
if (this.modContainer instanceof FMLModContainer)
|
||||||
|
{
|
||||||
|
return ((FMLModContainer)(this.modContainer)).searchForVersionProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user