Changeset 627

Show
Ignore:
Timestamp:
01/19/08 15:15:24 (11 months ago)
Author:
boo..@youngpup.net
Message:

Backup gm_scripts dir the first time 0.8 runs. Paranoia and all that.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/chrome/chromeFiles/content/updater.js

    r624 r627  
    103103  this.update(); 
    104104}; 
    105  
    106 /** 
    107  * Compares two version numbers 
    108  * 
    109  * @param {String} aV1 Version of first item in 1.2.3.4..9. format 
    110  * @param {String} aV2 Version of second item in 1.2.3.4..9. format 
    111  * 
    112  * @returns {Int}  1 if first argument is higher 
    113  *                 0 if arguments are equal 
    114  *                 -1 if second argument is higher 
    115  */ 
    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 v1 
    138   return 0; 
    139 } 
    140105 
    141106/** 
     
    271236           "updateLink: " + this.updateLink); 
    272237 
    273     if (this.compareVersions(this.updateVersion, this.currentVersion) == 1) { 
     238    if (GM_compareVersions(this.updateVersion, this.currentVersion) == 1) { 
    274239      GM_log("ExtensionUpdater: Local version is old, now installing " + 
    275240             "update..."); 
  • trunk/src/chrome/chromeFiles/content/utils.js

    r626 r627  
    334334 
    335335/** 
     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 */ 
     345function 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/** 
    336371 * Takes the place of the traditional prompt() function which became broken 
    337372 * in FF 1.0.1. :( 
  • trunk/src/chrome/chromeFiles/content/versioning.js

    r548 r627  
    99  var initialized = GM_prefRoot.getValue("version", "0.0"); 
    1010 
    11   if (!GM_versionIsGreaterOrEqual(initialized, "0.3")) { 
     11  if (GM_compareVersions(initialized, "0.3") == -1) { 
    1212    GM_pointThreeMigrate(); 
    1313  } 
    1414 
    15   if (!GM_versionIsGreaterOrEqual(initialized, "0.4.2")) { 
     15  if (GM_compareVersions(initialized, "0.4.2") == -1) { 
    1616    GM_pointFourMigrate(); 
     17  } 
     18 
     19  if (GM_compareVersions(initialized, "0.8") == -1) { 
     20    GM_pointEightBackup(); 
    1721  } 
    1822 
     
    2529 
    2630  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 */ 
     38function 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  } 
    2745}; 
    2846 
     
    149167}; 
    150168 
    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  
    180169function GM_getPointThreeScriptDir() { 
    181170  var file = getContentDir(); 
  • trunk/src/components/greasemonkey.js

    r626 r627  
    124124    Cc["@mozilla.org/moz/jssubscript-loader;1"] 
    125125      .getService(Ci.mozIJSSubScriptLoader) 
     126      .loadSubScript("chrome://greasemonkey/content/utils.js"); 
     127 
     128    Cc["@mozilla.org/moz/jssubscript-loader;1"] 
     129      .getService(Ci.mozIJSSubScriptLoader) 
    126130      .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"); 
    131131 
    132132    Cc["@mozilla.org/moz/jssubscript-loader;1"]