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 / filD647A2F90FA636FDF685DAB61A80EE33 < prev    next >
Extensible Markup Language  |  2010-07-12  |  22KB  |  450 lines

  1. <?xml version="1.0"?>
  2. <!DOCTYPE bindings>
  3.  
  4. <bindings xmlns="http://www.mozilla.org/xbl"
  5.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  6.           xmlns:xbl="http://www.mozilla.org/xbl"
  7.           xmlns:html="http://www.w3.org/1999/xhtml">
  8.     
  9.     <binding id="package-management"
  10.              inheritstyle="false">
  11.         <resources>
  12.             <stylesheet src="package-management.css"/>
  13.             
  14.             <image src="head/exclamation.png"/>
  15.             <image src="disclaimer/exclamation.png"/>
  16.             <image src="placement/images/after.png"/>
  17.             <image src="placement/images/before.png"/>
  18.             <image src="placement/images/replace.png"/>
  19.         </resources>
  20.         
  21.         <implementation>
  22.             <field name="dialog">document.documentElement</field>
  23.             <field name="parameters">window.parameters</field>
  24.             <field name="_mode">this.parameters.mode</field>
  25.             <field name="_application">this.parameters.application</field>
  26.             <field name="_widgetLibrary">this._application.widgetLibrary</field>
  27.             <field name="_packageManager">this._application.packageManager</field>
  28.             <field name="_overlayProvider">this._application.overlayProvider</field>
  29.             <field name="_XB">this._application.core.Lib.XB</field>
  30.             <field name="_misc">this._application.core.Lib.misc</field>
  31.             <field name="_errors">this._application.core.Lib.CustomErrors</field>
  32.             <field name="_logger">this._application.core.Log4Moz.repository.getLogger(this._application.name + ".PackageManagementDialog")</field>
  33.             <field name="_bundle">new this._misc.StringBundle("package-management/package-management.properties")</field>
  34.             <field name="_comparator">this._Cc["@mozilla.org/xpcom/version-comparator;1"].getService(this._Ci.nsIVersionComparator)</field>
  35.             
  36.             <field name="flags">{}</field>
  37.             
  38.             <field name="_Cc">Components.classes</field>
  39.             <field name="_Ci">Components.interfaces</field>
  40.             <field name="_Cr">Components.results</field>
  41.             
  42.             <!-- nodes -->
  43.             <field name="_nodeConfirmHead">document.getAnonymousElementByAttribute(this, "class", "confirm-head")</field>
  44.             <field name="_nodeConfirmComponents">document.getAnonymousElementByAttribute(this, "class", "confirm-components")</field>
  45.             <field name="_nodeDownloadHead">document.getAnonymousElementByAttribute(this, "class", "download-head")</field>
  46.             <field name="_nodeDownloadProgressmeter">document.getAnonymousElementByAttribute(this, "class", "download-progressmeter")</field>
  47.             <field name="_nodeConflictHead">document.getAnonymousElementByAttribute(this, "class", "conflict-head")</field>
  48.             <field name="_nodeConflictDeleted">document.getAnonymousElementByAttribute(this, "class", "conflict-deleted")</field>
  49.             <field name="_nodePlacementHead">document.getAnonymousElementByAttribute(this, "class", "placement-head")</field>
  50.             <field name="_nodePlacementWidgets">document.getAnonymousElementByAttribute(this, "class", "placement-widgets")</field>
  51.             <field name="_nodePlacementPlacement">document.getAnonymousElementByAttribute(this, "class", "placement-placement")</field>
  52.             
  53.             <field name="_nodeErrorHead">document.getAnonymousElementByAttribute(this, "class", "error-head")</field>
  54.             <field name="_nodeErrorButtons">document.getAnonymousElementByAttribute(this, "anonid", "error-buttons")</field>
  55.             <field name="_nodeErrorDetails">document.getAnonymousElementByAttribute(this, "class", "error-details")</field>
  56.             <field name="_nodeErrorRepeat">document.getAnonymousElementByAttribute(this, "class", "error-repeat")</field>
  57.             <field name="_nodeErrorMore">document.getAnonymousElementByAttribute(this, "class", "error-more")</field>
  58.             
  59.             <constructor><![CDATA[
  60.                 this.flags = {};
  61.             ]]></constructor>
  62.             
  63.             <destructor><![CDATA[
  64.                 this._clean();
  65.             ]]></destructor>
  66.             
  67.             <!-- steps -->
  68.             
  69.             <method name="_stepDownloadPackages">
  70.                 <body><![CDATA[
  71.                     var items = [];
  72.                     for each (let component in this.packages) {
  73.                         items.push({
  74.                             component: component,
  75.                             url: component.info.fileURL
  76.                         });
  77.                     }
  78.                     
  79.                     this.step("download");
  80.                     
  81.                     var context = this;
  82.                     this.queue = new this._misc.DownloadQueue(
  83.                         items,
  84.                         function (items) { context._stepPreinstall(items); },
  85.                         this._nodeDownloadProgressmeter
  86.                     );
  87.                 ]]></body>
  88.             </method>
  89.             
  90.             <method name="_stepPreinstall">
  91.                 <parameter name="items"/>
  92.                 <body><![CDATA[
  93.                     var index = {};
  94.                     this.deleted = [];
  95.                     for each (let item in items) {
  96.                         if (item.status === this._Cr.NS_OK) {
  97.                             let component = item.component;
  98.                             try {
  99.                                 let directory = item.file.clone();
  100.                                 directory.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
  101.                                 this._application.core.Lib.sysutils.extractZipArchive(item.file, directory);
  102.                                 item.file.remove(true);
  103.                                 component.file = directory;
  104.                                 component.checked = false;
  105.                                 component.pkg = new this._application.core.Lib.XB.WidgetPackage(directory, component.manifest.packageID);
  106.                             } catch (e) {
  107.                                 try {
  108.                                     directory.remove(true);
  109.                                 }
  110.                                 catch(e) {
  111.                                 }
  112.                                 
  113.                                 this._clean();
  114.                                 
  115.                                 this._logger.error("Failed creating package object. " +
  116.                                                    this._application.core.Lib.misc.formatError(e));
  117.                                 this._error(e);
  118.                                 return;
  119.                             }
  120.                             
  121.                             let damage = false;
  122.                             for each (let widget in component.widgets) {
  123.                                 let available = !!component.pkg.findFile(widget.unit.name + ".xml");
  124.                                 widget.available = available;
  125.                                 if (!available)
  126.                                     damage = true;
  127.                             }
  128.                             if (damage) {
  129.                                 component.type = "package-remove";
  130.                                 this.deleted.push(component);
  131.                             }
  132.                         }
  133.                         else {
  134.                             this.flags.downloadError = true;
  135.                         }
  136.                     }
  137.                     
  138.                     this.queue.clean();
  139.                     
  140.                     if (this.flags.downloadError) {
  141.                         this._error("error.situation.network", {"accept": "_stepConflict();"});
  142.                         return;
  143.                     }
  144.                     
  145.                     this._stepConflict();
  146.                 ]]></body>
  147.             </method>
  148.             
  149.             <method name="_stepConflict">
  150.                 <body><![CDATA[
  151.                     if (this.deleted.length == 0) {
  152.                         return this._stepConflictResolved();
  153.                     }
  154.                     else {
  155.                         this.step("conflict");
  156.                         this._nodeConflictDeleted.items = this.deleted;
  157.                     }
  158.                 ]]></body>
  159.             </method>
  160.             
  161.             <method name="_stepConflictResolved">
  162.                 <body><![CDATA[
  163.                     this._filterComponent(this.packages, function(component) {
  164.                         component.type = "package";
  165.                         return !component.checked;
  166.                     });
  167.                     
  168.                     this._stepCreateWidgets();
  169.                 ]]></body>
  170.             </method>
  171.             
  172.             <method name="_stepCreateWidgets">
  173.                 <body><![CDATA[
  174.                     this.widgets = [];
  175.                     
  176.                     var ids = {};
  177.                     try {
  178.                         for each (let preset in this.presets) {
  179.                             for each (let info in preset.widgetsInfo) {
  180.                                 let id = info.protoID;
  181.                                 if (id in ids)
  182.                                     continue;
  183.                                 ids[id] = 1;
  184.                                 
  185.                                 if (this.mode == "install" || !this._widgetLibrary.isKnownWidget(id)) {
  186.                                     let prototype = this._getWidgetPrototypeById(id);
  187.                                     if (prototype)
  188.                                         this.widgets.push({
  189.                                             type: "widget",
  190.                                             checked: true,
  191.                                             info: info,
  192.                                             widget: prototype
  193.                                         });
  194.                                     else
  195.                                         this.flags.widgetError = true;
  196.                                 }
  197.                             }
  198.                         }
  199.                     }
  200.                     catch (e) {
  201.                         this._logger.error("Failed creating widget object. " + this._application.core.Lib.misc.formatError(e));
  202.                         this._error(e);
  203.                         return;
  204.                     }
  205.                     
  206.                     this._stepCheckErrors();
  207.                 ]]></body>
  208.             </method>
  209.             
  210.             <!-- <method name="_stepCheckErrors"/> pure virtual -->
  211.             
  212.             <!-- <method name="_stepPlacement"/> pure virtual -->
  213.             
  214.             <method name="_stepApply">
  215.                 <body><![CDATA[
  216.                     if (this._stepInstall())
  217.                         this.dialog.close();
  218.                 ]]></body>
  219.             </method>
  220.             
  221.             <method name="_stepInstall">
  222.                 <body><![CDATA[
  223.                     var packageIDs = [];
  224.                     var lostWidgetIds = [];
  225.                     for each (let package_ in this.packages) {
  226.                         packageIDs.push(package_.info.id);
  227.                         
  228.                         for each (let widget in package_.widgets)
  229.                             if (!widget.available)
  230.                                 lostWidgetIds.push(widget.id);
  231.                     }
  232.                     
  233.                     var newKnownWidgetIds = [];
  234.                     var widgetInfos = [];
  235.                     for each (let widget in this.widgets) {
  236.                         newKnownWidgetIds.push(widget.info.protoID);
  237.                         if (widget.checked)
  238.                             widgetInfos.push(widget.info);
  239.                     }
  240.                     
  241.                     for each (let id in packageIDs)
  242.                         this._application.switchWidgets(id, false);
  243.                     
  244.                     try {
  245.                         this._widgetLibrary.forgetWidgets(lostWidgetIds);
  246.                         
  247.                         for each (let component in this.packages) {
  248.                             this._packageManager.installPackage(component.file.clone(), component.info);
  249.                         }
  250.                         
  251.                         this._widgetLibrary.acquaintWithWidgets(newKnownWidgetIds);
  252.                         this._application.forEachWindow(
  253.                             function(controller) {
  254.                                 controller.updatePalette(packageIDs);
  255.                                 controller.deleteObsoleteWidgetItems();
  256.                             }
  257.                         );
  258.                     }
  259.                     catch (e) {
  260.                         this._logger.error("Failed installing components. " + this._application.core.Lib.misc.formatError(e));
  261.                         this._logger.debug(e.stack);
  262.                         this._error(e);
  263.                         return false;
  264.                     }
  265.                     finally {
  266.                         for each (let id in packageIDs)
  267.                             this._application.switchWidgets(id, true);
  268.                     }
  269.                     
  270.                     try {
  271.                         var placement = this._nodePlacementPlacement.mode;
  272.                         this._application.forEachWindow(
  273.                             function(controller) {
  274.                                 controller.setWidgets(widgetInfos, placement);
  275.                             }
  276.                         );
  277.                     }
  278.                     catch(e) {
  279.                         this._logger.error("Failed placing widgets. " + this._application.core.Lib.misc.formatError(e));
  280.                         this._logger.debug(e.stack);
  281.                     }
  282.                     
  283.                     for each (let preset in this.presets)
  284.                         this._savePreset(preset);
  285.                     
  286.                     return true;
  287.                 ]]></body>
  288.             </method>
  289.             
  290.             <method name="_savePreset">
  291.                 <parameter name="preset"/>
  292.                 <body><![CDATA[
  293.                     try {
  294.                         var name = encodeURIComponent(preset.address);
  295.                         var file = this._application.directories.XBPresets;
  296.                         file.append(name);
  297.                         this._application.core.Lib.sysutils.writeTextFile(file, preset.content, 0755);
  298.                     }
  299.                     catch(e) {
  300.                         this._logger.error("Failed saving preset. " + this._application.core.Lib.misc.formatError(e));
  301.                         this._logger.debug(e.stack);
  302.                     }
  303.                 ]]></body>
  304.             </method>
  305.             
  306.             <method name="step">
  307.                 <parameter name="name"/>
  308.                 <body><![CDATA[
  309.                     var nodes = document.getAnonymousNodes(this);
  310.                     for each (let node in nodes)
  311.                         if (node.nodeType == this.ELEMENT_NODE)
  312.                             node.style.display = ((node.getAttribute("step") == name) ? "-moz-box" : "none");
  313.                     
  314.                     this.dialog.sizeToContent();
  315.                 ]]></body>
  316.             </method>
  317.             
  318.             <method name="_error">
  319.                 <parameter name="exception"/>
  320.                 <parameter name="buttons"/>
  321.                 <body><![CDATA[
  322.                     var bundle = new this._misc.StringBundle("errors.properties"),
  323.                         description = "";
  324.                         
  325.                     if (typeof exception == "string") {
  326.                         description = bundle.get(exception);
  327.                         exception = null;
  328.                     }
  329.                     if (exception)
  330.                         if (exception instanceof this._errors.EDownload)
  331.                             description = bundle.get("error.situation.network");
  332.                         else
  333.                             description = bundle.get("error.situation.install.generic");
  334.                     
  335.                     this._nodeErrorHead.description = description;
  336.                     
  337.                     this._nodeErrorMore.style.display = !!exception ? "" : "none";
  338.                     if (exception)
  339.                         this._nodeErrorDetails.textContent = this._application.core.Lib.misc.formatError(exception);
  340.                     
  341.                     buttons = buttons || {"close": "dialog.close();"};
  342.                     var node = this._nodeErrorButtons.firstChild;
  343.                     while(node) {
  344.                         if (node.nodeType == this.ELEMENT_NODE) {
  345.                             let action = node.getAttribute("action");
  346.                             if (action in buttons)
  347.                                 node.removeAttribute("hidden");
  348.                             else
  349.                                 node.setAttribute("hidden", true);
  350.                             let oncommand = buttons[action] || null;
  351.                             // Firefox can cache a oncommand property value, related @oncommand attribute. Supress this.
  352.                             node.removeAttribute("oncommand");
  353.                             if (oncommand)
  354.                                 node.setAttribute("oncommand", oncommand);
  355.                         }
  356.                         node = node.nextSibling;
  357.                     }
  358.                     
  359.                     this.step("error");
  360.                 ]]></body>
  361.             </method>
  362.             
  363.             <method name="_clean">
  364.                 <body><![CDATA[
  365.                     for each (let component in this.components)
  366.                         this._cleanComponent(component);
  367.                     
  368.                     if (this.queue)
  369.                         this.queue.clean();
  370.                 ]]></body>
  371.             </method>
  372.             
  373.             <method name="_cleanComponent">
  374.                 <parameter name="component"/>
  375.                 <body><![CDATA[
  376.                     try {
  377.                         if (component.file)
  378.                             this._misc.removeFileSafe(component.file);
  379.                     } catch(e) {}
  380.                     try {
  381.                         if (component.pkg)
  382.                             component.pkg.finalize();
  383.                     } catch(e) {}
  384.                 ]]></body>
  385.             </method>
  386.             
  387.             <method name="_filterComponent">
  388.                 <parameter name="components"/>
  389.                 <parameter name="check"/>
  390.                 <body><![CDATA[
  391.                     for(let i = components.length; i--;) {
  392.                         if (check(components[i]))
  393.                             continue;
  394.                         this._cleanComponent(components[i]);
  395.                         components.splice(i, 1);
  396.                     }
  397.                 ]]></body>
  398.             </method>
  399.             
  400.             <method name="_compare">
  401.                 <parameter name="a"/>
  402.                 <parameter name="b"/>
  403.                 <body><![CDATA[
  404.                     return this._comparator.compare(a, b);
  405.                 ]]></body>
  406.             </method>
  407.             
  408.             
  409.             <method name="_knownWidgetsInPackage">
  410.                 <parameter name="packageId"/>
  411.                 <body><![CDATA[
  412.                     var prototypes = [];
  413.                     for each (let id in this._widgetLibrary.getWidgetProtoIDs()) {
  414.                         let [widgetPackageID, ] = this._widgetLibrary.parseWidgetProtoID(id);
  415.                         if (widgetPackageID == packageId)
  416.                             prototypes.push(this._widgetLibrary.getWidgetProto(id));
  417.                     }
  418.                     return prototypes;
  419.                 ]]></body>
  420.             </method>
  421.             
  422.             <method name="_getWidgetPrototypeById">
  423.                 <parameter name="id"/>
  424.                 <body><![CDATA[
  425.                     var [packageId, widgetName] = this._widgetLibrary.parseWidgetProtoID(id);
  426.                     var prototype = null;
  427.                     for each (let component in this.packages)
  428.                         if (component.pkg.id == packageId) {
  429.                             if (component.pkg.findFile(widgetName + ".xml"))
  430.                                 return component.pkg.getUnit(widgetName).widgetProto;
  431.                             break;
  432.                         }
  433.                     
  434.                     if (this._widgetLibrary.isKnownWidget(id))
  435.                         return this._widgetLibrary.getWidgetProto(id);
  436.                     
  437.                     try {
  438.                         let pkg = null;
  439.                         if (pkg = this._packageManager.getPackage(packageId))
  440.                             return pkg.getUnit(widgetName).widgetProto;
  441.                     } catch (e) {
  442.                     }
  443.                     return null;
  444.                 ]]></body>
  445.             </method>
  446.             
  447.         </implementation>
  448.     </binding>
  449. </bindings>
  450.