Skip to content

Commit

Permalink
AqcuireProductService: better handling of zip files for Windows that …
Browse files Browse the repository at this point in the history
…should fix freezing bug
  • Loading branch information
joshtynjala committed Jun 16, 2016
1 parent 4ce131f commit d7e8029
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions source/services/AcquireProductService.as
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package services

import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.NativeProcessExitEvent;
Expand All @@ -38,18 +37,19 @@ package services
import flash.system.Capabilities;
import flash.utils.ByteArray;

import model.SDKManagerModel;
import model.ProductConfigurationItem;
import model.SDKManagerModel;

import org.as3commons.zip.Zip;
import org.as3commons.zip.ZipErrorEvent;
import org.as3commons.zip.ZipEvent;
import org.as3commons.zip.ZipFile;
import org.robotlegs.starling.mvcs.Actor;

import starling.events.Event;

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

this._zip.addEventListener(ZipEvent.FILE_LOADED, onFileLoaded, false, 0, true);
this._zip.addEventListener(flash.events.Event.COMPLETE, decompress_completeHandler, false, 0, true);
this._zip.addEventListener(ErrorEvent.ERROR, decompress_errorHandler, false, 0, true);
this._zip.loadBytes(zipFileBytes);
this._zip.addEventListener(ZipErrorEvent.PARSE_ERROR, decompress_errorHandler, false, 0, true);
try
{
//I discovered that an error can be thrown during loadBytes()
//where ZipErrorEvent.PARSE_ERROR is not dispatched
this._zip.loadBytes(zipFileBytes);
}
catch(error:Error)
{
this.cleanup();
this.sdkManagerModel.log(DECOMPRESS_ERROR);
this.dispatchWith(AcquireProductServiceEventType.ERROR, false, DECOMPRESS_ERROR);
return;
}
}

private function onFileLoaded(e:ZipEvent):void
Expand Down Expand Up @@ -366,6 +378,8 @@ package services
this.dispatchWith(AcquireProductServiceEventType.COMPLETE);
}

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

0 comments on commit d7e8029

Please sign in to comment.