home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Systeme / UpdateFreezer / UpdateFreezer_1.6.102.exe / Scenarios / Skype.Updater.js < prev    next >
Text File  |  2012-06-18  |  7KB  |  244 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.SkypeUpdater = 
  40. {
  41.     name:             "Skype.Updater",
  42.     displayName:    "Skype",
  43.     version:         "1.0",
  44.     description:     "Checks if any of Skype Update facilities are enabled and allows freezing of these facilities",
  45.     link:            "http://www.updatefreezer.org/index.php?id=4",
  46.     icon:            "Resources/Skype.Updater.png",
  47.     actions:        ["query", "backup", "restore", "enable", "disable"],
  48.  
  49.     programs: [{path: "%PROGRAMFILES%\\Skype\\Phone\\Skype.exe"}],
  50.     registry: [{section: Util.Registry.HKLM, key: "SOFTWARE\\Policies\\Skype\\Phone", value: "DisableVersionCheckPolicy"}],
  51.     services: [{name: "SkypeUpdate"}],
  52.     updaterFile: "%USERPROFILE%\\AppData\\Local\\Temp\\SkypeSetup.exe",
  53.     
  54.     skypeDataFileName: "Skype.Updater.json",
  55.     
  56.     inherits: [ScenarioController, RegistryController, ServiceController],
  57.  
  58. //#region Enums
  59.     ENABLED:         0,
  60.     DISABLEDREG:     1,
  61.     DISABLEDFILE:      2,
  62.     DISABLEDSERVICE: 3,
  63. //#endregion
  64.  
  65. //#region Actions
  66.     QuerySkype: function()
  67.     {
  68.         var result = this.QueryRegistry(true);
  69.         var serviceResult = this.QueryServices();
  70.         if (Util.FileSecurity.IsFileAccessDenied(Util.Shell.ExpandEnvironmentString(this.updaterFile))
  71.             || serviceResult.values[0].startType == Util.Service.StartType.SERVICE_DISABLED)
  72.         {
  73.             this.state = this.DISABLEDFILE;
  74.         }
  75.         else 
  76.         {
  77.             if (result && result.values && result.values[0].data == 1)
  78.             {
  79.                 this.state = this.DISABLEDREG
  80.             }
  81.             else
  82.             {
  83.                 this.state = this.ENABLED;
  84.                 this.updaterEnabled = true;            
  85.             }
  86.         }
  87.     },
  88.     
  89.     Query: function()
  90.     {
  91.         if (!this.CheckProgramInstalled())
  92.         {
  93.             return false;
  94.         }
  95.         
  96.         this.QuerySkype();
  97.         
  98.         if (this.updaterEnabled)
  99.         {
  100.             queryResult.push({msg: "<b>" + S("Skype.Updater.UpdaterEnabled") + "</b>"});
  101.         }
  102.         else
  103.         {
  104.             queryResult.push({msg: "<b>" + S("Skype.Updater.UpdaterDisabled") + "</b>"});
  105.         }        
  106.         
  107.         var dataFileName =  Util.IO.CombinePath(this.dataFolderPath, this.skypeDataFileName);
  108.         Util.IO.WriteJsonToFile(dataFileName, this.state);        
  109.     },
  110.     
  111.     ChangeUpdater: function(state)
  112.     {
  113.         this.state = state;
  114.         updaterExe = Util.Shell.ExpandEnvironmentString(this.updaterFile);
  115.         switch (state)
  116.         {
  117.             case this.ENABLED:
  118.                 this.ChangeServices(Util.Service.StartType.SERVICE_AUTO_START);
  119.                 this.ChangeRegistry(0);
  120.                 Util.FileSecurity.GrantFileAccess(updaterExe);
  121.                 break;
  122.                 
  123.             case this.DISABLEDREG:
  124.                 this.ChangeServices(Util.Service.StartType.SERVICE_AUTO_START);
  125.                 this.ChangeRegistry(1);
  126.                 Util.FileSecurity.GrantFileAccess(updaterExe);
  127.                 break;
  128.                 
  129.             case this.DISABLEDFILE:
  130.                 if (!Util.IO.CheckFileExists(updaterExe))
  131.                 {
  132.                     Util.IO.WriteFile(updaterExe, "empty");
  133.                 }
  134.                 this.ChangeRegistry(1);
  135.                 this.ChangeServices(Util.Service.StartType.SERVICE_DISABLED);
  136.                 Util.FileSecurity.DenyFileAccess(updaterExe);
  137.                 break;    
  138.         }
  139.     },
  140.     
  141.     MajorOnly: function()
  142.     {
  143.         this.ChangeUpdater(this.DISABLEDREG);
  144.     },
  145.     
  146.     Disable: function()
  147.     {
  148.         this.ChangeUpdater(this.DISABLEDFILE);
  149.     },
  150.     
  151.     Enable: function()
  152.     {
  153.         this.ChangeUpdater(this.ENABLED);
  154.     },
  155.         
  156.     Backup: function()
  157.     {
  158.         this.Query();
  159.     },
  160.     
  161.     Restore: function()
  162.     {
  163.         var dataFileName =  Util.IO.CombinePath(this.dataFolderPath, this.skypeDataFileName);
  164.         var p = Util.IO.ReadJsonFromFile(dataFileName);        
  165.         this.ChangeUpdater(p);
  166.     },
  167. //#endregion    
  168.     
  169.     GetScenarioInfo: function()
  170.     {
  171.         Scenario.currentScenario = this;
  172.         
  173.         if (this.IsProgramInstalled)
  174.         {
  175.             if (false == this.IsProgramInstalled())
  176.             {
  177.                     return {name: this.name, 
  178.                             displayName: this.displayName,
  179.                             icon: this.icon,
  180.                             status: S("UI.NotInstalled"),
  181.                             link: this.link};
  182.             }
  183.         }
  184.  
  185.         // do backup if first time
  186.         var backupFolder = Util.Scenario.GetDataFolderPath(this.name, "backup");        
  187.         var files = _GetFilesInFolder(backupFolder);
  188.         if (files.length == 0)
  189.         {
  190.             action = "backup";
  191.             Execute(this);
  192.         }
  193.     
  194.         // do query
  195.         this.updaterEnabled = false;
  196.         action = "query";
  197.         var status = Execute(this);
  198.         
  199.         // get current state of updates
  200.         var dataFileName = Util.IO.CombinePath(this.dataFolderPath, this.skypeDataFileName);
  201.         var result = Util.IO.ReadJsonFromFile(dataFileName);
  202.         var state = result;
  203.         
  204.         var actionInfo = 
  205.         {
  206.             name: this.name,
  207.             displayName: this.displayName,
  208.             icon: this.icon,
  209.             status: status,
  210.             link: this.link,
  211.             actions: [
  212.                 {
  213.                     action: "Disable", 
  214.                     buttonName: "Disabled", 
  215.                     active: this.state == this.DISABLEDFILE
  216.                 },           
  217.                 {
  218.                     action: "MajorOnly", 
  219.                     buttonName: "Major", 
  220.                     active: this.state == this.DISABLEDREG
  221.                 },
  222.                 {
  223.                     action: "Enable",
  224.                     buttonName: "Enabled",
  225.                     active: this.state == this.ENABLED
  226.                 }
  227.             ]
  228.         };
  229.     
  230.         return actionInfo;
  231.     }    
  232. };
  233.  
  234. Util.Scenario.InitializeScenario(Scenario.SkypeUpdater);
  235.  
  236. if (typeof(g_executeInBatch) == "undefined")
  237. {
  238.     Util.Locale.Load();
  239.     Execute(Scenario.SkypeUpdater);
  240. }
  241.  
  242. Scenario.SkypeUpdater.OutputDependencies();
  243.  
  244.