diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 7a65c534e..82af2ae50 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -164,6 +164,16 @@ Zotero.File = new function(){ } + this.createDirectoryIfMissing = function (dir) { + if (!dir.exists() || !dir.isDirectory()) { + if (dir.exists() && !dir.isDirectory()) { + dir.remove(null); + } + dir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); + } + } + + // Strip potentially invalid characters // See http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words function getValidFileName(fileName) { diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 2050ab753..d01dd7bc2 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -345,16 +345,12 @@ var Zotero = new function(){ else { var file = Zotero.getProfileDirectory(); file.append('zotero'); - - // If it doesn't exist, create - if (!file.exists() || !file.isDirectory()){ - file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); - } + Zotero.File.createDirectoryIfMissing(file); } Zotero.debug("Using data directory " + file.path); _zoteroDirectory = file; - return file; + return file.clone(); } @@ -362,10 +358,7 @@ var Zotero = new function(){ var file = Zotero.getZoteroDirectory(); file.append('storage'); - // If it doesn't exist, create - if (!file.exists() || !file.isDirectory()){ - file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); - } + Zotero.File.createDirectoryIfMissing(file); return file; } @@ -385,16 +378,27 @@ var Zotero = new function(){ function getTempDirectory() { var tmp = this.getZoteroDirectory(); tmp.append('tmp'); - if (!tmp.exists() || !tmp.isDirectory()) { - if (tmp.exists() && !tmp.isDirectory()) { - tmp.remove(null); - } - tmp.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); - } + Zotero.File.createDirectoryIfMissing(tmp); return tmp; } + this.getStylesDirectory = function () { + var dir = this.getZoteroDirectory(); + dir.append('styles'); + Zotero.File.createDirectoryIfMissing(dir); + return dir; + } + + + this.getTranslatorsDirectory = function () { + var dir = this.getZoteroDirectory(); + dir.append('translators'); + Zotero.File.createDirectoryIfMissing(dir); + return dir; + } + + function chooseZoteroDirectory(forceRestartNow, useProfileDir) { var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator);