Changeset 627
- Timestamp:
- 01/19/08 15:15:24 (11 months ago)
- Files:
-
- trunk/src/chrome/chromeFiles/content/updater.js (modified) (2 diffs)
- trunk/src/chrome/chromeFiles/content/utils.js (modified) (1 diff)
- trunk/src/chrome/chromeFiles/content/versioning.js (modified) (3 diffs)
- trunk/src/components/greasemonkey.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/chrome/chromeFiles/content/updater.js
r624 r627 103 103 this.update(); 104 104 }; 105 106 /**107 * Compares two version numbers108 *109 * @param {String} aV1 Version of first item in 1.2.3.4..9. format110 * @param {String} aV2 Version of second item in 1.2.3.4..9. format111 *112 * @returns {Int} 1 if first argument is higher113 * 0 if arguments are equal114 * -1 if second argument is higher115 */116 ExtensionUpdater.prototype.compareVersions = function(aV1, aV2) {117 var v1 = aV1.split(".");118 var v2 = aV2.split(".");119 var numSubversions = (v1.length > v2.length) ? v1.length : v2.length;120 121 for (var i = 0; i < numSubversions; i++) {122 if (typeof v2[i] == 'undefined') {123 return 1;124 }125 126 if (typeof v1[i] == 'undefined') {127 return -1;128 }129 130 if (parseInt(v2[i], 10) > parseInt(v1[i], 10)) {131 return -1;132 } else if (parseInt(v2[i], 10) < parseInt(v1[i], 10)) {133 return 1;134 }135 }136 137 // v2 was never higher or lower than v1138 return 0;139 }140 105 141 106 /** … … 271 236 "updateLink: " + this.updateLink); 272 237 273 if ( this.compareVersions(this.updateVersion, this.currentVersion) == 1) {238 if (GM_compareVersions(this.updateVersion, this.currentVersion) == 1) { 274 239 GM_log("ExtensionUpdater: Local version is old, now installing " + 275 240 "update..."); trunk/src/chrome/chromeFiles/content/utils.js
r626 r627 334 334 335 335 /** 336 * Compares two version numbers 337 * 338 * @param {String} aV1 Version of first item in 1.2.3.4..9. format 339 * @param {String} aV2 Version of second item in 1.2.3.4..9. format 340 * 341 * @returns {Int} 1 if first argument is higher 342 * 0 if arguments are equal 343 * -1 if second argument is higher 344 */ 345 function GM_compareVersions(aV1, aV2) { 346 var v1 = aV1.split("."); 347 var v2 = aV2.split("."); 348 var numSubversions = (v1.length > v2.length) ? v1.length : v2.length; 349 350 for (var i = 0; i < numSubversions; i++) { 351 if (typeof v2[i] == 'undefined') { 352 return 1; 353 } 354 355 if (typeof v1[i] == 'undefined') { 356 return -1; 357 } 358 359 if (parseInt(v2[i], 10) > parseInt(v1[i], 10)) { 360 return -1; 361 } else if (parseInt(v2[i], 10) < parseInt(v1[i], 10)) { 362 return 1; 363 } 364 } 365 366 // v2 was never higher or lower than v1 367 return 0; 368 } 369 370 /** 336 371 * Takes the place of the traditional prompt() function which became broken 337 372 * in FF 1.0.1. :( trunk/src/chrome/chromeFiles/content/versioning.js
r548 r627 9 9 var initialized = GM_prefRoot.getValue("version", "0.0"); 10 10 11 if ( !GM_versionIsGreaterOrEqual(initialized, "0.3")) {11 if (GM_compareVersions(initialized, "0.3") == -1) { 12 12 GM_pointThreeMigrate(); 13 13 } 14 14 15 if ( !GM_versionIsGreaterOrEqual(initialized, "0.4.2")) {15 if (GM_compareVersions(initialized, "0.4.2") == -1) { 16 16 GM_pointFourMigrate(); 17 } 18 19 if (GM_compareVersions(initialized, "0.8") == -1) { 20 GM_pointEightBackup(); 17 21 } 18 22 … … 25 29 26 30 log("< GM_updateVersion"); 31 }; 32 33 /** 34 * In Greasemonkey 0.8 there was a format change to the gm_scripts folder and 35 * testing found several bugs where the entire folder would get nuked. So we are 36 * paranoid and backup the folder the first time 0.8 runs. 37 */ 38 function GM_pointEightBackup() { 39 var scriptDir = getNewScriptDir(); 40 var scriptDirBackup = scriptDir.clone(); 41 scriptDirBackup.leafName += "_08bak"; 42 if (scriptDir.exists() && !scriptDirBackup.exists()) { 43 scriptDir.copyTo(scriptDirBackup.parent, scriptDirBackup.leafName); 44 } 27 45 }; 28 46 … … 149 167 }; 150 168 151 function GM_versionIsGreaterOrEqual(v1, v2) {152 v1 = v1.split(".");153 v2 = v2.split(".");154 155 if (v1[0] == "") v1[0] = "0";156 if (v2[0] == "") v2[0] = "0";157 158 while (v1.length < v2.length) {159 v1.push("0");160 }161 162 while (v2.length < v1.length) {163 v2.push("0");164 }165 166 var diff;167 for (var i = 0; i < v1.length; i++) {168 diff = parseInt(v1[i]) - parseInt(v2[i]);169 170 if (diff != 0) {171 return diff > 0;172 } else {173 continue;174 }175 }176 177 return 0;178 };179 180 169 function GM_getPointThreeScriptDir() { 181 170 var file = getContentDir(); trunk/src/components/greasemonkey.js
r626 r627 124 124 Cc["@mozilla.org/moz/jssubscript-loader;1"] 125 125 .getService(Ci.mozIJSSubScriptLoader) 126 .loadSubScript("chrome://greasemonkey/content/utils.js"); 127 128 Cc["@mozilla.org/moz/jssubscript-loader;1"] 129 .getService(Ci.mozIJSSubScriptLoader) 126 130 .loadSubScript("chrome://greasemonkey/content/versioning.js"); 127 128 Cc["@mozilla.org/moz/jssubscript-loader;1"]129 .getService(Ci.mozIJSSubScriptLoader)130 .loadSubScript("chrome://greasemonkey/content/utils.js");131 131 132 132 Cc["@mozilla.org/moz/jssubscript-loader;1"]
