Skip to content

Commit

Permalink
Testing symlink fixes (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
rat-moonshine committed Jul 20, 2021
1 parent f037c0d commit abdc4be
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ApacheFlexSDKInstallerLib/src/InstallApacheFlex.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -2587,7 +2587,7 @@ variables are not required because the locations of these pieces are known.
completeHandler(null);
}
}
private function progressEventHandler(event:ProgressEvent):void
{
if (logProgressEvents)
Expand Down
Binary file modified MoonshineSDKInstaller/libs/ApacheFlexSDKInstallerLib.swc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package actionScripts.utils
{
import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.NativeProcessExitEvent;
import flash.events.ProgressEvent;
import flash.filesystem.File;
import flash.utils.Dictionary;
import flash.utils.IDataInput;

public class HarmanInstallerSymlinkFix extends EventDispatcher
{
public static const EVENT_ANT_SCRIPT_GENERATED:String = "eventAntScriptFileGenerated";

private static const LIST_STATIC_SYMLINKS:String = "runtimes/air-captive/mac/Adobe AIR.framework/Adobe AIR -> Versions/Current/Adobe AIR\n" +
"runtimes/air-captive/mac/Adobe AIR.framework/Versions/1.0/Adobe AIR_64 -> Adobe AIR\n" +
"runtimes/air-captive/mac/Adobe AIR.framework/Versions/Current -> 1.0\n" +
"runtimes/air-captive/mac/Adobe AIR.framework/Resources -> Versions/Current/Resources\n" +
"runtimes/air/mac/Adobe AIR.framework/Adobe AIR -> Versions/Current/Adobe AIR\n" +
"runtimes/air/mac/Adobe AIR.framework/Versions/1.0/Adobe AIR_64 -> Adobe AIR\n" +
"runtimes/air/mac/Adobe AIR.framework/Versions/Current -> 1.0\n" +
"runtimes/air/mac/Adobe AIR.framework/Headers -> Versions/Current/Headers\n" +
"runtimes/air/mac/Adobe AIR.framework/Resources -> Versions/Current/Resources";

private var baseDirectory:File;
private var customProcess:NativeProcess;
private var symlinkPairs:Dictionary;
private var queue:Vector.<String> = new Vector.<String>();

private var _antScriptPath:File;
public function get antScriptPath():File
{
return _antScriptPath;
}

public function HarmanInstallerSymlinkFix()
{
}

public function runCheck(baseDirectory:File):void
{
this.baseDirectory = baseDirectory;
symlinkPairs = new Dictionary();

var tmpLines:Array = LIST_STATIC_SYMLINKS.split("\n");
var tmpLine:Array;
for each (var line:String in tmpLines)
{
tmpLine = line.split(" -> ");
if (tmpLine.length > 1)
{
symlinkPairs[tmpLine[0]] = tmpLine[1];
}
}

generateNewSymlinkFiles();
}

private function flush():void
{
if (queue.length == 0) return;

var npInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
npInfo.executable = File.documentsDirectory.resolvePath("/bin/bash");

npInfo.arguments = Vector.<String>(["-c", queue.shift()]);
npInfo.workingDirectory = this.baseDirectory;

startShell(true);
customProcess.start(npInfo);
}

private function startShell(start:Boolean):void
{
if (start)
{
customProcess = new NativeProcess();
customProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, shellData);
customProcess.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, shellError);
customProcess.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, shellError);
customProcess.addEventListener(NativeProcessExitEvent.EXIT, shellExit);
}
else
{
if (!customProcess) return;
if (customProcess.running) customProcess.exit();
customProcess.removeEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, shellData);
customProcess.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA, shellData);
customProcess.removeEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, shellError);
customProcess.removeEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, shellError);
customProcess.removeEventListener(NativeProcessExitEvent.EXIT, shellExit);
customProcess = null;
}
}

private function shellData(event:ProgressEvent):void
{
//var output:IDataInput = (customProcess.standardOutput.bytesAvailable != 0) ? customProcess.standardOutput : customProcess.standardError;
//var data:String = output.readUTFBytes(output.bytesAvailable);
}

private function shellError(event:ProgressEvent):void
{
if (customProcess)
{
var output:IDataInput = customProcess.standardError;
var data:String = output.readUTFBytes(output.bytesAvailable).toLowerCase();

trace(data);
dispose();
}
}

private function shellExit(e:NativeProcessExitEvent):void
{
if (customProcess)
{
dispose();
}
}

private function dispose():void
{
startShell(false);
flush();
}

private function generateNewSymlinkFiles():void
{
var symlinkFilePath:File;
for (var key:String in symlinkPairs)
{
symlinkFilePath = baseDirectory.resolvePath(key);
// delete existing symlink
queue.push('rm "'+ symlinkFilePath.nativePath +'"');
// generate new symlink
queue.push('ln -s "'+ symlinkFilePath.parent.resolvePath(symlinkPairs[key]).nativePath +'" "'+ symlinkFilePath.nativePath +'"');
}

flush();
dispatchEvent(new Event(EVENT_ANT_SCRIPT_GENERATED));
}
}
}
26 changes: 20 additions & 6 deletions MoonshineSDKInstaller/src/components/HelperInstaller.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
horizontalAlign="center" gap="0">
<fx:Script>
<![CDATA[
import flash.utils.clearTimeout;
import actionScripts.utils.HarmanInstallerSymlinkFix;
import flash.utils.clearTimeout;
import flash.utils.setTimeout;
import mx.events.FlexEvent;
Expand Down Expand Up @@ -397,11 +399,23 @@
flexConfigContent = flexConfigContent.replace(/<swf-version>43<\/swf-version>/g, "<swf-version>44</swf-version>");
FileUtils.writeToFile(flexConfig, flexConfigContent);
flexConfig = installFolder.resolvePath("frameworks/air-config.xml");
flexConfigContent = FileUtils.readFromFile(flexConfig) as String;
flexConfigContent = flexConfigContent.replace(/<target-player>28.0<\/target-player>/g, "<target-player>33.1</target-player>");
flexConfigContent = flexConfigContent.replace(/<swf-version>43<\/swf-version>/g, "<swf-version>44</swf-version>");
FileUtils.writeToFile(flexConfig, flexConfigContent);
if (HelperConstants.IS_MACOS && !isHarmanAIRDownloading)
{
isHarmanAIRDownloading = true;
itemDownloading.isDownloaded = false;
itemDownloading.isDownloading = true;
var symLinkFix:HarmanInstallerSymlinkFix = new HarmanInstallerSymlinkFix();
symLinkFix.addEventListener(HarmanInstallerSymlinkFix.EVENT_ANT_SCRIPT_GENERATED, onAntScriptFileGenerated);
symLinkFix.runCheck(installFolder);
function onAntScriptFileGenerated(symLinkEvent:Event):void
{
symLinkEvent.target.removeEventListener(HarmanInstallerSymlinkFix.EVENT_ANT_SCRIPT_GENERATED, onAntScriptFileGenerated);
flushDownloadQueue();
}
return;
}
}
/*if (itemDownloading.type == ComponentTypes.TYPE_FLEX_HARMAN && !isHarmanAIRDownloading)
Expand Down

0 comments on commit abdc4be

Please sign in to comment.