Skip to content

Commit

Permalink
Move scriptDir into an util module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Lieuallen committed Aug 22, 2011
1 parent afcb8fa commit 21408cc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions content/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Components.utils.import('resource://greasemonkey/util.js');
function Config() {
this._saveTimer = null;
this._scripts = null;
this._configFile = GM_scriptDir();
this._configFile = GM_util.scriptDir();
this._configFile.append("config.xml");
this._initScriptDir();

Expand Down Expand Up @@ -367,7 +367,7 @@ Config.prototype.move = function(script, destination) {
* Create an empty configuration if none exist.
*/
Config.prototype._initScriptDir = function() {
var dir = GM_scriptDir();
var dir = GM_util.scriptDir();
if (!dir.exists()) {
dir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, GM_constants.directoryMask);
GM_util.writeToFile("<UserScriptConfig/>", this._configFile);
Expand Down
8 changes: 4 additions & 4 deletions content/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function Script_getFile() {

Script.prototype.__defineGetter__('_basedirFile',
function Script_getBasedirFile() {
var file = GM_scriptDir();
var file = GM_util.scriptDir();
file.append(this._basedir);
try {
// Can fail if this path does not exist.
Expand Down Expand Up @@ -360,7 +360,7 @@ Script.prototype._initFile = function(tempFile) {
this._basedir = name;

var nsIFile = Components.interfaces.nsIFile;
var file = GM_scriptDir();
var file = GM_util.scriptDir();
file.append(name);
file.createUnique(nsIFile.DIRECTORY_TYPE, GM_constants.directoryMask);
this._basedir = file.leafName;
Expand Down Expand Up @@ -465,7 +465,7 @@ Script.prototype.updateFromNewScript = function(newScript, safeWin, chromeWin) {

Script.prototype.allFiles = function() {
var files = [];
if (!this._basedirFile.equals(GM_scriptDir())) {
if (!this._basedirFile.equals(GM_util.scriptDir())) {
files.push(this._basedirFile);
}
files.push(this.file);
Expand Down Expand Up @@ -493,7 +493,7 @@ Script.prototype.allFilesExist = function() {
Script.prototype.uninstall = function(forUpdate) {
if ('undefined' == typeof(forUpdate)) forUpdate = false;

if (this._basedirFile.equals(GM_scriptDir())) {
if (this._basedirFile.equals(GM_util.scriptDir())) {
// if script is in the root, just remove the file
try {
this.file.remove(false);
Expand Down
12 changes: 0 additions & 12 deletions content/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,6 @@ function GM_setEnabled(enabled) {
GM_prefRoot.setValue("enabled", enabled);
}

var GM_scriptDirCache = null;
function GM_scriptDir() {
if (!GM_scriptDirCache) {
GM_scriptDirCache = Components
.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsILocalFile);
GM_scriptDirCache.append("gm_scripts");
}
return GM_scriptDirCache.clone();
}

// Open the add-ons manager and show the installed user scripts.
if (typeof GM_OpenScriptsMgr == "undefined") {
function GM_OpenScriptsMgr() { BrowserOpenAddonsMgr('userscripts'); }
Expand Down
13 changes: 13 additions & 0 deletions modules/util/scriptDir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Components.utils.import('resource://greasemonkey/util.js');

const EXPORTED_SYMBOLS = ['scriptDir'];

const SCRIPT_DIR = Components
.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsILocalFile);
SCRIPT_DIR.append("gm_scripts");

function scriptDir() {
return SCRIPT_DIR.clone();
}

0 comments on commit 21408cc

Please sign in to comment.