home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Systeme / UpdateFreezer / UpdateFreezer_1.6.102.exe / Scenarios / Adobe.Updater.js next >
Text File  |  2012-08-06  |  7KB  |  232 lines

  1. /************************************************************************ 
  2.   Copyright 2011-2012, IceJS Team. All rights reserved.
  3.   Redistribution and use in source and binary forms, with or without
  4.   modification, are permitted provided that the following conditions are
  5.   met:
  6.   
  7.       * Redistributions of source code must retain the above copyright
  8.         notice, this list of conditions and the following disclaimer.
  9.       * Redistributions in binary form must reproduce the above
  10.         copyright notice, this list of conditions and the following
  11.         disclaimer in the documentation and/or other materials provided
  12.         with the distribution.
  13.       * Neither the name of Update Freezer Team nor the names of its
  14.         contributors may be used to endorse or promote products derived
  15.         from this software without specific prior written permission.
  16.   
  17.   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18.   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19.   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20.   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21.   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22.   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23.   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24.   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25.   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26.   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27.   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28.  ***********************************************************************/
  29.  
  30. if (typeof(g_executeInBatch) == "undefined")
  31. {
  32.     Include("Wrappers/Common.js")
  33.     Include("Controllers/Controller.js");
  34. }
  35.  
  36. if (typeof(Scenario) == "undefined")
  37.     Scenario = {};
  38.  
  39.  
  40. Scenario.AdobeUpdater = 
  41. {
  42.     name:             "Adobe.Updater",
  43.     displayName:    "Adobe Acrobat & Reader",
  44.     version:         "1.3",
  45.     description:     "Checks if Adobe update is enabled and allows to disable and enable update facilities",
  46.     link:            "http://www.updatefreezer.org/index.php?id=2",
  47.     icon:            "Resources/Adobe.Updater.png",
  48.     actions:        ["query", "backup", "restore", "enable", "disable"],
  49.  
  50.     programs:        [{path: "%PROGRAMFILES%\\Adobe"}],
  51.     inherits:         [ScenarioController],
  52.     
  53. //#region Implementation
  54.     adobeProductsDataFileName: "Adobe.Products.json",
  55.     regRoot: "SOFTWARE\\Policies\\Adobe",
  56.     lockKeyName: "FeatureLockDown",
  57.     rk: "bUpdater",
  58.     supportedProducts: ["Acrobat", "Acrobat Reader"],
  59.     
  60.     _isProductSupported: function(productName)
  61.     {
  62.         for(var i = 0; i < this.supportedProducts.length; i++)
  63.         {
  64.             if (this.supportedProducts[i] == productName)
  65.             {
  66.                 return true;
  67.             }
  68.         }
  69.         return false;
  70.     },
  71.     
  72.     IsProgramInstalledExt: function()
  73.     {
  74.         // check that required registry keys exist
  75.         var someProductsExist = false;
  76.         for(var i = 0; i < this.supportedProducts.length; i++)
  77.         {
  78.             if (Util.Registry.IsKeyExists(Util.Registry.HKLM, "SOFTWARE\\Policies\\Adobe\\" + this.supportedProducts[i]))
  79.             {
  80.                 someProductsExist = true;
  81.             }
  82.         }
  83.         
  84.         return someProductsExist;
  85.     },
  86.  
  87.     _EnumerateProducts: function()
  88.     {
  89.         var p = [];
  90.         //To disable the Updater and remove the Updater configuration UI in the Preferences panel:
  91.         //HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Adobe\{product}\{version}\FeatureLockdown
  92.         //Create the new DWord bUpdater.
  93.         //Set the value to 0.
  94.         var products = Util.Registry.EnumChildrenKeyNames(Util.Registry.HKLM, this.regRoot);
  95.         for(var i = 0; i < products.length; i++)
  96.         {
  97.             var productName = products[i].name;
  98.             
  99.             if (!this._isProductSupported(productName))
  100.             {
  101.                 continue;
  102.             }
  103.             
  104.             var versions = Util.Registry.EnumChildrenKeyNames(Util.Registry.HKLM, this.regRoot + "\\" + productName);
  105.             for(var v = 0; v < versions.length; v++)
  106.             {
  107.                 var version = versions[v].name;
  108.                 if(Util.Registry.IsKeyExists(Util.Registry.HKLM, this.regRoot + "\\" + productName + "\\" + version + "\\" + this.lockKeyName))
  109.                 {
  110.                     var product = {"name": productName, "version": version, "enabled": true};
  111.                     // check enable
  112.                     var q = Util.Registry.GetKeyValueDWORD(Util.Registry.HKLM, 
  113.                                                            this.regRoot + "\\" + productName + "\\" + version + "\\" + this.lockKeyName,
  114.                                                            this.rk);
  115.                     if(q === 0)
  116.                     {
  117.                         product.enabled = false;
  118.                     }
  119.                     p.push(product);
  120.                 }
  121.             }
  122.         }
  123.         return p;
  124.     },
  125.  
  126.     QueryAdobeProducts: function()
  127.     {
  128.         var result = {
  129.             products:[],
  130.             hasProducts: function()
  131.             {
  132.                 return this.products.length > 0;
  133.             },
  134.             hasEnabled: function()
  135.             {
  136.                 for(var i = 0; i < this.products.length; i++)
  137.                 {
  138.                     if (this.products[i].enabled)
  139.                         return true;
  140.                 }
  141.                 return false;
  142.             }
  143.         };
  144.         
  145.         result.products = this._EnumerateProducts();
  146.         var dataFileName =  Util.IO.CombinePath(this.dataFolderPath, this.adobeProductsDataFileName);
  147.         Util.IO.WriteJsonToFile(dataFileName, result);
  148.         
  149.         if (result.hasProducts())
  150.         {
  151.             if (result.hasEnabled())
  152.             {
  153.                 this.updaterEnabled = true;
  154.                 queryResult.push({msg: S("Adobe.Updater.ProductsEnabled")});
  155.             }
  156.             else
  157.                 queryResult.push({msg: S("Adobe.Updater.ProductsDisabled")});
  158.         }
  159.         else
  160.         {
  161.             queryResult.push({msg: S("Adobe.Updater.ProductsNotFound")});
  162.         }
  163.         return result;
  164.     },
  165.     
  166.     ChangeAdobeProducts: function(enable)
  167.     {
  168.         var dataFileName =  Util.IO.CombinePath(this.dataFolderPath, this.adobeProductsDataFileName);
  169.         var p = Util.IO.ReadJsonFromFile(dataFileName);
  170.         if (p && p.products)
  171.         {
  172.             for(var i = 0; i < p.products.length; i++)
  173.             {
  174.                 var product = p.products[i];
  175.                 var et = enable;
  176.                 if (enable === undefined)
  177.                     et = product.enabled;
  178.                     
  179.                 Util.Registry.SetKeyValueDWORD(Util.Registry.HKLM, this.regRoot + "\\" + product.name + "\\" + product.version + "\\" + this.lockKeyName, this.rk, et ? 1 : 0);
  180.             }
  181.         }
  182.     },
  183. //#endregion    
  184.  
  185.     
  186. //#region Actions
  187.     Query: function()
  188.     {
  189.         if (!this.CheckProgramInstalled())
  190.         {
  191.             return false;
  192.         }    
  193.         
  194.         this.QueryAdobeProducts();
  195.         this.LogUpdaterStatus();
  196.     },
  197.     
  198.     Disable: function()
  199.     {
  200.         this.ChangeAdobeProducts(false);
  201.     },
  202.     
  203.     Enable: function()
  204.     {
  205.         this.ChangeAdobeProducts(true);
  206.     },
  207.     
  208.     Backup: function()
  209.     {
  210.         this.QueryAdobeProducts();
  211.     },
  212.     
  213.     Restore: function()
  214.     {
  215.         this.ChangeAdobeProducts();
  216.     }
  217. //#endregion    
  218.     
  219.  
  220. };
  221.  
  222.  
  223. Util.Scenario.InitializeScenario(Scenario.AdobeUpdater);
  224.  
  225. if (typeof(g_executeInBatch) == "undefined")
  226. {
  227.     Util.Locale.Load();
  228.     Execute(Scenario.AdobeUpdater);
  229. }
  230.  
  231. Scenario.AdobeUpdater.OutputDependencies();
  232.