+ InputStream cbzIn = null;
+ ZipInputStream zipIn = null;
+ try {
+ cbzIn = new MarkableFileInputStream(getSourceFileOriginal());
+ zipIn = new ZipInputStream(cbzIn);
+ for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn
+ .getNextEntry()) {
+ if (!entry.isDirectory()
+ && entry.getName().startsWith(getDataPrefix())) {
+ String entryLName = entry.getName().toLowerCase();
+ boolean imageEntry = false;
+ for (String ext : bsImages.getImageExt(false)) {
+ if (entryLName.endsWith(ext)) {
+ imageEntry = true;
+ }
+ }
+
+ if (imageEntry) {
+ String uuid = meta.getUuid() + "_" + entry.getName();
+ try {
+ images.put(uuid, new Image(zipIn));
+ } catch (Exception e) {
+ Instance.getTraceHandler().error(e);
+ }
+
+ if (pg.getProgress() < 85) {
+ pg.add(1);
+ }
+ } else if (entryLName.endsWith(".info")) {
+ basename = entryLName.substring(0, entryLName.length()
+ - ".info".length());
+ IOUtils.write(zipIn, new File(tmpDir, entryLName));
+ } else if (entryLName.endsWith(".txt")) {
+ IOUtils.write(zipIn, new File(tmpDir, entryLName));
+ }
+ }
+ }
+
+ pg.setProgress(85);
+
+ // ZIP order is not correct for us
+ List<String> imagesList = new ArrayList<String>(images.keySet());
+ Collections.sort(imagesList);
+
+ pg.setProgress(90);
+
+ // only the description is kept
+ Story origStory = getStoryFromTxt(tmpDir, basename);
+ if (origStory != null) {
+ if (origStory.getMeta().getCover() == null) {
+ origStory.getMeta().setCover(story.getMeta().getCover());
+ }
+ story.setMeta(origStory.getMeta());
+ }
+ story.setChapters(new ArrayList<Chapter>());
+
+ // Check if we can find non-images chapters, for hybrid-cbz support
+ if (origStory != null) {
+ for (Chapter chap : origStory) {
+ Boolean isImages = null;
+ for (Paragraph para : chap) {
+ ParagraphType t = para.getType();
+ if (isImages == null && !t.isText(true)) {
+ isImages = true;
+ }
+ if (t.isText(false)) {
+ String line = para.getContent();
+ // Images are saved in text mode as "[image-link]"
+ if (!(line.startsWith("[") && line.endsWith("]"))) {
+ isImages = false;
+ }
+ }
+ }
+
+ if (isImages != null && !isImages) {
+ story.getChapters().add(chap);
+ chap.setNumber(story.getChapters().size());