Changeset 657

Show
Ignore:
Timestamp:
02/10/08 07:03:52 (10 months ago)
Author:
ma..@jesperkristensen.dk
Message:

Make versioning.js part of config.js to allow better code separation later on.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/config-service/src/chrome/chromeFiles/content/browser.js

    r655 r657  
    2929  this.currentMenuCommander = null; 
    3030 
    31   GM_updateVersion(); 
     31  (new Config()).updateVersion(); 
    3232 
    3333  GM_listen(window, "load", GM_hitch(this, "chromeLoad")); 
  • branches/config-service/src/chrome/chromeFiles/content/browser.xul

    r590 r657  
    1111  <script type="application/x-javascript" src="chrome://greasemonkey/content/prefmanager.js" /> 
    1212  <script type="application/x-javascript" src="chrome://greasemonkey/content/convert2RegExp.js" /> 
    13   <script type="application/x-javascript" src="chrome://greasemonkey/content/versioning.js" /> 
    1413  <script type="application/x-javascript" src="chrome://greasemonkey/content/menucommander.js" /> 
    1514  <script type="application/x-javascript" src="chrome://greasemonkey/content/xmlhttprequester.js" /> 
  • branches/config-service/src/chrome/chromeFiles/content/config.js

    r656 r657  
    55  this.configFile.append("config.xml"); 
    66}; 
     7 
     8Components.classes["@mozilla.org/moz/jssubscript-loader;1"] 
     9  .getService(Components.interfaces.mozIJSSubScriptLoader) 
     10  .loadSubScript("chrome://greasemonkey/content/versioning.js"); 
    711 
    812Config.prototype.find = function(namespace, name) { 
     
    290294 
    291295Config.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; 
    306315}); 
    307316 
  • branches/config-service/src/chrome/chromeFiles/content/versioning.js

    r655 r657  
    33 * any necessary upgrades. 
    44 */ 
    5 function GM_updateVersion() { 
     5Config.prototype.updateVersion = function() 
     6
    67  log("> GM_updateVersion"); 
    78 
     
    1011 
    1112  if (GM_compareVersions(initialized, "0.3") == -1) { 
    12     GM_pointThreeMigrate(); 
     13    this._pointThreeMigrate(); 
    1314  } 
    1415 
    1516  if (GM_compareVersions(initialized, "0.4.2") == -1) { 
    16     GM_pointFourMigrate(); 
     17    this._pointFourMigrate(); 
    1718  } 
    1819 
    1920  if (GM_compareVersions(initialized, "0.8") == -1) { 
    20     GM_pointEightBackup(); 
     21    this._pointEightBackup(); 
    2122  } 
    2223 
     
    2930 
    3031  log("< GM_updateVersion"); 
    31 }; 
     32} 
    3233 
    3334/** 
     
    3637 * paranoid and backup the folder the first time 0.8 runs. 
    3738 */ 
    38 function GM_pointEightBackup() { 
    39   var config = new Config(); 
    40   var scriptDir = config.newScriptDir; 
     39Config.prototype._pointEightBackup = function() 
     40
     41  var scriptDir = this.newScriptDir; 
    4142  var scriptDirBackup = scriptDir.clone(); 
    4243  scriptDirBackup.leafName += "_08bak"; 
     
    4445    scriptDir.copyTo(scriptDirBackup.parent, scriptDirBackup.leafName); 
    4546  } 
    46 }; 
     47} 
    4748 
    4849/** 
    4950 * Copies the entire scripts directory to the new location, if it exists. 
    5051 */ 
    51 function GM_pointFourMigrate() { 
     52Config.prototype._pointFourMigrate = function() 
     53
    5254  log("> GM_pointFourMigrate"); 
    5355 
    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; 
    6158 
    6259  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
    8061 
    8162/** 
    8263 * Migrates the configuration directory from the old format to the new one 
    8364 */ 
    84 function GM_pointThreeMigrate() { 
     65Config.prototype._pointThreeMigrate = function() 
     66
    8567  log("> GM_pointThreeMigrate"); 
    8668 
    8769  // 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(); 
    8973 
    9074  log("config file exists: " + configExists); 
     
    9680  // if an error happens, report it and exit 
    9781  try { 
    98     var scriptDir = GM_getPointThreeScriptDir()
     82    var scriptDir = this.oldScriptDir
    9983    var tempDir = getTempFile(); 
    10084 
     
    10892    var scriptFile = null; 
    10993    var doc = document.implementation.createDocument("", "", null); 
    110     var configFile = GM_getPointThreeScriptFile("config.xml"); 
    11194 
    11295    var configURI = Components.classes["@mozilla.org/network/io-service;1"] 
     
    138121 
    139122    // now, load config normally and reinitialize all scripts's filenames 
    140     var config = new Config(); 
    141     config.load(); 
     123    this.load(); 
    142124 
    143125    log("config reloaded, moving files."); 
    144126 
    145     for (var i = 0; (script = config.scripts[i]); i++) { 
     127    for (var i = 0; (script = this.scripts[i]); i++) { 
    146128      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); 
    149132        log("renaming script " + scriptFile.leafName + " to " + script.filename); 
    150133        scriptFile.moveTo(scriptFile.parent, script.filename); 
     
    155138 
    156139    // save the config file 
    157     config.save(); 
     140    this.save(); 
    158141 
    159142    log("0.3 migration completed successfully!"); 
     
    167150    log("< GM_pointThreeMigrate"); 
    168151  } 
    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  
    132132      .getService(Ci.mozIJSSubScriptLoader) 
    133133      .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"); 
    138134 
    139135    Cc["@mozilla.org/moz/jssubscript-loader;1"]