Some fixes: output types, libraries, remote
[nikiroo-utils.git] / src / be / nikiroo / fanfix / Main.java
index ee122bd508349e461544055fa818a037da9e3fed..c17a1d8b988f0a52c7c763efd9bad67f48bebd92 100644 (file)
@@ -199,6 +199,7 @@ public class Main {
                mainProgress.addProgressListener(new Progress.ProgressListener() {
                        private int current = mainProgress.getMin();
 
+                       @Override
                        public void progress(Progress progress, String name) {
                                int diff = progress.getProgress() - current;
                                current += diff;
@@ -252,12 +253,30 @@ public class Main {
                                updates.ok(); // we consider it read
                                break;
                        case LIST:
+                               if (BasicReader.getReader() == null) {
+                                       Instance.syserr(new Exception(
+                                                       "No reader type has been configured"));
+                                       exitCode = 10;
+                                       break;
+                               }
                                exitCode = list(sourceString);
                                break;
                        case READ:
+                               if (BasicReader.getReader() == null) {
+                                       Instance.syserr(new Exception(
+                                                       "No reader type has been configured"));
+                                       exitCode = 10;
+                                       break;
+                               }
                                exitCode = read(luid, chapString, true);
                                break;
                        case READ_URL:
+                               if (BasicReader.getReader() == null) {
+                                       Instance.syserr(new Exception(
+                                                       "No reader type has been configured"));
+                                       exitCode = 10;
+                                       break;
+                               }
                                exitCode = read(urlString, chapString, false);
                                break;
                        case HELP:
@@ -276,6 +295,12 @@ public class Main {
                                updates.ok(); // we consider it read
                                break;
                        case START:
+                               if (BasicReader.getReader() == null) {
+                                       Instance.syserr(new Exception(
+                                                       "No reader type has been configured"));
+                                       exitCode = 10;
+                                       break;
+                               }
                                BasicReader.getReader().browse(null);
                                break;
                        case SERVER:
@@ -292,7 +317,7 @@ public class Main {
                                }
                                return;
                        case REMOTE:
-                               exitCode = 255;
+                               exitCode = 255; // should not be reachable (REMOTE -> START)
                                break;
                        }
                }
@@ -347,7 +372,7 @@ public class Main {
         */
        public static int export(String luid, String typeString, String target,
                        Progress pg) {
-               OutputType type = OutputType.valueOfNullOkUC(typeString);
+               OutputType type = OutputType.valueOfNullOkUC(typeString, null);
                if (type == null) {
                        Instance.syserr(new Exception(trans(StringId.OUTPUT_DESC,
                                        typeString)));
@@ -398,14 +423,15 @@ public class Main {
                try {
                        Reader reader = BasicReader.getReader();
                        if (library) {
-                               reader.setStory(story, null);
+                               reader.setMeta(story);
                        } else {
-                               reader.setStory(BasicReader.getUrl(story), null);
+                               reader.setMeta(BasicReader.getUrl(story), null);
                        }
 
                        if (chapString != null) {
                                try {
-                                       reader.read(Integer.parseInt(chapString));
+                                       reader.setChapter(Integer.parseInt(chapString));
+                                       reader.read();
                                } catch (NumberFormatException e) {
                                        Instance.syserr(new IOException(
                                                        "Chapter number cannot be parsed: " + chapString, e));
@@ -451,7 +477,7 @@ public class Main {
                                sourceName = sourceName.substring("file://".length());
                        }
 
-                       OutputType type = OutputType.valueOfAllOkUC(typeString);
+                       OutputType type = OutputType.valueOfAllOkUC(typeString, null);
                        if (type == null) {
                                Instance.syserr(new IOException(trans(
                                                StringId.ERR_BAD_OUTPUT_TYPE, typeString)));