[r11]: trunk / SWFInvestigator / src / updateManager / AirFileUpdater.as  Maximize  Restore  History

Download this file

183 lines (161 with data), 5.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/****************************************************************************
* ADOBE SYSTEMS INCORPORATED
* Copyright 2012 Adobe Systems Incorporated and it’s licensors
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file
* in accordance with the terms of the license agreement accompanying it.
* ****************************************************************************/
package updateManager
{
import air.update.ApplicationUpdaterUI;
import air.update.events.UpdateEvent;
import air.update.events.StatusUpdateEvent;
import air.update.events.DownloadErrorEvent;
import air.update.events.StatusUpdateErrorEvent;
import flash.events.ErrorEvent;
import flash.filesystem.File;
import mx.controls.Alert;
public class AirFileUpdater implements IUpdater
{
private var appUpdater:ApplicationUpdaterUI;
private var manualUpdate:Boolean;
private var configFile:String;
/**
* @public
* This constructor will load the config file necessary for the AirFileUpdater.
*
* @param configFile A string showing the path of the config file relative to the app: directory
*/
public function AirFileUpdater(confFile:String)
{
if (confFile != null) {
this.configFile = confFile;
}
var config:File = File.applicationDirectory.resolvePath(configFile);
this.appUpdater = new ApplicationUpdaterUI();
this.appUpdater.configurationFile = config;
this.appUpdater.isNewerVersionFunction = isNewerFunction;
this.appUpdater.addEventListener(UpdateEvent.INITIALIZED, onUpdate);
this.appUpdater.addEventListener(ErrorEvent.ERROR, onError);
this.appUpdater.addEventListener(StatusUpdateErrorEvent.UPDATE_ERROR, statusError);
this.appUpdater.addEventListener(DownloadErrorEvent.DOWNLOAD_ERROR, downloadError);
this.appUpdater.addEventListener(StatusUpdateEvent.UPDATE_STATUS, statusUpdate);
}
/**
* @private
* Compares versions to see if there is a newer version available.
* Assumes version is in X.Y.Z format where X,Y and Z are numbers
*
* @param currentVersion A string representing the current version
* @param updateVersion A string represneting the updated version
* @return True if there is a newer version, false if the data is bad or it is not new
*/
private function isNewerFunction(currentVersion:String, updateVersion:String):Boolean
{
var curNums:Array = currentVersion.split(".");
var updateNums:Array = updateVersion.split(".");
if (updateNums == null || updateNums.length != 3) {
return false;
}
var testNum:Number = parseInt(updateNums[0]);
var curNum:Number = parseInt(curNums[0]);
if (isNaN(testNum)) {
return false;
} else if (curNum > testNum) {
return false;
}
testNum = parseInt(updateNums[1]);
curNum = parseInt(curNums[1]);
if (isNaN(testNum)) {
return false;
} else if (curNum > testNum) {
return false;
}
testNum = parseInt(updateNums[2]);
curNum = parseInt(curNums[2]);
if (isNaN(testNum)) {
return false;
} else if (curNum >= testNum) {
return false;
}
return true;
}
/**
* @public
* Initialize the application updater
*/
public function initialize():void {
this.appUpdater.initialize();
}
/**
* @public
* Check for new AIR file updates.
* If this is user initiated, then the system will show error messages.
*
* @param userInitiated Indicates whether this is a user initiated check
*/
public function checkForUpdates(userInitiated:Boolean):void {
this.manualUpdate = userInitiated;
if (userInitiated) {
this.appUpdater.cancelUpdate();
}
this.appUpdater.checkNow();
}
/**
* @private
* Once the application updater is initialized, we can check for the update
*
* @param event The UpdateEvent.INITIALIZED event
*/
private function onUpdate(event:UpdateEvent):void {
if (this.manualUpdate) {
this.appUpdater.checkNow();
}
}
/**
* @private
* This listens for StatusUpdateEvent update errors
*
* @param event The StatusUpdateEvent error event
*/
private function statusUpdate(event:StatusUpdateEvent):void {
if (this.manualUpdate && event.available == false) {
mx.controls.Alert.show("There is no update available","Sorry");
}
}
/**
* @private
* This error handler will display errors if it is a manual update
*
* @param event The EVENT.ErrorEvent from the updater
*/
private function onError(event:ErrorEvent):void {
if (this.manualUpdate) {
mx.controls.Alert.show("There was an error in the update process:\n\n" + event.toString(),"Update Error");
}
}
/**
* @private
* This listens for StatusUpdateErrorEvent update errors
*
* @param event The StatusUpdateErrorEvent error event
*/
private function statusError(event:StatusUpdateErrorEvent):void {
if (this.manualUpdate) {
mx.controls.Alert.show("Update failed: Could not download or parse the server's update descriptor file.","Sorry");
}
}
/**
* @private
* This listens for DownloadErrorEvent update errors
*
* @param event The DownloadErrorEvent error event
*/
private function downloadError(event:DownloadErrorEvent):void {
if (this.manualUpdate) {
mx.controls.Alert.show("A download error occurred: " + event.errorID,"Sorry");
}
}
}
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks