From fe999aa400c2627291325558f1ae8c734da7900c Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sun, 12 Feb 2017 18:29:19 +0100 Subject: [PATCH] Library fixes + "make install" fix The library had some problems to retrieve metadata from CBZ files, "make install" created a script that did not pass the arguments --- Makefile.base | 2 +- src/be/nikiroo/fanfix/Instance.java | 56 +++++++++---------- src/be/nikiroo/fanfix/Library.java | 28 +++++++--- src/be/nikiroo/fanfix/data/MetaData.java | 20 +++++++ src/be/nikiroo/fanfix/output/BasicOutput.java | 4 ++ src/be/nikiroo/fanfix/output/Cbz.java | 3 + src/be/nikiroo/fanfix/output/InfoCover.java | 1 + src/be/nikiroo/fanfix/supported/Epub.java | 1 + 8 files changed, 79 insertions(+), 36 deletions(-) diff --git a/Makefile.base b/Makefile.base index a88eb4a..559b89d 100644 --- a/Makefile.base +++ b/Makefile.base @@ -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)" diff --git a/src/be/nikiroo/fanfix/Instance.java b/src/be/nikiroo/fanfix/Instance.java index ea66aec..2289445 100644 --- a/src/be/nikiroo/fanfix/Instance.java +++ b/src/be/nikiroo/fanfix/Instance.java @@ -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); diff --git a/src/be/nikiroo/fanfix/Library.java b/src/be/nikiroo/fanfix/Library.java index 602a25f..a120df1 100644 --- a/src/be/nikiroo/fanfix/Library.java +++ b/src/be/nikiroo/fanfix/Library.java @@ -28,8 +28,6 @@ import be.nikiroo.fanfix.supported.BasicSupport.SupportType; public class Library { private File baseDir; private Map stories; - private BasicSupport itSupport = BasicSupport - .getSupport(SupportType.INFO_TEXT); private int lastId; /** @@ -82,8 +80,15 @@ public class Library { for (Entry 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 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); diff --git a/src/be/nikiroo/fanfix/data/MetaData.java b/src/be/nikiroo/fanfix/data/MetaData.java index 3980e96..76a9c7b 100644 --- a/src/be/nikiroo/fanfix/data/MetaData.java +++ b/src/be/nikiroo/fanfix/data/MetaData.java @@ -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. * diff --git a/src/be/nikiroo/fanfix/output/BasicOutput.java b/src/be/nikiroo/fanfix/output/BasicOutput.java index 2e77eae..8728284 100644 --- a/src/be/nikiroo/fanfix/output/BasicOutput.java +++ b/src/be/nikiroo/fanfix/output/BasicOutput.java @@ -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()); } diff --git a/src/be/nikiroo/fanfix/output/Cbz.java b/src/be/nikiroo/fanfix/output/Cbz.java index 51cf732..67175b1 100644 --- a/src/be/nikiroo/fanfix/output/Cbz.java +++ b/src/be/nikiroo/fanfix/output/Cbz.java @@ -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 { diff --git a/src/be/nikiroo/fanfix/output/InfoCover.java b/src/be/nikiroo/fanfix/output/InfoCover.java index 2280e2d..1cf32a0 100644 --- a/src/be/nikiroo/fanfix/output/InfoCover.java +++ b/src/be/nikiroo/fanfix/output/InfoCover.java @@ -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(); diff --git a/src/be/nikiroo/fanfix/supported/Epub.java b/src/be/nikiroo/fanfix/supported/Epub.java index 31bf725..82ebb2b 100644 --- a/src/be/nikiroo/fanfix/supported/Epub.java +++ b/src/be/nikiroo/fanfix/supported/Epub.java @@ -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)) { -- 2.27.0