commit 6ac65373a3bea25f901de7e447b6505fbe62cd0b
parent 2939b3ae95c520432b14f9674429d713db1aa70f
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 5 Jun 2018 08:29:28 -0400
Mendeley import: Look for Downloaded files relative to DB if not found
Addresses #1451
Diffstat:
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/import/mendeley/mendeleyImport.js b/chrome/content/zotero/import/mendeley/mendeleyImport.js
@@ -740,21 +740,37 @@ Zotero_Import_Mendeley.prototype._saveItems = async function (libraryID, json) {
* Saves attachments and extracted annotations for a given document
*/
Zotero_Import_Mendeley.prototype._saveFilesAndAnnotations = async function (files, libraryID, parentItemID, annotations) {
+ var dataDir = OS.Path.dirname(this._file);
for (let file of files) {
try {
if (!file.fileURL) continue;
let path = OS.Path.fromFileURI(file.fileURL);
+ let isDownloadedFile = this._isDownloadedFile(path);
+ let fileExists = false;
- let attachment;
if (await OS.File.exists(path)) {
+ fileExists = true;
+ }
+ // For file paths in Downloaded folder, try relative to database if not found at the
+ // absolute location, in case this is a DB backup
+ else if (isDownloadedFile) {
+ let altPath = OS.Path.join(dataDir, 'Downloaded', OS.Path.basename(path));
+ if (altPath != path && await OS.File.exists(altPath)) {
+ path = altPath;
+ fileExists = true;
+ }
+ }
+
+ let attachment;
+ if (fileExists) {
let options = {
libraryID,
parentItemID,
file: path
};
// If file is in Mendeley downloads folder, import it
- if (OS.Path.dirname(path).endsWith(OS.Path.join('Mendeley Desktop', 'Downloaded'))) {
+ if (isDownloadedFile) {
attachment = await Zotero.Attachments.importFromFile(options);
}
// Otherwise link it
@@ -789,6 +805,13 @@ Zotero_Import_Mendeley.prototype._saveFilesAndAnnotations = async function (file
}
}
+Zotero_Import_Mendeley.prototype._isDownloadedFile = async function (path) {
+ var parentDir = OS.Path.dirname(path);
+ return parentDir.endsWith(OS.Path.join('Application Support', 'Mendeley Desktop', 'Downloaded'))
+ || parentDir.endsWith(OS.Path.join('Local', 'Mendeley Ltd', 'Desktop', 'Downloaded'))
+ || parentDir.endsWith(OS.Path.join('data', 'Mendeley Ltd.', 'Mendeley Desktop', 'Downloaded'));
+}
+
Zotero_Import_Mendeley.prototype._saveAnnotations = async function (annotations, parentItemID, attachmentItemID) {
if (!annotations.length) return;
var noteStrings = [];