Use Flash native trace, handle Flash logs and pipe to terminal window

This commit is contained in:
Joshua Granick
2015-06-02 13:00:44 -07:00
parent 70840b0b9a
commit f33eede96a
3 changed files with 142 additions and 3 deletions

View File

@@ -47,6 +47,8 @@
<dependency path="dependencies/webgl-debug.js" if="html5 debug" />
<dependency path="dependencies/stats.min.js" if="html5 stats" />
<haxedef name="native-trace" if="flash" unless="haxe-trace || haxetrace" />
<architecture name="armv7" if="android" />
<haxedef name="lime-cairo" unless="flash || html5" />

View File

@@ -570,6 +570,29 @@ class FlashHelper {
}*/
public static function enableLogging ():Void {
try {
var path = switch (PlatformHelper.hostPlatform) {
case WINDOWS: Sys.getEnv ("HOMEDRIVE") + "/" + Sys.getEnv ("HOMEPATH") + "/mm.cfg";
case MAC: "/Library/Application Support/Macromedia/mm.cfg";
default: Sys.getEnv ("HOME") + "/mm.cfg";
}
if (!FileSystem.exists (path)) {
File.saveContent (path, "ErrorReportingEnable=1\nTraceOutputFileEnable=1\nMaxWarnings=50");
}
} catch (e:Dynamic) {}
}
private static function compileSWC (project:HXProject, assets:Array<Asset>, id:Int):Void {
#if format
@@ -874,6 +897,31 @@ class FlashHelper {
}
public static function getLogLength ():Int {
try {
var path = switch (PlatformHelper.hostPlatform) {
case WINDOWS: PathHelper.escape (Sys.getEnv ("APPDATA") + "/Macromedia/Flash Player/Logs/flashlog.txt");
case MAC: Sys.getEnv ("HOME") + "/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt";
default: Sys.getEnv ("HOME") + "/.macromedia/Flash_Player/Logs/flashlog.txt";
}
if (FileSystem.exists (path)) {
return FileSystem.stat (path).size;
}
} catch (e:Dynamic) { }
return 0;
}
private static function nextAssetID () {
return swfAssetID++;
@@ -903,5 +951,65 @@ class FlashHelper {
}
public static function tailLog (start:Int = 0):Void {
try {
var path = switch (PlatformHelper.hostPlatform) {
case WINDOWS: PathHelper.escape (Sys.getEnv ("APPDATA") + "/Macromedia/Flash Player/Logs/flashlog.txt");
case MAC: Sys.getEnv ("HOME") + "/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt";
default: Sys.getEnv ("HOME") + "/.macromedia/Flash_Player/Logs/flashlog.txt";
}
var position = start;
if (FileSystem.exists (path)) {
while (true) {
Sys.sleep (1);
var input = null;
try {
input = File.read (path, false);
input.seek (position, FileSeek.SeekBegin);
if (!input.eof ()) {
var bytes = input.readAll ();
position = input.tell ();
if (bytes.length > 0) {
Sys.print (bytes.getString (0, bytes.length));
}
}
input.close ();
} catch (e:Dynamic) {
if (input != null) {
input.close ();
}
}
}
}
} catch (e:Dynamic) {}
}
}

View File

@@ -24,6 +24,7 @@ class FlashPlatform extends PlatformTarget {
private var embedded:Bool;
private var logLength:Int;
public function new (command:String, _project:HXProject, targetFlags:Map <String, String>) {
@@ -194,6 +195,13 @@ class FlashPlatform extends PlatformTarget {
public override function run ():Void {
if (traceEnabled) {
FlashHelper.enableLogging ();
//logLength = FlashHelper.getLogLength ();
}
if (project.app.url != null && project.app.url != "") {
ProcessHelper.openURL (project.app.url);
@@ -209,7 +217,22 @@ class FlashPlatform extends PlatformTarget {
}
FlashHelper.run (project, destination, targetPath);
if (traceEnabled) {
neko.vm.Thread.create (function () {
FlashHelper.run (project, destination, targetPath);
Sys.exit (0);
});
Sys.sleep (0.1);
} else {
FlashHelper.run (project, destination, targetPath);
}
}
@@ -272,6 +295,13 @@ class FlashPlatform extends PlatformTarget {
}
public override function trace ():Void {
FlashHelper.tailLog (0);
}
/*private function getIcon (size:Int, targetPath:String):Void {
var icon = icons.findIcon (size, size);
@@ -291,7 +321,6 @@ class FlashPlatform extends PlatformTarget {
@ignore public override function install ():Void {}
@ignore public override function rebuild ():Void {}
@ignore public override function trace ():Void {}
@ignore public override function uninstall ():Void {}
}