001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import java.io.File; 006 import java.util.ArrayList; 007 import java.util.Arrays; 008 import java.util.Collections; 009 import java.util.HashMap; 010 import java.util.Iterator; 011 import java.util.List; 012 import java.util.Map; 013 import net.minecraft.client.Minecraft; 014 015 @SideOnly(Side.CLIENT) 016 public class TexturePackList 017 { 018 private static final TexturePackBase field_77314_a = new TexturePackDefault(); 019 020 /** The Minecraft instance. */ 021 private final Minecraft mc; 022 023 /** The directory the texture packs will be loaded from. */ 024 private final File texturePackDir; 025 026 /** Folder for the multi-player texturepacks. Returns File. */ 027 private final File mpTexturePackFolder; 028 029 /** The list of the available texture packs. */ 030 private List availableTexturePacks = new ArrayList(); 031 private Map field_77308_f = new HashMap(); 032 033 /** The TexturePack that will be used. */ 034 private TexturePackBase selectedTexturePack; 035 private boolean field_77315_h; 036 037 public TexturePackList(File par1File, Minecraft par2Minecraft) 038 { 039 this.mc = par2Minecraft; 040 this.texturePackDir = new File(par1File, "texturepacks"); 041 this.mpTexturePackFolder = new File(par1File, "texturepacks-mp-cache"); 042 this.func_77307_h(); 043 this.updateAvaliableTexturePacks(); 044 } 045 046 private void func_77307_h() 047 { 048 if (!this.texturePackDir.isDirectory()) 049 { 050 this.texturePackDir.delete(); 051 this.texturePackDir.mkdirs(); 052 } 053 054 if (!this.mpTexturePackFolder.isDirectory()) 055 { 056 this.mpTexturePackFolder.delete(); 057 this.mpTexturePackFolder.mkdirs(); 058 } 059 } 060 061 /** 062 * Sets the new TexturePack to be used, returning true if it has actually changed, false if nothing changed. 063 */ 064 public boolean setTexturePack(TexturePackBase par1TexturePackBase) 065 { 066 if (par1TexturePackBase == this.selectedTexturePack) 067 { 068 return false; 069 } 070 else 071 { 072 this.field_77315_h = false; 073 this.selectedTexturePack = par1TexturePackBase; 074 this.mc.gameSettings.skin = par1TexturePackBase.func_77538_c(); 075 this.mc.gameSettings.saveOptions(); 076 return true; 077 } 078 } 079 080 /** 081 * filename must end in .zip 082 */ 083 public void requestDownloadOfTexture(String par1Str) 084 { 085 String var2 = par1Str.substring(par1Str.lastIndexOf("/") + 1); 086 087 if (var2.contains("?")) 088 { 089 var2 = var2.substring(0, var2.indexOf("?")); 090 } 091 092 if (var2.endsWith(".zip")) 093 { 094 File var3 = new File(this.mpTexturePackFolder, var2); 095 this.downloadTexture(par1Str, var3); 096 } 097 } 098 099 private void downloadTexture(String par1Str, File par2File) 100 { 101 HashMap var3 = new HashMap(); 102 GuiProgress var4 = new GuiProgress(); 103 var3.put("X-Minecraft-Username", this.mc.session.username); 104 var3.put("X-Minecraft-Version", "1.3.2"); 105 var3.put("X-Minecraft-Supported-Resolutions", "16"); 106 this.field_77315_h = true; 107 this.mc.displayGuiScreen(var4); 108 HttpUtil.downloadTexturePack(par2File, par1Str, new TexturePackDownloadSuccess(this), var3, 10000000, var4); 109 } 110 111 public boolean func_77295_a() 112 { 113 return this.field_77315_h; 114 } 115 116 public void func_77304_b() 117 { 118 this.field_77315_h = false; 119 this.updateAvaliableTexturePacks(); 120 this.mc.func_71395_y(); 121 } 122 123 /** 124 * check the texture packs the client has installed 125 */ 126 public void updateAvaliableTexturePacks() 127 { 128 ArrayList var1 = new ArrayList(); 129 this.selectedTexturePack = field_77314_a; 130 var1.add(field_77314_a); 131 Iterator var2 = this.func_77299_i().iterator(); 132 133 while (var2.hasNext()) 134 { 135 File var3 = (File)var2.next(); 136 String var4 = this.func_77302_a(var3); 137 138 if (var4 != null) 139 { 140 Object var5 = (TexturePackBase)this.field_77308_f.get(var4); 141 142 if (var5 == null) 143 { 144 var5 = var3.isDirectory() ? new TexturePackFolder(var4, var3) : new TexturePackCustom(var4, var3); 145 this.field_77308_f.put(var4, var5); 146 } 147 148 if (((TexturePackBase)var5).func_77538_c().equals(this.mc.gameSettings.skin)) 149 { 150 this.selectedTexturePack = (TexturePackBase)var5; 151 } 152 153 var1.add(var5); 154 } 155 } 156 157 this.availableTexturePacks.removeAll(var1); 158 var2 = this.availableTexturePacks.iterator(); 159 160 while (var2.hasNext()) 161 { 162 TexturePackBase var6 = (TexturePackBase)var2.next(); 163 var6.func_77533_a(this.mc.renderEngine); 164 this.field_77308_f.remove(var6.func_77536_b()); 165 } 166 167 this.availableTexturePacks = var1; 168 } 169 170 private String func_77302_a(File par1File) 171 { 172 return par1File.isFile() && par1File.getName().toLowerCase().endsWith(".zip") ? par1File.getName() + ":" + par1File.length() + ":" + par1File.lastModified() : (par1File.isDirectory() && (new File(par1File, "pack.txt")).exists() ? par1File.getName() + ":folder:" + par1File.lastModified() : null); 173 } 174 175 private List func_77299_i() 176 { 177 return this.texturePackDir.exists() && this.texturePackDir.isDirectory() ? Arrays.asList(this.texturePackDir.listFiles()) : Collections.emptyList(); 178 } 179 180 /** 181 * Returns a list of the available texture packs. 182 */ 183 public List availableTexturePacks() 184 { 185 return Collections.unmodifiableList(this.availableTexturePacks); 186 } 187 188 public TexturePackBase getSelectedTexturePack() 189 { 190 return this.selectedTexturePack; 191 } 192 193 public boolean func_77300_f() 194 { 195 if (!this.mc.gameSettings.serverTextures) 196 { 197 return false; 198 } 199 else 200 { 201 ServerData var1 = this.mc.getServerData(); 202 return var1 == null ? true : var1.func_78840_c(); 203 } 204 } 205 206 public boolean getAcceptsTextures() 207 { 208 if (!this.mc.gameSettings.serverTextures) 209 { 210 return false; 211 } 212 else 213 { 214 ServerData var1 = this.mc.getServerData(); 215 return var1 == null ? false : var1.getAcceptsTextures(); 216 } 217 } 218 219 static boolean func_77301_a(TexturePackList par0TexturePackList) 220 { 221 return par0TexturePackList.field_77315_h; 222 } 223 224 static TexturePackBase func_77303_a(TexturePackList par0TexturePackList, TexturePackBase par1TexturePackBase) 225 { 226 return par0TexturePackList.selectedTexturePack = par1TexturePackBase; 227 } 228 229 static String func_77291_a(TexturePackList par0TexturePackList, File par1File) 230 { 231 return par0TexturePackList.func_77302_a(par1File); 232 } 233 234 static Minecraft getMinecraft(TexturePackList par0TexturePackList) 235 { 236 return par0TexturePackList.mc; 237 } 238 }