Small fixes, including better external launcher
authorNiki Roo <niki@nikiroo.be>
Mon, 4 Dec 2017 21:29:07 +0000 (22:29 +0100)
committerNiki Roo <niki@nikiroo.be>
Mon, 4 Dec 2017 21:29:07 +0000 (22:29 +0100)
src/be/nikiroo/fanfix/Instance.java
src/be/nikiroo/fanfix/library/LocalLibrary.java
src/be/nikiroo/fanfix/reader/BasicReader.java
src/be/nikiroo/fanfix/reader/Reader.java

index 82f442791b673262932988b4f3c054cc031e10e0..fe73f7f51351ee44b3b664ced844f4f063894871 100644 (file)
@@ -108,12 +108,16 @@ public class Instance {
 
                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(":");
@@ -405,9 +409,23 @@ public class Instance {
         * @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) {
index 041db1013dbf85bfd0a41112676dcc6e4f31c055..4cdfb944e0cd7b62bdbdedadac580cefa61f895b 100644 (file)
@@ -431,77 +431,81 @@ public class LocalLibrary extends BasicLibrary {
                                }
                        });
 
-                       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;
        }
 
index 4b444940c11a07cfeb15a108171126c4bfe14baf..e9100e2e036a2bb7456bf0ab7be4670de9d87186 100644 (file)
@@ -264,7 +264,8 @@ public abstract class BasicReader implements Reader {
        protected void start(File target, String program) throws IOException {
                if (program == null) {
                        boolean ok = false;
-                       for (String starter : new String[] { "xdg-open", "start", "run" }) {
+                       for (String starter : new String[] { "xdg-open", "open", "see",
+                                       "start", "run" }) {
                                try {
                                        Runtime.getRuntime().exec(
                                                        new String[] { starter, target.getAbsolutePath() });
index f98f12c53f0c21b811341bc79703799bbc646080..5fe1c5d67d55bef4993bcd6e55ce7f6c95d8bb6d 100644 (file)
@@ -27,6 +27,8 @@ public interface Reader {
                GUI,
                /** A text (UTF-8) reader with menu and text windows */
                TUI,
+               /** A GUI reader implemented with the Android framework */
+               ANDROID,
 
                ;
 
@@ -45,6 +47,8 @@ public interface Reader {
                                return pkg + "tui.TuiReader";
                        case GUI:
                                return pkg + "ui.GuiReader";
+                       case ANDROID:
+                               return pkg + "android.AndroidReader";
                        }
 
                        return null;