From: Niki Roo Date: Thu, 23 Nov 2017 19:01:17 +0000 (+0100) Subject: Update nikiroo-utils (Progress) + GuiReader perf X-Git-Tag: fanfix-swing-0.0.1~12^2~420 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=b89dfb6ece936486563734818ed62488a59e5897;p=fanfix-swing.git Update nikiroo-utils (Progress) + GuiReader perf --- diff --git a/libs/nikiroo-utils-2.2.0-sources.jar b/libs/nikiroo-utils-2.2.1-sources.jar similarity index 84% rename from libs/nikiroo-utils-2.2.0-sources.jar rename to libs/nikiroo-utils-2.2.1-sources.jar index 3dde5dd5..199beb39 100644 Binary files a/libs/nikiroo-utils-2.2.0-sources.jar and b/libs/nikiroo-utils-2.2.1-sources.jar differ diff --git a/src/be/nikiroo/fanfix/library/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java index 63ffdb65..cf17a2be 100644 --- a/src/be/nikiroo/fanfix/library/BasicLibrary.java +++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java @@ -340,6 +340,41 @@ abstract public class BasicLibrary { return save(support.process(url, pg), null); } + /** + * Import the story from one library to another, and keep the same LUID. + * + * @param other + * the other library to import from + * @param luid + * the Library UID + * @param pg + * the optional progress reporter + * + * @throws IOException + * in case of I/O error + */ + public void imprt(BasicLibrary other, String luid, Progress pg) + throws IOException { + Progress pgGetStory = new Progress(); + Progress pgSave = new Progress(); + if (pg == null) { + pg = new Progress(); + } + + pg.setMinMax(0, 2); + pg.addProgress(pgGetStory, 1); + pg.addProgress(pgSave, 1); + + Story story = other.getStory(luid, pgGetStory); + if (story != null) { + story = this.save(story, luid, pgSave); + pg.done(); + } else { + pg.done(); + throw new IOException("Cannot find story in Library: " + luid); + } + } + /** * Export the {@link Story} to the given target in the given format. * diff --git a/src/be/nikiroo/fanfix/library/LocalLibrary.java b/src/be/nikiroo/fanfix/library/LocalLibrary.java index bc411573..ab5a82b5 100644 --- a/src/be/nikiroo/fanfix/library/LocalLibrary.java +++ b/src/be/nikiroo/fanfix/library/LocalLibrary.java @@ -181,6 +181,59 @@ public class LocalLibrary extends BasicLibrary { } } + @Override + public void imprt(BasicLibrary other, String luid, Progress pg) + throws IOException { + if (pg == null) { + pg = new Progress(); + } + + // Check if we can simply copy the files instead of the whole process + if (other instanceof LocalLibrary) { + LocalLibrary otherLibrary = (LocalLibrary) other; + MetaData meta = otherLibrary.getInfo(luid); + String expectedType = "" + (meta.isImageDocument() ? image : text); + if (meta.getType().equals(expectedType)) { + File from = otherLibrary.getExpectedDir(meta.getSource()); + File to = this.getExpectedDir(meta.getSource()); + List sources = otherLibrary.getRelatedFiles(luid); + if (!sources.isEmpty()) { + pg.setMinMax(0, sources.size()); + } + + for (File source : sources) { + File target = new File(source.getAbsolutePath().replace( + from.getAbsolutePath(), to.getAbsolutePath())); + if (!source.equals(target)) { + InputStream in = null; + try { + in = new FileInputStream(source); + IOUtils.write(in, target); + } catch (IOException e) { + if (in != null) { + try { + in.close(); + } catch (Exception ee) { + } + } + + pg.done(); + throw e; + } + } + + pg.add(1); + } + + clearCache(); + pg.done(); + return; + } + } + + super.imprt(other, luid, pg); + } + /** * Return the {@link OutputType} for this {@link Story}. * diff --git a/src/be/nikiroo/fanfix/reader/GuiReader.java b/src/be/nikiroo/fanfix/reader/GuiReader.java index 73df7fb8..8559cf11 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReader.java +++ b/src/be/nikiroo/fanfix/reader/GuiReader.java @@ -93,21 +93,8 @@ class GuiReader extends BasicReader { * in case of I/O error */ public void imprt(String luid, Progress pg) throws IOException { - Progress pgGetStory = new Progress(); - Progress pgSave = new Progress(); - if (pg != null) { - pg.setMax(2); - pg.addProgress(pgGetStory, 1); - pg.addProgress(pgSave, 1); - } - try { - Story story = getLibrary().getStory(luid, pgGetStory); - if (story != null) { - story = localLibrary.save(story, luid, pgSave); - } else { - throw new IOException("Cannot find story in Library: " + luid); - } + localLibrary.imprt(getLibrary(), luid, pg); } catch (IOException e) { throw new IOException( "Cannot import story from library to LocalReader library: "