Search in sources :

Example 1 with ResFileValue

use of brut.androlib.res.data.value.ResFileValue in project Apktool by iBotPeaches.

the class ResFileDecoder method decode.

public void decode(ResResource res, Directory inDir, Directory outDir) throws AndrolibException {
    ResFileValue fileValue = (ResFileValue) res.getValue();
    String inFileName = fileValue.getStrippedPath();
    String outResName = res.getFilePath();
    String typeName = res.getResSpec().getType().getName();
    String ext = null;
    String outFileName;
    int extPos = inFileName.lastIndexOf(".");
    if (extPos == -1) {
        outFileName = outResName;
    } else {
        ext = inFileName.substring(extPos).toLowerCase();
        outFileName = outResName + ext;
    }
    try {
        if (typeName.equals("raw")) {
            decode(inDir, inFileName, outDir, outFileName, "raw");
            return;
        }
        if (typeName.equals("drawable") || typeName.equals("mipmap")) {
            if (inFileName.toLowerCase().endsWith(".9" + ext)) {
                outFileName = outResName + ".9" + ext;
                // check for htc .r.9.png
                if (inFileName.toLowerCase().endsWith(".r.9" + ext)) {
                    outFileName = outResName + ".r.9" + ext;
                }
                // check for samsung qmg & spi
                if (inFileName.toLowerCase().endsWith(".qmg") || inFileName.toLowerCase().endsWith(".spi")) {
                    copyRaw(inDir, outDir, outFileName);
                    return;
                }
                // check for xml 9 patches which are just xml files
                if (inFileName.toLowerCase().endsWith(".xml")) {
                    decode(inDir, inFileName, outDir, outFileName, "xml");
                    return;
                }
                try {
                    decode(inDir, inFileName, outDir, outFileName, "9patch");
                    return;
                } catch (CantFind9PatchChunk ex) {
                    LOGGER.log(Level.WARNING, String.format("Cant find 9patch chunk in file: \"%s\". Renaming it to *.png.", inFileName), ex);
                    outDir.removeFile(outFileName);
                    outFileName = outResName + ext;
                }
            }
            if (!".xml".equals(ext)) {
                decode(inDir, inFileName, outDir, outFileName, "raw");
                return;
            }
        }
        decode(inDir, inFileName, outDir, outFileName, "xml");
    } catch (AndrolibException ex) {
        LOGGER.log(Level.SEVERE, String.format("Could not decode file, replacing by FALSE value: %s", inFileName), ex);
        res.replace(new ResBoolValue(false, 0, null));
    }
}
Also used : ResFileValue(brut.androlib.res.data.value.ResFileValue) CantFind9PatchChunk(brut.androlib.err.CantFind9PatchChunk) AndrolibException(brut.androlib.AndrolibException) ResBoolValue(brut.androlib.res.data.value.ResBoolValue)

Aggregations

AndrolibException (brut.androlib.AndrolibException)1 CantFind9PatchChunk (brut.androlib.err.CantFind9PatchChunk)1 ResBoolValue (brut.androlib.res.data.value.ResBoolValue)1 ResFileValue (brut.androlib.res.data.value.ResFileValue)1