Skip to content

Commit

Permalink
Simplify Config file-system properties
Browse files Browse the repository at this point in the history
 * _scriptDir becomes dir
 * _configFile becomes a _file getter
  • Loading branch information
ocornu committed Sep 27, 2009
1 parent a813a14 commit 885a02f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
33 changes: 20 additions & 13 deletions src/modules/config.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ const CONFIG_FILE = "config.xml";
function Config() {
this._scripts = null;

this._scriptDir = File.profile();
this._scriptDir.name = REPOSITORY_DIR;
if (!this._scriptDir.exists())
this._scriptDir.create(File.DIR);

this._configFile = new File(this._scriptDir);
this._configFile.name = CONFIG_FILE;
if (!this._configFile.exists()) {
this._configFile.create(File.FILE);
this._configFile.write("<UserScriptConfig/>");
}
var dir = File.profile();
dir.name = REPOSITORY_DIR;
if (!dir.exists())
dir.create(File.DIR);
/**
* @type File
*/
this.dir = dir;

this._observers = [];

Expand All @@ -38,6 +35,16 @@ function Config() {
}

Config.prototype = {
get _file() {
var file = new File(this.dir);
file.name = CONFIG_FILE;
if (!file.exists()) {
file.create(File.FILE);
file.write("<UserScriptConfig/>");
}
return file;
},

addObserver: function(observer, script) {
var observers = script ? script._observers : this._observers;
observers.push(observer);
Expand Down Expand Up @@ -81,7 +88,7 @@ Config.prototype = {
},

_loadFromXml: function() {
var doc = this._configFile.readXML();
var doc = this._file.readXML();
var nodes = doc.evaluate("/UserScriptConfig/Script", doc, null, 0, null);
this._scripts = [];
for (var node; node = nodes.iterateNext();)
Expand All @@ -100,7 +107,7 @@ Config.prototype = {
config.appendChild(scriptNode);
}
config.appendChild(doc.createTextNode("\n"));
this._configFile.writeXML(doc);
this._file.writeXML(doc);
},

install: function(script) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/script.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Script.prototype = {
*/
install: function(/**Config*/ aConfig) {
this._config = aConfig;
var dir = new File(aConfig._scriptDir);
var dir = new File(aConfig.dir);
dir.name = this._filename.replace(/\.user\.js$/, "");
dir.createUnique(File.DIR);
dir.remove(true);
Expand Down Expand Up @@ -238,7 +238,7 @@ Script.fromSource = function(/**string*/ aSource, /**nsIURI*/ aUri) {
Script.fromConfig = function(/**Config*/ aConfig, /**nsiDOMNode*/ aNode) {
var script = new Script();
script._config = aConfig;
script._fromXml(aNode, aConfig._scriptDir);
script._fromXml(aNode, aConfig.dir);
return script;
};

Expand Down

0 comments on commit 885a02f

Please sign in to comment.