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