| 1 | package net.minecraft.client.resources;
|
| 2 |
|
| 3 | import com.google.common.base.Charsets;
|
| 4 | import com.google.common.collect.Maps;
|
| 5 | import com.google.common.io.Files;
|
| 6 | import com.google.gson.JsonElement;
|
| 7 | import com.google.gson.JsonObject;
|
| 8 | import com.google.gson.JsonParseException;
|
| 9 | import com.google.gson.JsonParser;
|
| 10 | import java.io.BufferedReader;
|
| 11 | import java.io.File;
|
| 12 | import java.io.FileNotFoundException;
|
| 13 | import java.io.Reader;
|
| 14 | import java.util.Map;
|
| 15 | import java.util.Map.Entry;
|
| 16 | import net.minecraft.util.JsonUtils;
|
| 17 | import org.apache.commons.io.IOUtils;
|
| 18 | import org.apache.logging.log4j.LogManager;
|
| 19 | import org.apache.logging.log4j.Logger;
|
| 20 |
|
| 21 | public class ResourceIndex
|
| 22 | {
|
| 23 | private static final Logger logger = LogManager.getLogger();
|
| 24 | private final Map<String, File> resourceMap = Maps.<String, File>newHashMap();
|
| 25 |
|
| 26 | public ResourceIndex(File p_i1047_1_, String p_i1047_2_)
|
| 27 | {
|
| 28 | if (p_i1047_2_ != null)
|
| 29 | {
|
| 30 | File file1 = new File(p_i1047_1_, "objects");
|
| 31 | File file2 = new File(p_i1047_1_, "indexes/" + p_i1047_2_ + ".json");
|
| 32 | BufferedReader bufferedreader = null;
|
| 33 |
|
| 34 | try
|
| 35 | {
|
| 36 | bufferedreader = Files.newReader(file2, Charsets.UTF_8);
|
| 37 | JsonObject jsonobject = (new JsonParser()).parse((Reader)bufferedreader).getAsJsonObject();
|
| 38 | JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonobject, "objects", (JsonObject)null);
|
| 39 |
|
| 40 | if (jsonobject1 != null)
|
| 41 | {
|
| 42 | for (Entry<String, JsonElement> entry : jsonobject1.entrySet())
|
| 43 | {
|
| 44 | JsonObject jsonobject2 = (JsonObject)entry.getValue();
|
| 45 | String s = (String)entry.getKey();
|
| 46 | String[] astring = s.split("/", 2);
|
| 47 | String s1 = astring.length == 1 ? astring[0] : astring[0] + ":" + astring[1];
|
| 48 | String s2 = JsonUtils.getString(jsonobject2, "hash");
|
| 49 | File file3 = new File(file1, s2.substring(0, 2) + "/" + s2);
|
| 50 | this.resourceMap.put(s1, file3);
|
| 51 | }
|
| 52 | }
|
| 53 | }
|
| 54 | catch (JsonParseException var20)
|
| 55 | {
|
| 56 | logger.error("Unable to parse resource index file: " + file2);
|
| 57 | }
|
| 58 | catch (FileNotFoundException var21)
|
| 59 | {
|
| 60 | logger.error("Can\'t find the resource index file: " + file2);
|
| 61 | }
|
| 62 | finally
|
| 63 | {
|
| 64 | IOUtils.closeQuietly((Reader)bufferedreader);
|
| 65 | }
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | public Map<String, File> getResourceMap()
|
| 70 | {
|
| 71 | return this.resourceMap;
|
| 72 | }
|
| 73 | }
|
| 74 |
|