diff --git a/src/brut/androlib/err/CantFind9PatchChunk.java b/src/brut/androlib/err/CantFind9PatchChunk.java new file mode 100644 index 00000000..8d98244a --- /dev/null +++ b/src/brut/androlib/err/CantFind9PatchChunk.java @@ -0,0 +1,40 @@ +/* + * Copyright 2010 Ryszard Wiśniewski . + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * under the License. + */ +package brut.androlib.err; + +import brut.androlib.AndrolibException; + +/** + * @author Ryszard Wiśniewski + */ +public class CantFind9PatchChunk extends AndrolibException { + + public CantFind9PatchChunk(Throwable cause) { + super(cause); + } + + public CantFind9PatchChunk(String message, Throwable cause) { + super(message, cause); + } + + public CantFind9PatchChunk(String message) { + super(message); + } + + public CantFind9PatchChunk() { + } +} diff --git a/src/brut/androlib/res/decoder/Res9patchStreamDecoder.java b/src/brut/androlib/res/decoder/Res9patchStreamDecoder.java index cadba789..f6549e38 100644 --- a/src/brut/androlib/res/decoder/Res9patchStreamDecoder.java +++ b/src/brut/androlib/res/decoder/Res9patchStreamDecoder.java @@ -18,6 +18,7 @@ package brut.androlib.res.decoder; import brut.androlib.AndrolibException; +import brut.androlib.err.CantFind9PatchChunk; import brut.util.ExtDataInput; import java.awt.image.BufferedImage; import java.io.*; @@ -79,7 +80,7 @@ public class Res9patchStreamDecoder implements ResStreamDecoder { try { size = di.readInt(); } catch (IOException ex) { - throw new AndrolibException("Cant find nine patch chunk", ex); + throw new CantFind9PatchChunk("Cant find nine patch chunk", ex); } if (di.readInt() == NP_CHUNK_TYPE) { return; diff --git a/src/brut/androlib/res/decoder/ResFileDecoder.java b/src/brut/androlib/res/decoder/ResFileDecoder.java index 79b24399..0b54cf45 100644 --- a/src/brut/androlib/res/decoder/ResFileDecoder.java +++ b/src/brut/androlib/res/decoder/ResFileDecoder.java @@ -18,6 +18,7 @@ package brut.androlib.res.decoder; import brut.androlib.AndrolibException; +import brut.androlib.err.CantFind9PatchChunk; import brut.androlib.res.data.ResResource; import brut.androlib.res.data.value.ResFileValue; import brut.directory.Directory; @@ -62,8 +63,19 @@ public class ResFileDecoder { if (typeName.equals("drawable")) { if (inFileName.toLowerCase().endsWith(".9.png")) { outFileName = outResName + ".9" + ext; - decode(inDir, inFileName, outDir, outFileName, "9patch"); - 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 (! ext.equals(".xml")) { decode(inDir, inFileName, outDir, outFileName, "raw");