    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.IOException;
    007import java.io.InputStream;
    008import java.util.zip.ZipEntry;
    009import java.util.zip.ZipFile;
    010import net.minecraft.client.renderer.RenderEngine;
    011
    012@SideOnly(Side.CLIENT)
    013public class TexturePackCustom extends TexturePackImplementation
    014{
    015    /** ZipFile object used to access the texture pack file's contents. */
    016    private ZipFile texturePackZipFile;
    017
    018    public TexturePackCustom(String par1Str, File par2File)
    019    {
    020        super(par1Str, par2File, par2File.getName());
    021    }
    022
    023    /**
    024     * Delete the OpenGL texture id of the pack's thumbnail image, and close the zip file in case of TexturePackCustom.
    025     */
    026    public void deleteTexturePack(RenderEngine par1RenderEngine)
    027    {
    028        super.deleteTexturePack(par1RenderEngine);
    029
    030        try
    031        {
    032            if (this.texturePackZipFile != null)
    033            {
    034                this.texturePackZipFile.close();
    035            }
    036        }
    037        catch (IOException var3)
    038        {
    039            ;
    040        }
    041
    042        this.texturePackZipFile = null;
    043    }
    044
    045    /**
    046     * Gives a texture resource as InputStream.
    047     */
    048    public InputStream getResourceAsStream(String par1Str)
    049    {
    050        this.openTexturePackFile();
    051
    052        try
    053        {
    054            ZipEntry var2 = this.texturePackZipFile.getEntry(par1Str.substring(1));
    055
    056            if (var2 != null)
    057            {
    058                return this.texturePackZipFile.getInputStream(var2);
    059            }
    060        }
    061        catch (Exception var3)
    062        {
    063            ;
    064        }
    065
    066        return super.getResourceAsStream(par1Str);
    067    }
    068
    069    /**
    070     * Open the texture pack's file and initialize texturePackZipFile
    071     */
    072    private void openTexturePackFile()
    073    {
    074        if (this.texturePackZipFile == null)
    075        {
    076            try
    077            {
    078                this.texturePackZipFile = new ZipFile(this.texturePackFile);
    079            }
    080            catch (IOException var2)
    081            {
    082                ;
    083            }
    084        }
    085    }
    086}