From 925298fd058a953144058f8b70d939c2a3e7ea5b Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sat, 2 Dec 2017 17:23:33 +0100 Subject: [PATCH] Fix some CBZ cover/fake cover issues --- src/be/nikiroo/fanfix/Main.java | 4 +-- .../nikiroo/fanfix/library/BasicLibrary.java | 2 +- .../nikiroo/fanfix/library/LocalLibrary.java | 2 +- src/be/nikiroo/fanfix/output/BasicOutput.java | 36 +++++++++++-------- src/be/nikiroo/fanfix/output/Cbz.java | 9 +++-- src/be/nikiroo/fanfix/output/Epub.java | 4 +-- src/be/nikiroo/fanfix/output/Html.java | 4 +-- .../nikiroo/fanfix/output/package-info.java | 2 +- .../nikiroo/fanfix/reader/GuiReaderFrame.java | 17 +++++---- src/be/nikiroo/fanfix/supported/Cbz.java | 1 + 10 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/be/nikiroo/fanfix/Main.java b/src/be/nikiroo/fanfix/Main.java index 9d462c4..f18e03c 100644 --- a/src/be/nikiroo/fanfix/Main.java +++ b/src/be/nikiroo/fanfix/Main.java @@ -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, diff --git a/src/be/nikiroo/fanfix/library/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java index 42c6c9d..df283db 100644 --- a/src/be/nikiroo/fanfix/library/BasicLibrary.java +++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java @@ -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); } diff --git a/src/be/nikiroo/fanfix/library/LocalLibrary.java b/src/be/nikiroo/fanfix/library/LocalLibrary.java index 4c45425..e6018df 100644 --- a/src/be/nikiroo/fanfix/library/LocalLibrary.java +++ b/src/be/nikiroo/fanfix/library/LocalLibrary.java @@ -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; diff --git a/src/be/nikiroo/fanfix/output/BasicOutput.java b/src/be/nikiroo/fanfix/output/BasicOutput.java index 30c2ac6..03218bc 100644 --- a/src/be/nikiroo/fanfix/output/BasicOutput.java +++ b/src/be/nikiroo/fanfix/output/BasicOutput.java @@ -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 .info 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); } } diff --git a/src/be/nikiroo/fanfix/output/Cbz.java b/src/be/nikiroo/fanfix/output/Cbz.java index 8853c76..a84428c 100644 --- a/src/be/nikiroo/fanfix/output/Cbz.java +++ b/src/be/nikiroo/fanfix/output/Cbz.java @@ -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()) { diff --git a/src/be/nikiroo/fanfix/output/Epub.java b/src/be/nikiroo/fanfix/output/Epub.java index 1ff6888..48da65a 100644 --- a/src/be/nikiroo/fanfix/output/Epub.java +++ b/src/be/nikiroo/fanfix/output/Epub.java @@ -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"); diff --git a/src/be/nikiroo/fanfix/output/Html.java b/src/be/nikiroo/fanfix/output/Html.java index f5fbb83..d1559b4 100644 --- a/src/be/nikiroo/fanfix/output/Html.java +++ b/src/be/nikiroo/fanfix/output/Html.java @@ -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)); diff --git a/src/be/nikiroo/fanfix/output/package-info.java b/src/be/nikiroo/fanfix/output/package-info.java index 6b7e490..8314c80 100644 --- a/src/be/nikiroo/fanfix/output/package-info.java +++ b/src/be/nikiroo/fanfix/output/package-info.java @@ -3,7 +3,7 @@ *

* 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. * diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java index 9174380..99091d3 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java @@ -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" diff --git a/src/be/nikiroo/fanfix/supported/Cbz.java b/src/be/nikiroo/fanfix/supported/Cbz.java index f67f28a..77a4008 100644 --- a/src/be/nikiroo/fanfix/supported/Cbz.java +++ b/src/be/nikiroo/fanfix/supported/Cbz.java @@ -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); -- 2.27.0