| <?xml version="1.0" encoding="utf-8"?> |
| <!-- |
| |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| |
| --> |
| <s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" |
| xmlns:s="library://ns.adobe.com/flex/spark" |
| xmlns:mx="library://ns.adobe.com/flex/mx" |
| width="600" height="412" |
| title="Update available" |
| xmlns:controls="ws.tink.spark.controls.*" |
| skinClass="ws.tink.spark.skins.controls.UpdaterDialogSkin"> |
| |
| <fx:Script><![CDATA[ |
| |
| import air.update.events.DownloadErrorEvent; |
| import air.update.events.StatusUpdateEvent; |
| import air.update.events.UpdateEvent; |
| |
| import com.riaspace.nativeApplicationUpdater.utils.HdiutilHelper; |
| |
| import mx.controls.Alert; |
| import mx.core.Application; |
| import mx.core.FlexGlobals; |
| import mx.events.CloseEvent; |
| import mx.utils.DisplayUtil; |
| |
| import org.apache.flex.packageflexsdk.util.DownloadUtil; |
| import org.apache.flex.utilities.common.Constants; |
| import org.apache.flex.utilities.common.Tools; |
| |
| [Bindable] |
| private var _newVersion:String; |
| |
| private var _fileWindows:File; |
| private var _fileMac:File; |
| |
| protected function handleYesBtnClick(event:MouseEvent):void |
| { |
| currentState = "downloading"; |
| downloadUpdater(); |
| } |
| |
| protected function downloadUpdater():void |
| { |
| var applicationExtension:String = Tools.getApplicationExtension(); |
| var downloadCompleteHandler:Function = |
| (applicationExtension == Constants.APPLICATION_EXTENSION_WIN) ? |
| handleWindowsInstallerDownloadComplete : handleMacInstallerDownloadComplete; |
| |
| var main:Object = FlexGlobals.topLevelApplication; |
| |
| var url:String = |
| main.installerAppPath + main.installerAppFileName + applicationExtension; |
| |
| DownloadUtil.download(url, downloadCompleteHandler, handleDownloadError, handleDownloadProgress); |
| } |
| |
| protected function handleWindowsInstallerDownloadComplete(event:Event):void |
| { |
| _fileWindows = File.createTempFile(); |
| writeFileToDirectory(_fileWindows,event.target.data); |
| installFromFile(_fileWindows); |
| } |
| |
| protected function installFromFile(file:File):void |
| { |
| DownloadUtil.executeFile(file); |
| setTimeout(NativeApplication.nativeApplication.exit, 200); |
| } |
| |
| protected function handleMacInstallerDownloadComplete(event:Event):void |
| { |
| _fileMac = File.createTempFile(); |
| writeFileToDirectory(_fileMac,event.target.data); |
| var hdiutilHelper:HdiutilHelper = new HdiutilHelper(_fileMac); |
| hdiutilHelper.addEventListener(Event.COMPLETE, handleHdiutilHelperComplete); |
| hdiutilHelper.addEventListener(ErrorEvent.ERROR, handleHdiutilHelperError); |
| hdiutilHelper.attach(); |
| } |
| |
| private function handleHdiutilHelperComplete(event:Event):void |
| { |
| var hdiutilHelper:HdiutilHelper = event.target as HdiutilHelper; |
| hdiutilHelper.removeEventListener(Event.COMPLETE, handleHdiutilHelperComplete); |
| hdiutilHelper.removeEventListener(ErrorEvent.ERROR, handleHdiutilHelperError); |
| |
| var attachedDmg:File = new File(hdiutilHelper.mountPoint); |
| var files:Array = attachedDmg.getDirectoryListing(); |
| |
| if (files.length == 1) |
| { |
| var installFileFolder:File = File(files[0]).resolvePath("Contents/MacOS"); |
| var installFiles:Array = installFileFolder.getDirectoryListing(); |
| |
| if (installFiles.length == 1) |
| { |
| installFromFile(installFiles[0]); |
| } |
| else |
| dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, |
| "Contents/MacOS folder should contain only 1 install file!")); |
| } |
| else |
| { |
| dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, |
| "Mounted volume should contain only 1 install file!")); |
| } |
| } |
| |
| private function handleHdiutilHelperError(event:ErrorEvent):void |
| { |
| var hdiutilHelper:HdiutilHelper = event.target as HdiutilHelper; |
| hdiutilHelper.removeEventListener(Event.COMPLETE, handleHdiutilHelperComplete); |
| hdiutilHelper.removeEventListener(ErrorEvent.ERROR, handleHdiutilHelperError); |
| |
| dispatchEvent(new ErrorEvent(ErrorEvent.ERROR, false, false, |
| "Error attaching dmg file!")); |
| } |
| |
| protected function handleDownloadProgress(event:ProgressEvent):void |
| { |
| var bytesTotal:int = event.bytesTotal; |
| var bytesLoaded:int = event.bytesLoaded; |
| var percentLoaded:int = Math.round(bytesLoaded*100/bytesTotal); |
| progressBar.percent = percentLoaded; |
| } |
| |
| |
| private function handleDownloadError(event:Event):void |
| { |
| Alert.show("Error downloading update file, try again later."); |
| } |
| |
| public function set latestVersion(value:String):void |
| { |
| _newVersion = value; |
| } |
| |
| private function writeFileToDirectory(file:File,data:ByteArray):void |
| { |
| var fs:FileStream = new FileStream(); |
| fs.open(file, FileMode.WRITE); |
| fs.writeBytes(data); |
| fs.close(); |
| } |
| |
| protected function handleNoBtnClick(event:MouseEvent):void |
| { |
| dispatchEvent(new CloseEvent(CloseEvent.CLOSE)); |
| } |
| |
| ]]></fx:Script> |
| |
| <s:states> |
| <s:State name="normal" /> |
| <s:State name="downloading" /> |
| </s:states> |
| |
| <s:HGroup width="100%" |
| top="210" |
| horizontalCenter="0" |
| verticalAlign="top"> |
| <s:VGroup width="100%" |
| horizontalAlign="center"> |
| <s:Label text="New version ({_newVersion}) is available." |
| fontSize="14"/> |
| <s:Label text="Do you want to download and install it?" |
| fontSize="14"/> |
| <controls:ProgressBar id="progressBar" |
| width="80%" |
| height="21" /> |
| <s:Spacer height="20" /> |
| <s:HGroup> |
| <s:Button id="btnYes" |
| height="30" |
| styleName="mainBtnStyle" |
| label="UPDATE" |
| click="handleYesBtnClick(event)" |
| enabled.downloading="false" /> |
| <s:Button id="btnNo" |
| height="30" |
| styleName="negativeBtnStyle" |
| label="DON'T UPDATE" |
| click="handleNoBtnClick(event)" |
| enabled.downloading="false" /> |
| </s:HGroup> |
| </s:VGroup> |
| </s:HGroup> |
| </s:TitleWindow> |