From: Niki Roo Date: Wed, 8 Aug 2018 14:58:26 +0000 (+0200) Subject: Fixes: X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=81b5e730677858a7e9c9fc6f2f8f7992a4b8b1c3;p=fanfix-jexer.git Fixes: - tmp files deleted too soon in GUI mode - cover unavailable could cause a crash - EPUB import error when no cover --- diff --git a/src/be/nikiroo/fanfix/Main.java b/src/be/nikiroo/fanfix/Main.java index 42f3924..4120656 100644 --- a/src/be/nikiroo/fanfix/Main.java +++ b/src/be/nikiroo/fanfix/Main.java @@ -351,12 +351,18 @@ public class Main { } } - try { - Instance.getTempFiles().close(); - } catch (IOException e) { - Instance.getTraceHandler() - .error(new IOException( - "Cannot dispose of the temporary files", e)); + // We cannot do it when in GUI mode, because it is async... + // So if we close the temp files before it is actually used, + // we have a problem... + // TODO: close it at the correct time (for now, finalize try to do it) + if (false) { + try { + Instance.getTempFiles().close(); + } catch (IOException e) { + Instance.getTraceHandler().error( + new IOException( + "Cannot dispose of the temporary files", e)); + } } if (exitCode == 255) { diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java index 4343ca5..72af3f1 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java @@ -393,11 +393,12 @@ class GuiReaderBook extends JPanel { if (resizedImage == null) { try { Image cover = null; - if (meta.getLuid() == null) { + if (meta.getLuid() != null) { + cover = reader.getLibrary().getCover(meta.getLuid()); + } + if (cover == null) { cover = reader.getLibrary() .getSourceCover(meta.getSource()); - } else { - cover = reader.getLibrary().getCover(meta.getLuid()); } BufferedImage coverb = ImageUtilsAwt.fromImage(cover); diff --git a/src/be/nikiroo/fanfix/supported/Text.java b/src/be/nikiroo/fanfix/supported/Text.java index f6803cd..cba23bf 100644 --- a/src/be/nikiroo/fanfix/supported/Text.java +++ b/src/be/nikiroo/fanfix/supported/Text.java @@ -18,6 +18,7 @@ import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.bundles.Config; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.utils.Image; +import be.nikiroo.utils.ImageUtils; import be.nikiroo.utils.MarkableFileInputStream; import be.nikiroo.utils.Progress; @@ -188,8 +189,20 @@ class Text extends BasicSupport { } } - return BasicSupportImages.getImage(this, sourceFile.getParentFile(), - path); + Image cover = BasicSupportImages.getImage(this, + sourceFile.getParentFile(), path); + if (cover != null) { + try { + File tmp = Instance.getTempFiles().createTempFile( + "test_cover_image"); + ImageUtils.getInstance().saveAsImage(cover, tmp, "png"); + tmp.delete(); + } catch (IOException e) { + cover = null; + } + } + + return cover; } @Override