Changeset 667
- Timestamp:
- 02/18/08 09:46:14 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/config-service/src/chrome/chromeFiles/content/config.js
r666 r667 2 2 // used anywhere within this file and versioning.js 3 3 4 function Config() 5 { 4 function Config() { 6 5 this._scripts = null; 7 6 this._configFile = this._scriptDir; … … 15 14 16 15 Config.prototype = { 17 addObserver: function(observer, script) 18 { 16 addObserver: function(observer, script) { 19 17 var observers = script ? script._observers : this._observers; 20 18 observers.push(observer); 21 19 }, 22 20 23 removeObserver: function(observer, script) 24 { 21 removeObserver: function(observer, script) { 25 22 var observers = script ? script._observers : this._observers; 26 23 var index = observers.indexOf(observer); … … 29 26 }, 30 27 31 _notifyObservers: function(script, event, data) 32 { 28 _notifyObservers: function(script, event, data) { 33 29 var observers = this._observers.concat(script._observers); 34 30 for (var i = 0, observer; observer = observers[i]; i++) … … 36 32 }, 37 33 38 _changed: function(script, event, data) 39 { 34 _changed: function(script, event, data) { 40 35 this._save(); 41 36 this._notifyObservers(script, event, data); 42 37 }, 43 38 44 installIsUpdate: function(script) 45 { 39 installIsUpdate: function(script) { 46 40 return this._find(script) > -1; 47 41 }, 48 42 49 _find: function(aScript) 50 { 43 _find: function(aScript) { 51 44 namespace = aScript._namespace.toLowerCase(); 52 45 name = aScript._name.toLowerCase(); … … 59 52 }, 60 53 61 _load: function() 62 { 54 _load: function() { 63 55 var domParser = Components.classes["@mozilla.org/xmlextras/domparser;1"] 64 56 .createInstance(Components.interfaces.nsIDOMParser); … … 91 83 scriptResource._filename = childNode.getAttribute("filename"); 92 84 scriptResource._mimetype = childNode.getAttribute("mimetype"); 93 scriptResource._charset = childNode.getAttribute("charset");85 scriptResource._charset = childNode.getAttribute("charset"); 94 86 script._resources.push(scriptResource); 95 87 break; … … 108 100 }, 109 101 110 _save: function() 111 { 102 _save: function() { 112 103 var doc = Components.classes["@mozilla.org/xmlextras/domparser;1"] 113 104 .createInstance(Components.interfaces.nsIDOMParser) … … 141 132 } 142 133 143 for (var j = 0; j < scriptObj._resources.length; j++) {134 for (var j = 0; j < scriptObj._resources.length; j++) { 144 135 var imp = scriptObj._resources[j]; 145 136 var resourceNode = doc.createElement("Resource"); … … 148 139 resourceNode.setAttribute("filename", imp._filename); 149 140 resourceNode.setAttribute("mimetype", imp._mimetype); 150 if (imp._charset) {141 if (imp._charset) 151 142 resourceNode.setAttribute("charset", imp._charset); 152 }153 143 154 144 scriptNode.appendChild(doc.createTextNode("\n\t\t")); … … 178 168 }, 179 169 180 parse: function(source, uri) 181 { 170 parse: function(source, uri) { 182 171 var ioservice = Components.classes["@mozilla.org/network/io-service;1"] 183 172 .getService(Components.interfaces.nsIIOService); … … 206 195 207 196 while ((result = lines[lnIdx++])) { 208 if (result.indexOf("// ==/UserScript==") == 0) {197 if (result.indexOf("// ==/UserScript==") == 0) 209 198 break; 210 }211 199 212 200 var match = result.match(/\/\/ \@(\S+)\s+([^\n]+)/); … … 260 248 261 249 // if no meta info, default to reasonable values 262 if (script._name == null) {250 if (script._name == null) 263 251 script._name = parseScriptName(uri); 264 } 265 266 if (script._namespace == null) { 252 253 if (script._namespace == null) 267 254 script._namespace = uri.host; 268 }269 255 270 256 if (!script._description) 271 257 script._description = ""; 272 258 273 if (script._includes.length == 0) {259 if (script._includes.length == 0) 274 260 script._includes.push("*"); 275 }276 261 277 262 return script; 278 263 }, 279 264 280 install: function(script) 281 { 265 install: function(script) { 282 266 GM_log("> Config.install"); 283 267 … … 301 285 }, 302 286 303 uninstall: function(script, uninstallPrefs) 304 { 287 uninstall: function(script, uninstallPrefs) { 305 288 var idx = this._find(script); 306 289 this._scripts.splice(idx, 1); … … 327 310 * the script will be moved. 328 311 */ 329 move: function(script, destination) 330 { 312 move: function(script, destination) { 331 313 var from = this._scripts.indexOf(script); 332 314 var to = -1; … … 352 334 }, 353 335 354 get _scriptDir() 355 { 336 get _scriptDir() { 356 337 var newDir = this._newScriptDir; 357 338 if (newDir.exists()) … … 375 356 }, 376 357 377 get _newScriptDir() 378 { 358 get _newScriptDir() { 379 359 var file = Components.classes["@mozilla.org/file/directory_service;1"] 380 360 .getService(Components.interfaces.nsIProperties) … … 384 364 }, 385 365 386 get _oldScriptDir() 387 { 366 get _oldScriptDir() { 388 367 var file = getContentDir(); 389 368 file.append("scripts"); … … 391 370 }, 392 371 393 get scripts() 394 { 372 get scripts() { 395 373 return this._scripts.concat(); 396 374 }, 397 375 398 getScriptsForUrl: function(url, includeDisabled) 399 { 376 getScriptsForUrl: function(url, includeDisabled) { 400 377 var scripts = []; 401 378 … … 425 402 .loadSubScript("chrome://greasemonkey/content/versioning.js"); 426 403 427 function Script(config) 428 { 404 function Script(config) { 429 405 this._config = config; 430 406 this._observers = []; … … 464 440 get resources() { return this._resources.concat(); }, 465 441 466 get _file() 467 { 442 get _file() { 468 443 var file = this._basedirFile; 469 444 file.append(this._filename); … … 473 448 get editFile() { return this._file; }, 474 449 475 get _basedirFile() 476 { 450 get _basedirFile() { 477 451 var file = this._config._scriptDir; 478 452 file.append(this._basedir); … … 483 457 get textContent() { return getContents(this._file); }, 484 458 485 _initFileName: function(name, useExt) 486 { 459 _initFileName: function(name, useExt) { 487 460 var ext = ""; 488 461 name = name.toLowerCase(); … … 511 484 }, 512 485 513 _initFile: function(tempFile) 514 { 486 _initFile: function(tempFile) { 515 487 var file = this._config._scriptDir; 516 488 var name = this._initFileName(this._name, false); … … 534 506 }; 535 507 536 function ScriptRequire(script) 537 { 508 function ScriptRequire(script) { 538 509 this._script = script; 539 510 … … 544 515 545 516 ScriptRequire.prototype = { 546 get _file() 547 { 517 get _file() { 548 518 var file = this._script._basedirFile; 549 519 file.append(this._filename); … … 554 524 get textContent() { return getContents(this._file); }, 555 525 556 _initFile: function() 557 { 526 _initFile: function() { 558 527 var name = this._downloadUrl.substr(this._downloadUrl.lastIndexOf("/") + 1); 559 528 if(name.indexOf("?") > 0) … … 577 546 }; 578 547 579 function ScriptResource(script) 580 { 548 function ScriptResource(script) { 581 549 this._script = script; 582 550 … … 593 561 get name() { return this._name; }, 594 562 595 get _file() 596 { 563 get _file() { 597 564 var file = this._script._basedirFile; 598 565 file.append(this._filename); … … 602 569 get textContent() { return getContents(this._file); }, 603 570 604 get dataContent() 605 { 571 get dataContent() { 606 572 var appSvc = Components.classes["@mozilla.org/appshell/appShellService;1"] 607 573 .getService(Components.interfaces.nsIAppShellService); … … 622 588 623 589 get urlToDownload() { return this._downloadUrl; }, 624 setDownloadedFile: function(tempFile, mimetype, charset) 625 { 590 setDownloadedFile: function(tempFile, mimetype, charset) { 626 591 this._tempFile = tempFile; 627 592 this._mimetype = mimetype; branches/config-service/src/chrome/chromeFiles/content/versioning.js
r662 r667 6 6 * any necessary upgrades. 7 7 */ 8 Config.prototype._updateVersion = function() 9 { 8 Config.prototype._updateVersion = function() { 10 9 log("> GM_updateVersion"); 11 10 … … 13 12 var initialized = GM_prefRoot.getValue("version", "0.0"); 14 13 15 if (GM_compareVersions(initialized, "0.3") == -1) {14 if (GM_compareVersions(initialized, "0.3") == -1) 16 15 this._pointThreeMigrate(); 17 }18 16 19 if (GM_compareVersions(initialized, "0.4.2") == -1) {17 if (GM_compareVersions(initialized, "0.4.2") == -1) 20 18 this._pointFourMigrate(); 21 }22 19 23 if (GM_compareVersions(initialized, "0.8") == -1) {20 if (GM_compareVersions(initialized, "0.8") == -1) 24 21 this._pointEightBackup(); 25 }26 22 27 23 // update the currently initialized version so we don't do this work again. … … 40 36 * paranoid and backup the folder the first time 0.8 runs. 41 37 */ 42 Config.prototype._pointEightBackup = function() 43 { 38 Config.prototype._pointEightBackup = function() { 44 39 var scriptDir = this._newScriptDir; 45 40 var scriptDirBackup = scriptDir.clone(); 46 41 scriptDirBackup.leafName += "_08bak"; 47 if (scriptDir.exists() && !scriptDirBackup.exists()) {42 if (scriptDir.exists() && !scriptDirBackup.exists()) 48 43 scriptDir.copyTo(scriptDirBackup.parent, scriptDirBackup.leafName); 49 }50 44 }; 51 45 … … 53 47 * Copies the entire scripts directory to the new location, if it exists. 54 48 */ 55 Config.prototype._pointFourMigrate = function() 56 { 49 Config.prototype._pointFourMigrate = function() { 57 50 log("> GM_pointFourMigrate"); 58 51 … … 66 59 * Migrates the configuration directory from the old format to the new one 67 60 */ 68 Config.prototype._pointThreeMigrate = function() 69 { 61 Config.prototype._pointThreeMigrate = function() { 70 62 log("> GM_pointThreeMigrate"); 71 63 … … 76 68 77 69 log("config file exists: " + configExists); 78 if (!configExists) {70 if (!configExists) 79 71 return; 80 }81 72 82 73 // back up the config directory … … 92 83 93 84 // update the format of the config.xml file and move each file 94 var script = null;95 var scriptFile = null;96 85 var doc = document.implementation.createDocument("", "", null); 97 86 … … 104 93 var nodes = document.evaluate("/UserScriptConfig/Script", doc, null, 105 94 XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); 106 var node;107 95 108 for (var i = 0 ; (node = nodes.snapshotItem(i)); i++) {109 if (node.hasAttribute("id")) {96 for (var i = 0, node; node = nodes.snapshotItem(i); i++) 97 if (node.hasAttribute("id")) 110 98 node.setAttribute("filename", node.getAttribute("id")); 111 }112 }113 99 114 100 // save the config file … … 124 110 log("config reloaded, moving files."); 125 111 126 for (var i = 0 ; (script = this._scripts[i]); i++) {112 for (var i = 0, script = null; script = this._scripts[i]; i++) { 127 113 if (script._filename.match(/^\d+$/)) { 128 114 var scriptFile = this._oldScriptDir;
