From 60f723111f3f7f5bd60760afa7d0b645406b48d7 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 21 Mar 2019 16:56:52 +0100 Subject: [PATCH] cached lib can now getStory() --- .../nikiroo/fanfix/library/BasicLibrary.java | 93 ++++++++++++------- .../nikiroo/fanfix/library/CacheLibrary.java | 14 +++ src/be/nikiroo/fanfix/supported/Html.java | 17 ++++ 3 files changed, 92 insertions(+), 32 deletions(-) diff --git a/src/be/nikiroo/fanfix/library/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java index 78d20d65..b8b8185c 100644 --- a/src/be/nikiroo/fanfix/library/BasicLibrary.java +++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java @@ -565,6 +565,42 @@ abstract public class BasicLibrary { * @return the corresponding {@link Story} or NULL if not found */ public synchronized Story getStory(String luid, Progress pg) { + Progress pgMetas = new Progress(); + Progress pgStory = new Progress(); + if (pg != null) { + pg.setMinMax(0, 100); + pg.addProgress(pgMetas, 10); + pg.addProgress(pgStory, 90); + } + + MetaData meta = null; + for (MetaData oneMeta : getMetas(pgMetas)) { + if (oneMeta.getLuid().equals(luid)) { + meta = oneMeta; + break; + } + } + + pgMetas.done(); + + Story story = getStory(luid, meta, pgStory); + pgStory.done(); + + return story; + } + + /** + * Retrieve a specific {@link Story}. + * + * @param luid + * the meta of the story + * @param pg + * the optional progress reporter + * + * @return the corresponding {@link Story} or NULL if not found + */ + public synchronized Story getStory(String luid, MetaData meta, Progress pg) { + if (pg == null) { pg = new Progress(); } @@ -577,39 +613,32 @@ abstract public class BasicLibrary { pg.addProgress(pgProcess, 1); Story story = null; - for (MetaData meta : getMetas(null)) { - if (meta.getLuid().equals(luid)) { - File file = getFile(luid, pgGet); - pgGet.done(); - try { - SupportType type = SupportType.valueOfAllOkUC(meta - .getType()); - URL url = file.toURI().toURL(); - if (type != null) { - story = BasicSupport.getSupport(type, url) // - .process(pgProcess); - - // Because we do not want to clear the meta cache: - meta.setCover(story.getMeta().getCover()); - meta.setResume(story.getMeta().getResume()); - story.setMeta(meta); - // - } else { - throw new IOException("Unknown type: " + meta.getType()); - } - } catch (IOException e) { - // We should not have not-supported files in the - // library - Instance.getTraceHandler().error( - new IOException("Cannot load file from library: " - + file, e)); - } finally { - pgProcess.done(); - pg.done(); - } - - break; + File file = getFile(luid, pgGet); + pgGet.done(); + try { + SupportType type = SupportType.valueOfAllOkUC(meta.getType()); + URL url = file.toURI().toURL(); + if (type != null) { + story = BasicSupport.getSupport(type, url) // + .process(pgProcess); + + // Because we do not want to clear the meta cache: + meta.setCover(story.getMeta().getCover()); + meta.setResume(story.getMeta().getResume()); + story.setMeta(meta); + // + } else { + throw new IOException("Unknown type: " + meta.getType()); } + } catch (IOException e) { + // We should not have not-supported files in the + // library + Instance.getTraceHandler() + .error(new IOException("Cannot load file from library: " + + file, e)); + } finally { + pgProcess.done(); + pg.done(); } return story; diff --git a/src/be/nikiroo/fanfix/library/CacheLibrary.java b/src/be/nikiroo/fanfix/library/CacheLibrary.java index 9432b33f..ea1fd707 100644 --- a/src/be/nikiroo/fanfix/library/CacheLibrary.java +++ b/src/be/nikiroo/fanfix/library/CacheLibrary.java @@ -65,6 +65,20 @@ public class CacheLibrary extends BasicLibrary { return metas; } + @Override + public synchronized Story getStory(String luid, MetaData meta, Progress pg) { + String normal = Instance.getUiConfig().getString( + UiConfig.GUI_NON_IMAGES_DOCUMENT_TYPE); + String images = Instance.getUiConfig().getString( + UiConfig.GUI_IMAGES_DOCUMENT_TYPE); + String type = meta.isImageDocument() ? images : normal; + + MetaData cachedMeta = meta.clone(); + cachedMeta.setType(type); + + return super.getStory(luid, cachedMeta, pg); + } + @Override public synchronized File getFile(final String luid, Progress pg) { if (pg == null) { diff --git a/src/be/nikiroo/fanfix/supported/Html.java b/src/be/nikiroo/fanfix/supported/Html.java index c7db5d83..5fe28397 100644 --- a/src/be/nikiroo/fanfix/supported/Html.java +++ b/src/be/nikiroo/fanfix/supported/Html.java @@ -32,6 +32,23 @@ class Html extends InfoText { return false; } + @Override + protected File getInfoFile() { + File source = getSourceFile(); + if ("index.html".equals(source.getName())) { + source = source.getParentFile(); + } + + String src = source.getPath(); + File infoFile = new File(src + ".info"); + if (!infoFile.exists() && src.endsWith(".txt")) { + infoFile = new File( + src.substring(0, src.length() - ".txt".length()) + ".info"); + } + + return infoFile; + } + @Override public URL getCanonicalUrl(URL source) { File txt = getTxt(source); -- 2.27.0