Library fixes + "make install" fix
authorNiki Roo <niki@nikiroo.be>
Sun, 12 Feb 2017 17:29:19 +0000 (18:29 +0100)
committerNiki Roo <niki@nikiroo.be>
Sun, 12 Feb 2017 17:29:19 +0000 (18:29 +0100)
The library had some problems to retrieve metadata from CBZ files,
"make install" created a script that did not pass the arguments

Makefile.base
src/be/nikiroo/fanfix/Instance.java
src/be/nikiroo/fanfix/Library.java
src/be/nikiroo/fanfix/data/MetaData.java
src/be/nikiroo/fanfix/output/BasicOutput.java
src/be/nikiroo/fanfix/output/Cbz.java
src/be/nikiroo/fanfix/output/InfoCover.java
src/be/nikiroo/fanfix/supported/Epub.java

index a88eb4a2df0d9c09378831aeda1945beccbc4d2e..559b89d9020a53df2b6212600233c68cd88841a2 100644 (file)
@@ -142,6 +142,6 @@ install:
        mkdir -p "$(PREFIX)/lib" "$(PREFIX)/bin"
        cp $(NAME).jar "$(PREFIX)/lib/"
        echo "#!/bin/sh" > "$(PREFIX)/bin/$(NAME)"
-       echo "$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"$$@\"" >> "$(PREFIX)/bin/$(NAME)"
+       echo "$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"\$$@\"" >> "$(PREFIX)/bin/$(NAME)"
        chmod a+rx "$(PREFIX)/bin/$(NAME)"
 
index ea66aec0d1b3c7fcedc65dfc31366e29a9b67708..2289445b968a60cb7bd7b5fdf6556a559647b34c 100644 (file)
@@ -26,6 +26,34 @@ public class Instance {
                // Most of the rest is dependent upon this:
                config = new ConfigBundle();
 
+               String configDir = System.getenv("CONFIG_DIR");
+               if (configDir == null) {
+                       configDir = new File(System.getProperty("user.home"), ".fanfix")
+                                       .getPath();
+               }
+               if (configDir != null) {
+                       if (!new File(configDir).exists()) {
+                               new File(configDir).mkdirs();
+                       } else {
+                               Bundles.setDirectory(configDir);
+                       }
+
+                       try {
+                               config = new ConfigBundle();
+                               config.updateFile(configDir);
+                       } catch (IOException e) {
+                               syserr(e);
+                       }
+                       try {
+                               trans = new StringIdBundle(getLang());
+                               trans.updateFile(configDir);
+                       } catch (IOException e) {
+                               syserr(e);
+                       }
+
+                       Bundles.setDirectory(configDir);
+               }
+
                trans = new StringIdBundle(getLang());
                lib = new Library(getFile(Config.LIBRARY_DIR));
                debug = Instance.getConfig().getBoolean(Config.DEBUG_ERR, false);
@@ -63,34 +91,6 @@ public class Instance {
                        coverDir = null;
                }
 
-               String configDir = System.getenv("CONFIG_DIR");
-               if (configDir == null) {
-                       configDir = new File(System.getProperty("user.home"), ".fanfix")
-                                       .getPath();
-               }
-               if (configDir != null) {
-                       if (!new File(configDir).exists()) {
-                               new File(configDir).mkdirs();
-                       } else {
-                               Bundles.setDirectory(configDir);
-                       }
-
-                       try {
-                               config = new ConfigBundle();
-                               config.updateFile(configDir);
-                       } catch (IOException e) {
-                               syserr(e);
-                       }
-                       try {
-                               trans = new StringIdBundle(getLang());
-                               trans.updateFile(configDir);
-                       } catch (IOException e) {
-                               syserr(e);
-                       }
-
-                       Bundles.setDirectory(configDir);
-               }
-
                try {
                        String ua = config.getString(Config.USER_AGENT);
                        int hours = config.getInteger(Config.CACHE_MAX_TIME_CHANGING, -1);
index 602a25fd16e702dcea6e64fc79e479f9c9614884..a120df1a09c850bab29338736b587ffac9a5767b 100644 (file)
@@ -28,8 +28,6 @@ import be.nikiroo.fanfix.supported.BasicSupport.SupportType;
 public class Library {
        private File baseDir;
        private Map<MetaData, File> stories;
-       private BasicSupport itSupport = BasicSupport
-                       .getSupport(SupportType.INFO_TEXT);
        private int lastId;
 
        /**
@@ -82,8 +80,15 @@ public class Library {
                        for (Entry<MetaData, File> entry : getStories().entrySet()) {
                                if (luid.equals(entry.getKey().getLuid())) {
                                        try {
-                                               return itSupport.process(entry.getValue().toURI()
-                                                               .toURL());
+                                               SupportType type = SupportType.valueOfAllOkUC(entry
+                                                               .getKey().getType());
+                                               URL url = entry.getValue().toURI().toURL();
+                                               if (type != null) {
+                                                       return BasicSupport.getSupport(type).process(url);
+                                               } else {
+                                                       throw new IOException("Unknown type: "
+                                                                       + entry.getKey().getType());
+                                               }
                                        } catch (IOException e) {
                                                // We should not have not-supported files in the
                                                // library
@@ -219,8 +224,9 @@ public class Library {
        private Map<MetaData, File> getStories() {
                if (stories.isEmpty()) {
                        lastId = 0;
-                       String format = Instance.getConfig()
-                                       .getString(Config.IMAGE_FORMAT_COVER).toLowerCase();
+                       String format = "."
+                                       + Instance.getConfig().getString(Config.IMAGE_FORMAT_COVER)
+                                                       .toLowerCase();
                        for (File dir : baseDir.listFiles()) {
                                if (dir.isDirectory()) {
                                        for (File file : dir.listFiles()) {
@@ -228,7 +234,15 @@ public class Library {
                                                        String path = file.getPath().toLowerCase();
                                                        if (!path.endsWith(".info")
                                                                        && !path.endsWith(format)) {
-                                                               MetaData meta = itSupport.processMeta(
+                                                               // TODO: export .info reading to a class and use
+                                                               // it here
+                                                               SupportType type = SupportType.INFO_TEXT;
+                                                               if (path.toLowerCase().endsWith(".cbz")) {
+                                                                       type = SupportType.CBZ;
+                                                               }
+                                                               BasicSupport support = BasicSupport
+                                                                               .getSupport(type);
+                                                               MetaData meta = support.processMeta(
                                                                                file.toURI().toURL()).getMeta();
                                                                if (meta != null) {
                                                                        stories.put(meta, file);
index 3980e96bc77b8ad359bee903381633daf832e3f4..76a9c7ba97f43c687e932692ecd5eff44a4bcda0 100644 (file)
@@ -21,6 +21,7 @@ public class MetaData {
        private String luid;
        private String lang;
        private String publisher;
+       private String type;
        private boolean imageDocument;
 
        /**
@@ -255,6 +256,25 @@ public class MetaData {
                this.publisher = publisher;
        }
 
+       /**
+        * The output type this {@link Story} is in.
+        * 
+        * @return the type the type
+        */
+       public String getType() {
+               return type;
+       }
+
+       /**
+        * The output type this {@link Story} is in.
+        * 
+        * @param type
+        *            the new type to set
+        */
+       public void setType(String type) {
+               this.type = type;
+       }
+
        /**
         * Document catering mostly to image files.
         * 
index 2e77eaebdc6d13de7d24bd42e19061b28131bc41..8728284c5e074bfc2dc5f86428a2d4bccf946afb 100644 (file)
@@ -240,6 +240,10 @@ public abstract class BasicOutput {
                String paragraphNumber = String.format("%04d", 0);
                imageName = paragraphNumber + "_" + chapterNameNum + ".png";
 
+               if (story.getMeta() != null) {
+                       story.getMeta().setType(getType().toString());
+               }
+               
                if (writeCover) {
                        InfoCover.writeCover(targetDir, targetName, story.getMeta());
                }
index 51cf732a966cbb7b70e3941f7cf2eee00c2a18ff..67175b143d007ce916a261d5ec00f7228f126692 100644 (file)
@@ -26,6 +26,9 @@ class Cbz extends BasicOutput {
 
                // will also save the images!
                new InfoText().process(story, dir, targetNameOrig);
+               InfoCover.writeInfo(dir, targetNameOrig, story.getMeta());
+               InfoCover.writeCover(dir, targetNameOrig, story.getMeta());
+
                IOUtils.writeSmallFile(dir, "version", "3.0");
 
                try {
index 2280e2dc4487bbdb0adf84f139a1a135c0c35772..1cf32a06adb75331ff7a2bf3759b05d96e7b75d0 100644 (file)
@@ -44,6 +44,7 @@ class InfoCover {
                                writeMeta(infoWriter, "LANG", lang);
                                writeMeta(infoWriter, "IMAGES_DOCUMENT",
                                                meta.isImageDocument() ? "true" : "false");
+                               writeMeta(infoWriter, "TYPE", meta.getType());
                                if (meta.getCover() != null) {
                                        String format = Instance.getConfig()
                                                        .getString(Config.IMAGE_FORMAT_COVER).toLowerCase();
index 31bf72577bddbaae4d5af8f3ca4ab5fec6087d12..82ebb2b0ea025bdeb77c88a323b193f1a266b9ed 100644 (file)
@@ -195,6 +195,7 @@ class Epub extends BasicSupport {
                        if (!entry.isDirectory()
                                        && entry.getName().startsWith(getDataPrefix())) {
                                String entryLName = entry.getName().toLowerCase();
+
                                boolean imageEntry = false;
                                for (String ext : getImageExt(false)) {
                                        if (entryLName.endsWith(ext)) {