Move data dire getters to Z.DataDirectory
Add Z.DataDirectory.getSubdirectory which, optionally, creates the directory. Add async Z.DataDirectory.removeSubdirectory and use it for Z.removeTempDirectory (was sync call before!).
This commit is contained in:
parent
fc8037a83b
commit
7f2d83a602
2 changed files with 36 additions and 43 deletions
|
@ -1228,5 +1228,27 @@ Zotero.DataDirectory = {
|
|||
ext = ext ? '.' + ext : '';
|
||||
|
||||
return OS.Path.join(this.dir, name + ext);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} name - the name of the subdirectory
|
||||
* @param {Boolean} createIfMissing - ensure that the directory exists
|
||||
* @return {String} the path to the subdirectory
|
||||
*/
|
||||
getSubdirectory: function (name, createIfMissing = false) {
|
||||
let dir = OS.Path.join(this.dir, name);
|
||||
if (createIfMissing) {
|
||||
Zotero.File.createDirectoryIfMissing(dir);
|
||||
}
|
||||
return dir;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} name - the name of the subdirectory
|
||||
* @return {Promise<Boolean>} true if the subdirectory was deleted,
|
||||
* or false if it did not exist
|
||||
*/
|
||||
removeSubdirectory: function (name) {
|
||||
return Zotero.File.removeIfExists(OS.Path.join(this.dir, name));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -941,7 +941,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
|||
}
|
||||
|
||||
// remove temp directory
|
||||
Zotero.removeTempDirectory();
|
||||
yield Zotero.removeTempDirectory();
|
||||
|
||||
if (Zotero.DB) {
|
||||
// close DB
|
||||
|
@ -964,63 +964,34 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
|||
return Zotero.File.pathToFile(Zotero.Profile.dir);
|
||||
}
|
||||
|
||||
|
||||
this.getZoteroDirectory = function () {
|
||||
Zotero.warn("Zotero.getZoteroDirectory() is deprecated -- use Zotero.DataDirectory.dir");
|
||||
return Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
||||
}
|
||||
|
||||
|
||||
function getStorageDirectory(){
|
||||
var file = OS.Path.join(Zotero.DataDirectory.dir, 'storage');
|
||||
file = Zotero.File.pathToFile(file);
|
||||
Zotero.File.createDirectoryIfMissing(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
this.getZoteroDatabase = function (name, ext) {
|
||||
Zotero.warn("Zotero.getZoteroDatabase() is deprecated -- use Zotero.DataDirectory.getDatabase()");
|
||||
return Zotero.File.pathToFile(Zotero.DataDirectory.getDatabase(name, ext));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {nsIFile}
|
||||
*/
|
||||
this.getTempDirectory = function () {
|
||||
var tmp = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
||||
tmp.append('tmp');
|
||||
Zotero.File.createDirectoryIfMissing(tmp);
|
||||
return tmp;
|
||||
function getStorageDirectory() {
|
||||
return Zotero.DataDirectory.getSubdirectory('storage', true);
|
||||
}
|
||||
|
||||
|
||||
this.removeTempDirectory = function () {
|
||||
var tmp = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
||||
tmp.append('tmp');
|
||||
if (tmp.exists()) {
|
||||
try {
|
||||
tmp.remove(true);
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.getStylesDirectory = function () {
|
||||
var dir = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
||||
dir.append('styles');
|
||||
Zotero.File.createDirectoryIfMissing(dir);
|
||||
return dir;
|
||||
return Zotero.DataDirectory.getSubdirectory('styles', true);
|
||||
}
|
||||
|
||||
|
||||
this.getTranslatorsDirectory = function () {
|
||||
var dir = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
||||
dir.append('translators');
|
||||
Zotero.File.createDirectoryIfMissing(dir);
|
||||
return dir;
|
||||
return Zotero.DataDirectory.getSubdirectory('translators', true);
|
||||
}
|
||||
|
||||
this.getTempDirectory = function () {
|
||||
return Zotero.DataDirectory.getSubdirectory('tmp', true);
|
||||
}
|
||||
|
||||
this.removeTempDirectory = function () {
|
||||
return Zotero.DataDirectory.removeSubdirectory('tmp');
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue