- /**
- * Fix the source cover to the given story cover.
- *
- * @param source
- * the source to change
- * @param coverImage
- * the cover image
- */
- void setSourceCover(String source, Image coverImage) {
- sourceCovers.put(source, coverImage);
- File cover = new File(getExpectedDir(source), ".cover");
- try {
- Instance.getCache().saveAsImage(sourceCovers.get(source), cover,
- true);
- } catch (IOException e) {
- Instance.getTraceHandler().error(e);
- sourceCovers.remove(source);
+ private void addToStories(Progress pgFiles, File dir) {
+ File[] infoFilesAndSubdirs = dir.listFiles(new FileFilter() {
+ @Override
+ public boolean accept(File file) {
+ boolean info = file != null && file.isFile()
+ && file.getPath().toLowerCase().endsWith(".info");
+ boolean dir = file != null && file.isDirectory();
+ boolean isExpandedHtml = new File(file, "index.html").isFile();
+ return info || (dir && !isExpandedHtml);
+ }
+ });
+
+ if (pgFiles != null) {
+ pgFiles.setMinMax(0, infoFilesAndSubdirs.length);
+ }
+
+ for (File infoFileOrSubdir : infoFilesAndSubdirs) {
+ if (pgFiles != null) {
+ pgFiles.setName(infoFileOrSubdir.getName());
+ }
+
+ if (infoFileOrSubdir.isDirectory()) {
+ addToStories(null, infoFileOrSubdir);
+ } else {
+ try {
+ MetaData meta = InfoReader
+ .readMeta(infoFileOrSubdir, false);
+ try {
+ int id = Integer.parseInt(meta.getLuid());
+ if (id > lastId) {
+ lastId = id;
+ }
+
+ stories.put(meta, new File[] { infoFileOrSubdir,
+ getTargetFile(meta, infoFileOrSubdir) });
+ } catch (Exception e) {
+ // not normal!!
+ throw new IOException("Cannot understand the LUID of "
+ + infoFileOrSubdir + ": " + 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: "
+ + infoFileOrSubdir, e));
+ }
+ }
+
+ if (pgFiles != null) {
+ pgFiles.add(1);
+ }