Issue #707 Debugger for logging messages

This commit is contained in:
Jindra Petřík
2014-10-28 15:57:31 +01:00
parent 9a5361e8e3
commit 2746f3bc32
49 changed files with 1351 additions and 28 deletions

View File

@@ -0,0 +1,67 @@
package com.jpexs.decompiler.flash.debugger {
import flash.net.Socket;
import flash.utils.ByteArray;
import flash.events.Event;
import flash.display.Sprite;
public class DebugConnection {
private static var s:Socket;
private static var q = [];
private static var first:Boolean = true;
private static var inited:Boolean = false;
private static var name:String;
private static function sendQueue(){
var qo = q;
q = [];
for each(var m in qo){
writeMsg(m);
}
}
private static function writeString(msg){
var b:ByteArray = new ByteArray();
b.writeUTFBytes(msg);
s.writeByte(b.length);
s.writeBytes(b,0,b.length);
}
public static function initClient(sname){
if(inited){
return;
}
name = sname;
inited = true;
s = new Socket();
s.addEventListener(Event.CONNECT, function(){
sendQueue();
});
var port:int = 0;
port = 123456;
s.connect("localhost",port);
inited = true;
}
public static function writeMsg(msg){
if(!inited){
initClient("");
}
if(s.connected){
if(first){
s.writeByte(0);
writeString(name);
first = false;
}
writeString(msg);
}else{
q.push(msg);
}
}
}
}

View File

@@ -0,0 +1,17 @@
package com.jpexs.decompiler.flash.debugger {
import flash.display.MovieClip;
public class DebugMain extends MovieClip {
public function DebugMain() {
debugAlert("test alert");
debugConsole("test console");
debugSocket("test proxy");
debugTrace("test trace");
}
}
}

View File

@@ -0,0 +1,11 @@
package com.jpexs.decompiler.flash.debugger {
import flash.external.ExternalInterface;
public function debugAlert(msg):*{
if(ExternalInterface.available)
ExternalInterface.call("alert",""+msg);
return msg;
}
}

View File

@@ -0,0 +1,11 @@
package com.jpexs.decompiler.flash.debugger {
import flash.external.ExternalInterface;
public function debugConsole(msg):*{
if(ExternalInterface.available)
ExternalInterface.call("console.log",""+msg);
return msg;
}
}

View File

@@ -0,0 +1,8 @@
package com.jpexs.decompiler.flash.debugger {
public function debugInit(name){
DebugConnection.iniClient(name);
}
}

View File

@@ -0,0 +1,13 @@
package com.jpexs.decompiler.flash.debugger {
import flash.system.Capabilities;
public function debugSocket(msg):*{
//only on webpages or activex
if(Capabilities.playerType == 'PlugIn'
|| Capabilities.playerType == 'ActiveX'){
DebugConnection.writeMsg(msg);
}
return msg;
}
}

View File

@@ -0,0 +1,9 @@
package com.jpexs.decompiler.flash.debugger {
public function debugTrace(name){
debugConsole(name);
debugSocket(name);
}
}