Fix some CBZ cover/fake cover issues
authorNiki Roo <niki@nikiroo.be>
Sat, 2 Dec 2017 16:23:33 +0000 (17:23 +0100)
committerNiki Roo <niki@nikiroo.be>
Sat, 2 Dec 2017 16:23:33 +0000 (17:23 +0100)
src/be/nikiroo/fanfix/Main.java
src/be/nikiroo/fanfix/library/BasicLibrary.java
src/be/nikiroo/fanfix/library/LocalLibrary.java
src/be/nikiroo/fanfix/output/BasicOutput.java
src/be/nikiroo/fanfix/output/Cbz.java
src/be/nikiroo/fanfix/output/Epub.java
src/be/nikiroo/fanfix/output/Html.java
src/be/nikiroo/fanfix/output/package-info.java
src/be/nikiroo/fanfix/reader/GuiReaderFrame.java
src/be/nikiroo/fanfix/supported/Cbz.java

index 9d462c402f619246a8ae4854ed1ffe8c185e6250..f18e03ca5dcefed8b616fae27e280d062da299ef 100644 (file)
@@ -542,8 +542,8 @@ public class Main {
                                                Story story = support.process(source, pgIn);
                                                try {
                                                        target = new File(target).getAbsolutePath();
-                                                       BasicOutput.getOutput(type, infoCover).process(
-                                                                       story, target, pgOut);
+                                                       BasicOutput.getOutput(type, infoCover, infoCover)
+                                                                       .process(story, target, pgOut);
                                                } catch (IOException e) {
                                                        Instance.getTraceHandler().error(
                                                                        new IOException(trans(StringId.ERR_SAVING,
index 42c6c9d843063dc64956dc90e285ac476e068b1d..df283db258304a475714156de90abec37f344945 100644 (file)
@@ -445,7 +445,7 @@ abstract public class BasicLibrary {
                        pg.addProgress(pgOut, 1);
                }
 
-               BasicOutput out = BasicOutput.getOutput(type, false);
+               BasicOutput out = BasicOutput.getOutput(type, false, false);
                if (out == null) {
                        throw new IOException("Output type not supported: " + type);
                }
index 4c4542551410d06cbe9d9e074961214d64c48129..e6018dfc20654a0f9b109032a1acf427586da6d5 100644 (file)
@@ -157,7 +157,7 @@ public class LocalLibrary extends BasicLibrary {
                File expectedTarget = getExpectedFile(meta);
                expectedTarget.getParentFile().mkdirs();
 
-               BasicOutput it = BasicOutput.getOutput(getOutputType(meta), true);
+               BasicOutput it = BasicOutput.getOutput(getOutputType(meta), true, true);
                it.process(story, expectedTarget.getPath(), pg);
 
                return story;
index 30c2ac66642d2608391b8543af76a9366e679b9e..03218bcdf8f22f80404261f41998c3a19dd36722 100644 (file)
@@ -86,7 +86,7 @@ public abstract class BasicOutput {
                 * @return the extension
                 */
                public String getDefaultExtension(boolean readerTarget) {
-                       BasicOutput output = BasicOutput.getOutput(this, false);
+                       BasicOutput output = BasicOutput.getOutput(this, false, false);
                        if (output != null) {
                                return output.getDefaultExtension(readerTarget);
                        }
@@ -264,18 +264,18 @@ public abstract class BasicOutput {
         * 
         * @param type
         *            the new type
-        * @param writeInfo
-        *            TRUE to enable the creation of a .info file
         * @param writeCover
         *            TRUE to enable the creation of a cover if possible
+        * @param writeInfo
+        *            TRUE to enable the creation of a .info file
         * 
         * @return this
         */
-       protected BasicOutput setType(OutputType type, boolean writeCover,
-                       boolean writeInfo) {
+       protected BasicOutput setType(OutputType type, boolean writeInfo,
+                       boolean writeCover) {
                this.type = type;
-               this.writeCover = writeCover;
                this.writeInfo = writeInfo;
+               this.writeCover = writeCover;
 
                return this;
        }
@@ -334,6 +334,10 @@ public abstract class BasicOutput {
                        story.getMeta().setType("" + getType());
                }
 
+               System.out.println(story.getMeta().getTitle() + " -> write cover: "
+                               + writeCover);
+               new Exception().printStackTrace();
+
                if (writeCover) {
                        InfoCover.writeCover(targetDir, targetName, story.getMeta());
                }
@@ -514,29 +518,33 @@ public abstract class BasicOutput {
         * 
         * @param type
         *            the type
-        * @param infoCover
-        *            force the <tt>.info</tt> file and the cover to be saved next
+        * @param writeCover
+        *            TRUE to enable the creation of a cover if possible to be saved
+        *            next to the main target file
+        * @param writeInfo
+        *            TRUE to enable the creation of a .info file to be saved next
         *            to the main target file
         * 
         * @return the {@link BasicOutput}
         */
-       public static BasicOutput getOutput(OutputType type, boolean infoCover) {
+       public static BasicOutput getOutput(OutputType type, boolean writeInfo,
+                       boolean writeCover) {
                if (type != null) {
                        switch (type) {
                        case EPUB:
-                               return new Epub().setType(type, infoCover, infoCover);
+                               return new Epub().setType(type, writeInfo, writeCover);
                        case TEXT:
-                               return new Text().setType(type, true, infoCover);
+                               return new Text().setType(type, writeInfo, true);
                        case INFO_TEXT:
                                return new InfoText().setType(type, true, true);
                        case SYSOUT:
                                return new Sysout().setType(type, false, false);
                        case CBZ:
-                               return new Cbz().setType(type, infoCover, infoCover);
+                               return new Cbz().setType(type, writeInfo, writeCover);
                        case LATEX:
-                               return new LaTeX().setType(type, infoCover, infoCover);
+                               return new LaTeX().setType(type, writeInfo, writeCover);
                        case HTML:
-                               return new Html().setType(type, infoCover, infoCover);
+                               return new Html().setType(type, writeInfo, writeCover);
                        }
                }
 
index 8853c7695a2c6ac94883f6b8d1b80146e0710d3f..a84428c4f155d35273649ed8c550918b9606f12d 100644 (file)
@@ -26,9 +26,12 @@ class Cbz extends BasicOutput {
                dir.delete();
                dir.mkdir();
                try {
-                       // will also save the images!
-                       BasicOutput.getOutput(OutputType.TEXT, isWriteInfo()).process(
-                                       story, dir, targetNameOrig);
+                       // will also save the images! (except the cover -> false)
+                       BasicOutput
+                                       .getOutput(OutputType.TEXT, isWriteInfo(), isWriteCover())
+                                       // Force cover to FALSE:
+                                       .setType(OutputType.TEXT, isWriteInfo(), false)
+                                       .process(story, dir, targetNameOrig);
 
                        InfoCover.writeInfo(dir, targetNameOrig, story.getMeta());
                        if (story.getMeta() != null && !story.getMeta().isFakeCover()) {
index 1ff6888ac42e13a185b2e1bda96b3ab9c552aa3d..48da65a293704fc5eb13c9ee69ac17975b9d2f34 100644 (file)
@@ -44,8 +44,8 @@ class Epub extends BasicOutput {
                // "Originals"
                File data = new File(tmpDir, "DATA");
                data.mkdir();
-               BasicOutput.getOutput(OutputType.TEXT, isWriteInfo()).process(story,
-                               data, targetNameOrig);
+               BasicOutput.getOutput(OutputType.TEXT, isWriteInfo(), isWriteCover())
+                               .process(story, data, targetNameOrig);
                InfoCover.writeInfo(data, targetNameOrig, story.getMeta());
                IOUtils.writeSmallFile(data, "version", "3.0");
 
index f5fbb831c51cf063d856e89bbe095a687de107f7..d1559b401326bbc1815b8743040e807c17290d27 100644 (file)
@@ -37,8 +37,8 @@ class Html extends BasicOutput {
                // write a copy of the originals inside
                InfoCover.writeInfo(dir, targetName, story.getMeta());
                InfoCover.writeCover(dir, targetName, story.getMeta());
-               BasicOutput.getOutput(OutputType.TEXT, isWriteInfo()).process(story,
-                               dir, targetNameOrig);
+               BasicOutput.getOutput(OutputType.TEXT, isWriteInfo(), isWriteCover())
+                               .process(story, dir, targetNameOrig);
 
                target = new File(targetDir, targetName + getDefaultExtension(true));
 
index 6b7e490e408793ab63bb5b3dcc93a94566588372..8314c80363b307e75c184afe16fc32595d94490b 100644 (file)
@@ -3,7 +3,7 @@
  * <p>
  * Of those, only {@link be.nikiroo.fanfix.output.BasicOutput} is public,
  * but it contains a method 
- * ({@link be.nikiroo.fanfix.output.BasicOutput#getOutput(be.nikiroo.fanfix.output.BasicOutput.OutputType, boolean)})
+ * ({@link be.nikiroo.fanfix.output.BasicOutput#getOutput(be.nikiroo.fanfix.output.BasicOutput.OutputType, boolean,boolean)})
  * to get all the other 
  * {@link be.nikiroo.fanfix.output.BasicOutput.OutputType}s.
  * 
index 9174380aa507526e4cdc1fba62cf771b967f4353..99091d376ed03de370002f75fceb4538c52a9f26 100644 (file)
@@ -901,12 +901,15 @@ class GuiReaderFrame extends JFrame {
                new Thread(new Runnable() {
                        @Override
                        public void run() {
-                               run.run();
-                               refreshBooks();
-                               reload.done();
-                               if (!pg.isDone()) {
-                                       // will trigger pgBar ActionListener:
-                                       pg.done();
+                               try {
+                                       run.run();
+                                       refreshBooks();
+                               } finally {
+                                       reload.done();
+                                       if (!pg.isDone()) {
+                                               // will trigger pgBar ActionListener:
+                                               pg.done();
+                                       }
                                }
                        }
                }, "outOfUi thread").start();
@@ -989,7 +992,7 @@ class GuiReaderFrame extends JFrame {
                                pgOnSuccess.setProgress(0);
                                if (!ok) {
                                        if (e instanceof UnknownHostException) {
-                                               error("Failed to import " + url, "Cannot import URL",
+                                               error("URL not supported: " + url, "Cannot import URL",
                                                                null);
                                        } else {
                                                error("Failed to import " + url + ": \n"
index f67f28ae6f936af9235305b8c568e4ad8ed7310f..77a4008068f4a6ec1b3ea876701dea70b0a830fb 100644 (file)
@@ -122,6 +122,7 @@ class Cbz extends Epub {
 
                if (meta.getCover() == null && !images.isEmpty()) {
                        meta.setCover(images.get(imagesList.get(0)));
+                       meta.setFakeCover(true);
                }
 
                pg.setProgress(100);