This works for debugging, but fails for release builds, ironically because there is nothing to fix. This version works for both debugging and release. /** @param extensionID:String id of the ane extension to fix
* @param onExit:Function callback function with first arguments the value of extensionID and for the second the boolean state of the fix operation
**/
private function fixANE(extensionID:String, onExit:Function=null):Boolean
{ var error : Error = null;
var fileFailed : int = 0;
var fileFixed : int = 0;
try
{
if (!NativeProcess.isSupported) {
trace("Unsupported exit");
if (onExit!=null)
onExit(extensionID, false);
return false;
}
// init event listners
if (callback_output==null)
callback_output =
function(event:ProgressEvent):void {
var process:NativeProcess = event.target as NativeProcess;
trace("OUT -", process.standardOutput.readUTFBytes(process.standardError.bytesAvailable));
};
if (callback_error==null)
callback_error =
function(event:ProgressEvent):void {
var process:NativeProcess = event.target as NativeProcess;
trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable));
};
if (callback_ioerror==null)
callback_ioerror =
function(event:IOErrorEvent):void {
trace(event.toString());
};
var ext_dir:File;
try {
ext_dir = ExtensionContext.getExtensionDirectory(extensionID);
} catch (e:*) {
trace("GetExtensionDirectory error "+e);
if (onExit!=null)
onExit(extensionID, false);
return false;
}
if (!ext_dir.isDirectory) {
trace(ext_dir + "not isDirectory ")
if (onExit!=null)
onExit(extensionID, false);
return false;
}
var ane_dir:File = ext_dir.resolvePath("META-INF/ANE/");
var ext_stream:FileStream = new FileStream();
ext_stream.open(ane_dir.resolvePath("extension.xml"), FileMode.READ);
var ext_xml:XML = XML(ext_stream.readUTFBytes(ext_stream.bytesAvailable));
ext_stream.close();
var defaultNS:Namespace = ext_xml.namespace("");
var framework:String = ext_xml.defaultNS::platforms.defaultNS::platform.(@name=="MacOS-x86").defaultNS::applicationDeployment.defaultNS::nativeLibrary.text();
if (!framework) {
trace("No MacOS framework "+framework);
if (onExit!=null)
onExit(extensionID, false);
return false;
}
var framework_dir:File = ane_dir.resolvePath('MacOS-x86/'+framework);
// list of symlink files
var symlink:Vector. = new Vector.(3, true);
symlink[0] = 'Resources';
symlink[1] = framework_dir.name.substr(0, framework_dir.name.length-framework_dir.extension.length-1);
symlink[2] = 'Versions/Current';
var fileToFix:int = symlink.length;
symlink.every(
function(item:String, index:int, a:Vector.):Boolean {
var f:File = framework_dir.resolvePath(item);
if (!f.isSymbolicLink) {
var fs:FileStream = new FileStream();
fs.open(f, FileMode.READ);
var lnk:String = fs.readUTFBytes(fs.bytesAvailable);
fs.close();
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = new File('/bin/ln');
nativeProcessStartupInfo.workingDirectory = f.parent;
nativeProcessStartupInfo.arguments = new Vector.(3, true);
nativeProcessStartupInfo.arguments[0] = "-Fs";
nativeProcessStartupInfo.arguments[1] = lnk;
nativeProcessStartupInfo.arguments[2] = f.name;
var process:NativeProcess = new NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, callback_output);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, callback_error);
process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, callback_ioerror);
process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, callback_ioerror);
process.addEventListener(
NativeProcessExitEvent.EXIT,
function (event:NativeProcessExitEvent):void {
if (event.exitCode==0)
{ fileFixed++;
}
else
{ fileFailed++
}
}
);
} else
fileFixed++; // count as fixed if it doesn't appear to be in need of fixing
return true;
}
);
} // end of outer try
catch (err : *)
{ error = err;
trace("fixANE error "+err);
}
if (onExit!=null)
{onExit(extensionID, fileFailed==0 && (error==null));
}
return(true);
}
}
... View more