Invalidate info for one luid instead of all
[fanfix.git] / src / be / nikiroo / fanfix / library / LocalLibrary.java
index 11c36630adcef96ea73d17c8712d84495260299a..92676b3530288eac94244b9b84c4f23c24bd82c8 100644 (file)
@@ -122,7 +122,7 @@ public class LocalLibrary extends BasicLibrary {
                                        meta = InfoReader.readMeta(infoFile, true);
                                        return meta.getCover();
                                } catch (IOException e) {
-                                       Instance.syserr(e);
+                                       Instance.getTraceHandler().error(e);
                                }
                        }
                }
@@ -131,7 +131,7 @@ public class LocalLibrary extends BasicLibrary {
        }
 
        @Override
-       protected void clearCache() {
+       protected void invalidateInfo(String luid) {
                stories = null;
                sourceCovers = new HashMap<String, BufferedImage>();
        }
@@ -147,6 +147,7 @@ public class LocalLibrary extends BasicLibrary {
                for (File file : getRelatedFiles(luid)) {
                        // TODO: throw an IOException if we cannot delete the files?
                        IOUtils.deltree(file);
+                       file.getParentFile().delete();
                }
        }
 
@@ -157,7 +158,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;
@@ -182,15 +183,17 @@ public class LocalLibrary extends BasicLibrary {
                                                        "\\.info$", "");
                                        InfoCover.writeInfo(newDir, name, meta);
                                        relatedFile.delete();
+                                       relatedFile.getParentFile().delete();
                                } catch (IOException e) {
-                                       Instance.syserr(e);
+                                       Instance.getTraceHandler().error(e);
                                }
                        } else {
                                relatedFile.renameTo(new File(newDir, relatedFile.getName()));
+                               relatedFile.getParentFile().delete();
                        }
                }
 
-               clearCache();
+               invalidateInfo();
        }
 
        @Override
@@ -209,7 +212,7 @@ public class LocalLibrary extends BasicLibrary {
                try {
                        ImageIO.write(sourceCovers.get(source), "png", cover);
                } catch (IOException e) {
-                       Instance.syserr(e);
+                       Instance.getTraceHandler().error(e);
                        sourceCovers.remove(source);
                }
        }
@@ -261,7 +264,7 @@ public class LocalLibrary extends BasicLibrary {
                                        pg.add(1);
                                }
 
-                               clearCache();
+                               invalidateInfo();
                                pg.done();
                                return;
                        }
@@ -269,7 +272,7 @@ public class LocalLibrary extends BasicLibrary {
 
                super.imprt(other, luid, pg);
 
-               clearCache();
+               invalidateInfo();
        }
 
        /**
@@ -383,7 +386,8 @@ public class LocalLibrary extends BasicLibrary {
                }
 
                String coverExt = "."
-                               + Instance.getConfig().getString(Config.IMAGE_FORMAT_COVER);
+                               + Instance.getConfig().getString(Config.IMAGE_FORMAT_COVER)
+                                               .toLowerCase();
                File coverFile = new File(path + coverExt);
                if (!coverFile.exists()) {
                        coverFile = new File(path.substring(0,
@@ -403,7 +407,7 @@ public class LocalLibrary extends BasicLibrary {
         * {@link LocalLibrary#baseDir}.
         * <p>
         * Will use a cached list when possible (see
-        * {@link BasicLibrary#clearCache()}).
+        * {@link BasicLibrary#invalidateInfo()}).
         * 
         * @param pg
         *            the optional {@link Progress}
@@ -472,8 +476,10 @@ public class LocalLibrary extends BasicLibrary {
                                        } catch (IOException e) {
                                                // We should not have not-supported files in the
                                                // library
-                                               Instance.syserr(new IOException(
-                                                               "Cannot load file from library: " + infoFile, e));
+                                               Instance.getTraceHandler().error(
+                                                               new IOException(
+                                                                               "Cannot load file from library: "
+                                                                                               + infoFile, e));
                                        }
                                        pgFiles.add(1);
                                }
@@ -489,7 +495,7 @@ public class LocalLibrary extends BasicLibrary {
                                                        in.close();
                                                }
                                        } catch (IOException e) {
-                                               Instance.syserr(e);
+                                               Instance.getTraceHandler().error(e);
                                        }
                                }
 
@@ -516,7 +522,7 @@ public class LocalLibrary extends BasicLibrary {
                try {
                        ImageIO.write(sourceCovers.get(source), "png", cover);
                } catch (IOException e) {
-                       Instance.syserr(e);
+                       Instance.getTraceHandler().error(e);
                        sourceCovers.remove(source);
                }
        }