From b4f9071c1bd4534e9cca989f1e873310c94986c3 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Mon, 4 Dec 2017 22:29:07 +0100 Subject: [PATCH] Small fixes, including better external launcher --- src/be/nikiroo/fanfix/Instance.java | 24 +++- .../nikiroo/fanfix/library/LocalLibrary.java | 120 +++++++++--------- src/be/nikiroo/fanfix/reader/BasicReader.java | 3 +- src/be/nikiroo/fanfix/reader/Reader.java | 4 + 4 files changed, 89 insertions(+), 62 deletions(-) diff --git a/src/be/nikiroo/fanfix/Instance.java b/src/be/nikiroo/fanfix/Instance.java index 82f4427..fe73f7f 100644 --- a/src/be/nikiroo/fanfix/Instance.java +++ b/src/be/nikiroo/fanfix/Instance.java @@ -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) { diff --git a/src/be/nikiroo/fanfix/library/LocalLibrary.java b/src/be/nikiroo/fanfix/library/LocalLibrary.java index 041db10..4cdfb94 100644 --- a/src/be/nikiroo/fanfix/library/LocalLibrary.java +++ b/src/be/nikiroo/fanfix/library/LocalLibrary.java @@ -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; } diff --git a/src/be/nikiroo/fanfix/reader/BasicReader.java b/src/be/nikiroo/fanfix/reader/BasicReader.java index 4b44494..e9100e2 100644 --- a/src/be/nikiroo/fanfix/reader/BasicReader.java +++ b/src/be/nikiroo/fanfix/reader/BasicReader.java @@ -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() }); diff --git a/src/be/nikiroo/fanfix/reader/Reader.java b/src/be/nikiroo/fanfix/reader/Reader.java index f98f12c..5fe1c5d 100644 --- a/src/be/nikiroo/fanfix/reader/Reader.java +++ b/src/be/nikiroo/fanfix/reader/Reader.java @@ -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; -- 2.27.0