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 / fil8C1A0D8F711E18EC09F1987048B0DAF4 < prev    next >
Text File  |  2010-07-12  |  7KB  |  188 lines

  1. function Update(application) {
  2.     this._application = application;
  3.     
  4.     (this._timerOne = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer))
  5.         .initWithCallback(this, 24 * 3600 * 1000, Ci.nsITimer.TYPE_REPEATING_SLACK);
  6.     
  7.     let Preferences = this._application.core.Preferences;
  8.     let now = parseInt(Date.now() / 1000, 10);
  9.     let PREF_LAST_UPDATE_TIME = this._application.name + ".updates.widgets.lastUpdateTime";
  10.     
  11.     if (Math.abs((Preferences.get(PREF_LAST_UPDATE_TIME) || 0) - now) > 24 * 3600) {
  12.         Preferences.set(PREF_LAST_UPDATE_TIME, now);
  13.         
  14.         (this._timerTwo = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer))
  15.             .initWithCallback(this, 30 * 1000, Ci.nsITimer.TYPE_ONE_SHOT);
  16.     }
  17. };
  18.  
  19. Update.prototype = {
  20.     notify: function() {
  21.         this._update();
  22.     },
  23.     
  24.     _activePresets: function() {
  25.         var presets = [];
  26.         var entries = this._application.directories.XBPresets.directoryEntries;
  27.         
  28.         while (entries.hasMoreElements()) {
  29.             let file = entries.getNext().QueryInterface(Ci.nsIFile);
  30.             let address = decodeURIComponent(file.leafName);
  31.             let preset = new this._application.core.Lib.XB.Preset(file, address);
  32.             
  33.             let used = false;
  34.             for each (let widgetInfo in preset.widgetsInfo)
  35.                 if (this._widgetLibrary.isKnownWidget(widgetInfo.protoID)) {
  36.                     used = true;
  37.                     break;
  38.                 }
  39.             
  40.             if (used)
  41.                 presets.push(preset);
  42.             else
  43.                 file.remove(false);
  44.         }
  45.         
  46.         return presets;
  47.     },
  48.     
  49.     _compareVersion: function (a, b) {
  50.         if (!this._comparator)
  51.             this._comparator = Cc["@mozilla.org/xpcom/version-comparator;1"].getService(Ci.nsIVersionComparator);
  52.         return this._comparator.compare(a.version, b.version);
  53.     },
  54.     
  55.     _update: function() {
  56.         this._presets = [];
  57.         this._manifests = [];
  58.         
  59.         this._packageManager = this._application.packageManager;
  60.         this._widgetLibrary = this._application.widgetLibrary;
  61.         this._misc = this._application.core.Lib.misc;
  62.         
  63.         this._updateStepOne();
  64.     },
  65.     
  66.     _updateStepOne: function() {
  67.         var knownPresets = this._activePresets();
  68.         
  69.         var items = [];
  70.         
  71.         for each (let preset in knownPresets) {
  72.             items.push({
  73.                 url: preset.address,
  74.                 preset: preset
  75.             });
  76.         }
  77.         
  78.         var context = this;
  79.         this.queue = new this._misc.DownloadQueue(
  80.             items,
  81.             function (items) { context._updateStepTwo(items); },
  82.             null
  83.         );
  84.     },
  85.     
  86.     _updateStepTwo: function(items) {
  87.         var unknownPackageIds = [],
  88.             knownPackageIds = this._packageManager.packagesIDs;
  89.         
  90.         knownPackageIds = knownPackageIds.filter(function(id) {
  91.             return !this._application.isPreinstalledPackage(id);
  92.         }, this);
  93.         
  94.         for each (let item in items) {
  95.             if (item.status === Cr.NS_OK) {
  96.                 try {
  97.                     let preset = new this._application.core.Lib.XB.Preset(item.file, item.url);
  98.                     if (this._compareVersion(preset, item.preset) > 0) {
  99.                         this._presets.push(preset);
  100.                         
  101.                         for each (let info in preset.widgetsInfo)
  102.                             if (!this._packageManager.isPackageInstalled(info.packageID) && (unknownPackageIds.indexOf(info.packageID) == -1))
  103.                                 unknownPackageIds.push(info.packageID);
  104.                     }
  105.                 }
  106.                 catch(e) {
  107.                 }
  108.             }
  109.         }
  110.         
  111.         this.queue.destroy();
  112.         items = [];
  113.         
  114.         for each (let id in unknownPackageIds) {
  115.             let url = id;
  116.             items.push({
  117.                 url: url
  118.             });
  119.         }
  120.         
  121.         for each (let id in knownPackageIds) {
  122.             if (this._widgetLibrary.getWidgetProtoIDs(id).length == 0)
  123.                 continue;
  124.             let info = this._packageManager.getPackageInfo(id);
  125.             items.push({
  126.                 url: info.uri,
  127.                 info: info
  128.             });
  129.         }
  130.         
  131.         var context = this;
  132.         this.queue = new this._misc.DownloadQueue(
  133.             items,
  134.             function (items) { context._updateStepThree(items); },
  135.             null
  136.         );
  137.     },
  138.     
  139.     _updateStepThree: function(items) {
  140.         for each (let item in items) {
  141.             if (item.status === Cr.NS_OK) {
  142.                 try {
  143.                     let manifest = new this._application.core.Lib.XB.PackageManifest(item.url, item.file);
  144.                     if (item.info) {
  145.                         let [info, ] = this._application.selectBestPackage(manifest);
  146.                         if (info && this._compareVersion(info, item.info) > 0)
  147.                             this._manifests.push(manifest);
  148.                     }
  149.                     else
  150.                         this._manifests.push(manifest);
  151.                 }
  152.                 catch (e) {
  153.                 }
  154.             }
  155.         }
  156.         
  157.         this.queue.destroy();
  158.         
  159.         if (this._presets.length == 0 && this._manifests == 0)
  160.             return;
  161.         
  162.         var context = this;
  163.         var window = this._application.core.Lib.misc.openWindow({
  164.                 url: "chrome://" + this._application.name +
  165.                      "/content/custombar/dialogs/package-management/notification-update/notification-update.xul",
  166.                 features: "__popup__",
  167.                 name: "notification-update",
  168.                 presets: this._presets,
  169.                 manifests: this._manifests,
  170.                 application: this._application,
  171.                 install: function(simple) { context._openDialog(simple); }
  172.             });
  173.     },
  174.     
  175.     _openDialog: function(simple) {
  176.         var window = this._application.core.Lib.misc.openWindow({
  177.                 url: "chrome://" + this._application.name +
  178.                      "/content/custombar/dialogs/package-management/update/update.xul",
  179.                 features: "__popup__",
  180.                 name: "package-management-update",
  181.                 mode: "update",
  182.                 presets: this._presets,
  183.                 manifests: this._manifests,
  184.                 application: this._application,
  185.                 simple: !!simple
  186.             });
  187.     }
  188. };