home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Systeme / UpdateFreezer / UpdateFreezer_1.6.102.exe / Wrappers / Util.Scenario.js < prev    next >
Text File  |  2012-05-31  |  6KB  |  205 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. function Info()
  31. {
  32.     if (typeof(Scenario.currentScenario) != "undefined")
  33.     {
  34.         scenarioName = Scenario.currentScenario.name;
  35.         if(l1) Log1("Scenario '" + scenarioName + "'");
  36.  
  37.         if (typeof(Scenario.currentScenario.parts) == "undefined")
  38.         {
  39.             //if(l0) Log("Scenatio is empty");
  40.             return;
  41.         }
  42.  
  43.         if(l2) Log2("Configuration");
  44.         for(var i = 0; i < Scenario.currentScenario.parts.length; i++)
  45.         {
  46.             var part = Scenario.currentScenario.parts[i];
  47.             if(l2) Log2("Part: " + part.name);
  48.             if(l2) Log2("\tEnabled: " + part.enabled);
  49.             var actions = "";
  50.             for(var j = 0; j < part.actions.length; j++)
  51.             {
  52.                 var action = part.actions[j];
  53.                 actions += action.name;
  54.                 if (j <part.actions.length - 1) actions += ", ";
  55.             }
  56.             if(l2) Log2("\tAvailable actions: " + actions);
  57.         }
  58.     }
  59.     else
  60.     {
  61.         if(l1) Log1("Current scenario is not specified");
  62.     }
  63. }
  64.  
  65. var queryResult = [];
  66.  
  67. function Execute(scen)
  68. {
  69.     function _launch(scen, part, actionName)
  70.     {
  71.         for(var i = 0; i < part.actions.length; i++)
  72.         {
  73.             var action = part.actions[i];
  74.             if (action.name == actionName)
  75.             {
  76.                 scen.dataFolderPath = Util.Scenario.GetDataFolderPath(scen.name, actionName);
  77.                 action.handler.apply(scen, action.arguments);
  78.             }
  79.         }
  80.     }
  81.     
  82.     Scenario.currentScenario = scen;
  83.     
  84.     if (typeof(action) == "undefined")
  85.     {
  86.         Log("No Action specified");
  87.         Log("Default action is 'query'");
  88.         action = "query";
  89.     }
  90.  
  91.     Info();
  92.  
  93.     if (typeof(Scenario.currentScenario) != "undefined")
  94.     {    
  95.         var scen = Scenario.currentScenario;
  96.     
  97.         if(l1) Log1("Running scenario '" + scen.name + "', action '" + action + "'");
  98.     
  99.         Util.IO.CreateDirectory(Util.Scenario.GetDataFolderPath(scen.name, "query"));
  100.         
  101.         if (scen.CheckProgramInstalled())
  102.         {
  103.             Util.IO.CreateDirectory(Util.Scenario.GetDataFolderPath(scen.name, "backup"));
  104.         }
  105.         
  106.         queryResult = [];
  107.         
  108.         scen.dataFolderPath = Util.Scenario.GetDataFolderPath(scen.name, action);
  109.         for(var member in scen)
  110.         {
  111.             if (member.toLowerCase() == action.toLowerCase())
  112.             {
  113.                 if(l1) Log1("Action found");    
  114.                 if (scen[member + "Ext"])
  115.                     scen[member + "Ext"]();
  116.                 scen[member]();
  117.             }
  118.         }
  119.  
  120.         if(l1) Log1("Result");
  121.     
  122.         for(var i = 0; i < queryResult.length; i++)
  123.         {
  124.             var qr = queryResult[i];
  125.             if (l0) Log(qr.msg);
  126.         }
  127.         
  128.         return queryResult;
  129.     }
  130. }
  131.  
  132.  
  133. if (typeof(Util) == "undefined")
  134.     Util = {};
  135.     
  136. Util.Scenario = 
  137. {
  138.     GetDataFolderPath: function(scenarioName, actionName)
  139.     {
  140.         var actionLwc = actionName.toLowerCase();
  141.         if (actionLwc == "backup" || actionLwc == "restore")
  142.         {
  143.             return Util.IO.GetCurrentDirectory() + "\\Scenarios\\" + scenarioName + ".backup";
  144.         }
  145.  
  146.         return Util.IO.GetCurrentDirectory() + "\\Scenarios\\" + scenarioName;
  147.     },
  148.     
  149.     GetScenarioForName: function(name)
  150.     {
  151.         for(i in Scenario)
  152.         {
  153.             var scenario = Scenario[i];
  154.             if (scenario.name && scenario.name == name)
  155.             {
  156.                 return scenario;
  157.             }
  158.         }
  159.         return null;
  160.     },
  161.     
  162.     InitializeScenario: function(scen)
  163.     {
  164.         this._initializeScenario(scen, scen);
  165.     },
  166.     
  167.     _initializeScenario: function(scen, obj)
  168.     {
  169.         if (obj && obj.inherits)
  170.         {
  171.             for(var i = 0; i < obj.inherits.length; i++)
  172.             {
  173.                 var base = obj.inherits[i];
  174.                 for(var member in base)
  175.                 {
  176.                     if (member != "inherits")
  177.                     {
  178.                         if (scen[member] === undefined)
  179.                         {
  180.                             if (l2) Log2("Appending member '" + member + "' to scenario '" + scen.name + "'");
  181.                             scen[member] = base[member];
  182.                         }
  183.                     }
  184.                 }
  185.                 this._initializeScenario(scen, base);
  186.             }
  187.         }
  188.     },
  189.  
  190.     HasAction: function(name)
  191.     {
  192.         var scen = Scenario.currentScenario;
  193.         if (scen && scen.actions.length)
  194.         {
  195.             for(var i = 0; i < scen.actions.length; i++)
  196.             {
  197.                 if (scen.actions[i] == name)
  198.                     return true;
  199.             }
  200.         }
  201.         return false;
  202.     }
  203. }
  204.  
  205.