Changeset 657
- Timestamp:
- 02/10/08 07:03:52 (10 months ago)
- Files:
-
- branches/config-service/src/chrome/chromeFiles/content/browser.js (modified) (1 diff)
- branches/config-service/src/chrome/chromeFiles/content/browser.xul (modified) (1 diff)
- branches/config-service/src/chrome/chromeFiles/content/config.js (modified) (2 diffs)
- branches/config-service/src/chrome/chromeFiles/content/versioning.js (modified) (10 diffs)
- branches/config-service/src/components/greasemonkey.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/config-service/src/chrome/chromeFiles/content/browser.js
r655 r657 29 29 this.currentMenuCommander = null; 30 30 31 GM_updateVersion();31 (new Config()).updateVersion(); 32 32 33 33 GM_listen(window, "load", GM_hitch(this, "chromeLoad")); branches/config-service/src/chrome/chromeFiles/content/browser.xul
r590 r657 11 11 <script type="application/x-javascript" src="chrome://greasemonkey/content/prefmanager.js" /> 12 12 <script type="application/x-javascript" src="chrome://greasemonkey/content/convert2RegExp.js" /> 13 <script type="application/x-javascript" src="chrome://greasemonkey/content/versioning.js" />14 13 <script type="application/x-javascript" src="chrome://greasemonkey/content/menucommander.js" /> 15 14 <script type="application/x-javascript" src="chrome://greasemonkey/content/xmlhttprequester.js" /> branches/config-service/src/chrome/chromeFiles/content/config.js
r656 r657 5 5 this.configFile.append("config.xml"); 6 6 }; 7 8 Components.classes["@mozilla.org/moz/jssubscript-loader;1"] 9 .getService(Components.interfaces.mozIJSSubScriptLoader) 10 .loadSubScript("chrome://greasemonkey/content/versioning.js"); 7 11 8 12 Config.prototype.find = function(namespace, name) { … … 290 294 291 295 Config.prototype.__defineGetter__("scriptDir", function() { 292 var dir = this.newScriptDir; 293 294 if (dir.exists()) { 295 return dir; 296 } else { 297 var oldDir = this.oldScriptDir; 298 if (oldDir.exists()) { 299 return oldDir; 300 } else { 301 // if we called this function, we want a script dir. 302 // but, at this branch, neither the old nor new exists, so create one 303 return GM_createScriptsDir(dir); 304 } 305 } 296 var newDir = this.newScriptDir; 297 if (newDir.exists()) 298 return newDir; 299 300 var oldDir = this.oldScriptDir; 301 if (oldDir.exists()) 302 return oldDir; 303 304 // if we called this function, we want a script dir. 305 // but, at this branch, neither the old nor new exists, so create one 306 newDir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); 307 308 var defaultConfigFile = getContentDir(); 309 defaultConfigFile.append("default-config.xml"); 310 311 defaultConfigFile.copyTo(newDir, "config.xml"); 312 defaultConfigFile.permissions = 0644; 313 314 return newDir; 306 315 }); 307 316 branches/config-service/src/chrome/chromeFiles/content/versioning.js
r655 r657 3 3 * any necessary upgrades. 4 4 */ 5 function GM_updateVersion() { 5 Config.prototype.updateVersion = function() 6 { 6 7 log("> GM_updateVersion"); 7 8 … … 10 11 11 12 if (GM_compareVersions(initialized, "0.3") == -1) { 12 GM_pointThreeMigrate();13 this._pointThreeMigrate(); 13 14 } 14 15 15 16 if (GM_compareVersions(initialized, "0.4.2") == -1) { 16 GM_pointFourMigrate();17 this._pointFourMigrate(); 17 18 } 18 19 19 20 if (GM_compareVersions(initialized, "0.8") == -1) { 20 GM_pointEightBackup();21 this._pointEightBackup(); 21 22 } 22 23 … … 29 30 30 31 log("< GM_updateVersion"); 31 } ;32 } 32 33 33 34 /** … … 36 37 * paranoid and backup the folder the first time 0.8 runs. 37 38 */ 38 function GM_pointEightBackup() { 39 var config = new Config(); 40 var scriptDir = config.newScriptDir;39 Config.prototype._pointEightBackup = function() 40 { 41 var scriptDir = this.newScriptDir; 41 42 var scriptDirBackup = scriptDir.clone(); 42 43 scriptDirBackup.leafName += "_08bak"; … … 44 45 scriptDir.copyTo(scriptDirBackup.parent, scriptDirBackup.leafName); 45 46 } 46 } ;47 } 47 48 48 49 /** 49 50 * Copies the entire scripts directory to the new location, if it exists. 50 51 */ 51 function GM_pointFourMigrate() { 52 Config.prototype._pointFourMigrate = function() 53 { 52 54 log("> GM_pointFourMigrate"); 53 55 54 var config = new Config(); 55 var oldDir = config.oldScriptDir; 56 var newDir = config.newScriptDir; 57 58 if (!oldDir.exists() && !newDir.exists()) { 59 GM_createScriptsDir(newDir); 60 } 56 // Create a scripts dir if it does not exist 57 this.scriptDir; 61 58 62 59 log("< GM_pointFourMigrate"); 63 }; 64 65 /** 66 * Given a nsILocalFile object, create a directory of that name and fill 67 * it with the default (empty) config.js. 68 */ 69 function GM_createScriptsDir(newDir) { 70 newDir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); 71 72 var defaultConfigFile = getContentDir(); 73 defaultConfigFile.append("default-config.xml"); 74 75 defaultConfigFile.copyTo(newDir, "config.xml"); 76 defaultConfigFile.permissions = 0644; 77 78 return newDir; 79 }; 60 } 80 61 81 62 /** 82 63 * Migrates the configuration directory from the old format to the new one 83 64 */ 84 function GM_pointThreeMigrate() { 65 Config.prototype._pointThreeMigrate = function() 66 { 85 67 log("> GM_pointThreeMigrate"); 86 68 87 69 // check to see whether there's any config to migrate 88 var configExists = GM_getPointThreeScriptFile("config.xml").exists(); 70 var configFile = this.oldScriptDir; 71 configFile.append("config.xml"); 72 var configExists = configFile.exists(); 89 73 90 74 log("config file exists: " + configExists); … … 96 80 // if an error happens, report it and exit 97 81 try { 98 var scriptDir = GM_getPointThreeScriptDir();82 var scriptDir = this.oldScriptDir; 99 83 var tempDir = getTempFile(); 100 84 … … 108 92 var scriptFile = null; 109 93 var doc = document.implementation.createDocument("", "", null); 110 var configFile = GM_getPointThreeScriptFile("config.xml");111 94 112 95 var configURI = Components.classes["@mozilla.org/network/io-service;1"] … … 138 121 139 122 // now, load config normally and reinitialize all scripts's filenames 140 var config = new Config(); 141 config.load(); 123 this.load(); 142 124 143 125 log("config reloaded, moving files."); 144 126 145 for (var i = 0; (script = config.scripts[i]); i++) {127 for (var i = 0; (script = this.scripts[i]); i++) { 146 128 if (script.filename.match(/^\d+$/)) { 147 scriptFile = GM_getPointThreeScriptFile(script.filename); 148 config.initFilename(script); 129 var scriptFile = this.oldScriptDir; 130 scriptFile.append(script.filename); 131 this.initFilename(script); 149 132 log("renaming script " + scriptFile.leafName + " to " + script.filename); 150 133 scriptFile.moveTo(scriptFile.parent, script.filename); … … 155 138 156 139 // save the config file 157 config.save();140 this.save(); 158 141 159 142 log("0.3 migration completed successfully!"); … … 167 150 log("< GM_pointThreeMigrate"); 168 151 } 169 }; 170 171 function GM_getPointThreeScriptDir() { 172 var file = getContentDir(); 173 file.append("scripts"); 174 return file; 175 }; 176 177 function GM_getPointThreeScriptFile(fileName) { 178 var file = GM_getPointThreeScriptDir(); 179 file.append(fileName); 180 return file; 181 }; 152 } branches/config-service/src/components/greasemonkey.js
r655 r657 132 132 .getService(Ci.mozIJSSubScriptLoader) 133 133 .loadSubScript("chrome://greasemonkey/content/utils.js"); 134 135 Cc["@mozilla.org/moz/jssubscript-loader;1"]136 .getService(Ci.mozIJSSubScriptLoader)137 .loadSubScript("chrome://greasemonkey/content/versioning.js");138 134 139 135 Cc["@mozilla.org/moz/jssubscript-loader;1"]
