+ @Override
+ public BufferedImage getSourceCover(String source) {
+ if (!sourceCovers.containsKey(source)) {
+ sourceCovers.put(source, super.getSourceCover(source));
+ }
+
+ return sourceCovers.get(source);
+ }
+
+ @Override
+ public void setSourceCover(String source, String luid) {
+ sourceCovers.put(source, getCover(luid));
+ File cover = new File(getExpectedDir(source), ".cover.png");
+ try {
+ ImageIO.write(sourceCovers.get(source), "png", cover);
+ } catch (IOException e) {
+ Instance.syserr(e);
+ sourceCovers.remove(source);
+ }
+ }
+
+ @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 otherLocalLibrary = (LocalLibrary) other;
+
+ MetaData meta = otherLocalLibrary.getInfo(luid);
+ String expectedType = ""
+ + (meta != null && meta.isImageDocument() ? image : text);
+ if (meta != null && meta.getType().equals(expectedType)) {
+ File from = otherLocalLibrary.getExpectedDir(meta.getSource());
+ File to = this.getExpectedDir(meta.getSource());
+ List<File> sources = otherLocalLibrary.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)) {
+ target.getParentFile().mkdirs();
+ 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);
+
+ clearCache();
+ }
+