From 1e2346eba14b7d818714df1555407a9207aaac4e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 8 Apr 2015 14:40:31 -0400 Subject: [PATCH] Revert to modified 3.02 binaries on Windows To deal with issues running .vbs scripts on some systems. If the 3.02 binaries haven't been reinstalled since this version, reinstall them as 3.02a automatically or on manual upgrade to fix corrupted binaries from previous gzip issue. Other platforms unchanged --- .../zotero/preferences/preferences_search.js | 41 +++++++++----- chrome/content/zotero/recognizePDF.js | 2 +- chrome/content/zotero/xpcom/fulltext.js | 32 +++++++++-- chrome/content/zotero/xpcom/schema.js | 56 +++++++++++++------ 4 files changed, 95 insertions(+), 36 deletions(-) diff --git a/chrome/content/zotero/preferences/preferences_search.js b/chrome/content/zotero/preferences/preferences_search.js index 51930fd72e..50202bbc95 100644 --- a/chrome/content/zotero/preferences/preferences_search.js +++ b/chrome/content/zotero/preferences/preferences_search.js @@ -182,23 +182,34 @@ Zotero_Preferences.Search = { 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; + latestVersion = "3.02a"; + } // Install if not installed, version unknown, outdated, or // Xpdf 3.02/3.04 (to upgrade to Poppler), - 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; + 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) { diff --git a/chrome/content/zotero/recognizePDF.js b/chrome/content/zotero/recognizePDF.js index 2dc988449a..819761caa5 100644 --- a/chrome/content/zotero/recognizePDF.js +++ b/chrome/content/zotero/recognizePDF.js @@ -142,7 +142,7 @@ var Zotero_RecognizePDF = new function() { var {exec, args} = Zotero.Fulltext.getPDFConverterExecAndArgs(); args.push('-enc', 'UTF-8', '-nopgbrk', '-layout', '-l', pages, file.path, cacheFile.path); - Zotero.debug("RecognizePDF: Running " + exec + " " + args.map(arg => "'" + arg + "'").join(" ")); + Zotero.debug("RecognizePDF: Running " + exec.path + " " + args.map(arg => "'" + arg + "'").join(" ")); return Zotero.Utilities.Internal.exec(exec, args).then(function() { if(!cacheFile.exists()) { diff --git a/chrome/content/zotero/xpcom/fulltext.js b/chrome/content/zotero/xpcom/fulltext.js index 3da6d83a3b..09654e246b 100644 --- a/chrome/content/zotero/xpcom/fulltext.js +++ b/chrome/content/zotero/xpcom/fulltext.js @@ -191,7 +191,6 @@ Zotero.Fulltext = new function(){ Components.utils.import("resource://gre/modules/FileUtils.jsm"); Zotero.debug("Saving " + uri.spec + " to " + file.path); - var output = FileUtils.openSafeFileOutputStream(file); NetUtil.asyncFetch(uri, function (is, status) { if (!Components.isSuccessCode(status)) { Zotero.debug(status, 1); @@ -204,9 +203,28 @@ Zotero.Fulltext = new function(){ Zotero.File.putContentsAsync(file, is) .then(function () { + // Delete if too small, since a 404 might not be detected above + if (file.fileSize < 50000) { + var msg = file.path + " is too small -- deleting"; + Zotero.debug(msg, 1); + Components.utils.reportError(msg); + try { + file.remove(false); + } + catch (e) { + Zotero.debug(e, 1); + Components.utils.reportError(e); + } + if (callback) { + callback(false); + } + return; + } + var scriptExt = _getScriptExtension(); // On Windows, write out script to hide pdftotext console window - if (tool == 'converter') { + // TEMP: disabled + if (false && tool == 'converter') { if (Zotero.isWin) { var content = Zotero.File.getContentsFromURL('resource://zotero/hide.' + scriptExt); var scriptFile = Zotero.getTempDirectory(); @@ -215,7 +233,8 @@ Zotero.Fulltext = new function(){ } } // Write out output redirection script for pdfinfo - else if (tool == 'info') { + // TEMP: disabled on Windows + else if (!Zotero.isWin && tool == 'info') { var content = Zotero.File.getContentsFromURL('resource://zotero/redirect.' + scriptExt); var scriptFile = Zotero.getTempDirectory(); scriptFile.append('pdfinfo.' + scriptExt); @@ -246,6 +265,10 @@ Zotero.Fulltext = new function(){ // Write the version number to a file var versionFile = destDir.clone(); versionFile.append(fileName + '.version'); + // TEMP + if (Zotero.isWin) { + version = '3.02a'; + } Zotero.File.putContents(versionFile, version + ''); Zotero.Fulltext.registerPDFTool(tool); @@ -327,7 +350,8 @@ Zotero.Fulltext = new function(){ // If scripts exist, use those instead switch (tool) { case 'converter': - if (Zotero.isWin) { + // TEMP: disabled + if (false && Zotero.isWin) { var script = Zotero.getZoteroDirectory(); script.append('pdftotext.' + _getScriptExtension()) if (script.exists()) { diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 1ec995ecc3..71ea7ad84b 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -1604,27 +1604,51 @@ Zotero.Schema = new function(){ return; } - if (Zotero.Fulltext.pdfInfoIsRegistered()) { - let currentVersion = Zotero.Fulltext.pdfInfoVersion; - if (currentVersion < availableVersion || currentVersion.startsWith('3.02') - || currentVersion == 'UNKNOWN') { + // 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; } - } - // 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') { + 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'; } - // Install missing component if one is installed - else if (Zotero.Fulltext.pdfInfoIsRegistered()) { - installConverter = true; + 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';