X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=inline;f=Main.java;h=e48f4f53ec7ab7d1951ea4760cacdb64afbccc51;hb=6d465e886ae46c9da99117cc4302948f700a51c4;hp=b49cf0fb13e38338c293166027882e3df3876e67;hpb=2e3043a997ce891af4013f5291d0f288b6a1ef4c;p=nikiroo-utils.git diff --git a/Main.java b/Main.java index b49cf0f..e48f4f5 100644 --- a/Main.java +++ b/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 { *
* For this, it will simply forward the call to * {@link Main#checkUpdates(String)} with a value of "nikiroo/fanfix". + *
+ * You may want to override it so you call the forward method with the right + * parameters (or also if you want it to be asynchronous). * * @return the newer version information or NULL if nothing new */ @@ -710,12 +726,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; } @@ -724,9 +745,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 @@ -1017,20 +1038,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); + } } /** @@ -1048,10 +1078,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, Integer 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(); + } } /**