X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2FMain.java;h=35365444682489d81adf7b25ed864416d6c47abe;hb=34f8780d16faf3a5466c45261bd84f1b31516790;hp=9d9592eefd3356e9d7c1e61b9e0b5142ab7b2376;hpb=868e32295fb975158cb8456cb559e79924b73151;p=nikiroo-utils.git
diff --git a/src/be/nikiroo/fanfix/Main.java b/src/be/nikiroo/fanfix/Main.java
index 9d9592e..3536544 100644
--- a/src/be/nikiroo/fanfix/Main.java
+++ b/src/be/nikiroo/fanfix/Main.java
@@ -19,6 +19,8 @@ import be.nikiroo.fanfix.library.CacheLibrary;
import be.nikiroo.fanfix.library.LocalLibrary;
import be.nikiroo.fanfix.library.RemoteLibrary;
import be.nikiroo.fanfix.library.RemoteLibraryServer;
+import be.nikiroo.fanfix.library.WebLibrary;
+import be.nikiroo.fanfix.library.WebLibraryServer;
import be.nikiroo.fanfix.output.BasicOutput;
import be.nikiroo.fanfix.output.BasicOutput.OutputType;
import be.nikiroo.fanfix.reader.BasicReader;
@@ -28,7 +30,7 @@ import be.nikiroo.fanfix.supported.BasicSupport;
import be.nikiroo.fanfix.supported.SupportType;
import be.nikiroo.utils.Progress;
import be.nikiroo.utils.Version;
-import be.nikiroo.utils.serial.server.ServerObject;
+import be.nikiroo.utils.VersionCheck;
/**
* Main program entry point.
@@ -78,7 +80,7 @@ public class Main {
*
--version: get the version of the program
* --server: start the server mode (see config file for parameters)
* --stop-server: stop the running server on this port if any
- * --remote [key] [host] [port]: use a the given remote library
+ * --remote [key] [host] [port]: use the given remote library
*
*
* @param args
@@ -350,7 +352,14 @@ public class Main {
} else if (port == null) {
port = Integer.parseInt(args[i]);
- BasicLibrary lib = new RemoteLibrary(key, host, port);
+ BasicLibrary lib;
+ if (host.startsWith("http://")
+ || host.startsWith("https://")) {
+ lib = new WebLibrary(key, host, port);
+ } else {
+ lib = new RemoteLibrary(key, host, port);
+ }
+
lib = new CacheLibrary(
Instance.getInstance().getRemoteDir(host), lib,
Instance.getInstance().getUiConfig());
@@ -397,8 +406,10 @@ public class Main {
if (exitCode == 0) {
switch (action) {
case IMPORT:
- if (updates != null)
- updates.ok(); // we consider it read
+ if (updates != null) {
+ // we consider it read
+ Instance.getInstance().setVersionChecked();
+ }
try {
exitCode = imprt(BasicReader.getUrl(urlString), pg);
@@ -409,8 +420,10 @@ public class Main {
break;
case EXPORT:
- if (updates != null)
- updates.ok(); // we consider it read
+ if (updates != null) {
+ // we consider it read
+ Instance.getInstance().setVersionChecked();
+ }
OutputType exportType = OutputType.valueOfNullOkUC(sourceString, null);
if (exportType == null) {
@@ -423,8 +436,10 @@ public class Main {
break;
case CONVERT:
- if (updates != null)
- updates.ok(); // we consider it read
+ if (updates != null) {
+ // we consider it read
+ Instance.getInstance().setVersionChecked();
+ }
OutputType convertType = OutputType.valueOfAllOkUC(sourceString, null);
if (convertType == null) {
@@ -599,8 +614,10 @@ public class Main {
exitCode = 0;
break;
case VERSION:
- if (updates != null)
- updates.ok(); // we consider it read
+ if (updates != null) {
+ // we consider it read
+ Instance.getInstance().setVersionChecked();
+ }
System.out
.println(String.format("Fanfix version %s"
@@ -617,15 +634,8 @@ public class Main {
}
break;
case SERVER:
- key = Instance.getInstance().getConfig().getString(Config.SERVER_KEY);
- port = Instance.getInstance().getConfig().getInteger(Config.SERVER_PORT);
- if (port == null) {
- System.err.println("No port configured in the config file");
- exitCode = 15;
- break;
- }
try {
- startServer(key, port);
+ startServer();
} catch (IOException e) {
Instance.getInstance().getTraceHandler().error(e);
}
@@ -633,10 +643,36 @@ public class Main {
break;
case STOP_SERVER:
// Can be given via "--remote XX XX XX"
- if (key == null)
- key = Instance.getInstance().getConfig().getString(Config.SERVER_KEY);
- if (port == null)
+ if (key == null) {
+ key = Instance.getInstance().getConfig()
+ .getString(Config.SERVER_KEY);
+
+ // If a subkey in RW mode exists, use it
+ for (String subkey : Instance.getInstance().getConfig()
+ .getList(Config.SERVER_ALLOWED_SUBKEYS,
+ new ArrayList())) {
+ if ((subkey + "|").contains("|rw|")) {
+ key = key + "|" + subkey;
+ break;
+ }
+ }
+ }
+
+ if (port == null) {
port = Instance.getInstance().getConfig().getInteger(Config.SERVER_PORT);
+ }
+
+ if (host == null) {
+ String mode = Instance.getInstance().getConfig()
+ .getString(Config.SERVER_MODE, "fanfix");
+ if ("http".equals(mode)) {
+ host = "http://localhost";
+ } else if ("https".equals(mode)) {
+ host = "https://localhost";
+ } else if ("fanfix".equals(mode)) {
+ host = "fanfix://localhost";
+ }
+ }
if (port == null) {
System.err.println("No port given nor configured in the config file");
@@ -716,12 +752,17 @@ public class Main {
* @return the newer version information or NULL if nothing new
*/
protected VersionCheck checkUpdates(String githubProject) {
- VersionCheck updates = VersionCheck.check(githubProject);
- if (updates.isNewVersionAvailable()) {
- notifyUpdates(updates);
- return updates;
+ try {
+ VersionCheck updates = VersionCheck.check(githubProject,
+ Instance.getInstance().getTrans().getLocale());
+ if (updates.isNewVersionAvailable()) {
+ notifyUpdates(updates);
+ return updates;
+ }
+ } catch (IOException e) {
+ // Maybe no internet. Do not report any update.
}
-
+
return null;
}
@@ -730,9 +771,9 @@ public class Main {
*
* Will only be called when a version is available.
*
- * Note that you can call {@link VersionCheck#ok()} on it if the user has
- * read the information (by default, it is marked read only on certain other
- * actions).
+ * Note that you can call {@link Instance#setVersionChecked()} on it if the
+ * user has read the information (by default, it is marked read only on
+ * certain other actions).
*
* @param updates
* the new version information
@@ -1023,20 +1064,29 @@ public class Main {
/**
* Start a Fanfix server.
*
- * @param key
- * the key taht will be needed to contact the Fanfix server
- * @param port
- * the port on which to run
- *
* @throws IOException
* in case of I/O errors
* @throws SSLException
* when the key was not accepted
*/
- private void startServer(String key, int port) throws IOException {
- ServerObject server = new RemoteLibraryServer(key, port);
- server.setTraceHandler(Instance.getInstance().getTraceHandler());
- server.run();
+ private void startServer() throws IOException {
+ String mode = Instance.getInstance().getConfig()
+ .getString(Config.SERVER_MODE, "fanfix");
+ if (mode.equals("fanfix")) {
+ RemoteLibraryServer server = new RemoteLibraryServer();
+ server.setTraceHandler(Instance.getInstance().getTraceHandler());
+ server.run();
+ } else if (mode.equals("http")) {
+ WebLibraryServer server = new WebLibraryServer(false);
+ server.setTraceHandler(Instance.getInstance().getTraceHandler());
+ server.run();
+ } else if (mode.equals("https")) {
+ WebLibraryServer server = new WebLibraryServer(true);
+ server.setTraceHandler(Instance.getInstance().getTraceHandler());
+ server.run();
+ } else {
+ throw new IOException("Unknown server mode: " + mode);
+ }
}
/**
@@ -1045,7 +1095,7 @@ public class Main {
* @param key
* the key to contact the Fanfix server
* @param host
- * the host on which it runs (NULL means localhost)
+ * the host on which it runs
* @param port
* the port on which it runs
*
@@ -1054,10 +1104,13 @@ public class Main {
* @throws SSLException
* when the key was not accepted
*/
- private void stopServer(
- String key, String host, Integer port)
+ private void stopServer(String key, String host, int port)
throws IOException, SSLException {
- new RemoteLibrary(key, host, port).exit();
+ if (host.startsWith("http://") || host.startsWith("https://")) {
+ new WebLibrary(key, host, port).stop();
+ } else {
+ new RemoteLibrary(key, host, port).stop();
+ }
}
/**