String remoteLib = config.getString(Config.DEFAULT_LIBRARY);
if (remoteLib == null || remoteLib.trim().isEmpty()) {
+ String libDir = System.getProperty("fanfix.libdir");
+ if (libDir == null || libDir.isEmpty()) {
+ config.getString(Config.LIBRARY_DIR);
+ }
try {
- lib = new LocalLibrary(getFile(Config.LIBRARY_DIR));
+ lib = new LocalLibrary(getFile(libDir));
} catch (Exception e) {
tracer.error(new IOException(
"Cannot create library for directory: "
- + getFile(Config.LIBRARY_DIR), e));
+ + getFile(libDir), e));
}
} else {
int pos = remoteLib.lastIndexOf(":");
* @return the home
*/
private static String getHome() {
- String home = System.getProperty("user.home");
+ String home = System.getProperty("fanfix.home");
+ if (home != null && new File(home).isFile()) {
+ home = null;
+ }
+
+ if (home == null || home.trim().isEmpty()) {
+ home = System.getProperty("user.home");
+ if (!new File(home).isDirectory()) {
+ home = null;
+ }
+ }
+
if (home == null || home.trim().isEmpty()) {
home = System.getProperty("java.io.tmpdir");
+ if (!new File(home).isDirectory()) {
+ home = null;
+ }
}
if (home == null) {
}
});
- Progress pgDirs = new Progress(0, 100 * dirs.length);
- pg.addProgress(pgDirs, 100);
-
- for (File dir : dirs) {
- File[] infoFiles = dir.listFiles(new FileFilter() {
- @Override
- public boolean accept(File file) {
- return file != null
- && file.getPath().toLowerCase()
- .endsWith(".info");
- }
- });
-
- Progress pgFiles = new Progress(0, infoFiles.length);
- pgDirs.addProgress(pgFiles, 100);
- pgDirs.setName("Loading from: " + dir.getName());
-
- String source = null;
- for (File infoFile : infoFiles) {
- pgFiles.setName(infoFile.getName());
- try {
- MetaData meta = InfoReader.readMeta(infoFile, false);
- source = meta.getSource();
+ if (dirs != null) {
+ Progress pgDirs = new Progress(0, 100 * dirs.length);
+ pg.addProgress(pgDirs, 100);
+
+ for (File dir : dirs) {
+ File[] infoFiles = dir.listFiles(new FileFilter() {
+ @Override
+ public boolean accept(File file) {
+ return file != null
+ && file.getPath().toLowerCase()
+ .endsWith(".info");
+ }
+ });
+
+ Progress pgFiles = new Progress(0, infoFiles.length);
+ pgDirs.addProgress(pgFiles, 100);
+ pgDirs.setName("Loading from: " + dir.getName());
+
+ String source = null;
+ for (File infoFile : infoFiles) {
+ pgFiles.setName(infoFile.getName());
try {
- int id = Integer.parseInt(meta.getLuid());
- if (id > lastId) {
- lastId = id;
- }
+ MetaData meta = InfoReader
+ .readMeta(infoFile, false);
+ source = meta.getSource();
+ try {
+ int id = Integer.parseInt(meta.getLuid());
+ if (id > lastId) {
+ lastId = id;
+ }
- stories.put(meta, new File[] { infoFile,
- getTargetFile(meta, infoFile) });
- } catch (Exception e) {
- // not normal!!
- throw new IOException(
- "Cannot understand the LUID of "
- + infoFile
- + ": "
- + (meta == null ? "[meta is NULL]"
- : meta.getLuid()), e);
+ stories.put(meta, new File[] { infoFile,
+ getTargetFile(meta, infoFile) });
+ } catch (Exception e) {
+ // not normal!!
+ throw new IOException(
+ "Cannot understand the LUID of "
+ + infoFile
+ + ": "
+ + (meta == null ? "[meta is NULL]"
+ : meta.getLuid()), e);
+ }
+ } catch (IOException e) {
+ // We should not have not-supported files in the
+ // library
+ Instance.getTraceHandler().error(
+ new IOException(
+ "Cannot load file from library: "
+ + infoFile, e));
}
- } catch (IOException e) {
- // We should not have not-supported files in the
- // library
- Instance.getTraceHandler().error(
- new IOException(
- "Cannot load file from library: "
- + infoFile, e));
+ pgFiles.add(1);
}
- pgFiles.add(1);
- }
- File cover = new File(dir, ".cover.png");
- if (cover.exists()) {
- try {
- InputStream in = new FileInputStream(cover);
+ File cover = new File(dir, ".cover.png");
+ if (cover.exists()) {
try {
- sourceCovers.put(source, new Image(in));
- } finally {
- in.close();
+ InputStream in = new FileInputStream(cover);
+ try {
+ sourceCovers.put(source, new Image(in));
+ } finally {
+ in.close();
+ }
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
}
- } catch (IOException e) {
- Instance.getTraceHandler().error(e);
}
+
+ pgFiles.setName(null);
}
- pgFiles.setName(null);
+ pgDirs.setName("Loading directories");
}
-
- pgDirs.setName("Loading directories");
}
+ pg.done();
return stories;
}