Use the bundled PDF tools
This commit is contained in:
parent
e3dee4dee7
commit
0d5ea8520a
15 changed files with 42 additions and 954 deletions
|
@ -145,15 +145,7 @@ var Zotero_DownloadOverlay = new function() {
|
|||
// to happen automatically
|
||||
if(zoteroSelected) document.getElementById('rememberChoice').selected = false;
|
||||
document.getElementById('rememberChoice').disabled = zoteroSelected;
|
||||
|
||||
// disable recognizePDF checkbox as necessary
|
||||
if(!Zotero.Fulltext.pdfConverterIsRegistered()) {
|
||||
document.getElementById('zotero-noPDFTools-description').hidden = !zoteroSelected;
|
||||
document.getElementById('zotero-recognizePDF').disabled = true;
|
||||
window.sizeToContent();
|
||||
} else {
|
||||
document.getElementById('zotero-recognizePDF').disabled = !zoteroSelected;
|
||||
}
|
||||
document.getElementById('zotero-recognizePDF').disabled = !zoteroSelected;
|
||||
|
||||
Zotero_DownloadOverlay.updateLibraryNote();
|
||||
};
|
||||
|
@ -212,9 +204,6 @@ var Zotero_DownloadOverlay = new function() {
|
|||
recognizePDF.label = Zotero.getString("pane.items.menu.recognizePDF");
|
||||
recognizePDF.hidden = false;
|
||||
recognizePDF.disabled = true;
|
||||
if(!Zotero.Fulltext.pdfConverterIsRegistered()) {
|
||||
recognizePDF.checked = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
<vbox style="margin-left: 15px">
|
||||
<description id="zotero-saveToLibrary-description" style="font: small-caption; font-weight: normal" hidden="true">&zotero.downloadManager.saveToLibrary.description;</description>
|
||||
<checkbox id="zotero-recognizePDF" hidden="true" persist="checked" disabled="true"/>
|
||||
<description style="margin-left: 20px; font: small-caption; font-weight: normal" id="zotero-noPDFTools-description" hidden="true">&zotero.downloadManager.noPDFTools.description;</description>
|
||||
</vbox>
|
||||
</vbox>
|
||||
</radiogroup>
|
||||
|
|
|
@ -33,264 +33,10 @@ Zotero_Preferences.Search = {
|
|||
document.getElementById('fulltext-clearIndex').setAttribute('label',
|
||||
Zotero.getString('zotero.preferences.search.clearIndex')
|
||||
+ Zotero.getString('punctuation.ellipsis'));
|
||||
this.updatePDFToolsStatus();
|
||||
|
||||
this.updateIndexStats();
|
||||
|
||||
// Quick hack to support install prompt from PDF recognize option
|
||||
var io = window.arguments[0];
|
||||
if (io.action && io.action == 'pdftools-install') {
|
||||
this.checkPDFToolsDownloadVersion();
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Update window according to installation status for PDF tools
|
||||
* (e.g. status line, install/update button, etc.)
|
||||
*/
|
||||
updatePDFToolsStatus: function () {
|
||||
var converterIsRegistered = Zotero.Fulltext.pdfConverterIsRegistered();
|
||||
var infoIsRegistered = Zotero.Fulltext.pdfInfoIsRegistered();
|
||||
|
||||
var converterStatusLabel = document.getElementById('pdfconverter-status');
|
||||
var infoStatusLabel = document.getElementById('pdfinfo-status');
|
||||
var requiredLabel = document.getElementById('pdftools-required');
|
||||
var updateButton = document.getElementById('pdftools-update-button');
|
||||
var documentationLink = document.getElementById('pdftools-documentation-link');
|
||||
var settingsBox = document.getElementById('pdftools-settings');
|
||||
|
||||
// If we haven't already generated the required and documentation messages
|
||||
if (!converterIsRegistered && !requiredLabel.hasChildNodes()) {
|
||||
|
||||
// Xpdf link
|
||||
var str = Zotero.getString('zotero.preferences.search.pdf.toolsRequired',
|
||||
[Zotero.Fulltext.pdfConverterName, Zotero.Fulltext.pdfInfoName,
|
||||
'<a href="' + Zotero.Fulltext.pdfToolsURL + '">'
|
||||
+ Zotero.Fulltext.pdfToolsName + '</a>']);
|
||||
var parts = Zotero.Utilities.parseMarkup(str);
|
||||
for (var i=0; i<parts.length; i++) {
|
||||
var part = parts[i];
|
||||
if (part.type == 'text') {
|
||||
var elem = document.createTextNode(part.text);
|
||||
}
|
||||
else if (part.type == 'link') {
|
||||
var elem = document.createElement('label');
|
||||
elem.setAttribute('value', part.text);
|
||||
elem.setAttribute('class', 'zotero-text-link');
|
||||
for (var key in part.attributes) {
|
||||
elem.setAttribute(key, part.attributes[key]);
|
||||
|
||||
if (key == 'href') {
|
||||
elem.setAttribute('tooltiptext', part.attributes[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
requiredLabel.appendChild(elem);
|
||||
}
|
||||
|
||||
requiredLabel.appendChild(document.createTextNode(' '
|
||||
+ Zotero.getString('zotero.preferences.search.pdf.automaticInstall')));
|
||||
|
||||
// Documentation link
|
||||
var link = '<a href="http://www.zotero.org/documentation/pdf_fulltext_indexing">'
|
||||
+ Zotero.getString('zotero.preferences.search.pdf.documentationLink')
|
||||
+ '</a>';
|
||||
var str = Zotero.getString('zotero.preferences.search.pdf.advancedUsers', link);
|
||||
var parts = Zotero.Utilities.parseMarkup(str);
|
||||
|
||||
for (var i=0; i<parts.length; i++) {
|
||||
var part = parts[i];
|
||||
if (part.type == 'text') {
|
||||
var elem = document.createTextNode(part.text);
|
||||
}
|
||||
else if (part.type == 'link') {
|
||||
var elem = document.createElement('label');
|
||||
elem.setAttribute('value', part.text);
|
||||
elem.setAttribute('class', 'zotero-text-link');
|
||||
for (var key in part.attributes) {
|
||||
elem.setAttribute(key, part.attributes[key]);
|
||||
|
||||
if (key == 'href') {
|
||||
elem.setAttribute('tooltiptext', part.attributes[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
documentationLink.appendChild(elem);
|
||||
}
|
||||
}
|
||||
|
||||
// converter status line
|
||||
var prefix = 'zotero.preferences.search.pdf.tool';
|
||||
if (converterIsRegistered) {
|
||||
var version = Zotero.Fulltext.pdfConverterVersion;
|
||||
str = Zotero.getString(prefix + 'Registered',
|
||||
Zotero.getString('zotero.preferences.search.pdf.toolVersionPlatform',
|
||||
[Zotero.Fulltext.pdfConverterName, version]));
|
||||
}
|
||||
else {
|
||||
str = Zotero.getString(prefix + 'NotRegistered',
|
||||
[Zotero.Fulltext.pdfConverterFileName]);
|
||||
}
|
||||
converterStatusLabel.setAttribute('value', str);
|
||||
|
||||
// pdfinfo status line
|
||||
if (infoIsRegistered) {
|
||||
var version = Zotero.Fulltext.pdfInfoVersion;
|
||||
str = Zotero.getString(prefix + 'Registered',
|
||||
Zotero.getString('zotero.preferences.search.pdf.toolVersionPlatform',
|
||||
[Zotero.Fulltext.pdfInfoName, version]));
|
||||
}
|
||||
else {
|
||||
str = Zotero.getString(prefix + 'NotRegistered',
|
||||
[Zotero.Fulltext.pdfInfoFileName]);
|
||||
}
|
||||
infoStatusLabel.setAttribute('value', str);
|
||||
|
||||
str = converterIsRegistered ?
|
||||
Zotero.getString('general.checkForUpdate') :
|
||||
Zotero.getString('zotero.preferences.search.pdf.checkForInstaller');
|
||||
updateButton.setAttribute('label', str);
|
||||
|
||||
requiredLabel.setAttribute('hidden', converterIsRegistered);
|
||||
documentationLink.setAttribute('hidden', converterIsRegistered);
|
||||
settingsBox.setAttribute('hidden', !converterIsRegistered);
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
* Check available versions of PDF tools from server and prompt for installation
|
||||
* if a newer version is available
|
||||
*/
|
||||
checkPDFToolsDownloadVersion: Zotero.Promise.coroutine(function* () {
|
||||
try {
|
||||
var latestVersion = yield Zotero.Fulltext.getLatestPDFToolsVersion();
|
||||
|
||||
var converterIsRegistered = Zotero.Fulltext.pdfConverterIsRegistered();
|
||||
var infoIsRegistered = Zotero.Fulltext.pdfInfoIsRegistered();
|
||||
var bothRegistered = converterIsRegistered && infoIsRegistered;
|
||||
|
||||
// On Windows, install if not installed or anything other than 3.02a
|
||||
if (Zotero.isWin) {
|
||||
var converterVersionAvailable = !converterIsRegistered
|
||||
|| Zotero.Fulltext.pdfConverterVersion != '3.02a';
|
||||
var infoVersionAvailable = !infoIsRegistered
|
||||
|| Zotero.Fulltext.pdfInfoVersion != '3.02a';
|
||||
var bothAvailable = converterVersionAvailable && infoVersionAvailable;
|
||||
}
|
||||
// Install if not installed, version unknown, outdated, or
|
||||
// Xpdf 3.02/3.04 (to upgrade to Poppler),
|
||||
else {
|
||||
var converterVersionAvailable = (!converterIsRegistered ||
|
||||
Zotero.Fulltext.pdfConverterVersion == 'UNKNOWN'
|
||||
|| latestVersion > Zotero.Fulltext.pdfConverterVersion
|
||||
|| (!latestVersion.startsWith('3.02')
|
||||
&& Zotero.Fulltext.pdfConverterVersion.startsWith('3.02'))
|
||||
|| (!latestVersion.startsWith('3.02') && latestVersion != '3.04'
|
||||
&& Zotero.Fulltext.pdfConverterVersion == '3.04'));
|
||||
var infoVersionAvailable = (!infoIsRegistered ||
|
||||
Zotero.Fulltext.pdfInfoVersion == 'UNKNOWN'
|
||||
|| latestVersion > Zotero.Fulltext.pdfInfoVersion
|
||||
|| (!latestVersion.startsWith('3.02')
|
||||
&& Zotero.Fulltext.pdfInfoVersion.startsWith('3.02'))
|
||||
|| (!latestVersion.startsWith('3.02') && latestVersion != '3.04'
|
||||
&& Zotero.Fulltext.pdfInfoVersion == '3.04'));
|
||||
var bothAvailable = converterVersionAvailable && infoVersionAvailable;
|
||||
}
|
||||
|
||||
// Up to date -- disable update button
|
||||
if (!converterVersionAvailable && !infoVersionAvailable) {
|
||||
var button = document.getElementById('pdftools-update-button');
|
||||
button.setAttribute('label', Zotero.getString('zotero.preferences.update.upToDate'));
|
||||
button.setAttribute('disabled', true);
|
||||
return;
|
||||
}
|
||||
|
||||
// New version available -- display update prompt
|
||||
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
|
||||
createInstance(Components.interfaces.nsIPromptService);
|
||||
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
|
||||
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
|
||||
|
||||
var msg = Zotero.getString('zotero.preferences.search.pdf.available'
|
||||
+ ((converterIsRegistered || infoIsRegistered) ? 'Updates' : 'Downloads'),
|
||||
[Zotero.platform, 'zotero.org']) + '\n\n';
|
||||
|
||||
if (converterVersionAvailable) {
|
||||
let tvp = Zotero.getString('zotero.preferences.search.pdf.toolVersionPlatform',
|
||||
[Zotero.Fulltext.pdfConverterName, latestVersion]);
|
||||
msg += '- ' + tvp + '\n';
|
||||
}
|
||||
if (infoVersionAvailable) {
|
||||
let tvp = Zotero.getString('zotero.preferences.search.pdf.toolVersionPlatform',
|
||||
[Zotero.Fulltext.pdfInfoName, latestVersion]);
|
||||
msg += '- ' + tvp + '\n';
|
||||
}
|
||||
msg += '\n';
|
||||
msg += Zotero.getString('zotero.preferences.search.pdf.zoteroCanInstallVersion'
|
||||
+ (bothAvailable ? 's' : ''));
|
||||
|
||||
var index = ps.confirmEx(null,
|
||||
converterIsRegistered ?
|
||||
Zotero.getString('general.updateAvailable') : '',
|
||||
msg,
|
||||
buttonFlags,
|
||||
converterIsRegistered ?
|
||||
Zotero.getString('general.upgrade') :
|
||||
Zotero.getString('general.install'),
|
||||
null, null, null, {});
|
||||
|
||||
if (index != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('pdftools-update-button').disabled = true;
|
||||
var str = Zotero.getString('zotero.preferences.search.pdf.downloading');
|
||||
document.getElementById('pdftools-update-button').setAttribute('label', str);
|
||||
|
||||
if (converterVersionAvailable) {
|
||||
yield Zotero.Fulltext.downloadPDFTool('converter', latestVersion)
|
||||
.catch(function (e) {
|
||||
Zotero.logError(e);
|
||||
throw new Error("Error downloading pdftotext");
|
||||
});
|
||||
}
|
||||
if (infoVersionAvailable) {
|
||||
yield Zotero.Fulltext.downloadPDFTool('info', latestVersion)
|
||||
.catch(function (e) {
|
||||
Zotero.logError(e);
|
||||
throw new Error("Error downloading pdfinfo");
|
||||
});
|
||||
}
|
||||
this.updatePDFToolsStatus();
|
||||
}
|
||||
catch (e) {
|
||||
this.onPDFToolsDownloadError(e);
|
||||
}
|
||||
}),
|
||||
|
||||
|
||||
onPDFToolsDownloadError: function (e) {
|
||||
if (e == 404) {
|
||||
var str = Zotero.getString('zotero.preferences.search.pdf.toolDownloadsNotAvailable',
|
||||
Zotero.Fulltext.pdfToolsName) + ' '
|
||||
+ Zotero.getString('zotero.preferences.search.pdf.viewManualInstructions');
|
||||
}
|
||||
else {
|
||||
Components.utils.reportError(e);
|
||||
var str = Zotero.getString('zotero.preferences.search.pdf.toolsDownloadError', Zotero.Fulltext.pdfToolsName)
|
||||
+ ' ' + Zotero.getString('zotero.preferences.search.pdf.tryAgainOrViewManualInstructions');
|
||||
}
|
||||
|
||||
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.createInstance(Components.interfaces.nsIPromptService);
|
||||
ps.alert(
|
||||
null,
|
||||
Zotero.getString('pane.item.attachments.PDF.installTools.title'),
|
||||
str
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
updateIndexStats: Zotero.Promise.coroutine(function* () {
|
||||
var stats = yield Zotero.Fulltext.getIndexStats();
|
||||
document.getElementById('fulltext-stats-indexed').
|
||||
|
|
|
@ -51,38 +51,6 @@
|
|||
</hbox>
|
||||
</groupbox>
|
||||
|
||||
<groupbox id="pdftools-box">
|
||||
<caption label="&zotero.preferences.search.pdfIndexing;"/>
|
||||
|
||||
<label id="pdfconverter-status"/>
|
||||
<separator class="thin"/>
|
||||
<label id="pdfinfo-status"/>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<!-- This doesn't wrap without an explicit width -->
|
||||
<label id="pdftools-required" width="45em" hidden="true"/>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<hbox>
|
||||
<button id="pdftools-update-button" flex="1" oncommand="Zotero_Preferences.Search.checkPDFToolsDownloadVersion()"/>
|
||||
</hbox>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<!-- This doesn't wrap without an explicit width -->
|
||||
<label id="pdftools-documentation-link" width="45em" hidden="true"/>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<hbox id="pdftools-settings" align="center" hidden="true">
|
||||
<label value="&zotero.preferences.fulltext.pdfMaxPages;"/>
|
||||
<textbox size="5" preference="pref-fulltext-pdfmaxpages"/>
|
||||
<label value="(&zotero.preferences.default; 100)"/>
|
||||
</hbox>
|
||||
</groupbox>
|
||||
|
||||
<groupbox id="fulltext-stats">
|
||||
<caption label="&zotero.preferences.search.indexStats;"/>
|
||||
|
||||
|
|
|
@ -49,11 +49,6 @@ var Zotero_RecognizePDF = new function() {
|
|||
* of the new items
|
||||
*/
|
||||
this.recognizeSelected = function() {
|
||||
var installed = ZoteroPane_Local.checkPDFConverter();
|
||||
if (!installed) {
|
||||
return;
|
||||
}
|
||||
|
||||
var items = ZoteroPane_Local.getSelectedItems();
|
||||
if (!items) return;
|
||||
var itemRecognizer = new Zotero_RecognizePDF.ItemRecognizer();
|
||||
|
|
|
@ -3140,7 +3140,6 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentHash', {
|
|||
*
|
||||
* - Currently works on HTML, PDF and plaintext attachments
|
||||
* - Paragraph breaks will be lost in PDF content
|
||||
* - For PDFs, will return empty string if Zotero.Fulltext.pdfConverterIsRegistered() is false
|
||||
*
|
||||
* @return {Promise<String>} - A promise for attachment text or empty string if unavailable
|
||||
*/
|
||||
|
@ -3194,10 +3193,6 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentText', {
|
|||
}
|
||||
|
||||
if (reindex) {
|
||||
if (!Zotero.Fulltext.pdfConverterIsRegistered()) {
|
||||
Zotero.debug("PDF converter is unavailable -- returning empty .attachmentText", 3);
|
||||
return '';
|
||||
}
|
||||
yield Zotero.Fulltext.indexItems(this.id, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,15 +24,8 @@
|
|||
*/
|
||||
|
||||
Zotero.Fulltext = Zotero.FullText = new function(){
|
||||
const CACHE_FILE = '.zotero-ft-cache';
|
||||
|
||||
this.pdfConverterIsRegistered = pdfConverterIsRegistered;
|
||||
this.pdfInfoIsRegistered = pdfInfoIsRegistered;
|
||||
this.isCachedMIMEType = isCachedMIMEType;
|
||||
|
||||
this.pdfToolsDownloadBaseURL = ZOTERO_CONFIG.PDF_TOOLS_URL;
|
||||
this.__defineGetter__("pdfToolsName", function() { return 'Xpdf'; });
|
||||
this.__defineGetter__("pdfToolsURL", function() { return 'http://www.foolabs.com/xpdf/'; });
|
||||
this.__defineGetter__("pdfConverterName", function() { return 'pdftotext'; });
|
||||
this.__defineGetter__("pdfInfoName", function() { return 'pdfinfo'; });
|
||||
this.__defineGetter__("pdfConverterCacheFile", function () { return '.zotero-ft-cache'; });
|
||||
|
@ -60,16 +53,12 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
|||
const kWbClassHiraganaLetter = 5;
|
||||
const kWbClassHWKatakanaLetter = 6;
|
||||
const kWbClassThaiLetter = 7;
|
||||
|
||||
|
||||
var _pdfConverterVersion = null;
|
||||
var _pdfConverterFileName = null;
|
||||
var _pdfConverterScript = null; // nsIFile of hidden window script on Windows
|
||||
var _pdfConverter = null; // nsIFile to executable
|
||||
var _pdfInfoVersion = null;
|
||||
var _pdfInfoFileName = null;
|
||||
var _pdfInfoScript = null; // nsIFile of redirection script
|
||||
var _pdfInfo = null; // nsIFile to executable
|
||||
var _popplerDatadir = null;
|
||||
|
||||
var _idleObserverIsRegistered = false;
|
||||
var _idleObserverDelay = 30;
|
||||
|
@ -84,22 +73,34 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
|||
|
||||
this.decoder = Components.classes["@mozilla.org/intl/utf8converterservice;1"].
|
||||
getService(Components.interfaces.nsIUTF8ConverterService);
|
||||
|
||||
var platform = Zotero.platform.replace(/ /g, '-');
|
||||
_pdfConverterFileName = this.pdfConverterName + '-' + platform;
|
||||
_pdfInfoFileName = this.pdfInfoName + '-' + platform;
|
||||
|
||||
_pdfConverterFileName = this.pdfConverterName;
|
||||
_pdfInfoFileName = this.pdfInfoName;
|
||||
|
||||
if (Zotero.isWin) {
|
||||
_pdfConverterFileName += '.exe';
|
||||
_pdfInfoFileName += '.exe';
|
||||
}
|
||||
|
||||
this.__defineGetter__("pdfConverterFileName", function() { return _pdfConverterFileName; });
|
||||
this.__defineGetter__("pdfConverterVersion", function() { return _pdfConverterVersion; });
|
||||
this.__defineGetter__("pdfInfoFileName", function() { return _pdfInfoFileName; });
|
||||
this.__defineGetter__("pdfInfoVersion", function() { return _pdfInfoVersion; });
|
||||
let dir = FileUtils.getFile('AChrom', []).parent;
|
||||
|
||||
yield this.registerPDFTool('converter');
|
||||
yield this.registerPDFTool('info');
|
||||
_popplerDatadir = dir.clone();
|
||||
_popplerDatadir.append('poppler-data');
|
||||
_popplerDatadir = _popplerDatadir.path;
|
||||
|
||||
_pdfConverter = dir.clone();
|
||||
_pdfInfo = dir.clone();
|
||||
|
||||
if(Zotero.isMac) {
|
||||
_pdfConverter = _pdfConverter.parent;
|
||||
_pdfConverter.append('MacOS');
|
||||
|
||||
_pdfInfo = _pdfInfo.parent;
|
||||
_pdfInfo.append('MacOS');
|
||||
}
|
||||
|
||||
_pdfConverter.append(_pdfConverterFileName);
|
||||
_pdfInfo.append(_pdfInfoFileName);
|
||||
|
||||
Zotero.uiReadyPromise.delay(30000).then(() => {
|
||||
this.registerContentProcessor();
|
||||
|
@ -197,279 +198,12 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
|||
}
|
||||
|
||||
|
||||
this.getLatestPDFToolsVersion = Zotero.Promise.coroutine(function* () {
|
||||
if (Zotero.isWin) {
|
||||
return "3.02a";
|
||||
}
|
||||
|
||||
// Find latest version for this platform
|
||||
var url = Zotero.Fulltext.pdfToolsDownloadBaseURL + 'latest.json';
|
||||
var xmlhttp = yield Zotero.HTTP.request("GET", url, { responseType: "json" });
|
||||
var json = xmlhttp.response;
|
||||
|
||||
var platform = Zotero.platform.replace(/\s/g, '-');
|
||||
var version = json[platform] || json['default'];
|
||||
|
||||
Zotero.debug("Latest PDF tools version for " + platform + " is " + version);
|
||||
|
||||
return version;
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* Download and install latest PDF tool
|
||||
*/
|
||||
this.downloadPDFTool = Zotero.Promise.coroutine(function* (tool, version) {
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
|
||||
if (tool == 'converter') {
|
||||
var fileName = this.pdfConverterFileName;
|
||||
}
|
||||
else {
|
||||
var fileName = this.pdfInfoFileName;
|
||||
}
|
||||
|
||||
var spec = this.pdfToolsDownloadBaseURL + version + "/" + fileName;
|
||||
var uri = ioService.newURI(spec, null, null);
|
||||
var tmpFile = OS.Path.join(Zotero.getTempDirectory().path, fileName);
|
||||
|
||||
yield Zotero.File.download(uri, tmpFile);
|
||||
|
||||
var fileInfo = yield OS.File.stat(tmpFile);
|
||||
|
||||
// Delete if too small, since a 404 might not be detected above
|
||||
if (fileInfo.size < 50000) {
|
||||
let msg = tmpFile + " is too small -- deleting";
|
||||
Zotero.logError(msg);
|
||||
try {
|
||||
yield OS.File.remove(tmpFile);
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.logError(e);
|
||||
}
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
var scriptExt = _getScriptExtension();
|
||||
// On Windows, write out script to hide pdftotext console window
|
||||
// TEMP: disabled
|
||||
if (false && tool == 'converter') {
|
||||
if (Zotero.isWin) {
|
||||
let content = yield Zotero.File.getContentsFromURLAsync(
|
||||
'resource://zotero/hide.' + scriptExt
|
||||
);
|
||||
var tmpScriptFile = OS.Path.join(
|
||||
Zotero.getTempDirectory().path,
|
||||
'pdftotext.' + scriptExt
|
||||
);
|
||||
yield Zotero.File.putContentsAsync(tmpScriptFile, content);
|
||||
}
|
||||
}
|
||||
// Write out output redirection script for pdfinfo
|
||||
// TEMP: disabled on Windows
|
||||
else if (!Zotero.isWin && tool == 'info') {
|
||||
let content = yield Zotero.File.getContentsFromURLAsync(
|
||||
'resource://zotero/redirect.' + scriptExt
|
||||
);
|
||||
var tmpScriptFile = OS.Path.join(
|
||||
Zotero.getTempDirectory().path,
|
||||
'pdfinfo.' + scriptExt
|
||||
);
|
||||
yield Zotero.File.putContentsAsync(tmpScriptFile, content);
|
||||
}
|
||||
|
||||
// Set permissions to 755
|
||||
if (Zotero.isMac || Zotero.isLinux) {
|
||||
yield OS.File.setPermissions(tmpFile, {
|
||||
unixMode: 0o755
|
||||
});
|
||||
if (tmpScriptFile) {
|
||||
yield OS.File.setPermissions(tmpScriptFile, {
|
||||
unixMode: 0o755
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var destDir = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
||||
// Move redirect script and executable into data dir
|
||||
if (tmpScriptFile) {
|
||||
yield OS.File.move(
|
||||
tmpScriptFile,
|
||||
OS.Path.join(destDir.path, OS.Path.basename(tmpScriptFile))
|
||||
);
|
||||
}
|
||||
yield OS.File.move(tmpFile, OS.Path.join(destDir.path, fileName));
|
||||
|
||||
// Write the version number to a file
|
||||
var versionFile = destDir.clone();
|
||||
versionFile.append(fileName + '.version');
|
||||
// TEMP
|
||||
if (Zotero.isWin) {
|
||||
version = '3.02a';
|
||||
}
|
||||
yield Zotero.File.putContentsAsync(versionFile, version + '');
|
||||
|
||||
yield Zotero.Fulltext.registerPDFTool(tool);
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* Looks for pdftotext-{platform}[.exe] in the Zotero data directory
|
||||
*
|
||||
* {platform} is navigator.platform, with spaces replaced by hyphens
|
||||
* e.g. "Win32", "Linux-i686", "MacPPC", "MacIntel", etc.
|
||||
*/
|
||||
this.registerPDFTool = Zotero.Promise.coroutine(function* (tool) {
|
||||
var errMsg = false;
|
||||
var exec = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
||||
|
||||
switch (tool) {
|
||||
case 'converter':
|
||||
var toolName = this.pdfConverterName;
|
||||
var fileName = _pdfConverterFileName;
|
||||
break;
|
||||
|
||||
case 'info':
|
||||
var toolName = this.pdfInfoName;
|
||||
var fileName = _pdfInfoFileName;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw ("Invalid PDF tool type '" + tool + "' in Zotero.Fulltext.registerPDFTool()");
|
||||
}
|
||||
|
||||
exec.append(fileName);
|
||||
if (!exec.exists()) {
|
||||
exec = null;
|
||||
errMsg = fileName + ' not found';
|
||||
}
|
||||
|
||||
if (!exec) {
|
||||
if (tool == 'converter') {
|
||||
Zotero.debug(errMsg + ' -- PDF indexing disabled');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
var versionFile = exec.parent;
|
||||
versionFile.append(fileName + '.version');
|
||||
if (versionFile.exists()) {
|
||||
try {
|
||||
var version = (yield Zotero.File.getSample(versionFile)).split(/[\r\n\s]/)[0];
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.debug(e, 1);
|
||||
Components.utils.reportError(e);
|
||||
}
|
||||
}
|
||||
if (!version) {
|
||||
var version = 'UNKNOWN';
|
||||
}
|
||||
|
||||
// If scripts exist, use those instead
|
||||
switch (tool) {
|
||||
case 'converter':
|
||||
// TEMP: disabled
|
||||
if (false && Zotero.isWin) {
|
||||
var script = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
||||
script.append('pdftotext.' + _getScriptExtension())
|
||||
if (script.exists()) {
|
||||
Zotero.debug(script.leafName + " registered");
|
||||
_pdfConverterScript = script;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'info':
|
||||
// Modified 3.02 version doesn't use redirection script
|
||||
if (version.startsWith('3.02')) break;
|
||||
|
||||
var script = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
||||
// TEMP: disabled on Win
|
||||
if (!Zotero.isWin) {
|
||||
script.append('pdfinfo.' + _getScriptExtension())
|
||||
// The redirection script is necessary to run pdfinfo
|
||||
if (!script.exists()) {
|
||||
Zotero.debug(script.leafName + " not found -- PDF statistics disabled");
|
||||
return false;
|
||||
}
|
||||
Zotero.debug(toolName + " redirection script registered");
|
||||
_pdfInfoScript = script;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (tool) {
|
||||
case 'converter':
|
||||
_pdfConverter = exec;
|
||||
_pdfConverterVersion = version;
|
||||
break;
|
||||
|
||||
case 'info':
|
||||
_pdfInfo = exec;
|
||||
_pdfInfoVersion = version;
|
||||
break;
|
||||
}
|
||||
|
||||
Zotero.debug(toolName + ' version ' + version + ' registered');
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Unregister and delete PDF tools
|
||||
*
|
||||
* Used only for tests
|
||||
*/
|
||||
this.uninstallPDFTools = Zotero.Promise.coroutine(function* () {
|
||||
Zotero.debug("Uninstalling PDF tools");
|
||||
|
||||
if (_pdfConverter) {
|
||||
yield Zotero.File.removeIfExists(_pdfConverter.path);
|
||||
yield Zotero.File.removeIfExists(_pdfConverter.path + ".version");
|
||||
}
|
||||
if (_pdfInfo) {
|
||||
yield Zotero.File.removeIfExists(_pdfInfo.path);
|
||||
yield Zotero.File.removeIfExists(_pdfInfo.path + ".version");
|
||||
}
|
||||
if (_pdfConverterScript) yield Zotero.File.removeIfExists(_pdfConverterScript.path);
|
||||
if (_pdfInfoScript) yield Zotero.File.removeIfExists(_pdfInfoScript.path);
|
||||
|
||||
_pdfConverter = null;
|
||||
_pdfInfo = null;
|
||||
_pdfInfoScript = null;
|
||||
});
|
||||
|
||||
|
||||
function pdfConverterIsRegistered() {
|
||||
return !!_pdfConverter;
|
||||
}
|
||||
|
||||
|
||||
function pdfInfoIsRegistered() {
|
||||
return !!_pdfInfo;
|
||||
}
|
||||
|
||||
|
||||
this.getPDFConverterExecAndArgs = function () {
|
||||
if (!this.pdfConverterIsRegistered()) {
|
||||
throw new Error("PDF converter is not registered");
|
||||
}
|
||||
|
||||
if (_pdfConverterScript) {
|
||||
return {
|
||||
exec: _pdfConverterScript,
|
||||
args: [_pdfConverter.path]
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
exec: _pdfConverter,
|
||||
args: []
|
||||
args: ['-datadir', _popplerDatadir]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
|
@ -674,11 +408,6 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
|||
* @return {Promise}
|
||||
*/
|
||||
this.indexPDF = Zotero.Promise.coroutine(function* (filePath, itemID, allPages) {
|
||||
if (!_pdfConverter) {
|
||||
Zotero.debug("PDF tools are not installed -- skipping indexing");
|
||||
return false;
|
||||
}
|
||||
|
||||
var maxPages = Zotero.Prefs.get('fulltext.pdfMaxPages');
|
||||
if (maxPages == 0) {
|
||||
return false;
|
||||
|
@ -697,38 +426,20 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
|||
var infoFilePath = OS.Path.join(parentDirPath, this.pdfInfoCacheFile);
|
||||
var cacheFilePath = OS.Path.join(parentDirPath, this.pdfConverterCacheFile);
|
||||
|
||||
// Modified 3.02 version that can output a text file directly
|
||||
if (_pdfInfo && _pdfInfoVersion.startsWith('3.02')) {
|
||||
let args = [filePath, infoFilePath];
|
||||
|
||||
try {
|
||||
yield Zotero.Utilities.Internal.exec(_pdfInfo, args);
|
||||
var totalPages = yield getTotalPagesFromFile(itemID);
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.debug("Error running pdfinfo");
|
||||
}
|
||||
|
||||
var args = [filePath, infoFilePath];
|
||||
|
||||
try {
|
||||
yield Zotero.Utilities.Internal.exec(_pdfInfo, args);
|
||||
var totalPages = yield getTotalPagesFromFile(itemID);
|
||||
}
|
||||
// Use redirection script
|
||||
else if (_pdfInfoScript) {
|
||||
let args = [_pdfInfo.path, filePath, infoFilePath];
|
||||
|
||||
try {
|
||||
yield Zotero.Utilities.Internal.exec(_pdfInfoScript, args);
|
||||
var totalPages = yield getTotalPagesFromFile(itemID);
|
||||
}
|
||||
catch (e) {
|
||||
Components.utils.reportError(e);
|
||||
Zotero.debug("Error running pdfinfo", 1);
|
||||
Zotero.debug(e, 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Zotero.debug(this.pdfInfoName + " is not available");
|
||||
catch (e) {
|
||||
Zotero.debug("Error running pdfinfo");
|
||||
}
|
||||
|
||||
|
||||
var {exec, args} = this.getPDFConverterExecAndArgs();
|
||||
args.push('-enc', 'UTF-8', '-nopgbrk');
|
||||
args.push('-nopgbrk');
|
||||
|
||||
if (allPages) {
|
||||
if (totalPages) {
|
||||
|
|
|
@ -1633,116 +1633,6 @@ Zotero.Schema = new function(){
|
|||
var translatorUpdates = xmlhttp.responseXML.getElementsByTagName('translator');
|
||||
var styleUpdates = xmlhttp.responseXML.getElementsByTagName('style');
|
||||
|
||||
var updatePDFTools = function () {
|
||||
// No updates for PPC
|
||||
if (Zotero.platform == 'MacPPC') return;
|
||||
|
||||
let pdfToolsUpdates = xmlhttp.responseXML.getElementsByTagName('pdftools');
|
||||
if (pdfToolsUpdates.length) {
|
||||
let availableVersion = pdfToolsUpdates[0].getAttribute('version');
|
||||
let installInfo = false;
|
||||
let installConverter = false;
|
||||
|
||||
// Don't auto-install if not installed
|
||||
if (!Zotero.Fulltext.pdfInfoIsRegistered() && !Zotero.Fulltext.pdfConverterIsRegistered()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TEMP
|
||||
if (Zotero.isWin) {
|
||||
if (Zotero.Fulltext.pdfInfoIsRegistered()) {
|
||||
if (Zotero.Fulltext.pdfInfoVersion != '3.02a') {
|
||||
installInfo = true;
|
||||
}
|
||||
}
|
||||
// Install missing component if one is installed
|
||||
else if (Zotero.Fulltext.pdfConverterIsRegistered()) {
|
||||
installInfo = true;
|
||||
}
|
||||
if (Zotero.Fulltext.pdfConverterIsRegistered()) {
|
||||
if (Zotero.Fulltext.pdfConverterVersion != '3.02a') {
|
||||
installConverter = true;
|
||||
}
|
||||
}
|
||||
// Install missing component if one is installed
|
||||
else if (Zotero.Fulltext.pdfInfoIsRegistered()) {
|
||||
installConverter = true;
|
||||
}
|
||||
availableVersion = '3.02';
|
||||
}
|
||||
else {
|
||||
if (Zotero.Fulltext.pdfInfoIsRegistered()) {
|
||||
let currentVersion = Zotero.Fulltext.pdfInfoVersion;
|
||||
if (currentVersion < availableVersion || currentVersion.startsWith('3.02')
|
||||
|| currentVersion == 'UNKNOWN') {
|
||||
installInfo = true;
|
||||
}
|
||||
}
|
||||
// Install missing component if one is installed
|
||||
else if (Zotero.Fulltext.pdfConverterIsRegistered()) {
|
||||
installInfo = true;
|
||||
}
|
||||
if (Zotero.Fulltext.pdfConverterIsRegistered()) {
|
||||
let currentVersion = Zotero.Fulltext.pdfConverterVersion;
|
||||
if (currentVersion < availableVersion || currentVersion.startsWith('3.02')
|
||||
|| currentVersion == 'UNKNOWN') {
|
||||
installConverter = true;
|
||||
}
|
||||
}
|
||||
// Install missing component if one is installed
|
||||
else if (Zotero.Fulltext.pdfInfoIsRegistered()) {
|
||||
installConverter = true;
|
||||
}
|
||||
}
|
||||
|
||||
let prefKey = 'pdfToolsInstallError';
|
||||
let lastTry = 0, delay = 43200000; // half a day, so doubles to a day initially
|
||||
try {
|
||||
[lastTry, delay] = Zotero.Prefs.get(prefKey).split(';');
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
// Allow an additional minute, since repo updates might not be exact
|
||||
if (Date.now() < (parseInt(lastTry) + parseInt(delay) - 60000)) {
|
||||
Zotero.debug("Now enough time since last PDF tools installation failure -- skipping", 2);
|
||||
return;
|
||||
}
|
||||
|
||||
var checkResult = function (success) {
|
||||
if (success) {
|
||||
try {
|
||||
Zotero.Prefs.clear(prefKey);
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
else {
|
||||
// Keep doubling delay, to a max of 1 week
|
||||
Zotero.Prefs.set(prefKey, Date.now() + ";" + Math.min(delay * 2, 7*24*60*60*1000));
|
||||
|
||||
let msg = "Error downloading PDF tool";
|
||||
Zotero.debug(msg, 1);
|
||||
throw new Error(msg);
|
||||
}
|
||||
};
|
||||
|
||||
if (installConverter && installInfo) {
|
||||
Zotero.Fulltext.downloadPDFTool('converter', availableVersion, function (success) {
|
||||
checkResult(success);
|
||||
Zotero.Fulltext.downloadPDFTool('info', availableVersion, checkResult);
|
||||
});
|
||||
}
|
||||
else if (installConverter) {
|
||||
Zotero.Fulltext.downloadPDFTool('converter', availableVersion, checkResult);
|
||||
}
|
||||
else if (installInfo) {
|
||||
Zotero.Fulltext.downloadPDFTool('info', availableVersion, checkResult);
|
||||
}
|
||||
else {
|
||||
Zotero.debug("PDF tools are up to date");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (!translatorUpdates.length && !styleUpdates.length){
|
||||
await Zotero.DB.executeTransaction(function* (conn) {
|
||||
// Store the timestamp provided by the server
|
||||
|
@ -1756,7 +1646,6 @@ Zotero.Schema = new function(){
|
|||
if (!force) {
|
||||
_setRepositoryTimer(ZOTERO_CONFIG.REPOSITORY_CHECK_INTERVAL);
|
||||
}
|
||||
updatePDFTools();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1790,8 +1679,6 @@ Zotero.Schema = new function(){
|
|||
});
|
||||
}
|
||||
|
||||
updatePDFTools();
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
|
|
|
@ -581,9 +581,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
|||
while (true) {
|
||||
let entry = yield iterator.next();
|
||||
// Don't delete some files
|
||||
if (entry.name == 'pipes'
|
||||
|| entry.name.startsWith(Zotero.Fulltext.pdfInfoName)
|
||||
|| entry.name.startsWith(Zotero.Fulltext.pdfConverterName)) {
|
||||
if (entry.name == 'pipes') {
|
||||
continue;
|
||||
}
|
||||
Zotero.debug("Deleting " + entry.path);
|
||||
|
|
|
@ -1735,30 +1735,6 @@ var ZoteroPane = new function()
|
|||
};
|
||||
|
||||
|
||||
this.checkPDFConverter = function () {
|
||||
if (Zotero.Fulltext.pdfConverterIsRegistered()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.getService(Components.interfaces.nsIPromptService);
|
||||
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
|
||||
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
|
||||
var index = ps.confirmEx(
|
||||
null,
|
||||
Zotero.getString('pane.item.attachments.PDF.installTools.title'),
|
||||
Zotero.getString('pane.item.attachments.PDF.installTools.text'),
|
||||
buttonFlags,
|
||||
Zotero.getString('general.openPreferences'),
|
||||
null, null, null, {}
|
||||
);
|
||||
if (index == 0) {
|
||||
ZoteroPane_Local.openPreferences('zotero-prefpane-search', { action: 'pdftools-install' });
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {Promise}
|
||||
*/
|
||||
|
@ -1769,24 +1745,11 @@ var ZoteroPane = new function()
|
|||
}
|
||||
|
||||
var itemIDs = [];
|
||||
var checkPDF = false;
|
||||
|
||||
for (var i=0; i<items.length; i++) {
|
||||
// If any PDFs, we need to make sure the converter is installed and
|
||||
// prompt for installation if not
|
||||
if (!checkPDF && items[i].attachmentContentType && items[i].attachmentContentType == "application/pdf") {
|
||||
checkPDF = true;
|
||||
}
|
||||
itemIDs.push(items[i].id);
|
||||
}
|
||||
|
||||
if (checkPDF) {
|
||||
var installed = this.checkPDFConverter();
|
||||
if (!installed) {
|
||||
yield document.getElementById('zotero-attachment-box').updateItemIndexedState();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
yield Zotero.Fulltext.indexItems(itemIDs, true);
|
||||
yield document.getElementById('zotero-attachment-box').updateItemIndexedState();
|
||||
});
|
||||
|
@ -2810,10 +2773,6 @@ var ZoteroPane = new function()
|
|||
var canMarkRead = collectionTreeRow.isFeed();
|
||||
var markUnread = true;
|
||||
|
||||
if (!Zotero.Fulltext.pdfConverterIsRegistered()) {
|
||||
canIndex = false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
let item = items[i];
|
||||
if (canMerge && !item.isRegularItem() || item.isFeedItem || collectionTreeRow.isDuplicates()) {
|
||||
|
@ -2935,8 +2894,7 @@ var ZoteroPane = new function()
|
|||
}
|
||||
|
||||
// If not linked URL, show reindex line
|
||||
if (Zotero.Fulltext.pdfConverterIsRegistered()
|
||||
&& (yield Zotero.Fulltext.canReindex(item))) {
|
||||
if (yield Zotero.Fulltext.canReindex(item)) {
|
||||
show.push(m.reindexItem);
|
||||
showSep4 = true;
|
||||
}
|
||||
|
|
|
@ -293,47 +293,6 @@ if(run) {
|
|||
window.onload = function() {
|
||||
Zotero.spawn(function* () {
|
||||
yield Zotero.Schema.schemaUpdatePromise;
|
||||
|
||||
// Download and cache PDF tools for this platform
|
||||
//
|
||||
// To reset, delete test/tests/data/pdf/ directory
|
||||
var cachePDFTools = Zotero.Promise.coroutine(function* () {
|
||||
var path = OS.Path.join(getTestDataDirectory().path, 'pdf');
|
||||
yield OS.File.makeDir(path, { ignoreExisting: true });
|
||||
|
||||
var baseURL = Zotero.Fulltext.pdfToolsDownloadBaseURL;
|
||||
// Point full-text code to the cache directory, so downloads come from there
|
||||
Zotero.Fulltext.pdfToolsDownloadBaseURL = OS.Path.toFileURI(path) + "/";
|
||||
|
||||
// Get latest tools version for the current platform
|
||||
yield Zotero.File.download(baseURL + 'latest.json', OS.Path.join(path, 'latest.json'));
|
||||
|
||||
var platform = Zotero.platform.replace(/\s/g, '-');
|
||||
var version = yield Zotero.Fulltext.getLatestPDFToolsVersion();
|
||||
|
||||
// Create version directory (e.g., data/pdf/3.04) and download tools to it if
|
||||
// they don't exist
|
||||
yield OS.File.makeDir(OS.Path.join(path, version), { ignoreExisting: true });
|
||||
|
||||
var fileName = "pdfinfo-" + platform + (Zotero.isWin ? ".exe" : "");
|
||||
var execPath = OS.Path.join(path, version, fileName);
|
||||
if (!(yield OS.File.exists(execPath))) {
|
||||
yield Zotero.File.download(baseURL + version + "/" + fileName, execPath);
|
||||
}
|
||||
fileName = "pdftotext-" + platform + (Zotero.isWin ? ".exe" : "");;
|
||||
execPath = OS.Path.join(path, version, fileName);
|
||||
if (!(yield OS.File.exists(execPath))) {
|
||||
yield Zotero.File.download(baseURL + version + "/" + fileName, execPath);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
yield cachePDFTools();
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.logError(e);
|
||||
}
|
||||
|
||||
return mocha.run();
|
||||
})
|
||||
};
|
||||
|
|
|
@ -473,27 +473,6 @@ function getPromiseError(promise) {
|
|||
return promise.thenReturn(false).catch(e => e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the PDF tools are installed, or installs them if not.
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
var installPDFTools = Zotero.Promise.coroutine(function* () {
|
||||
if(Zotero.Fulltext.pdfConverterIsRegistered() && Zotero.Fulltext.pdfInfoIsRegistered()) {
|
||||
return;
|
||||
}
|
||||
var version = yield Zotero.Fulltext.getLatestPDFToolsVersion();
|
||||
yield Zotero.Fulltext.downloadPDFTool('info', version);
|
||||
yield Zotero.Fulltext.downloadPDFTool('converter', version);
|
||||
});
|
||||
|
||||
/**
|
||||
* @return {Promise}
|
||||
*/
|
||||
function uninstallPDFTools() {
|
||||
return Zotero.Fulltext.uninstallPDFTools();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the nsIFile corresponding to the test data directory
|
||||
* (i.e., test/tests/data)
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
describe("Zotero.Fulltext", function () {
|
||||
var win, pdfToolsVersion;
|
||||
var win;
|
||||
|
||||
before(function* () {
|
||||
// Hidden browser, which requires a browser window, needed for charset detection
|
||||
// (until we figure out a better way)
|
||||
win = yield loadBrowserWindow();
|
||||
|
||||
pdfToolsVersion = Zotero.isWin ? '3.02a' : '3.04';
|
||||
});
|
||||
after(function () {
|
||||
if (win) {
|
||||
|
@ -15,11 +13,6 @@ describe("Zotero.Fulltext", function () {
|
|||
});
|
||||
|
||||
describe("Indexing", function () {
|
||||
before(function* () {
|
||||
yield Zotero.Fulltext.downloadPDFTool('info', pdfToolsVersion);
|
||||
yield Zotero.Fulltext.downloadPDFTool('converter', pdfToolsVersion);
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
Zotero.Prefs.clear('fulltext.textMaxLength');
|
||||
Zotero.Prefs.clear('fulltext.pdfMaxPages');
|
||||
|
@ -92,80 +85,7 @@ describe("Zotero.Fulltext", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("#downloadPDFTool()", function () {
|
||||
it("should install the PDF tools", function* () {
|
||||
yield Zotero.Fulltext.uninstallPDFTools();
|
||||
assert.isFalse(Zotero.Fulltext.pdfInfoIsRegistered());
|
||||
|
||||
var dataDir = Zotero.DataDirectory.dir;
|
||||
var execFileName = Zotero.Fulltext.pdfInfoFileName;
|
||||
var execPath = OS.Path.join(dataDir, execFileName);
|
||||
var versionFileName = execFileName + '.version';
|
||||
var versionPath = OS.Path.join(dataDir, versionFileName);
|
||||
var scriptExt = Zotero.isWin ? 'vbs' : 'sh';
|
||||
var scriptPath = OS.Path.join(dataDir, 'pdfinfo.' + scriptExt);
|
||||
var scriptContents = yield Zotero.File.getContentsFromURLAsync(
|
||||
'resource://zotero/redirect.' + scriptExt
|
||||
);
|
||||
var cacheExecPath = OS.Path.join(
|
||||
getTestDataDirectory().path, "pdf", pdfToolsVersion, execFileName
|
||||
);
|
||||
|
||||
// Delete existing files
|
||||
try {
|
||||
yield OS.File.remove(execPath);
|
||||
}
|
||||
catch (e) {}
|
||||
try {
|
||||
yield OS.File.remove(versionPath);
|
||||
}
|
||||
catch (e) {}
|
||||
try {
|
||||
yield OS.File.remove(scriptPath);
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
yield Zotero.Fulltext.downloadPDFTool('info', pdfToolsVersion);
|
||||
|
||||
assert.ok(Zotero.Fulltext.pdfInfoIsRegistered());
|
||||
|
||||
assert.equal(
|
||||
(yield Zotero.Utilities.Internal.md5Async(cacheExecPath, false)),
|
||||
(yield Zotero.Utilities.Internal.md5Async(execPath, false))
|
||||
);
|
||||
|
||||
if (!Zotero.isWin) {
|
||||
assert.equal((yield OS.File.stat(execPath)).unixMode, 0o755);
|
||||
}
|
||||
assert.equal(
|
||||
(yield Zotero.File.getContentsAsync(versionPath)),
|
||||
pdfToolsVersion
|
||||
);
|
||||
|
||||
//Temp: disabled on Windows
|
||||
if (!Zotero.isWin) {
|
||||
assert.equal(
|
||||
(yield Zotero.File.getContentsAsync(scriptPath)),
|
||||
scriptContents
|
||||
);
|
||||
assert.equal((yield OS.File.stat(scriptPath)).unixMode, 0o755);
|
||||
}
|
||||
|
||||
yield uninstallPDFTools();
|
||||
assert.isFalse(Zotero.Fulltext.pdfInfoIsRegistered());
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe("#getUnsyncedContent()", function () {
|
||||
before(function* () {
|
||||
yield installPDFTools();
|
||||
})
|
||||
|
||||
after(function* () {
|
||||
yield uninstallPDFTools();
|
||||
})
|
||||
|
||||
it("should get content that hasn't been uploaded", function* () {
|
||||
var toSync = [];
|
||||
var group = yield getGroup();
|
||||
|
|
|
@ -1,20 +1,5 @@
|
|||
describe("Search Preferences", function () {
|
||||
describe("PDF Indexing", function () {
|
||||
it("should install PDF tools if not installed", function* () {
|
||||
// Begin install procedure
|
||||
var win = yield loadWindow("chrome://zotero/content/preferences/preferences.xul", {
|
||||
pane: 'zotero-prefpane-search',
|
||||
action: 'pdftools-install'
|
||||
});
|
||||
// Wait for confirmation dialog
|
||||
yield waitForDialog();
|
||||
|
||||
// Wait for install to finish
|
||||
yield waitForCallback(function() {
|
||||
return Zotero.Fulltext.pdfConverterIsRegistered()
|
||||
&& Zotero.Fulltext.pdfInfoIsRegistered();
|
||||
}, 500)
|
||||
.finally(() => win.close());
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
|
|
@ -7,8 +7,7 @@ describe("PDF Recognition", function() {
|
|||
this.timeout(60000);
|
||||
// Load Zotero pane and install PDF tools
|
||||
yield Zotero.Promise.all([
|
||||
loadZoteroPane().then(w => win = w),
|
||||
installPDFTools(),
|
||||
loadZoteroPane().then(w => win = w)
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue