Update nikiroo-utils (Progress) + GuiReader perf
authorNiki Roo <niki@nikiroo.be>
Thu, 23 Nov 2017 19:01:17 +0000 (20:01 +0100)
committerNiki Roo <niki@nikiroo.be>
Thu, 23 Nov 2017 19:01:17 +0000 (20:01 +0100)
libs/nikiroo-utils-2.2.1-sources.jar [moved from libs/nikiroo-utils-2.2.0-sources.jar with 84% similarity]
src/be/nikiroo/fanfix/library/BasicLibrary.java
src/be/nikiroo/fanfix/library/LocalLibrary.java
src/be/nikiroo/fanfix/reader/GuiReader.java

similarity index 84%
rename from libs/nikiroo-utils-2.2.0-sources.jar
rename to libs/nikiroo-utils-2.2.1-sources.jar
index 3dde5dd5d89e47a3806b8498329932c59f0fe120..199beb397df2393d81a4d924bcff803426fab7e3 100644 (file)
Binary files a/libs/nikiroo-utils-2.2.0-sources.jar and b/libs/nikiroo-utils-2.2.1-sources.jar differ
index 63ffdb655bafa658b4bad2dcec37e5671fd4d867..cf17a2bef49fce8591150c6e93eb50eb9b41a30b 100644 (file)
@@ -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.
         * 
index bc41157328e7a0656b065c7b45ba2afc07872ba0..ab5a82b58b48a51ed4b1abc085118e986184f4fd 100644 (file)
@@ -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<File> 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}.
         * 
index 73df7fb8f4a25f89c5cc45782eb3fec05ad6ca9a..8559cf112eb34b47dd923cf14b0011c2c4ae561b 100644 (file)
@@ -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: "