Don't unpack xpi
This commit is contained in:
parent
0ce329abd1
commit
be38be66f7
11 changed files with 142 additions and 153 deletions
|
@ -1,6 +1,6 @@
|
||||||
content zotero chrome/content/zotero/
|
content zotero chrome/content/zotero/
|
||||||
content zotero-platform chrome/content/zotero-platform/ platform
|
content zotero-platform chrome/content/zotero-platform/ platform
|
||||||
content zotero-resource resource/
|
resource zotero resource/
|
||||||
|
|
||||||
locale zotero en-US chrome/locale/en-US/zotero/
|
locale zotero en-US chrome/locale/en-US/zotero/
|
||||||
locale zotero af-ZA chrome/locale/af-ZA/zotero/
|
locale zotero af-ZA chrome/locale/af-ZA/zotero/
|
||||||
|
|
|
@ -85,9 +85,16 @@ Zotero.File = new function(){
|
||||||
|
|
||||||
|
|
||||||
function getContents(file, charset, maxLength){
|
function getContents(file, charset, maxLength){
|
||||||
var fis = Components.classes["@mozilla.org/network/file-input-stream;1"].
|
var fis;
|
||||||
|
if(file instanceof Components.interfaces.nsIInputStream) {
|
||||||
|
fis = file;
|
||||||
|
} else if(file instanceof Components.interfaces.nsIFile) {
|
||||||
|
fis = Components.classes["@mozilla.org/network/file-input-stream;1"].
|
||||||
createInstance(Components.interfaces.nsIFileInputStream);
|
createInstance(Components.interfaces.nsIFileInputStream);
|
||||||
fis.init(file, 0x01, 0664, 0);
|
fis.init(file, 0x01, 0664, 0);
|
||||||
|
} else {
|
||||||
|
throw new Error("File is not an nsIInputStream or nsIFile");
|
||||||
|
}
|
||||||
|
|
||||||
if (charset){
|
if (charset){
|
||||||
charset = Zotero.CharacterSets.getName(charset);
|
charset = Zotero.CharacterSets.getName(charset);
|
||||||
|
@ -150,6 +157,7 @@ Zotero.File = new function(){
|
||||||
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||||
.createInstance();
|
.createInstance();
|
||||||
xmlhttp.open('GET', url, false);
|
xmlhttp.open('GET', url, false);
|
||||||
|
xmlhttp.overrideMimeType("text/plain");
|
||||||
xmlhttp.send(null);
|
xmlhttp.send(null);
|
||||||
return xmlhttp.responseText;
|
return xmlhttp.responseText;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ Zotero.LocateManager = new function() {
|
||||||
* Gets all default search engines (not currently used)
|
* Gets all default search engines (not currently used)
|
||||||
*/
|
*/
|
||||||
this.getDefaultEngines = function() [new LocateEngine(engine)
|
this.getDefaultEngines = function() [new LocateEngine(engine)
|
||||||
for each(engine in JSON.parse(Zotero.File.getContents(_getDefaultFile())))];
|
for each(engine in JSON.parse(Zotero.File.getContentsFromURL(_getDefaultFile())))];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of all search engines
|
* Returns an array of all search engines
|
||||||
|
@ -131,7 +131,8 @@ Zotero.LocateManager = new function() {
|
||||||
locateDir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0700);
|
locateDir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0700);
|
||||||
|
|
||||||
// copy default file to new locate dir
|
// copy default file to new locate dir
|
||||||
_getDefaultFile().copyTo(locateDir, LOCATE_FILE_NAME);
|
Zotero.File.putContents(_jsonFile,
|
||||||
|
Zotero.File.getContentsFromURL(_getDefaultFile()));
|
||||||
|
|
||||||
// reread locate engines
|
// reread locate engines
|
||||||
this.init();
|
this.init();
|
||||||
|
@ -170,9 +171,7 @@ Zotero.LocateManager = new function() {
|
||||||
* Gets the JSON file containing the engine info for the default engines
|
* Gets the JSON file containing the engine info for the default engines
|
||||||
*/
|
*/
|
||||||
function _getDefaultFile() {
|
function _getDefaultFile() {
|
||||||
var defaultFile = Zotero.getInstallDirectory();
|
return "resource://zotero/schema/"+LOCATE_FILE_NAME;
|
||||||
defaultFile.append(LOCATE_FILE_NAME);
|
|
||||||
return defaultFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,8 @@ Zotero.Schema = new function(){
|
||||||
var _dbVersions = [];
|
var _dbVersions = [];
|
||||||
var _schemaVersions = [];
|
var _schemaVersions = [];
|
||||||
var _repositoryTimer;
|
var _repositoryTimer;
|
||||||
var _remoteUpdateInProgress = false;
|
var _remoteUpdateInProgress = false,
|
||||||
|
_localUpdateInProgress = false;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
@ -207,19 +208,12 @@ Zotero.Schema = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var up4 = this.updateBundledFiles();
|
var up4 = this.updateBundledFiles(null, null, up2 || up3);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Zotero.debug(e);
|
Zotero.debug(e);
|
||||||
Zotero.logError(e);
|
Zotero.logError(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (up2 || up3 || up4) {
|
|
||||||
// Run a manual scraper update if upgraded and pref set
|
|
||||||
if (Zotero.Prefs.get('automaticScraperUpdates')){
|
|
||||||
this.updateFromRepository(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
Zotero.UnresponsiveScriptIndicator.enable();
|
Zotero.UnresponsiveScriptIndicator.enable();
|
||||||
|
@ -441,13 +435,56 @@ Zotero.Schema = new function(){
|
||||||
* since deleting uses a single version table key,
|
* since deleting uses a single version table key,
|
||||||
* it should only be updated the last time through
|
* it should only be updated the last time through
|
||||||
*/
|
*/
|
||||||
this.updateBundledFiles = function (mode, skipDeleteUpdate) {
|
this.updateBundledFiles = function(mode, skipDeleteUpdate, runRemoteUpdateWhenComplete) {
|
||||||
|
if(_localUpdateInProgress) return;
|
||||||
|
_localUpdateInProgress = true;
|
||||||
|
|
||||||
|
// Get path to addon and then call updateBundledFilesCallback, potentially asynchronously
|
||||||
|
if(Zotero.isStandalone) {
|
||||||
|
var appChrome = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||||
|
.getService(Components.interfaces.nsIProperties)
|
||||||
|
.get("AChrom", Components.interfaces.nsIFile);
|
||||||
|
_updateBundledFilesCallback(appChrome.parent, mode, skipDeleteUpdate,
|
||||||
|
runRemoteUpdateWhenComplete);
|
||||||
|
} else if(Zotero.isFx4) {
|
||||||
|
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
||||||
|
AddonManager.getAddonByID(ZOTERO_CONFIG['GUID'],
|
||||||
|
function(addon) {
|
||||||
|
_updateBundledFilesCallback(
|
||||||
|
addon.getResourceURI().QueryInterface(Components.interfaces.nsIFileURL).file,
|
||||||
|
mode, skipDeleteUpdate, runRemoteUpdateWhenComplete);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||||
|
.getService(Components.interfaces.nsIExtensionManager);
|
||||||
|
var itemLocation = gExtensionManager.getInstallLocation(ZOTERO_CONFIG['GUID'])
|
||||||
|
.getItemLocation(ZOTERO_CONFIG['GUID']);
|
||||||
|
_updateBundledFilesCallback(itemLocation, mode, skipDeleteUpdate,
|
||||||
|
runRemoteUpdateWhenComplete);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback to update bundled files, after finding the path to the Zotero install location
|
||||||
|
*/
|
||||||
|
function _updateBundledFilesCallback(installLocation, mode, skipDeleteUpdate,
|
||||||
|
runRemoteUpdateWhenComplete) {
|
||||||
|
_localUpdateInProgress = false;
|
||||||
|
|
||||||
if (!mode) {
|
if (!mode) {
|
||||||
var up1 = this.updateBundledFiles('translators', true);
|
var up1 = _updateBundledFilesCallback(installLocation, 'translators', true, false);
|
||||||
var up2 = this.updateBundledFiles('styles');
|
var up2 = _updateBundledFilesCallback(installLocation, 'styles', false,
|
||||||
|
runRemoteUpdateWhenComplete);
|
||||||
return up1 && up2;
|
return up1 && up2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var xpiZipReader, isUnpacked = installLocation.isDirectory();
|
||||||
|
if(!isUnpacked) {
|
||||||
|
xpiZipReader = Components.classes["@mozilla.org/libjar/zip-reader;1"]
|
||||||
|
.createInstance(Components.interfaces.nsIZipReader);
|
||||||
|
xpiZipReader.open(installLocation);
|
||||||
|
}
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case "translators":
|
case "translators":
|
||||||
var titleField = 'label';
|
var titleField = 'label';
|
||||||
|
@ -470,17 +507,10 @@ Zotero.Schema = new function(){
|
||||||
var Mode = mode[0].toUpperCase() + mode.substr(1);
|
var Mode = mode[0].toUpperCase() + mode.substr(1);
|
||||||
var Modes = Mode + "s";
|
var Modes = Mode + "s";
|
||||||
|
|
||||||
var extDir = Zotero.getInstallDirectory();
|
var repotime = Zotero.File.getContentsFromURL("resource://zotero/schema/repotime.txt");
|
||||||
|
|
||||||
var repotime = extDir.clone();
|
|
||||||
repotime.append('repotime.txt');
|
|
||||||
repotime = Zotero.File.getContents(repotime);
|
|
||||||
var date = Zotero.Date.sqlToDate(repotime, true);
|
var date = Zotero.Date.sqlToDate(repotime, true);
|
||||||
repotime = Zotero.Date.toUnixTimestamp(date);
|
repotime = Zotero.Date.toUnixTimestamp(date);
|
||||||
|
|
||||||
var zipFile = extDir.clone();
|
|
||||||
zipFile.append(modes + ".zip");
|
|
||||||
|
|
||||||
var fileNameRE = new RegExp("^[^\.].+\\" + fileExt + "$");
|
var fileNameRE = new RegExp("^[^\.].+\\" + fileExt + "$");
|
||||||
|
|
||||||
var destDir = Zotero["get" + Modes + "Directory"]();
|
var destDir = Zotero["get" + Modes + "Directory"]();
|
||||||
|
@ -505,14 +535,21 @@ Zotero.Schema = new function(){
|
||||||
var sql = "SELECT version FROM version WHERE schema='delete'";
|
var sql = "SELECT version FROM version WHERE schema='delete'";
|
||||||
var lastVersion = Zotero.DB.valueQuery(sql);
|
var lastVersion = Zotero.DB.valueQuery(sql);
|
||||||
|
|
||||||
var deleted = extDir.clone();
|
if(isUnpacked) {
|
||||||
|
var deleted = installLocation.clone();
|
||||||
deleted.append('deleted.txt');
|
deleted.append('deleted.txt');
|
||||||
// In source builds, deleted.txt is in the translators directory
|
// In source builds, deleted.txt is in the translators directory
|
||||||
if (!deleted.exists()) {
|
if (!deleted.exists()) {
|
||||||
deleted = extDir.clone();
|
deleted = installLocation.clone();
|
||||||
deleted.append('translators');
|
deleted.append('translators');
|
||||||
deleted.append('deleted.txt');
|
deleted.append('deleted.txt');
|
||||||
}
|
}
|
||||||
|
if (!deleted.exists()) {
|
||||||
|
deleted = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var deleted = xpiZipReader.getInputStream("deleted.txt");
|
||||||
|
}
|
||||||
|
|
||||||
deleted = Zotero.File.getContents(deleted);
|
deleted = Zotero.File.getContents(deleted);
|
||||||
deleted = deleted.match(/^([^\s]+)/gm);
|
deleted = deleted.match(/^([^\s]+)/gm);
|
||||||
|
@ -598,26 +635,47 @@ Zotero.Schema = new function(){
|
||||||
var sql = "SELECT version FROM version WHERE schema=?";
|
var sql = "SELECT version FROM version WHERE schema=?";
|
||||||
var lastModTime = Zotero.DB.valueQuery(sql, modes);
|
var lastModTime = Zotero.DB.valueQuery(sql, modes);
|
||||||
|
|
||||||
|
var zipFileName = modes + ".zip", zipFile;
|
||||||
|
if(isUnpacked) {
|
||||||
|
zipFile = installLocation.clone();
|
||||||
|
zipFile.append(zipFileName);
|
||||||
|
if(!zipFile.exists()) zipFile = undefined;
|
||||||
|
} else {
|
||||||
|
if(xpiZipReader.hasEntry(zipFileName)) {
|
||||||
|
zipFile = xpiZipReader.getEntry(zipFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// XPI installation
|
// XPI installation
|
||||||
if (zipFile.exists()) {
|
if (zipFile) {
|
||||||
var modTime = Math.round(zipFile.lastModifiedTime / 1000);
|
var modTime = Math.round(zipFile.lastModifiedTime / 1000);
|
||||||
|
|
||||||
if (!forceReinstall && lastModTime && modTime <= lastModTime) {
|
if (!forceReinstall && lastModTime && modTime <= lastModTime) {
|
||||||
Zotero.debug("Installed " + modes + " are up-to-date with " + modes + ".zip");
|
Zotero.debug("Installed " + modes + " are up-to-date with " + zipFileName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.debug("Updating installed " + modes + " from " + modes + ".zip");
|
Zotero.debug("Updating installed " + modes + " from " + zipFileName);
|
||||||
|
|
||||||
if (mode == 'translator') {
|
if (mode == 'translator') {
|
||||||
// Parse translators.index
|
// Parse translators.index
|
||||||
var indexFile = extDir.clone();
|
var indexFile;
|
||||||
|
if(isUnpacked) {
|
||||||
|
indexFile = installLocation.clone();
|
||||||
indexFile.append('translators.index');
|
indexFile.append('translators.index');
|
||||||
if (!indexFile.exists()) {
|
if (!indexFile.exists()) {
|
||||||
Components.utils.reportError("translators.index not found in Zotero.Schema.updateBundledFiles()");
|
Components.utils.reportError("translators.index not found in Zotero.Schema.updateBundledFiles()");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var indexFile = Zotero.File.getContents(indexFile);
|
} else {
|
||||||
|
if(!xpiZipReader.hasEntry("translators.index")) {
|
||||||
|
Components.utils.reportError("translators.index not found in Zotero.Schema.updateBundledFiles()");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var indexFile = xpiZipReader.getInputStream("translators.index");
|
||||||
|
}
|
||||||
|
|
||||||
|
indexFile = Zotero.File.getContents(indexFile);
|
||||||
indexFile = indexFile.split("\n");
|
indexFile = indexFile.split("\n");
|
||||||
var index = {};
|
var index = {};
|
||||||
for each(var line in indexFile) {
|
for each(var line in indexFile) {
|
||||||
|
@ -652,8 +710,12 @@ Zotero.Schema = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
var zipReader = Components.classes["@mozilla.org/libjar/zip-reader;1"]
|
var zipReader = Components.classes["@mozilla.org/libjar/zip-reader;1"]
|
||||||
.getService(Components.interfaces.nsIZipReader);
|
.createInstance(Components.interfaces.nsIZipReader);
|
||||||
|
if(isUnpacked) {
|
||||||
zipReader.open(zipFile);
|
zipReader.open(zipFile);
|
||||||
|
} else {
|
||||||
|
zipReader.openInner(xpiZipReader, zipFileName);
|
||||||
|
}
|
||||||
var tmpDir = Zotero.getTempDirectory();
|
var tmpDir = Zotero.getTempDirectory();
|
||||||
|
|
||||||
if (mode == 'translator') {
|
if (mode == 'translator') {
|
||||||
|
@ -742,10 +804,11 @@ Zotero.Schema = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
zipReader.close();
|
zipReader.close();
|
||||||
|
if(xpiZipReader) xpiZipReader.close();
|
||||||
}
|
}
|
||||||
// Source installation
|
// Source installation
|
||||||
else {
|
else {
|
||||||
var sourceDir = extDir.clone();
|
var sourceDir = installLocation.clone();
|
||||||
sourceDir.append(modes);
|
sourceDir.append(modes);
|
||||||
if (!sourceDir.exists()) {
|
if (!sourceDir.exists()) {
|
||||||
Components.utils.reportError("No " + modes + " ZIP file or directory "
|
Components.utils.reportError("No " + modes + " ZIP file or directory "
|
||||||
|
@ -850,6 +913,13 @@ Zotero.Schema = new function(){
|
||||||
Zotero.DB.commitTransaction();
|
Zotero.DB.commitTransaction();
|
||||||
|
|
||||||
Zotero[Modes].init();
|
Zotero[Modes].init();
|
||||||
|
|
||||||
|
if (runRemoteUpdateWhenComplete) {
|
||||||
|
// Run a manual scraper update if upgraded and pref set
|
||||||
|
if (Zotero.Prefs.get('automaticScraperUpdates')){
|
||||||
|
Zotero.Schema.updateFromRepository(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -899,6 +969,12 @@ Zotero.Schema = new function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_localUpdateInProgress) {
|
||||||
|
Zotero.debug('A local update is already in progress -- delaying repository check', 4);
|
||||||
|
_setRepositoryTimer(600);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (Zotero.locked) {
|
if (Zotero.locked) {
|
||||||
Zotero.debug('Zotero is locked -- delaying repository check', 4);
|
Zotero.debug('Zotero is locked -- delaying repository check', 4);
|
||||||
_setRepositoryTimer(600);
|
_setRepositoryTimer(600);
|
||||||
|
@ -973,22 +1049,13 @@ Zotero.Schema = new function(){
|
||||||
translatorsDir.remove(true);
|
translatorsDir.remove(true);
|
||||||
Zotero.getTranslatorsDirectory(); // recreate directory
|
Zotero.getTranslatorsDirectory(); // recreate directory
|
||||||
Zotero.Translators.init();
|
Zotero.Translators.init();
|
||||||
this.updateBundledFiles('translators');
|
this.updateBundledFiles('translators', null, false);
|
||||||
|
|
||||||
var stylesDir = Zotero.getStylesDirectory();
|
var stylesDir = Zotero.getStylesDirectory();
|
||||||
stylesDir.remove(true);
|
stylesDir.remove(true);
|
||||||
Zotero.getStylesDirectory(); // recreate directory
|
Zotero.getStylesDirectory(); // recreate directory
|
||||||
Zotero.Styles.init();
|
Zotero.Styles.init();
|
||||||
this.updateBundledFiles('styles');
|
this.updateBundledFiles('styles', null, true);
|
||||||
|
|
||||||
// Run a manual update from repository if pref set
|
|
||||||
if (Zotero.Prefs.get('automaticScraperUpdates')) {
|
|
||||||
this.updateFromRepository(2, function () {
|
|
||||||
if (callback) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
|
@ -1128,31 +1195,10 @@ Zotero.Schema = new function(){
|
||||||
* Retrieve the version from the top line of the schema SQL file
|
* Retrieve the version from the top line of the schema SQL file
|
||||||
*/
|
*/
|
||||||
function _getSchemaSQLVersion(schema){
|
function _getSchemaSQLVersion(schema){
|
||||||
if (!schema){
|
var sql = _getSchemaSQL(schema);
|
||||||
throw ('Schema type not provided to _getSchemaSQLVersion()');
|
|
||||||
}
|
|
||||||
|
|
||||||
var schemaFile = schema + '.sql';
|
|
||||||
|
|
||||||
if (_schemaVersions[schema]){
|
|
||||||
return _schemaVersions[schema];
|
|
||||||
}
|
|
||||||
|
|
||||||
var file = Zotero.getInstallDirectory();
|
|
||||||
file.append(schemaFile);
|
|
||||||
|
|
||||||
// Open an input stream from file
|
|
||||||
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
|
|
||||||
.createInstance(Components.interfaces.nsIFileInputStream);
|
|
||||||
istream.init(file, 0x01, 0444, 0);
|
|
||||||
istream.QueryInterface(Components.interfaces.nsILineInputStream);
|
|
||||||
|
|
||||||
var line = {};
|
|
||||||
|
|
||||||
// Fetch the schema version from the first line of the file
|
// Fetch the schema version from the first line of the file
|
||||||
istream.readLine(line);
|
var schemaVersion = sql.match(/^-- ([0-9]+)/)[1];
|
||||||
var schemaVersion = line.value.match(/-- ([0-9]+)/)[1];
|
|
||||||
istream.close();
|
|
||||||
|
|
||||||
_schemaVersions[schema] = schemaVersion;
|
_schemaVersions[schema] = schemaVersion;
|
||||||
return schemaVersion;
|
return schemaVersion;
|
||||||
|
@ -1169,33 +1215,7 @@ Zotero.Schema = new function(){
|
||||||
throw ('Schema type not provided to _getSchemaSQL()');
|
throw ('Schema type not provided to _getSchemaSQL()');
|
||||||
}
|
}
|
||||||
|
|
||||||
var schemaFile = schema + '.sql';
|
return Zotero.File.getContentsFromURL("resource://zotero/schema/"+schema+".sql");
|
||||||
|
|
||||||
// We pull the schema from an external file so we only have to process
|
|
||||||
// it when necessary
|
|
||||||
var file = Zotero.getInstallDirectory();
|
|
||||||
file.append(schemaFile);
|
|
||||||
|
|
||||||
// Open an input stream from file
|
|
||||||
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
|
|
||||||
.createInstance(Components.interfaces.nsIFileInputStream);
|
|
||||||
istream.init(file, 0x01, 0444, 0);
|
|
||||||
istream.QueryInterface(Components.interfaces.nsILineInputStream);
|
|
||||||
|
|
||||||
var line = {}, sql = '', hasmore;
|
|
||||||
|
|
||||||
// Skip the first line, which contains the schema version
|
|
||||||
istream.readLine(line);
|
|
||||||
//var schemaVersion = line.value.match(/-- ([0-9]+)/)[1];
|
|
||||||
|
|
||||||
do {
|
|
||||||
hasmore = istream.readLine(line);
|
|
||||||
sql += line.value + "\n";
|
|
||||||
} while(hasmore);
|
|
||||||
|
|
||||||
istream.close();
|
|
||||||
|
|
||||||
return sql;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1208,38 +1228,13 @@ Zotero.Schema = new function(){
|
||||||
* Returns the SQL statements as a string for feeding into query()
|
* Returns the SQL statements as a string for feeding into query()
|
||||||
*/
|
*/
|
||||||
function _getDropCommands(schema){
|
function _getDropCommands(schema){
|
||||||
if (!schema){
|
var sql = _getSchemaSQL(schema);
|
||||||
throw ('Schema type not provided to _getSchemaSQL()');
|
|
||||||
}
|
|
||||||
|
|
||||||
var schemaFile = schema + '.sql';
|
const re = /(?:[\r\n]|^)CREATE (TABLE|INDEX) IF NOT EXISTS ([^\s]+)/;
|
||||||
|
var m, str="";
|
||||||
// We pull the schema from an external file so we only have to process
|
while(matches = re.exec(sql)) {
|
||||||
// it when necessary
|
|
||||||
var file = Zotero.getInstallDirectory();
|
|
||||||
file.append(schemaFile);
|
|
||||||
|
|
||||||
// Open an input stream from file
|
|
||||||
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
|
|
||||||
.createInstance(Components.interfaces.nsIFileInputStream);
|
|
||||||
istream.init(file, 0x01, 0444, 0);
|
|
||||||
istream.QueryInterface(Components.interfaces.nsILineInputStream);
|
|
||||||
|
|
||||||
var line = {}, str = '', hasmore;
|
|
||||||
|
|
||||||
// Skip the first line, which contains the schema version
|
|
||||||
istream.readLine(line);
|
|
||||||
|
|
||||||
do {
|
|
||||||
hasmore = istream.readLine(line);
|
|
||||||
var matches =
|
|
||||||
line.value.match(/CREATE (TABLE|INDEX) IF NOT EXISTS ([^\s]+)/);
|
|
||||||
if (matches){
|
|
||||||
str += "DROP " + matches[1] + " IF EXISTS " + matches[2] + ";\n";
|
str += "DROP " + matches[1] + " IF EXISTS " + matches[2] + ";\n";
|
||||||
}
|
}
|
||||||
} while(hasmore);
|
|
||||||
|
|
||||||
istream.close();
|
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -1309,7 +1304,7 @@ Zotero.Schema = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Zotero.Schema.updateBundledFiles();
|
Zotero.Schema.updateBundledFiles(null, null, true);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Zotero.debug(e);
|
Zotero.debug(e);
|
||||||
|
|
|
@ -46,7 +46,6 @@ const ZOTERO_CONFIG = {
|
||||||
this.init = init;
|
this.init = init;
|
||||||
this.stateCheck = stateCheck;
|
this.stateCheck = stateCheck;
|
||||||
this.getProfileDirectory = getProfileDirectory;
|
this.getProfileDirectory = getProfileDirectory;
|
||||||
this.getInstallDirectory = getInstallDirectory;
|
|
||||||
this.getZoteroDirectory = getZoteroDirectory;
|
this.getZoteroDirectory = getZoteroDirectory;
|
||||||
this.getStorageDirectory = getStorageDirectory;
|
this.getStorageDirectory = getStorageDirectory;
|
||||||
this.getZoteroDatabase = getZoteroDatabase;
|
this.getZoteroDatabase = getZoteroDatabase;
|
||||||
|
@ -808,17 +807,6 @@ const ZOTERO_CONFIG = {
|
||||||
.get("ProfD", Components.interfaces.nsIFile);
|
.get("ProfD", Components.interfaces.nsIFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getInstallDirectory() {
|
|
||||||
var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
|
||||||
.getService(Components.interfaces.nsIChromeRegistry);
|
|
||||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIIOService);
|
|
||||||
var zoteroURI = ioService.newURI("chrome://zotero-resource/content/", "UTF-8", null);
|
|
||||||
zoteroURI = cr.convertChromeURL(zoteroURI).QueryInterface(Components.interfaces.nsIFileURL);
|
|
||||||
return zoteroURI.file.parent.parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDefaultProfile(prefDir) {
|
function getDefaultProfile(prefDir) {
|
||||||
// find profiles.ini file
|
// find profiles.ini file
|
||||||
var profilesIni = prefDir.clone();
|
var profilesIni = prefDir.clone();
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
<em:iconURL>chrome://zotero/skin/zotero_z_32px.png</em:iconURL>
|
<em:iconURL>chrome://zotero/skin/zotero_z_32px.png</em:iconURL>
|
||||||
<em:updateURL>https://www.zotero.org/download/update-source.rdf</em:updateURL>
|
<em:updateURL>https://www.zotero.org/download/update-source.rdf</em:updateURL>
|
||||||
<em:type>2</em:type> <!-- type=extension -->
|
<em:type>2</em:type> <!-- type=extension -->
|
||||||
<em:unpack>true</em:unpack>
|
|
||||||
|
|
||||||
<!-- Firefox -->
|
<!-- Firefox -->
|
||||||
<em:targetApplication>
|
<em:targetApplication>
|
||||||
|
|
Loading…
Reference in a new issue