home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / air / update / core / UpdaterConfiguration.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  7.8 KB  |  258 lines

  1. package air.update.core
  2. {
  3.    import air.update.descriptors.ConfigurationDescriptor;
  4.    import air.update.logging.Logger;
  5.    import air.update.utils.Constants;
  6.    import air.update.utils.FileUtils;
  7.    import air.update.utils.VersionUtils;
  8.    import flash.filesystem.File;
  9.    
  10.    public class UpdaterConfiguration
  11.    {
  12.       private static var logger:Logger = Logger.getLogger("air.update.core.UpdaterConfiguration");
  13.       
  14.       private var _delay:Number;
  15.       
  16.       private var configurationDescriptor:ConfigurationDescriptor;
  17.       
  18.       private var _isFileUpdateVisible:int;
  19.       
  20.       private var _configurationFile:File;
  21.       
  22.       private var _isDownloadProgressVisible:int;
  23.       
  24.       private var _isUnexpectedErrorVisible:int;
  25.       
  26.       private var _updateURL:String;
  27.       
  28.       private var _isNewerVersionFunction:Function;
  29.       
  30.       private var _isInstallUpdateVisible:int;
  31.       
  32.       private var _isDownloadUpdateVisible:int;
  33.       
  34.       private var _isCheckForUpdateVisible:int;
  35.       
  36.       public function UpdaterConfiguration()
  37.       {
  38.          super();
  39.          this._delay = -1;
  40.          this._isCheckForUpdateVisible = -1;
  41.          this._isDownloadUpdateVisible = -1;
  42.          this._isDownloadProgressVisible = -1;
  43.          this._isInstallUpdateVisible = -1;
  44.          this._isFileUpdateVisible = -1;
  45.          this._isUnexpectedErrorVisible = -1;
  46.          this._isNewerVersionFunction = VersionUtils.isNewerVersion;
  47.       }
  48.       
  49.       public function get delay() : Number
  50.       {
  51.          if(this._delay < 0)
  52.          {
  53.             if(Boolean(this.configurationDescriptor) && this.configurationDescriptor.checkInterval >= 0)
  54.             {
  55.                return this.configurationDescriptor.checkInterval;
  56.             }
  57.             return 0;
  58.          }
  59.          return this._delay;
  60.       }
  61.       
  62.       public function set delay(param1:Number) : void
  63.       {
  64.          this._delay = param1;
  65.       }
  66.       
  67.       public function get delayAsMilliseconds() : Number
  68.       {
  69.          return this.delay * Constants.DAY_IN_MILLISECONDS;
  70.       }
  71.       
  72.       public function set updateURL(param1:String) : void
  73.       {
  74.          this._updateURL = param1;
  75.       }
  76.       
  77.       public function get isNewerVersionFunction() : Function
  78.       {
  79.          return this._isNewerVersionFunction;
  80.       }
  81.       
  82.       public function set isUnexpectedErrorVisible(param1:Boolean) : void
  83.       {
  84.          this._isUnexpectedErrorVisible = param1 ? 1 : 0;
  85.       }
  86.       
  87.       public function get configurationFile() : File
  88.       {
  89.          return this._configurationFile;
  90.       }
  91.       
  92.       public function set isFileUpdateVisible(param1:Boolean) : void
  93.       {
  94.          this._isFileUpdateVisible = param1 ? 1 : 0;
  95.       }
  96.       
  97.       public function get isCheckForUpdateVisible() : Boolean
  98.       {
  99.          if(this._isCheckForUpdateVisible >= 0)
  100.          {
  101.             return this._isCheckForUpdateVisible == 1;
  102.          }
  103.          var _loc1_:int = this.dialogVisibilityInConfiguration(ConfigurationDescriptor.DIALOG_CHECK_FOR_UPDATE);
  104.          if(_loc1_ >= 0)
  105.          {
  106.             return _loc1_ == 1;
  107.          }
  108.          return true;
  109.       }
  110.       
  111.       public function get isDownloadUpdateVisible() : Boolean
  112.       {
  113.          if(this._isDownloadUpdateVisible >= 0)
  114.          {
  115.             return this._isDownloadUpdateVisible == 1;
  116.          }
  117.          var _loc1_:int = this.dialogVisibilityInConfiguration(ConfigurationDescriptor.DIALOG_DOWNLOAD_UPDATE);
  118.          if(_loc1_ >= 0)
  119.          {
  120.             return _loc1_ == 1;
  121.          }
  122.          return true;
  123.       }
  124.       
  125.       public function set isNewerVersionFunction(param1:Function) : void
  126.       {
  127.          this._isNewerVersionFunction = param1;
  128.       }
  129.       
  130.       public function get isFileUpdateVisible() : Boolean
  131.       {
  132.          if(this._isFileUpdateVisible >= 0)
  133.          {
  134.             return this._isFileUpdateVisible == 1;
  135.          }
  136.          var _loc1_:int = this.dialogVisibilityInConfiguration(ConfigurationDescriptor.DIALOG_FILE_UPDATE);
  137.          if(_loc1_ >= 0)
  138.          {
  139.             return _loc1_ == 1;
  140.          }
  141.          return true;
  142.       }
  143.       
  144.       public function set isInstallUpdateVisible(param1:Boolean) : void
  145.       {
  146.          this._isInstallUpdateVisible = param1 ? 1 : 0;
  147.       }
  148.       
  149.       public function set isDownloadProgressVisible(param1:Boolean) : void
  150.       {
  151.          this._isDownloadProgressVisible = param1 ? 1 : 0;
  152.       }
  153.       
  154.       public function get isDownloadProgressVisible() : Boolean
  155.       {
  156.          if(this._isDownloadProgressVisible >= 0)
  157.          {
  158.             return this._isDownloadProgressVisible == 1;
  159.          }
  160.          var _loc1_:int = this.dialogVisibilityInConfiguration(ConfigurationDescriptor.DIALOG_DOWNLOAD_PROGRESS);
  161.          if(_loc1_ >= 0)
  162.          {
  163.             return _loc1_ == 1;
  164.          }
  165.          return true;
  166.       }
  167.       
  168.       public function validate() : void
  169.       {
  170.          var _loc1_:XML = null;
  171.          if(this.configurationFile)
  172.          {
  173.             if(!this.configurationFile.exists)
  174.             {
  175.                throw new Error("Configuration file \"" + this.configurationFile.nativePath + "\" does not exists on disk",Constants.ERROR_CONFIGURATION_FILE_MISSING);
  176.             }
  177.             _loc1_ = FileUtils.readXMLFromFile(this.configurationFile);
  178.             this.configurationDescriptor = new ConfigurationDescriptor(_loc1_);
  179.             this.configurationDescriptor.validate();
  180.          }
  181.          if(!this._updateURL && !this.configurationDescriptor)
  182.          {
  183.             throw new Error("Update URL not set",Constants.ERROR_UPDATE_URL_MISSING);
  184.          }
  185.       }
  186.       
  187.       public function set configurationFile(param1:File) : void
  188.       {
  189.          this._configurationFile = param1;
  190.       }
  191.       
  192.       public function get updateURL() : String
  193.       {
  194.          return !!this._updateURL ? this._updateURL : this.configurationDescriptor.url;
  195.       }
  196.       
  197.       public function get isUnexpectedErrorVisible() : Boolean
  198.       {
  199.          if(this._isUnexpectedErrorVisible >= 0)
  200.          {
  201.             return this._isUnexpectedErrorVisible == 1;
  202.          }
  203.          var _loc1_:int = this.dialogVisibilityInConfiguration(ConfigurationDescriptor.DIALOG_UNEXPECTED_ERROR);
  204.          if(_loc1_ >= 0)
  205.          {
  206.             return _loc1_ == 1;
  207.          }
  208.          return true;
  209.       }
  210.       
  211.       public function set isDownloadUpdateVisible(param1:Boolean) : void
  212.       {
  213.          this._isDownloadUpdateVisible = param1 ? 1 : 0;
  214.       }
  215.       
  216.       public function get isInstallUpdateVisible() : Boolean
  217.       {
  218.          if(this._isInstallUpdateVisible >= 0)
  219.          {
  220.             return this._isInstallUpdateVisible == 1;
  221.          }
  222.          var _loc1_:int = this.dialogVisibilityInConfiguration(ConfigurationDescriptor.DIALOG_INSTALL_UPDATE);
  223.          if(_loc1_ >= 0)
  224.          {
  225.             return _loc1_ == 1;
  226.          }
  227.          return true;
  228.       }
  229.       
  230.       public function set isCheckForUpdateVisible(param1:Boolean) : void
  231.       {
  232.          this._isCheckForUpdateVisible = param1 ? 1 : 0;
  233.       }
  234.       
  235.       private function dialogVisibilityInConfiguration(param1:String) : int
  236.       {
  237.          var _loc4_:Object = null;
  238.          if(!this.configurationDescriptor)
  239.          {
  240.             return -1;
  241.          }
  242.          var _loc2_:Array = this.configurationDescriptor.defaultUI;
  243.          var _loc3_:int = 0;
  244.          while(_loc3_ < _loc2_.length)
  245.          {
  246.             _loc4_ = _loc2_[_loc3_];
  247.             if(param1.toLowerCase() == _loc4_.name.toLowerCase())
  248.             {
  249.                return !!_loc4_.visible ? 1 : 0;
  250.             }
  251.             _loc3_++;
  252.          }
  253.          return -1;
  254.       }
  255.    }
  256. }
  257.  
  258.