home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / AIMP2 / aimp_2.61.583.exe / $TEMP / YandexPackSetup.msi / fil753F8BAD0122C135E8FD934A8DAF3DA9 < prev    next >
Text File  |  2010-07-12  |  3KB  |  85 lines

  1. const ARBITER_NAME = "arbiter"
  2. const ARBITER_CLASS_ID_STR = "{19FB0AE6-E66A-11DE-B97E-E96F55D89593}";
  3. const ARBITER_CLASS_ID = Components.ID(ARBITER_CLASS_ID_STR);
  4. const ARBITER_CLASS_NAME = "Arbiter.";
  5. const ARBITER_CONTRACT_ID = "@yandex.ru/" + ARBITER_NAME + ";1";
  6.  
  7. const Cc = Components.classes,
  8.       Ci = Components.interfaces,
  9.       Cr = Components.results,
  10.       Cu = Components.utils;
  11.  
  12. Cu.import("resource://gre/modules/XPCOMUtils.jsm");
  13.  
  14. function Arbiter() {
  15.     this.base = {};
  16. };
  17.  
  18. Arbiter.prototype = {
  19.     base: null,
  20.     get wrappedJSObject() {
  21.         return this;
  22.     },
  23.     register: function(name, version) {
  24.         if (!this.base[name])
  25.             this.base[name] = {
  26.                 name: name,
  27.                 version: version,
  28.                 done: false
  29.             };
  30.         else {
  31.             var item = this.base[name];
  32.             if (this.compare(version, item.version) > 0)
  33.                 item.version = version;
  34.         }
  35.     },
  36.     accept: function(name, version) {
  37.         var item = this.base[name]; 
  38.         if (item) {
  39.             if (!item.done && (this.compare(version, item.version) >= 0)) {
  40.                 this.done(name);
  41.                 return true;
  42.             }
  43.             else
  44.                 return false; 
  45.         }
  46.         else {
  47.             return false;
  48.         }
  49.     },
  50.     done: function(name) {
  51.         var item = this.base[name];
  52.         if (item)
  53.             item.done = true;
  54.     },
  55.     compare: function(a, b) {
  56.         if (!this._checker)
  57.             this._checker = Cc["@mozilla.org/xpcom/version-comparator;1"].getService(Ci.nsIVersionComparator);
  58.         return this._checker.compare(a, b);
  59.     },
  60.     
  61.     classDescription: ARBITER_CLASS_NAME,
  62.     classID: ARBITER_CLASS_ID,
  63.     contractID: ARBITER_CONTRACT_ID,
  64.     QueryInterface: XPCOMUtils.generateQI([Ci.yIArbiter]),
  65.     _xpcom_factory: {
  66.         createInstance: function (outer, iid) {
  67.             if (outer != null)
  68.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  69.             if (!this._componentInstance)
  70.                 this._componentInstance = new Arbiter();
  71.             return this._componentInstance.QueryInterface(iid);
  72.         }
  73.     },
  74.     _xpcom_categories: [
  75.         {
  76.             category: "app-startup",
  77.             service: true
  78.         }
  79.     ]
  80. };
  81.  
  82. var components = [Arbiter];
  83. function NSGetModule(compMgr, fileSpec) {
  84.     return XPCOMUtils.generateModule(components);
  85. }