    001package cpw.mods.fml.common.event;
    002
    003import java.io.File;
    004import java.security.CodeSource;
    005import java.security.cert.Certificate;
    006import java.util.Properties;
    007import java.util.logging.Logger;
    008
    009import cpw.mods.fml.common.FMLLog;
    010import cpw.mods.fml.common.LoaderState.ModState;
    011import cpw.mods.fml.common.FMLModContainer;
    012import cpw.mods.fml.common.ModContainer;
    013import cpw.mods.fml.common.ModMetadata;
    014import cpw.mods.fml.common.discovery.ASMDataTable;
    015
    016public class FMLPreInitializationEvent extends FMLStateEvent
    017{
    018    private ModMetadata modMetadata;
    019    private File sourceFile;
    020    private File configurationDir;
    021    private File suggestedConfigFile;
    022    private ASMDataTable asmData;
    023    private ModContainer modContainer;
    024
    025    public FMLPreInitializationEvent(Object... data)
    026    {
    027        super(data);
    028        this.asmData = (ASMDataTable)data[0];
    029        this.configurationDir = (File)data[1];
    030    }
    031
    032    @Override
    033    public ModState getModState()
    034    {
    035        return ModState.PREINITIALIZED;
    036    }
    037
    038    @Override
    039    public void applyModContainer(ModContainer activeContainer)
    040    {
    041        this.modContainer = activeContainer;
    042        this.modMetadata = activeContainer.getMetadata();
    043        this.sourceFile = activeContainer.getSource();
    044        this.suggestedConfigFile = new File(configurationDir, activeContainer.getModId()+".cfg");
    045    }
    046
    047    public File getSourceFile()
    048    {
    049        return sourceFile;
    050    }
    051
    052    public ModMetadata getModMetadata()
    053    {
    054        return modMetadata;
    055    }
    056
    057    public File getModConfigurationDirectory()
    058    {
    059        return configurationDir;
    060    }
    061
    062    public File getSuggestedConfigurationFile()
    063    {
    064        return suggestedConfigFile;
    065    }
    066
    067    public ASMDataTable getAsmData()
    068    {
    069        return asmData;
    070    }
    071
    072    public Properties getVersionProperties()
    073    {
    074        if (this.modContainer instanceof FMLModContainer)
    075        {
    076            return ((FMLModContainer)this.modContainer).searchForVersionProperties();
    077        }
    078
    079        return null;
    080    }
    081
    082    /**
    083     * Get a logger instance configured to write to the FML Log as a parent, identified by modid. Handy for mod logging!
    084     * Configurations can be applied through the <code>config/logging.properties</code> file, specifying logging levels
    085     * for your ModID. Use this!
    086     *
    087     * @return A logger
    088     */
    089    public Logger getModLog()
    090    {
    091        Logger log = Logger.getLogger(modContainer.getModId());
    092        log.setParent(FMLLog.getLogger());
    093        return log;
    094    }
    095
    096
    097    /**
    098     * Retrieve the FML signing certificates, if any. Validate these against the
    099     * published FML certificates in your mod, if you wish.
    100     *
    101     * Deprecated because mods should <b>NOT</b> trust this code. Rather
    102     * they should copy this, or something like this, into their own mods.
    103     *
    104     * @return Certificates used to sign FML and Forge
    105     */
    106    @Deprecated
    107    public Certificate[] getFMLSigningCertificates()
    108    {
    109        CodeSource codeSource = getClass().getClassLoader().getParent().getClass().getProtectionDomain().getCodeSource();
    110        Certificate[] certs = codeSource.getCertificates();
    111        if (certs == null)
    112        {
    113            return new Certificate[0];
    114        }
    115        else
    116        {
    117            return certs;
    118        }
    119    }
    120}