Fix flashing console window for Retrieve Metadata on Windows

This commit is contained in:
Dan Stillman 2015-04-07 01:14:18 -04:00
parent 796a1a2898
commit 31941c0798
2 changed files with 33 additions and 24 deletions

View file

@ -139,13 +139,10 @@ var Zotero_RecognizePDF = new function() {
cacheFile.remove(false); cacheFile.remove(false);
} }
var exec = Zotero.getZoteroDirectory(); var {exec, args} = Zotero.Fulltext.getPDFConverterExecAndArgs();
exec.append(Zotero.Fulltext.pdfConverterFileName); args.push('-enc', 'UTF-8', '-nopgbrk', '-layout', '-l', pages, file.path, cacheFile.path);
var args = ['-enc', 'UTF-8', '-nopgbrk', '-layout', '-l', pages]; Zotero.debug("RecognizePDF: Running " + exec + " " + args.map(arg => "'" + arg + "'").join(" "));
args.push(file.path, cacheFile.path);
Zotero.debug('RecognizePDF: Running pdftotext '+args.join(" "));
return Zotero.Utilities.Internal.exec(exec, args).then(function() { return Zotero.Utilities.Internal.exec(exec, args).then(function() {
if(!cacheFile.exists()) { if(!cacheFile.exists()) {

View file

@ -381,6 +381,25 @@ Zotero.Fulltext = new function(){
} }
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: []
}
}
/* /*
* Returns true if MIME type is converted to text and cached before indexing * Returns true if MIME type is converted to text and cached before indexing
* (e.g. application/pdf is run through pdftotext) * (e.g. application/pdf is run through pdftotext)
@ -640,17 +659,18 @@ Zotero.Fulltext = new function(){
var totalPages = this.getTotalPagesFromFile(itemID); var totalPages = this.getTotalPagesFromFile(itemID);
} }
catch (e) { catch (e) {
Zotero.debug("Error running pdfinfo"); Components.utils.reportError(e);
Zotero.debug("Error running pdfinfo", 1);
Zotero.debug(e, 1);
} }
} }
else { else {
Zotero.debug(this.pdfInfoName + " is not available"); Zotero.debug(this.pdfInfoName + " is not available");
} }
var args = [] var proc = Components.classes["@mozilla.org/process/util;1"]
if (_pdfConverterScript) { .createInstance(Components.interfaces.nsIProcess);
args.push(_pdfConverter.path); var {exec, args} = this.getPDFConverterExecAndArgs();
}
args.push('-enc', 'UTF-8', '-nopgbrk'); args.push('-enc', 'UTF-8', '-nopgbrk');
if (allPages) { if (allPages) {
@ -664,24 +684,16 @@ Zotero.Fulltext = new function(){
} }
args.push(file.path, cacheFile.path); args.push(file.path, cacheFile.path);
var proc = Components.classes["@mozilla.org/process/util;1"] Zotero.debug("Running " + exec.path + " " + args.map(arg => "'" + arg + "'").join(" "));
.createInstance(Components.interfaces.nsIProcess);
if (_pdfConverterScript) {
Zotero.debug("Running " + _pdfConverterScript.path + ' '
+ args.map(arg => "'" + arg + "'").join(' '));
proc.init(_pdfConverterScript);
}
else {
Zotero.debug("Running " + _pdfConverter.path + ' '
+ args.map(arg => "'" + arg + "'").join(' '));
proc.init(_pdfConverter);
}
try { try {
proc.init(exec);
proc.runw(true, args, args.length); proc.runw(true, args, args.length);
} }
catch (e) { catch (e) {
Zotero.debug("Error running pdftotext"); Components.utils.reportError(e);
Zotero.debug("Error running pdftotext", 1);
Zotero.debug(e, 1);
return false; return false;
} }