X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FLocalLibrary.java;h=5e0ad40097f8add91f78d73cf1cf61b3334c53e7;hp=041db1013dbf85bfd0a41112676dcc6e4f31c055;hb=9fe3f17729759e933d7687cc2838f7255f2c9283;hpb=16a81ef7656c5c692fb831927e75edde25dd77a0 diff --git a/src/be/nikiroo/fanfix/library/LocalLibrary.java b/src/be/nikiroo/fanfix/library/LocalLibrary.java index 041db10..5e0ad40 100644 --- a/src/be/nikiroo/fanfix/library/LocalLibrary.java +++ b/src/be/nikiroo/fanfix/library/LocalLibrary.java @@ -128,7 +128,7 @@ public class LocalLibrary extends BasicLibrary { } @Override - protected void invalidateInfo(String luid) { + protected synchronized void invalidateInfo(String luid) { stories = null; sourceCovers = new HashMap(); } @@ -431,77 +431,81 @@ public class LocalLibrary extends BasicLibrary { } }); - Progress pgDirs = new Progress(0, 100 * dirs.length); - pg.addProgress(pgDirs, 100); + if (dirs != null) { + Progress pgDirs = new Progress(0, 100 * dirs.length); + pg.addProgress(pgDirs, 100); + + for (File dir : dirs) { + File[] infoFiles = dir.listFiles(new FileFilter() { + @Override + public boolean accept(File file) { + return file != null + && file.getPath().toLowerCase() + .endsWith(".info"); + } + }); - for (File dir : dirs) { - File[] infoFiles = dir.listFiles(new FileFilter() { - @Override - public boolean accept(File file) { - return file != null - && file.getPath().toLowerCase() - .endsWith(".info"); - } - }); - - Progress pgFiles = new Progress(0, infoFiles.length); - pgDirs.addProgress(pgFiles, 100); - pgDirs.setName("Loading from: " + dir.getName()); - - String source = null; - for (File infoFile : infoFiles) { - pgFiles.setName(infoFile.getName()); - try { - MetaData meta = InfoReader.readMeta(infoFile, false); - source = meta.getSource(); + Progress pgFiles = new Progress(0, infoFiles.length); + pgDirs.addProgress(pgFiles, 100); + pgDirs.setName("Loading from: " + dir.getName()); + + String source = null; + for (File infoFile : infoFiles) { + pgFiles.setName(infoFile.getName()); try { - int id = Integer.parseInt(meta.getLuid()); - if (id > lastId) { - lastId = id; - } + MetaData meta = InfoReader + .readMeta(infoFile, false); + source = meta.getSource(); + try { + int id = Integer.parseInt(meta.getLuid()); + if (id > lastId) { + lastId = id; + } - stories.put(meta, new File[] { infoFile, - getTargetFile(meta, infoFile) }); - } catch (Exception e) { - // not normal!! - throw new IOException( - "Cannot understand the LUID of " - + infoFile - + ": " - + (meta == null ? "[meta is NULL]" - : meta.getLuid()), e); + stories.put(meta, new File[] { infoFile, + getTargetFile(meta, infoFile) }); + } catch (Exception e) { + // not normal!! + throw new IOException( + "Cannot understand the LUID of " + + infoFile + + ": " + + (meta == null ? "[meta is NULL]" + : meta.getLuid()), e); + } + } catch (IOException e) { + // We should not have not-supported files in the + // library + Instance.getTraceHandler().error( + new IOException( + "Cannot load file from library: " + + infoFile, e)); } - } catch (IOException e) { - // We should not have not-supported files in the - // library - Instance.getTraceHandler().error( - new IOException( - "Cannot load file from library: " - + infoFile, e)); + pgFiles.add(1); } - pgFiles.add(1); - } - File cover = new File(dir, ".cover.png"); - if (cover.exists()) { - try { - InputStream in = new FileInputStream(cover); + File cover = new File(dir, ".cover.png"); + if (cover.exists()) { try { - sourceCovers.put(source, new Image(in)); - } finally { - in.close(); + InputStream in = new FileInputStream(cover); + try { + sourceCovers.put(source, new Image(in)); + } finally { + in.close(); + } + } catch (IOException e) { + Instance.getTraceHandler().error(e); } - } catch (IOException e) { - Instance.getTraceHandler().error(e); } + + pgFiles.setName(null); } - pgFiles.setName(null); + pgDirs.setName("Loading directories"); } - - pgDirs.setName("Loading directories"); } + pg.done(); return stories; }