    001package net.minecraft.client.texturepacks;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.io.File;
    006import java.io.FileNotFoundException;
    007import java.io.IOException;
    008import java.io.InputStream;
    009import java.util.Enumeration;
    010import java.util.zip.ZipEntry;
    011import java.util.zip.ZipException;
    012import java.util.zip.ZipFile;
    013import net.minecraft.client.renderer.RenderEngine;
    014
    015@SideOnly(Side.CLIENT)
    016public class TexturePackCustom extends TexturePackImplementation
    017{
    018    /** ZipFile object used to access the texture pack file's contents. */
    019    private ZipFile texturePackZipFile;
    020
    021    public TexturePackCustom(String par1Str, File par2File, ITexturePack par3ITexturePack)
    022    {
    023        super(par1Str, par2File, par2File.getName(), par3ITexturePack);
    024    }
    025
    026    /**
    027     * Delete the OpenGL texture id of the pack's thumbnail image, and close the zip file in case of TexturePackCustom.
    028     */
    029    public void deleteTexturePack(RenderEngine par1RenderEngine)
    030    {
    031        super.deleteTexturePack(par1RenderEngine);
    032
    033        try
    034        {
    035            if (this.texturePackZipFile != null)
    036            {
    037                this.texturePackZipFile.close();
    038            }
    039        }
    040        catch (IOException ioexception)
    041        {
    042            ;
    043        }
    044
    045        this.texturePackZipFile = null;
    046    }
    047
    048    protected InputStream func_98139_b(String par1Str) throws IOException
    049    {
    050        this.openTexturePackFile();
    051        ZipEntry zipentry = this.texturePackZipFile.getEntry(par1Str.substring(1));
    052
    053        if (zipentry == null)
    054        {
    055            throw new FileNotFoundException(par1Str);
    056        }
    057        else
    058        {
    059            return this.texturePackZipFile.getInputStream(zipentry);
    060        }
    061    }
    062
    063    public boolean func_98140_c(String par1Str)
    064    {
    065        try
    066        {
    067            this.openTexturePackFile();
    068            return this.texturePackZipFile.getEntry(par1Str.substring(1)) != null;
    069        }
    070        catch (Exception exception)
    071        {
    072            return false;
    073        }
    074    }
    075
    076    /**
    077     * Open the texture pack's file and initialize texturePackZipFile
    078     */
    079    private void openTexturePackFile() throws IOException, ZipException
    080    {
    081        if (this.texturePackZipFile == null)
    082        {
    083            this.texturePackZipFile = new ZipFile(this.texturePackFile);
    084        }
    085    }
    086
    087    public boolean isCompatible()
    088    {
    089        try
    090        {
    091            this.openTexturePackFile();
    092            Enumeration enumeration = this.texturePackZipFile.entries();
    093
    094            while (enumeration.hasMoreElements())
    095            {
    096                ZipEntry zipentry = (ZipEntry)enumeration.nextElement();
    097
    098                if (zipentry.getName().startsWith("textures/"))
    099                {
    100                    return true;
    101                }
    102            }
    103        }
    104        catch (Exception exception)
    105        {
    106            ;
    107        }
    108
    109        boolean flag = this.func_98140_c("terrain.png") || this.func_98140_c("gui/items.png");
    110        return !flag;
    111    }
    112}