    001    package cpw.mods.fml.common.event;
    002
    003    import java.io.File;
    004    import java.security.CodeSource;
    005    import java.security.cert.Certificate;
    006    import java.util.Properties;
    007    import java.util.logging.Logger;
    008
    009    import cpw.mods.fml.common.FMLLog;
    010    import cpw.mods.fml.common.LoaderState.ModState;
    011    import cpw.mods.fml.common.FMLModContainer;
    012    import cpw.mods.fml.common.ModContainer;
    013    import cpw.mods.fml.common.ModMetadata;
    014    import cpw.mods.fml.common.discovery.ASMDataTable;
    015
    016    public 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         *
    085         * @return A logger
    086         */
    087        public Logger getModLog()
    088        {
    089            Logger log = Logger.getLogger(modContainer.getModId());
    090            log.setParent(FMLLog.getLogger());
    091            return log;
    092        }
    093
    094
    095        /**
    096         * Retrieve the FML signing certificates, if any. Validate these against the
    097         * published FML certificates in your mod, if you wish.
    098         *
    099         * Deprecated because mods should <b>NOT</b> trust this code. Rather
    100         * they should copy this, or something like this, into their own mods.
    101         *
    102         * @return Certificates used to sign FML and Forge
    103         */
    104        @Deprecated
    105        public Certificate[] getFMLSigningCertificates()
    106        {
    107            CodeSource codeSource = getClass().getClassLoader().getParent().getClass().getProtectionDomain().getCodeSource();
    108            Certificate[] certs = codeSource.getCertificates();
    109            if (certs == null)
    110            {
    111                return new Certificate[0];
    112            }
    113            else
    114            {
    115                return certs;
    116            }
    117        }
    118    }