Update bundled file installation from XPI
- Use JSON translator index - Use original translator filename instead of label - Fix style installation error
This commit is contained in:
parent
92f081ca96
commit
7010742527
|
@ -514,9 +514,6 @@ Zotero.Schema = new function(){
|
||||||
xpiZipReader.close();
|
xpiZipReader.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
var zipFileName = OS.Path.basename(installLocation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
@ -683,40 +680,25 @@ Zotero.Schema = new function(){
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!forceReinstall && lastModTime && modTime <= lastModTime) {
|
if (!forceReinstall && lastModTime && modTime <= lastModTime) {
|
||||||
Zotero.debug("Installed " + mode + " are up-to-date with " + zipFileName);
|
Zotero.debug("Installed " + mode + " are up-to-date with XPI");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.debug("Updating installed " + mode + " from " + zipFileName);
|
Zotero.debug("Updating installed " + mode + " from XPI");
|
||||||
|
|
||||||
let tmpDir = Zotero.getTempDirectory().path;
|
let tmpDir = Zotero.getTempDirectory().path;
|
||||||
|
|
||||||
if (mode == 'translators') {
|
if (mode == 'translators') {
|
||||||
// Parse translators.index
|
// Parse translators.json
|
||||||
if (!xpiZipReader.hasEntry("translators.index")) {
|
if (!xpiZipReader.hasEntry("translators.json")) {
|
||||||
Components.utils.reportError("translators.index not found");
|
Zotero.logError("translators.json not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let indexFile = xpiZipReader.getInputStream("translators.index");
|
let index = JSON.parse(yield Zotero.File.getContentsAsync(
|
||||||
|
xpiZipReader.getInputStream("translators.json"))
|
||||||
indexFile = yield Zotero.File.getContentsAsync(indexFile);
|
);
|
||||||
indexFile = indexFile.split("\n");
|
for (let id in index) {
|
||||||
let index = {};
|
index[id].extract = true;
|
||||||
for (let i = 0; i < indexFile.length; i++) {
|
|
||||||
let line = indexFile[i];
|
|
||||||
if (!line) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let [translatorID, label, lastUpdated] = line.split(',');
|
|
||||||
if (!translatorID) {
|
|
||||||
Components.utils.reportError("Invalid translatorID '" + translatorID + "'");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
index[translatorID] = {
|
|
||||||
label: label,
|
|
||||||
lastUpdated: lastUpdated,
|
|
||||||
extract: true
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let sql = "SELECT metadataJSON FROM translatorCache";
|
let sql = "SELECT metadataJSON FROM translatorCache";
|
||||||
|
@ -754,11 +736,7 @@ Zotero.Schema = new function(){
|
||||||
yield Zotero.File.removeIfExists(existingObj.path);
|
yield Zotero.File.removeIfExists(existingObj.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileName = Zotero.Translators.getFileNameFromLabel(
|
let destFile = OS.Path.join(destDir, entry.fileName);
|
||||||
entry.label, translatorID
|
|
||||||
);
|
|
||||||
|
|
||||||
let destFile = OS.Path.join(destDir, fileName);
|
|
||||||
try {
|
try {
|
||||||
yield OS.File.move(tmpFile, destFile, {
|
yield OS.File.move(tmpFile, destFile, {
|
||||||
noOverwrite: true
|
noOverwrite: true
|
||||||
|
@ -780,14 +758,14 @@ Zotero.Schema = new function(){
|
||||||
}
|
}
|
||||||
// Styles
|
// Styles
|
||||||
else {
|
else {
|
||||||
let entries = zipReader.findEntries('styles/*.csl');
|
let entries = xpiZipReader.findEntries('styles/*.csl');
|
||||||
while (entries.hasMore()) {
|
while (entries.hasMore()) {
|
||||||
let entry = entries.getNext();
|
let entry = entries.getNext();
|
||||||
let fileName = entry.substr(7); // strip 'styles/'
|
let fileName = entry.substr(7); // strip 'styles/'
|
||||||
|
|
||||||
let tmpFile = OS.Path.join(tmpDir, fileName);
|
let tmpFile = OS.Path.join(tmpDir, fileName);
|
||||||
yield Zotero.File.removeIfExists(tmpFile);
|
yield Zotero.File.removeIfExists(tmpFile);
|
||||||
zipReader.extract(entry, new FileUtils.File(tmpFile));
|
xpiZipReader.extract(entry, new FileUtils.File(tmpFile));
|
||||||
let code = yield Zotero.File.getContentsAsync(tmpFile);
|
let code = yield Zotero.File.getContentsAsync(tmpFile);
|
||||||
let newObj = new Zotero.Style(code);
|
let newObj = new Zotero.Style(code);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user