+ if (exitCode == 0) {
+ switch (action) {
+ case IMPORT:
+ exitCode = imprt(urlString, pg);
+ updates.ok(); // we consider it read
+ break;
+ case EXPORT:
+ exitCode = export(luid, sourceString, target, pg);
+ updates.ok(); // we consider it read
+ break;
+ case CONVERT:
+ exitCode = convert(urlString, sourceString, target,
+ plusInfo == null ? false : plusInfo, pg);
+ updates.ok(); // we consider it read
+ break;
+ case LIST:
+ if (BasicReader.getReader() == null) {
+ Instance.getTraceHandler()
+ .error(new Exception(
+ "No reader type has been configured"));
+ exitCode = 10;
+ break;
+ }
+ exitCode = list(sourceString);
+ break;
+ case SET_SOURCE:
+ try {
+ Instance.getLibrary().changeSource(luid, sourceString, pg);
+ } catch (IOException e1) {
+ Instance.getTraceHandler().error(e1);
+ exitCode = 21;
+ }
+ break;
+ case SET_TITLE:
+ try {
+ Instance.getLibrary().changeTitle(luid, titleString, pg);
+ } catch (IOException e1) {
+ Instance.getTraceHandler().error(e1);
+ exitCode = 22;
+ }
+ break;
+ case SET_AUTHOR:
+ try {
+ Instance.getLibrary().changeAuthor(luid, authorString, pg);
+ } catch (IOException e1) {
+ Instance.getTraceHandler().error(e1);
+ exitCode = 23;
+ }
+ break;
+ case READ:
+ if (BasicReader.getReader() == null) {
+ Instance.getTraceHandler()
+ .error(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.getTraceHandler()
+ .error(new Exception(
+ "No reader type has been configured"));
+ exitCode = 10;
+ break;
+ }
+ exitCode = read(urlString, chapString, false);
+ break;
+ case SEARCH:
+ page = page == null ? 1 : page;
+ if (page < 0) {
+ Instance.getTraceHandler().error("Incorrect page number");
+ exitCode = 255;
+ break;
+ }
+
+ item = item == null ? 0 : item;
+ if (item < 0) {
+ Instance.getTraceHandler().error("Incorrect item number");
+ exitCode = 255;
+ break;
+ }
+
+ if (BasicReader.getReader() == null) {
+ Instance.getTraceHandler()
+ .error(new Exception(
+ "No reader type has been configured"));
+ exitCode = 10;
+ break;
+ }
+
+ try {
+ if (searchOn == null) {
+ BasicReader.getReader().search(true);
+ } else if (search != null) {
+
+ BasicReader.getReader().search(searchOn, search, page,
+ item, true);
+ } else {
+ exitCode = 255;
+ }
+ } catch (IOException e1) {
+ Instance.getTraceHandler().error(e1);
+ exitCode = 20;
+ }
+
+ break;
+ case SEARCH_TAG:
+ if (searchOn == null) {
+ exitCode = 255;
+ break;
+ }
+
+ page = page == null ? 1 : page;
+ if (page < 0) {
+ Instance.getTraceHandler().error("Incorrect page number");
+ exitCode = 255;
+ break;
+ }
+
+ item = item == null ? 0 : item;
+ if (item < 0) {
+ Instance.getTraceHandler().error("Incorrect item number");
+ exitCode = 255;
+ break;
+ }
+
+ if (BasicReader.getReader() == null) {
+ Instance.getTraceHandler()
+ .error(new Exception(
+ "No reader type has been configured"));
+ exitCode = 10;
+ break;
+ }
+
+ try {
+ BasicReader.getReader().searchTag(searchOn, page, item,
+ true, tags.toArray(new Integer[] {}));
+ } catch (IOException e1) {
+ Instance.getTraceHandler().error(e1);
+ }
+
+ break;
+ case HELP:
+ syntax(true);
+ exitCode = 0;
+ break;
+ case SET_READER:
+ exitCode = 255;
+ break;
+ case VERSION:
+ System.out
+ .println(String.format("Fanfix version %s"
+ + "%nhttps://github.com/nikiroo/fanfix/"
+ + "%n\tWritten by Nikiroo",
+ Version.getCurrentVersion()));
+ updates.ok(); // we consider it read
+ break;
+ case START:
+ if (BasicReader.getReader() == null) {
+ Instance.getTraceHandler()
+ .error(new Exception(
+ "No reader type has been configured"));
+ exitCode = 10;
+ break;
+ }
+ try {
+ BasicReader.getReader().browse(null);
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ exitCode = 66;
+ }
+ break;
+ case SERVER:
+ key = Instance.getConfig().getString(Config.SERVER_KEY);
+ port = Instance.getConfig().getInteger(Config.SERVER_PORT);
+ if (port == null) {
+ System.err.println("No port configured in the config file");
+ exitCode = 15;
+ break;
+ }
+ try {
+ ServerObject server = new RemoteLibraryServer(key, port);
+ server.setTraceHandler(Instance.getTraceHandler());
+ server.run();
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ }
+ return;
+ case STOP_SERVER:
+ key = Instance.getConfig().getString(Config.SERVER_KEY);
+ port = Instance.getConfig().getInteger(Config.SERVER_PORT);
+ if (port == null) {
+ System.err.println("No port configured in the config file");
+ exitCode = 15;
+ break;
+ }
+ try {
+ new RemoteLibrary(key, host, port).exit();
+ } catch (SSLException e) {
+ Instance.getTraceHandler().error(
+ "Bad access key for remote library");
+ exitCode = 43;
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ exitCode = 44;
+ }
+
+ break;
+ case REMOTE:
+ exitCode = 255; // should not be reachable (REMOTE -> START)
+ break;
+ }