From 4959535aff418fb7207565da1e03963e762f850f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 27 Jul 2006 08:45:48 +0000 Subject: [PATCH] Scholar DB now stored in scholar subfolder of profile directory New methods for retrieving profile directory, scholar subdirectory and scholar/storage subsubdirectory --- .../chromeFiles/content/scholar/xpcom/db.js | 8 ++--- .../content/scholar/xpcom/scholar.js | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/xpcom/db.js b/chrome/chromeFiles/content/scholar/xpcom/db.js index 3796448ba8..44ba108d25 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/db.js +++ b/chrome/chromeFiles/content/scholar/xpcom/db.js @@ -359,12 +359,10 @@ Scholar.DB = new function(){ var store = Components.classes["@mozilla.org/storage/service;1"]. getService(Components.interfaces.mozIStorageService); - // Get the profile directory - var file = Components.classes["@mozilla.org/file/directory_service;1"] - .getService(Components.interfaces.nsIProperties) - .get("ProfD", Components.interfaces.nsIFile); + // Get the storage directory + var file = Scholar.getScholarDirectory(); - // This makes file point to PROFILE_DIR/ + // This makes file point to PROFILE_DIR// file.append(SCHOLAR_CONFIG['DB_FILE']); _connection = store.openDatabase(file); diff --git a/chrome/chromeFiles/content/scholar/xpcom/scholar.js b/chrome/chromeFiles/content/scholar/xpcom/scholar.js index 84d12b2551..204568543c 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/scholar.js +++ b/chrome/chromeFiles/content/scholar/xpcom/scholar.js @@ -18,6 +18,9 @@ var Scholar = new function(){ // Privileged (public) methods this.init = init; + this.getProfileDirectory = getProfileDirectory; + this.getScholarDirectory = getScholarDirectory; + this.getStorageDirectory = getStorageDirectory; this.debug = debug; this.varDump = varDump; this.getString = getString; @@ -51,6 +54,7 @@ var Scholar = new function(){ this.version = gExtensionManager.getItemForID(SCHOLAR_CONFIG['GUID']).version; + // Load in the localization stringbundle for use by getString(name) var src = 'chrome://scholar/locale/scholar.properties'; var localeService = @@ -71,6 +75,37 @@ var Scholar = new function(){ } + function getProfileDirectory(){ + return Components.classes["@mozilla.org/file/directory_service;1"] + .getService(Components.interfaces.nsIProperties) + .get("ProfD", Components.interfaces.nsIFile); + } + + + function getScholarDirectory(){ + var file = Scholar.getProfileDirectory(); + + file.append('scholar'); + // If it doesn't exist, create + if (!file.exists() || !file.isDirectory()){ + file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0664); + } + return file; + } + + + function getStorageDirectory(){ + var file = Scholar.getScholarDirectory(); + + file.append('storage'); + // If it doesn't exist, create + if (!file.exists() || !file.isDirectory()){ + file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0664); + } + return file; + } + + /* * Debug logging function *