+ private static BasicLibrary createDefaultLibrary(File remoteDir) {
+ BasicLibrary lib = null;
+
+ 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");
+ if (!getFile(libDir).isAbsolute()) {
+ libDir = new File(configDir, libDir).getPath();
+ }
+ }
+ try {
+ lib = new LocalLibrary(getFile(libDir));
+ } catch (Exception e) {
+ tracer.error(new IOException(
+ "Cannot create library for directory: "
+ + getFile(libDir), e));
+ }