commit 4648ae0f3b597e89ca7df76c28a48272f25e7067
parent 5c6a050fa745c8381f69968da45e546ebdf47375
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 11 Sep 2008 17:20:09 +0000
Zotero.getStylesDirectory(), Zotero.getTranslatorsDirectory(), and Zotero.File.createDirectoryIfMissing(dir)
Diffstat:
2 files changed, 30 insertions(+), 16 deletions(-)
diff --git 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
@@ -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);