Search in sources :

Example 1 with LzmaInputStream

use of LZMA.LzmaInputStream in project MinecraftForge by MinecraftForge.

the class ClassPatchManager method setup.

public void setup(Side side) {
    Pattern binpatchMatcher = Pattern.compile(String.format("binpatch/%s/.*.binpatch", side.toString().toLowerCase(Locale.ENGLISH)));
    JarInputStream jis;
    try {
        InputStream binpatchesCompressed = getClass().getResourceAsStream("/binpatches.pack.lzma");
        if (binpatchesCompressed == null) {
            FMLRelaunchLog.log(Level.ERROR, "The binary patch set is missing. Either you are in a development environment, or things are not going to work!");
            return;
        }
        LzmaInputStream binpatchesDecompressed = new LzmaInputStream(binpatchesCompressed);
        ByteArrayOutputStream jarBytes = new ByteArrayOutputStream();
        JarOutputStream jos = new JarOutputStream(jarBytes);
        Pack200.newUnpacker().unpack(binpatchesDecompressed, jos);
        jis = new JarInputStream(new ByteArrayInputStream(jarBytes.toByteArray()));
    } catch (Exception e) {
        FMLRelaunchLog.log(Level.ERROR, e, "Error occurred reading binary patches. Expect severe problems!");
        throw Throwables.propagate(e);
    }
    patches = ArrayListMultimap.create();
    do {
        try {
            JarEntry entry = jis.getNextJarEntry();
            if (entry == null) {
                break;
            }
            if (binpatchMatcher.matcher(entry.getName()).matches()) {
                ClassPatch cp = readPatch(entry, jis);
                if (cp != null) {
                    patches.put(cp.sourceClassName, cp);
                }
            } else {
                jis.closeEntry();
            }
        } catch (IOException e) {
        }
    } while (true);
    FMLRelaunchLog.fine("Read %d binary patches", patches.size());
    if (DEBUG)
        FMLRelaunchLog.fine("Patch list :\n\t%s", Joiner.on("\t\n").join(patches.asMap().entrySet()));
    patchedClasses.clear();
}
Also used : Pattern(java.util.regex.Pattern) LzmaInputStream(LZMA.LzmaInputStream) JarInputStream(java.util.jar.JarInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) JarInputStream(java.util.jar.JarInputStream) LzmaInputStream(LZMA.LzmaInputStream) InputStream(java.io.InputStream) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry) IOException(java.io.IOException)

Aggregations

LzmaInputStream (LZMA.LzmaInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 JarEntry (java.util.jar.JarEntry)1 JarInputStream (java.util.jar.JarInputStream)1 JarOutputStream (java.util.jar.JarOutputStream)1 Pattern (java.util.regex.Pattern)1