X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FLocalLibrary.java;h=ab5a82b58b48a51ed4b1abc085118e986184f4fd;hp=bc41157328e7a0656b065c7b45ba2afc07872ba0;hb=b89dfb6ece936486563734818ed62488a59e5897;hpb=874f87f4aa5a4546cb5a3f3f319c50580e366ec0 diff --git a/src/be/nikiroo/fanfix/library/LocalLibrary.java b/src/be/nikiroo/fanfix/library/LocalLibrary.java index bc41157..ab5a82b 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}. *