Library scanning much quicker
[nikiroo-utils.git] / src / be / nikiroo / fanfix / Library.java
index 9864ad773d085527c28e1dba467bf7a01be6ca1b..1b9419a6cb73804c3b509fff15322fc30288f8ce 100644 (file)
@@ -9,13 +9,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.output.BasicOutput;
 import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.fanfix.supported.BasicSupport;
 import be.nikiroo.fanfix.supported.BasicSupport.SupportType;
+import be.nikiroo.fanfix.supported.InfoReader;
 
 /**
  * Manage a library of Stories: import, export, list.
@@ -28,8 +28,6 @@ import be.nikiroo.fanfix.supported.BasicSupport.SupportType;
 public class Library {
        private File baseDir;
        private Map<MetaData, File> stories;
-       private BasicSupport itSupport = BasicSupport
-                       .getSupport(SupportType.INFO_TEXT);
        private int lastId;
 
        /**
@@ -82,8 +80,15 @@ public class Library {
                        for (Entry<MetaData, File> entry : getStories().entrySet()) {
                                if (luid.equals(entry.getKey().getLuid())) {
                                        try {
-                                               return itSupport.process(entry.getValue().toURI()
-                                                               .toURL());
+                                               SupportType type = SupportType.valueOfAllOkUC(entry
+                                                               .getKey().getType());
+                                               URL url = entry.getValue().toURI().toURL();
+                                               if (type != null) {
+                                                       return BasicSupport.getSupport(type).process(url);
+                                               } else {
+                                                       throw new IOException("Unknown type: "
+                                                                       + entry.getKey().getType());
+                                               }
                                        } catch (IOException e) {
                                                // We should not have not-supported files in the
                                                // library
@@ -219,29 +224,27 @@ public class Library {
        private Map<MetaData, File> getStories() {
                if (stories.isEmpty()) {
                        lastId = 0;
-                       String format = Instance.getConfig()
-                                       .getString(Config.IMAGE_FORMAT_COVER).toLowerCase();
+
                        for (File dir : baseDir.listFiles()) {
                                if (dir.isDirectory()) {
                                        for (File file : dir.listFiles()) {
                                                try {
-                                                       String path = file.getPath().toLowerCase();
-                                                       if (!path.endsWith(".info")
-                                                                       && !path.endsWith(format)) {
-                                                               MetaData meta = itSupport.processMeta(
-                                                                               file.toURI().toURL()).getMeta();
-                                                               stories.put(meta, file);
-
+                                                       if (file.getPath().toLowerCase().endsWith(".info")) {
+                                                               MetaData meta = InfoReader.readMeta(file);
                                                                try {
                                                                        int id = Integer.parseInt(meta.getLuid());
                                                                        if (id > lastId) {
                                                                                lastId = id;
                                                                        }
+
+                                                                       stories.put(meta, file);
+
                                                                } catch (Exception e) {
                                                                        // not normal!!
                                                                        Instance.syserr(new IOException(
-                                                                                       "Cannot read the LUID of: "
-                                                                                                       + file.getPath(), e));
+                                                                                       "Cannot understand the LUID of "
+                                                                                                       + file.getPath() + ": "
+                                                                                                       + meta.getLuid(), e));
                                                                }
                                                        }
                                                } catch (IOException e) {