Allow IOError when saving CBZ
[fanfix.git] / src / be / nikiroo / fanfix / output / Text.java
index 28f3894b78b3b23f0d25c052006c3c7d0158d32a..4a45e5430fba9465b1e92a590bcae9cc18b28360 100644 (file)
@@ -5,7 +5,6 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.net.URL;
 
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.StringId;
@@ -18,6 +17,7 @@ import be.nikiroo.fanfix.data.Story;
 class Text extends BasicOutput {
        protected BufferedWriter writer;
        protected File targetDir;
+       private boolean nextParaIsCover = true;
 
        @Override
        public File process(Story story, File targetDir, String targetName)
@@ -105,8 +105,16 @@ class Text extends BasicOutput {
        protected void writeParagraphHeader(Paragraph para) throws IOException {
                if (para.getType() == ParagraphType.IMAGE) {
                        File file = new File(targetDir, getCurrentImageBestName(true));
-                       Instance.getCache().saveAsImage(new URL(para.getContent()), file);
+                       try {
+                               Instance.getCache().saveAsImage(para.getContentImage(), file,
+                                               nextParaIsCover);
+                       } catch (IOException e) {
+                               Instance.getTraceHandler().error(
+                                               new IOException("Cannot save an image", e));
+                       }
                }
+
+               nextParaIsCover = false;
        }
 
        @Override