Changeset 712

Show
Ignore:
Timestamp:
04/04/08 01:36:37 (8 months ago)
Author:
ma..@jesperkristensen.dk
Message:

Remove broken migration code and move the rest of the versioning code into config.js

Files:

Legend:

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

    r695 r712  
    1 // In this file protected properties (prefixed with an underscore) may be 
    2 // used anywhere within this file and versioning.js 
    3  
    41function Config() { 
    52  this._scripts = null; 
    63  this._configFile = this._scriptDir; 
    74  this._configFile.append("config.xml"); 
     5  this._initScriptDir(); 
    86 
    97  this._observers = []; 
     
    338336 
    339337  get _scriptDir() { 
    340     var newDir = this._newScriptDir; 
    341     if (newDir.exists()) return newDir; 
    342  
    343     var oldDir = this._oldScriptDir; 
    344     if (oldDir.exists()) return oldDir; 
    345  
    346     // if we called this function, we want a script dir. 
    347     // but, at this branch, neither the old nor new exists, so create one 
    348     newDir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); 
    349  
    350     var defaultConfigFile = getContentDir(); 
    351     defaultConfigFile.append("default-config.xml"); 
    352  
    353     defaultConfigFile.copyTo(newDir, "config.xml"); 
    354     defaultConfigFile.permissions = 0644; 
    355  
    356     return newDir; 
    357   }, 
    358  
    359   get _newScriptDir() { 
    360338    var file = Components.classes["@mozilla.org/file/directory_service;1"] 
    361339                         .getService(Components.interfaces.nsIProperties) 
     
    365343  }, 
    366344 
    367   get _oldScriptDir() { 
    368     var file = getContentDir(); 
    369     file.append("scripts"); 
    370     return file; 
     345  /** 
     346   * Create an empty configuration if none exist. 
     347   */ 
     348  _initScriptDir: function() { 
     349    var dir = this._scriptDir; 
     350 
     351    if (!dir.exists()) { 
     352      dir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); 
     353 
     354      var configStream = getWriteStream(this._configFile); 
     355      var xml = "<UserScriptConfig/>"; 
     356      configStream.write(xml, xml.length); 
     357      configStream.close(); 
     358    } 
    371359  }, 
    372360 
    373361  get scripts() { return this._scripts.concat(); }, 
    374   getMatchingScripts: function(testFunc) { return this._scripts.filter(testFunc); } 
     362  getMatchingScripts: function(testFunc) { return this._scripts.filter(testFunc); }, 
     363 
     364  /** 
     365   * Checks whether the version has changed since the last run and performs 
     366   * any necessary upgrades. 
     367   */ 
     368  _updateVersion: function() { 
     369    log("> GM_updateVersion"); 
     370 
     371    // this is the last version which has been run at least once 
     372    var initialized = GM_prefRoot.getValue("version", "0.0"); 
     373 
     374    if (GM_compareVersions(initialized, "0.8") == -1) 
     375      this._pointEightBackup(); 
     376 
     377    // update the currently initialized version so we don't do this work again. 
     378    var extMan = Components.classes["@mozilla.org/extensions/manager;1"] 
     379      .getService(Components.interfaces.nsIExtensionManager); 
     380 
     381    var item = extMan.getItemForID(GM_GUID); 
     382    GM_prefRoot.setValue("version", item.version); 
     383 
     384    log("< GM_updateVersion"); 
     385  }, 
     386 
     387  /** 
     388   * In Greasemonkey 0.8 there was a format change to the gm_scripts folder and 
     389   * testing found several bugs where the entire folder would get nuked. So we 
     390   * are paranoid and backup the folder the first time 0.8 runs. 
     391   */ 
     392  _pointEightBackup: function() { 
     393    var scriptDir = this._scriptDir; 
     394    var scriptDirBackup = scriptDir.clone(); 
     395    scriptDirBackup.leafName += "_08bak"; 
     396    if (scriptDir.exists() && !scriptDirBackup.exists()) 
     397      scriptDir.copyTo(scriptDirBackup.parent, scriptDirBackup.leafName); 
     398  } 
    375399}; 
    376  
    377 Components.classes["@mozilla.org/moz/jssubscript-loader;1"] 
    378   .getService(Components.interfaces.mozIJSSubScriptLoader) 
    379   .loadSubScript("chrome://greasemonkey/content/versioning.js"); 
    380400 
    381401function Script(config) { 
  • trunk/src/chrome/chromeFiles/content/utils.js

    r694 r712  
    272272} 
    273273 
    274 function getContentDir() { 
    275   var reg = Components.classes["@mozilla.org/chrome/chrome-registry;1"] 
    276                       .getService(Components.interfaces.nsIChromeRegistry); 
    277  
    278   var ioSvc = Components.classes["@mozilla.org/network/io-service;1"] 
    279                         .getService(Components.interfaces.nsIIOService); 
    280  
    281   var proto = Components.classes["@mozilla.org/network/protocol;1?name=file"] 
    282                         .getService(Components.interfaces.nsIFileProtocolHandler); 
    283  
    284   var chromeURL = ioSvc.newURI("chrome://greasemonkey/content", null, null); 
    285   var fileURL = reg.convertChromeURL(chromeURL); 
    286   var file = proto.getFileFromURLSpec(fileURL.spec).parent; 
    287  
    288   return file 
    289 } 
    290  
    291274/** 
    292275 * Compares two version numbers