Fixes:
authorNiki Roo <niki@nikiroo.be>
Wed, 8 Aug 2018 14:58:26 +0000 (16:58 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 8 Aug 2018 14:58:26 +0000 (16:58 +0200)
- tmp files deleted too soon in GUI mode
- cover unavailable could cause a crash
- EPUB import error when no cover

src/be/nikiroo/fanfix/Main.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderBook.java
src/be/nikiroo/fanfix/supported/Text.java

index 42f3924daa811bdb1bb6e121d38c01b651bf828b..41206560a3bde407bf0d1f12ddc1f9081dc00d4d 100644 (file)
@@ -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) {
index 4343ca522b207f335492210506bd1a4c13924d6c..72af3f1f9446e2e2e05e25f7424341786109faa2 100644 (file)
@@ -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);
index f6803cd09d6358880290cdf8e2c487caf5794e16..cba23bf8c2f1815d2eddba3ff611ed1951b9e4b6 100644 (file)
@@ -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