home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Systeme / UpdateFreezer / UpdateFreezer_1.6.102.exe / Scenarios / Windows.Update.js < prev   
Text File  |  2012-07-19  |  6KB  |  212 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. Scenario.WindowsUpdate = 
  40. {
  41.     name:             "Windows.Update",
  42.     displayName:    "Windows",
  43.     version:         "0.1",
  44.     description:     "Checks if Windows Update is enabled and allows freezing it",
  45.     link:            "http://www.updatefreezer.org/index.php?id=23",
  46.     icon:            "Resources/Windows.Update.png",
  47.     actions:        ["query", "backup", "restore", "enable", "disable"],
  48.     
  49.     registry: [{section: Util.Registry.HKLM, key: "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update", value: "AUOptions"}],
  50.  
  51.     inherits: [ScenarioController, RegistryController],
  52.     
  53. //#region Implementation    
  54.     NOTSET:             0,
  55.     DISABLED:          1,
  56.     NOTIFYONLY:      2,
  57.     DOWNLOADONLY:    3,
  58.     AUTOMATIC:          4,
  59. //#endregion    
  60.     
  61.     
  62. //#region Actions
  63.     Query: function()
  64.     {
  65.         this.QueryRegistry(true);
  66.         this.LogUpdaterStatus();
  67.     },
  68.     
  69.     Disable: function()
  70.     {
  71.         this.ChangeRegistry(1);
  72.     },
  73.     
  74.     Enable: function()
  75.     {
  76.         this.ChangeRegistry(2);
  77.     },
  78.     
  79.     Backup: function()
  80.     {
  81.         this.QueryRegistry();
  82.     },
  83.     
  84.     Restore: function()
  85.     {
  86.         this.ChangeRegistry();
  87.     },
  88.     
  89.     SetNotSet: function()
  90.     {
  91.         this.ChangeRegistry(0);
  92.     },
  93.     
  94.     SetDisabled: function()
  95.     {
  96.         this.ChangeRegistry(1);
  97.     },    
  98.     
  99.     SetNotifyOnly: function()
  100.     {
  101.         this.ChangeRegistry(2);
  102.     },    
  103.     
  104.     SetDownloadOnly: function()
  105.     {
  106.         this.ChangeRegistry(3);
  107.     },    
  108.     
  109.     SetAutomatic: function()
  110.     {
  111.         this.ChangeRegistry(4);
  112.     },
  113. //#endregion
  114.  
  115.     LogRegistryResult: function(result)
  116.     {
  117.         if (result && result.values && result.values.length && result.values[0].data > 1)
  118.         {
  119.             this.updaterEnabled = true;
  120.             queryResult.push({msg: S("Common.RegistryEnabled")});
  121.         }
  122.         else
  123.         {
  124.             queryResult.push({msg: S("Common.RegistryDisabled")});
  125.         }    
  126.     },
  127.  
  128.     GetScenarioInfo: function()
  129.     {
  130.         Scenario.currentScenario = this;
  131.         
  132.         if (this.IsProgramInstalled)
  133.         {
  134.             if (false == this.IsProgramInstalled())
  135.             {
  136.                     return {name: this.name, 
  137.                             displayName: this.displayName,
  138.                             icon: this.icon,
  139.                             status: S("UI.NotInstalled"),
  140.                             link: this.link};
  141.             }
  142.         }
  143.  
  144.         // do backup if first time
  145.         var backupFolder = Util.Scenario.GetDataFolderPath(this.name, "backup");        
  146.         var files = _GetFilesInFolder(backupFolder);
  147.         if (files.length == 0)
  148.         {
  149.             action = "backup";
  150.             Execute(this);
  151.         }
  152.     
  153.         // do query
  154.         this.updaterEnabled = false;
  155.         action = "query";
  156.         var status = Execute(this);
  157.         
  158.         // get current state of updates
  159.         var dataFileName =  Util.IO.CombinePath(this.dataFolderPath, this.GetRegistryDataFileName());
  160.         var result = Util.IO.ReadJsonFromFile(dataFileName);
  161.         var state = result.values[0].data;
  162.         
  163.         var actionInfo = 
  164.         {
  165.             name: this.name,
  166.             displayName: this.displayName,
  167.             icon: this.icon,
  168.             status: status,
  169.             link: this.link,
  170.             actions: [
  171.                 {
  172.                     action: "SetNotSet",
  173.                     buttonName: "NotSet",
  174.                     active: state == this.NOTSET
  175.                 },
  176.                 {
  177.                     action: "SetDisabled", 
  178.                     buttonName: "Disabled", 
  179.                     active: state == this.DISABLED
  180.                 },
  181.                 {
  182.                     action: "SetNotifyOnly", 
  183.                     buttonName: "NotifyOnly", 
  184.                     active: state == this.NOTIFYONLY
  185.                 },
  186.                 {
  187.                     action: "SetDownloadOnly", 
  188.                     buttonName: "DownloadOnly", 
  189.                     active: state == this.DOWNLOADONLY
  190.                 },
  191.                 {
  192.                     action: "SetAutomatic", 
  193.                     buttonName: "Automatic", 
  194.                     active: state == this.AUTOMATIC
  195.                 }
  196.             ]
  197.         };
  198.     
  199.         return actionInfo;
  200.     }        
  201. };
  202.  
  203. Util.Scenario.InitializeScenario(Scenario.WindowsUpdate);
  204.  
  205. if (typeof(g_executeInBatch) == "undefined")
  206. {
  207.     Util.Locale.Load();
  208.     Execute(Scenario.WindowsUpdate);
  209. }
  210.  
  211. Scenario.WindowsUpdate.OutputDependencies();
  212.