diff --git a/.gitignore b/.gitignore index dc1c293..6a51108 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ GraphicExport.app/ *.p12 *.airi +air*.tmp diff --git a/.gitignore b/.gitignore index dc1c293..6a51108 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ GraphicExport.app/ *.p12 *.airi +air*.tmp diff --git a/GraphicExport.as b/GraphicExport.as index c3586c2..45c7a03 100644 --- a/GraphicExport.as +++ b/GraphicExport.as @@ -13,6 +13,7 @@ import flash.display.StageAlign; import flash.display.StageScaleMode; import com.adobe.crypto.MD5; + import flash.system.fscommand; import flash.desktop.*; import djarts.core.*; @@ -110,14 +111,36 @@ private function WrapperData(e:ProgressEvent) { var data:String = wrapper.readUTF(); - DispatchCommand(data); - _strace("done"); + DispatchCommand(com.adobe.serialization.json.JSON.decode(data)); + SendCommand({command:"done"}); } - private function DispatchCommand(command) + private function DispatchCommand(msg) { - Log("Wrapper Command: " + command); - _strace("executing: " + command); + if (msg.hasOwnProperty("command")) + { + var cmd = msg.command; + switch (cmd) + { + case "quit": + Log("Quitting"); + fscommand("quit"); + NativeApplication.nativeApplication.exit(); + break; + default: + Log("Sent command: " + com.adobe.serialization.json.JSON.encode(msg)); + break; + } + } + } + + public static function SendCommand(obj) + { + if (wrapper != null) + { + wrapper.writeUTF(com.adobe.serialization.json.JSON.encode(obj)); + wrapper.flush(); + } } private function ConnectWrapper(port) diff --git a/.gitignore b/.gitignore index dc1c293..6a51108 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ GraphicExport.app/ *.p12 *.airi +air*.tmp diff --git a/GraphicExport.as b/GraphicExport.as index c3586c2..45c7a03 100644 --- a/GraphicExport.as +++ b/GraphicExport.as @@ -13,6 +13,7 @@ import flash.display.StageAlign; import flash.display.StageScaleMode; import com.adobe.crypto.MD5; + import flash.system.fscommand; import flash.desktop.*; import djarts.core.*; @@ -110,14 +111,36 @@ private function WrapperData(e:ProgressEvent) { var data:String = wrapper.readUTF(); - DispatchCommand(data); - _strace("done"); + DispatchCommand(com.adobe.serialization.json.JSON.decode(data)); + SendCommand({command:"done"}); } - private function DispatchCommand(command) + private function DispatchCommand(msg) { - Log("Wrapper Command: " + command); - _strace("executing: " + command); + if (msg.hasOwnProperty("command")) + { + var cmd = msg.command; + switch (cmd) + { + case "quit": + Log("Quitting"); + fscommand("quit"); + NativeApplication.nativeApplication.exit(); + break; + default: + Log("Sent command: " + com.adobe.serialization.json.JSON.encode(msg)); + break; + } + } + } + + public static function SendCommand(obj) + { + if (wrapper != null) + { + wrapper.writeUTF(com.adobe.serialization.json.JSON.encode(obj)); + wrapper.flush(); + } } private function ConnectWrapper(port) diff --git a/GraphicExport.exe b/GraphicExport.exe index 0f1c480..e0c5e49 100755 --- a/GraphicExport.exe +++ b/GraphicExport.exe Binary files differ diff --git a/.gitignore b/.gitignore index dc1c293..6a51108 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ GraphicExport.app/ *.p12 *.airi +air*.tmp diff --git a/GraphicExport.as b/GraphicExport.as index c3586c2..45c7a03 100644 --- a/GraphicExport.as +++ b/GraphicExport.as @@ -13,6 +13,7 @@ import flash.display.StageAlign; import flash.display.StageScaleMode; import com.adobe.crypto.MD5; + import flash.system.fscommand; import flash.desktop.*; import djarts.core.*; @@ -110,14 +111,36 @@ private function WrapperData(e:ProgressEvent) { var data:String = wrapper.readUTF(); - DispatchCommand(data); - _strace("done"); + DispatchCommand(com.adobe.serialization.json.JSON.decode(data)); + SendCommand({command:"done"}); } - private function DispatchCommand(command) + private function DispatchCommand(msg) { - Log("Wrapper Command: " + command); - _strace("executing: " + command); + if (msg.hasOwnProperty("command")) + { + var cmd = msg.command; + switch (cmd) + { + case "quit": + Log("Quitting"); + fscommand("quit"); + NativeApplication.nativeApplication.exit(); + break; + default: + Log("Sent command: " + com.adobe.serialization.json.JSON.encode(msg)); + break; + } + } + } + + public static function SendCommand(obj) + { + if (wrapper != null) + { + wrapper.writeUTF(com.adobe.serialization.json.JSON.encode(obj)); + wrapper.flush(); + } } private function ConnectWrapper(port) diff --git a/GraphicExport.exe b/GraphicExport.exe index 0f1c480..e0c5e49 100755 --- a/GraphicExport.exe +++ b/GraphicExport.exe Binary files differ diff --git a/GraphicExport.fla b/GraphicExport.fla index 1bfaa36..0b78ed7 100755 --- a/GraphicExport.fla +++ b/GraphicExport.fla Binary files differ diff --git a/.gitignore b/.gitignore index dc1c293..6a51108 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ GraphicExport.app/ *.p12 *.airi +air*.tmp diff --git a/GraphicExport.as b/GraphicExport.as index c3586c2..45c7a03 100644 --- a/GraphicExport.as +++ b/GraphicExport.as @@ -13,6 +13,7 @@ import flash.display.StageAlign; import flash.display.StageScaleMode; import com.adobe.crypto.MD5; + import flash.system.fscommand; import flash.desktop.*; import djarts.core.*; @@ -110,14 +111,36 @@ private function WrapperData(e:ProgressEvent) { var data:String = wrapper.readUTF(); - DispatchCommand(data); - _strace("done"); + DispatchCommand(com.adobe.serialization.json.JSON.decode(data)); + SendCommand({command:"done"}); } - private function DispatchCommand(command) + private function DispatchCommand(msg) { - Log("Wrapper Command: " + command); - _strace("executing: " + command); + if (msg.hasOwnProperty("command")) + { + var cmd = msg.command; + switch (cmd) + { + case "quit": + Log("Quitting"); + fscommand("quit"); + NativeApplication.nativeApplication.exit(); + break; + default: + Log("Sent command: " + com.adobe.serialization.json.JSON.encode(msg)); + break; + } + } + } + + public static function SendCommand(obj) + { + if (wrapper != null) + { + wrapper.writeUTF(com.adobe.serialization.json.JSON.encode(obj)); + wrapper.flush(); + } } private function ConnectWrapper(port) diff --git a/GraphicExport.exe b/GraphicExport.exe index 0f1c480..e0c5e49 100755 --- a/GraphicExport.exe +++ b/GraphicExport.exe Binary files differ diff --git a/GraphicExport.fla b/GraphicExport.fla index 1bfaa36..0b78ed7 100755 --- a/GraphicExport.fla +++ b/GraphicExport.fla Binary files differ diff --git a/GraphicExport.swf b/GraphicExport.swf index 285d862..bbd1a5d 100644 --- a/GraphicExport.swf +++ b/GraphicExport.swf Binary files differ diff --git a/.gitignore b/.gitignore index dc1c293..6a51108 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ GraphicExport.app/ *.p12 *.airi +air*.tmp diff --git a/GraphicExport.as b/GraphicExport.as index c3586c2..45c7a03 100644 --- a/GraphicExport.as +++ b/GraphicExport.as @@ -13,6 +13,7 @@ import flash.display.StageAlign; import flash.display.StageScaleMode; import com.adobe.crypto.MD5; + import flash.system.fscommand; import flash.desktop.*; import djarts.core.*; @@ -110,14 +111,36 @@ private function WrapperData(e:ProgressEvent) { var data:String = wrapper.readUTF(); - DispatchCommand(data); - _strace("done"); + DispatchCommand(com.adobe.serialization.json.JSON.decode(data)); + SendCommand({command:"done"}); } - private function DispatchCommand(command) + private function DispatchCommand(msg) { - Log("Wrapper Command: " + command); - _strace("executing: " + command); + if (msg.hasOwnProperty("command")) + { + var cmd = msg.command; + switch (cmd) + { + case "quit": + Log("Quitting"); + fscommand("quit"); + NativeApplication.nativeApplication.exit(); + break; + default: + Log("Sent command: " + com.adobe.serialization.json.JSON.encode(msg)); + break; + } + } + } + + public static function SendCommand(obj) + { + if (wrapper != null) + { + wrapper.writeUTF(com.adobe.serialization.json.JSON.encode(obj)); + wrapper.flush(); + } } private function ConnectWrapper(port) diff --git a/GraphicExport.exe b/GraphicExport.exe index 0f1c480..e0c5e49 100755 --- a/GraphicExport.exe +++ b/GraphicExport.exe Binary files differ diff --git a/GraphicExport.fla b/GraphicExport.fla index 1bfaa36..0b78ed7 100755 --- a/GraphicExport.fla +++ b/GraphicExport.fla Binary files differ diff --git a/GraphicExport.swf b/GraphicExport.swf index 285d862..bbd1a5d 100644 --- a/GraphicExport.swf +++ b/GraphicExport.swf Binary files differ diff --git a/_strace.as b/_strace.as index e2270cd..d2d2d0d 100644 --- a/_strace.as +++ b/_strace.as @@ -5,8 +5,7 @@ _trace(str); if (GraphicExport.wrapper != null) { - GraphicExport.wrapper.writeUTFBytes(str + "\n"); - GraphicExport.wrapper.flush(); + GraphicExport.SendCommand({command:"print",string:str + "\n"}); } } } \ No newline at end of file diff --git a/.gitignore b/.gitignore index dc1c293..6a51108 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ GraphicExport.app/ *.p12 *.airi +air*.tmp diff --git a/GraphicExport.as b/GraphicExport.as index c3586c2..45c7a03 100644 --- a/GraphicExport.as +++ b/GraphicExport.as @@ -13,6 +13,7 @@ import flash.display.StageAlign; import flash.display.StageScaleMode; import com.adobe.crypto.MD5; + import flash.system.fscommand; import flash.desktop.*; import djarts.core.*; @@ -110,14 +111,36 @@ private function WrapperData(e:ProgressEvent) { var data:String = wrapper.readUTF(); - DispatchCommand(data); - _strace("done"); + DispatchCommand(com.adobe.serialization.json.JSON.decode(data)); + SendCommand({command:"done"}); } - private function DispatchCommand(command) + private function DispatchCommand(msg) { - Log("Wrapper Command: " + command); - _strace("executing: " + command); + if (msg.hasOwnProperty("command")) + { + var cmd = msg.command; + switch (cmd) + { + case "quit": + Log("Quitting"); + fscommand("quit"); + NativeApplication.nativeApplication.exit(); + break; + default: + Log("Sent command: " + com.adobe.serialization.json.JSON.encode(msg)); + break; + } + } + } + + public static function SendCommand(obj) + { + if (wrapper != null) + { + wrapper.writeUTF(com.adobe.serialization.json.JSON.encode(obj)); + wrapper.flush(); + } } private function ConnectWrapper(port) diff --git a/GraphicExport.exe b/GraphicExport.exe index 0f1c480..e0c5e49 100755 --- a/GraphicExport.exe +++ b/GraphicExport.exe Binary files differ diff --git a/GraphicExport.fla b/GraphicExport.fla index 1bfaa36..0b78ed7 100755 --- a/GraphicExport.fla +++ b/GraphicExport.fla Binary files differ diff --git a/GraphicExport.swf b/GraphicExport.swf index 285d862..bbd1a5d 100644 --- a/GraphicExport.swf +++ b/GraphicExport.swf Binary files differ diff --git a/_strace.as b/_strace.as index e2270cd..d2d2d0d 100644 --- a/_strace.as +++ b/_strace.as @@ -5,8 +5,7 @@ _trace(str); if (GraphicExport.wrapper != null) { - GraphicExport.wrapper.writeUTFBytes(str + "\n"); - GraphicExport.wrapper.flush(); + GraphicExport.SendCommand({command:"print",string:str + "\n"}); } } } \ No newline at end of file diff --git a/exporter.py b/exporter.py index f223b1d..3bcd3c0 100755 --- a/exporter.py +++ b/exporter.py @@ -130,11 +130,15 @@ def send_cmd(conn, base_cmd, in_file): cmd = dict(base_cmd) cmd["input"] = in_file - data = json.dumps(cmd) + send_msg(conn, cmd) + +def send_msg(conn, msg): + data = json.dumps(msg) datalen = struct.pack(">H", len(data)) conn.send(datalen) conn.send(data) + conn = None while conn is None and g.returncode is None: try: @@ -160,16 +164,30 @@ for i in args["input"]: send_cmd(conn, base_cmd, i) +def handle_command(msg_str): + global quit + msg = json.loads(msg_str) + if "command" in msg: + cmd = msg["command"] + if cmd == "done": + quit = True + if cmd == "print" and "string" in msg: + sys.stdout.write(msg["string"]) + sys.stdout.flush() + +buf = "" quit = False while g.returncode is None: try: d = conn.recv(4096) if len(d): - if d.strip() == "done": - quit = True - else: - sys.stdout.write(d) - sys.stdout.flush() + buf += d + if len(buf) >= 2: + buf_len = struct.unpack_from(">H", buf, 0)[0] + if len(buf) >= 2 + buf_len: + msg = buf[2:2+buf_len] + buf = buf[2+buf_len:] + handle_command(msg) except socket.error, e: if e.args[0] == errno.EWOULDBLOCK or e.args[0] == errno.EAGAIN: pass @@ -190,6 +208,7 @@ for i in line_args["input"]: send_cmd(conn, base_cmd, i) if quit: + send_msg(conn, {"command":"quit"}) conn.close() s.close() g.kill()