X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2FInstance.java;h=561e2f685218442c05f98187df6738afc779ced2;hb=0013f760d69fd7db2b298c3da5d89bc0b102eabf;hp=74221b00916e499f3a2cbfdf41d6e1b65aa2fbf4;hpb=d0cad92991db43c8d8d00e9fe6bce349e0bbd780;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/Instance.java b/src/be/nikiroo/fanfix/Instance.java index 74221b0..561e2f6 100644 --- a/src/be/nikiroo/fanfix/Instance.java +++ b/src/be/nikiroo/fanfix/Instance.java @@ -451,8 +451,26 @@ public class Instance { private static BasicLibrary createDefaultLibrary(File remoteDir) { BasicLibrary lib = null; - String remoteLib = config.getString(Config.DEFAULT_LIBRARY); - if (remoteLib == null || remoteLib.trim().isEmpty()) { + boolean useRemote = config.getBoolean(Config.REMOTE_LIBRARY_ENABLED, + false); + + if (useRemote) { + String host = null; + int port = -1; + try { + host = config.getString(Config.REMOTE_LIBRARY_HOST); + port = config.getInteger(Config.REMOTE_LIBRARY_PORT, -1); + String key = config.getString(Config.REMOTE_LIBRARY_KEY); + + tracer.trace("Selecting remote library " + host + ":" + port); + lib = new RemoteLibrary(key, host, port); + lib = new CacheLibrary(getRemoteDir(remoteDir, host), lib); + } catch (Exception e) { + tracer.error(new IOException( + "Cannot create remote library for: " + host + ":" + + port, e)); + } + } else { String libDir = System.getenv("BOOKS_DIR"); if (libDir == null || libDir.isEmpty()) { libDir = config.getString(Config.LIBRARY_DIR, "$HOME/Books"); @@ -467,35 +485,6 @@ public class Instance { "Cannot create library for directory: " + getFile(libDir), e)); } - } else { - Exception ex = null; - int pos = remoteLib.lastIndexOf(":"); - if (pos >= 0) { - String port = remoteLib.substring(pos + 1).trim(); - remoteLib = remoteLib.substring(0, pos); - pos = remoteLib.lastIndexOf(":"); - if (pos >= 0) { - String host = remoteLib.substring(pos + 1).trim(); - String key = remoteLib.substring(0, pos).trim(); - - try { - tracer.trace("Selecting remote library " + host + ":" - + port); - lib = new RemoteLibrary(key, host, - Integer.parseInt(port)); - lib = new CacheLibrary(getRemoteDir(remoteDir, host), - lib); - - } catch (Exception e) { - ex = e; - } - } - } - - if (lib == null) { - tracer.error(new IOException( - "Cannot create remote library for: " + remoteLib, ex)); - } } return lib; @@ -507,11 +496,7 @@ public class Instance { * @return the path */ private static File getFile(Config id, File def) { - String path = config.getString(id); - if (path != null && path.isEmpty()) { - path = def.getPath(); - } - + String path = config.getString(id, def.getPath()); return getFile(path); } @@ -521,11 +506,7 @@ public class Instance { * @return the path */ private static File getFile(UiConfig id, File def) { - String path = uiconfig.getString(id); - if (path != null && path.isEmpty()) { - path = def.getPath(); - } - + String path = uiconfig.getString(id, def.getPath()); return getFile(path); }