Skip to content

Commit d7e8029

Browse files
committed
AqcuireProductService: better handling of zip files for Windows that should fix freezing bug
1 parent 4ce131f commit d7e8029

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

source/services/AcquireProductService.as

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ package services
2323

2424
import flash.desktop.NativeProcess;
2525
import flash.desktop.NativeProcessStartupInfo;
26-
import flash.events.ErrorEvent;
2726
import flash.events.Event;
2827
import flash.events.IOErrorEvent;
2928
import flash.events.NativeProcessExitEvent;
@@ -38,18 +37,19 @@ package services
3837
import flash.system.Capabilities;
3938
import flash.utils.ByteArray;
4039

41-
import model.SDKManagerModel;
4240
import model.ProductConfigurationItem;
41+
import model.SDKManagerModel;
4342

4443
import org.as3commons.zip.Zip;
44+
import org.as3commons.zip.ZipErrorEvent;
4545
import org.as3commons.zip.ZipEvent;
4646
import org.as3commons.zip.ZipFile;
4747
import org.robotlegs.starling.mvcs.Actor;
4848

4949
import starling.events.Event;
5050

5151
public class AcquireProductService extends Actor implements IAcquireProductService
52-
{
52+
{
5353
private static const ACQUISITION_IN_PROGRESS_ERROR:String = "Downloading the Feathers SDK failed. A download is already in progress.";
5454
private static const NO_PRODUCT_SELECTED_ERROR:String = "Downloading the Feathers SDK failed. No version of the Feathers SDK is selected.";
5555
private static const NOT_FOUND_ON_SERVER_ERROR:String = "Downloading the Feathers SDK failed. The binary distribution was not found on the server.";
@@ -222,7 +222,7 @@ package services
222222
this._zip.close();
223223
this._zip.removeEventListener(ZipEvent.FILE_LOADED, onFileLoaded);
224224
this._zip.removeEventListener(flash.events.Event.COMPLETE, decompress_completeHandler);
225-
this._zip.removeEventListener(ErrorEvent.ERROR, decompress_errorHandler);
225+
this._zip.removeEventListener(ZipErrorEvent.PARSE_ERROR, decompress_errorHandler);
226226
this._zip = null;
227227
}
228228
if(this._process)
@@ -262,8 +262,20 @@ package services
262262

263263
this._zip.addEventListener(ZipEvent.FILE_LOADED, onFileLoaded, false, 0, true);
264264
this._zip.addEventListener(flash.events.Event.COMPLETE, decompress_completeHandler, false, 0, true);
265-
this._zip.addEventListener(ErrorEvent.ERROR, decompress_errorHandler, false, 0, true);
266-
this._zip.loadBytes(zipFileBytes);
265+
this._zip.addEventListener(ZipErrorEvent.PARSE_ERROR, decompress_errorHandler, false, 0, true);
266+
try
267+
{
268+
//I discovered that an error can be thrown during loadBytes()
269+
//where ZipErrorEvent.PARSE_ERROR is not dispatched
270+
this._zip.loadBytes(zipFileBytes);
271+
}
272+
catch(error:Error)
273+
{
274+
this.cleanup();
275+
this.sdkManagerModel.log(DECOMPRESS_ERROR);
276+
this.dispatchWith(AcquireProductServiceEventType.ERROR, false, DECOMPRESS_ERROR);
277+
return;
278+
}
267279
}
268280

269281
private function onFileLoaded(e:ZipEvent):void
@@ -366,6 +378,8 @@ package services
366378
this.dispatchWith(AcquireProductServiceEventType.COMPLETE);
367379
}
368380

381+
//this listener is used for both unzip and untar, so the event types are
382+
//different, but they both extend from flash.events.Event
369383
private function decompress_errorHandler(event:flash.events.Event):void
370384
{
371385
this.cleanup();

0 commit comments

Comments
 (0)