diff --git a/.gitignore b/.gitignore index 5ad0b9e..d264257 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.swp RECOVER*.fla GraphicExport.app/ +Exporter.app/ *.p12 *.airi air*.tmp diff --git a/.gitignore b/.gitignore index 5ad0b9e..d264257 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.swp RECOVER*.fla GraphicExport.app/ +Exporter.app/ *.p12 *.airi air*.tmp diff --git a/Exporter-app.xml b/Exporter-app.xml new file mode 100644 index 0000000..7deb7c5 --- /dev/null +++ b/Exporter-app.xml @@ -0,0 +1,38 @@ + + + + Exporter + 1.0 + Exporter + + Exporter + + + Exporter.swf + standard + false + true + false + portrait + auto + + + false + false + diff --git a/.gitignore b/.gitignore index 5ad0b9e..d264257 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.swp RECOVER*.fla GraphicExport.app/ +Exporter.app/ *.p12 *.airi air*.tmp diff --git a/Exporter-app.xml b/Exporter-app.xml new file mode 100644 index 0000000..7deb7c5 --- /dev/null +++ b/Exporter-app.xml @@ -0,0 +1,38 @@ + + + + Exporter + 1.0 + Exporter + + Exporter + + + Exporter.swf + standard + false + true + false + portrait + auto + + + false + false + diff --git a/Exporter.as b/Exporter.as new file mode 100644 index 0000000..7a2a149 --- /dev/null +++ b/Exporter.as @@ -0,0 +1,179 @@ +package +{ + import flash.display.*; + import flash.net.*; + import flash.events.*; + import flash.desktop.*; + import flash.errors.*; + import flash.system.*; + + public class Exporter extends MovieClip + { + public static var Instance:Exporter = null; + + public static var DefaultPort:int = 7890; + private var driver:Socket = null; + public function Exporter() + { + Instance = this; + + try + { + NativeApplication.nativeApplication.addEventListener("invoke", ApplicationInvoked); + } + catch (e) + { + // not an air runtime app + ConnectDriver(DefaultPort); // try default port + } + } + + public function ApplicationInvoked(e) + { + if (e.arguments.length == 1) + { + ConnectDriver(parseInt(e.arguments[0])); + } + else + { + ConnectDriver(DefaultPort); + } + } + + private function ConnectDriver(port) + { + Trace("Attempting to connect to driver"); + try + { + var s:Socket = new Socket(); + s.addEventListener(IOErrorEvent.IO_ERROR, DriverError); + s.addEventListener(Event.CONNECT, DriverConnected); + s.connect("localhost", port); + } + catch (e) + { + Trace("Error establishing wrapper connection"); + } + } + + private function DriverError(e) + { + Trace(" Failed to connect"); + } + + private function DriverConnected(e) + { + Trace(" Connected"); + driver = e.target as Socket; + driver.addEventListener(ProgressEvent.SOCKET_DATA, DriverRecv); + } + + private function Quit() + { + fscommand("quit"); + try + { + NativeApplication.nativeApplication.exit(); + } catch (e) + { + + } + } + + private function DispatchCommand(msg) + { + if (msg.hasOwnProperty("command")) + { + var cmd = "" + msg.command; + switch (cmd) + { + case "trace": + Trace(msg.command); + break; + case "quit": + Quit(); + break; + default: + Trace("Recv: " + JSON.stringify(msg)); + break; + } + } + } + + private function DriverRecv(e) + { + try + { + var cmd = driver.readUTF(); + DispatchCommand(JSON.parse(cmd)); + } + catch (e:EOFError) + { + // wait for more data + } + catch (e:IOError) + { + Trace("Driver IO error"); + } + catch (e) + { + Trace("Problem reading from driver"); + } + } + + private function DriverCommand(cmd:String, data = null) + { + var obj = {command:cmd}; + if (data != null) + { + for (var k in data) + { + obj[k] = data[k]; + } + } + DriverSend(JSON.stringify(obj)); + } + + private function DriverSend(str:String) + { + if (driver != null) + { + driver.writeUTF(str); + } + } + + public function Trace(str:String) + { + traceText.x = 2; + + trace(str); + traceText.width = stage.stageWidth - 4; + traceText.height = stage.stageHeight - 4; + if (traceText.text == "") + { + traceText.text = str; + } + else + { + traceText.appendText("\n" + str); + } + traceText.y = stage.height - traceText.textHeight - 2; + } + + public function Print(str:String, localTrace:Boolean = true) + { + if (localTrace || driver == null) + { + Trace(str); + } + else + { + trace(str); + } + if (driver != null) + { + DriverCommand("print", {string:str}); + } + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5ad0b9e..d264257 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.swp RECOVER*.fla GraphicExport.app/ +Exporter.app/ *.p12 *.airi air*.tmp diff --git a/Exporter-app.xml b/Exporter-app.xml new file mode 100644 index 0000000..7deb7c5 --- /dev/null +++ b/Exporter-app.xml @@ -0,0 +1,38 @@ + + + + Exporter + 1.0 + Exporter + + Exporter + + + Exporter.swf + standard + false + true + false + portrait + auto + + + false + false + diff --git a/Exporter.as b/Exporter.as new file mode 100644 index 0000000..7a2a149 --- /dev/null +++ b/Exporter.as @@ -0,0 +1,179 @@ +package +{ + import flash.display.*; + import flash.net.*; + import flash.events.*; + import flash.desktop.*; + import flash.errors.*; + import flash.system.*; + + public class Exporter extends MovieClip + { + public static var Instance:Exporter = null; + + public static var DefaultPort:int = 7890; + private var driver:Socket = null; + public function Exporter() + { + Instance = this; + + try + { + NativeApplication.nativeApplication.addEventListener("invoke", ApplicationInvoked); + } + catch (e) + { + // not an air runtime app + ConnectDriver(DefaultPort); // try default port + } + } + + public function ApplicationInvoked(e) + { + if (e.arguments.length == 1) + { + ConnectDriver(parseInt(e.arguments[0])); + } + else + { + ConnectDriver(DefaultPort); + } + } + + private function ConnectDriver(port) + { + Trace("Attempting to connect to driver"); + try + { + var s:Socket = new Socket(); + s.addEventListener(IOErrorEvent.IO_ERROR, DriverError); + s.addEventListener(Event.CONNECT, DriverConnected); + s.connect("localhost", port); + } + catch (e) + { + Trace("Error establishing wrapper connection"); + } + } + + private function DriverError(e) + { + Trace(" Failed to connect"); + } + + private function DriverConnected(e) + { + Trace(" Connected"); + driver = e.target as Socket; + driver.addEventListener(ProgressEvent.SOCKET_DATA, DriverRecv); + } + + private function Quit() + { + fscommand("quit"); + try + { + NativeApplication.nativeApplication.exit(); + } catch (e) + { + + } + } + + private function DispatchCommand(msg) + { + if (msg.hasOwnProperty("command")) + { + var cmd = "" + msg.command; + switch (cmd) + { + case "trace": + Trace(msg.command); + break; + case "quit": + Quit(); + break; + default: + Trace("Recv: " + JSON.stringify(msg)); + break; + } + } + } + + private function DriverRecv(e) + { + try + { + var cmd = driver.readUTF(); + DispatchCommand(JSON.parse(cmd)); + } + catch (e:EOFError) + { + // wait for more data + } + catch (e:IOError) + { + Trace("Driver IO error"); + } + catch (e) + { + Trace("Problem reading from driver"); + } + } + + private function DriverCommand(cmd:String, data = null) + { + var obj = {command:cmd}; + if (data != null) + { + for (var k in data) + { + obj[k] = data[k]; + } + } + DriverSend(JSON.stringify(obj)); + } + + private function DriverSend(str:String) + { + if (driver != null) + { + driver.writeUTF(str); + } + } + + public function Trace(str:String) + { + traceText.x = 2; + + trace(str); + traceText.width = stage.stageWidth - 4; + traceText.height = stage.stageHeight - 4; + if (traceText.text == "") + { + traceText.text = str; + } + else + { + traceText.appendText("\n" + str); + } + traceText.y = stage.height - traceText.textHeight - 2; + } + + public function Print(str:String, localTrace:Boolean = true) + { + if (localTrace || driver == null) + { + Trace(str); + } + else + { + trace(str); + } + if (driver != null) + { + DriverCommand("print", {string:str}); + } + } + } +} \ No newline at end of file diff --git a/Exporter.exe b/Exporter.exe new file mode 100644 index 0000000..829fdd0 --- /dev/null +++ b/Exporter.exe Binary files differ diff --git a/.gitignore b/.gitignore index 5ad0b9e..d264257 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.swp RECOVER*.fla GraphicExport.app/ +Exporter.app/ *.p12 *.airi air*.tmp diff --git a/Exporter-app.xml b/Exporter-app.xml new file mode 100644 index 0000000..7deb7c5 --- /dev/null +++ b/Exporter-app.xml @@ -0,0 +1,38 @@ + + + + Exporter + 1.0 + Exporter + + Exporter + + + Exporter.swf + standard + false + true + false + portrait + auto + + + false + false + diff --git a/Exporter.as b/Exporter.as new file mode 100644 index 0000000..7a2a149 --- /dev/null +++ b/Exporter.as @@ -0,0 +1,179 @@ +package +{ + import flash.display.*; + import flash.net.*; + import flash.events.*; + import flash.desktop.*; + import flash.errors.*; + import flash.system.*; + + public class Exporter extends MovieClip + { + public static var Instance:Exporter = null; + + public static var DefaultPort:int = 7890; + private var driver:Socket = null; + public function Exporter() + { + Instance = this; + + try + { + NativeApplication.nativeApplication.addEventListener("invoke", ApplicationInvoked); + } + catch (e) + { + // not an air runtime app + ConnectDriver(DefaultPort); // try default port + } + } + + public function ApplicationInvoked(e) + { + if (e.arguments.length == 1) + { + ConnectDriver(parseInt(e.arguments[0])); + } + else + { + ConnectDriver(DefaultPort); + } + } + + private function ConnectDriver(port) + { + Trace("Attempting to connect to driver"); + try + { + var s:Socket = new Socket(); + s.addEventListener(IOErrorEvent.IO_ERROR, DriverError); + s.addEventListener(Event.CONNECT, DriverConnected); + s.connect("localhost", port); + } + catch (e) + { + Trace("Error establishing wrapper connection"); + } + } + + private function DriverError(e) + { + Trace(" Failed to connect"); + } + + private function DriverConnected(e) + { + Trace(" Connected"); + driver = e.target as Socket; + driver.addEventListener(ProgressEvent.SOCKET_DATA, DriverRecv); + } + + private function Quit() + { + fscommand("quit"); + try + { + NativeApplication.nativeApplication.exit(); + } catch (e) + { + + } + } + + private function DispatchCommand(msg) + { + if (msg.hasOwnProperty("command")) + { + var cmd = "" + msg.command; + switch (cmd) + { + case "trace": + Trace(msg.command); + break; + case "quit": + Quit(); + break; + default: + Trace("Recv: " + JSON.stringify(msg)); + break; + } + } + } + + private function DriverRecv(e) + { + try + { + var cmd = driver.readUTF(); + DispatchCommand(JSON.parse(cmd)); + } + catch (e:EOFError) + { + // wait for more data + } + catch (e:IOError) + { + Trace("Driver IO error"); + } + catch (e) + { + Trace("Problem reading from driver"); + } + } + + private function DriverCommand(cmd:String, data = null) + { + var obj = {command:cmd}; + if (data != null) + { + for (var k in data) + { + obj[k] = data[k]; + } + } + DriverSend(JSON.stringify(obj)); + } + + private function DriverSend(str:String) + { + if (driver != null) + { + driver.writeUTF(str); + } + } + + public function Trace(str:String) + { + traceText.x = 2; + + trace(str); + traceText.width = stage.stageWidth - 4; + traceText.height = stage.stageHeight - 4; + if (traceText.text == "") + { + traceText.text = str; + } + else + { + traceText.appendText("\n" + str); + } + traceText.y = stage.height - traceText.textHeight - 2; + } + + public function Print(str:String, localTrace:Boolean = true) + { + if (localTrace || driver == null) + { + Trace(str); + } + else + { + trace(str); + } + if (driver != null) + { + DriverCommand("print", {string:str}); + } + } + } +} \ No newline at end of file diff --git a/Exporter.exe b/Exporter.exe new file mode 100644 index 0000000..829fdd0 --- /dev/null +++ b/Exporter.exe Binary files differ diff --git a/Exporter.fla b/Exporter.fla new file mode 100644 index 0000000..62c62d2 --- /dev/null +++ b/Exporter.fla Binary files differ diff --git a/.gitignore b/.gitignore index 5ad0b9e..d264257 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.swp RECOVER*.fla GraphicExport.app/ +Exporter.app/ *.p12 *.airi air*.tmp diff --git a/Exporter-app.xml b/Exporter-app.xml new file mode 100644 index 0000000..7deb7c5 --- /dev/null +++ b/Exporter-app.xml @@ -0,0 +1,38 @@ + + + + Exporter + 1.0 + Exporter + + Exporter + + + Exporter.swf + standard + false + true + false + portrait + auto + + + false + false + diff --git a/Exporter.as b/Exporter.as new file mode 100644 index 0000000..7a2a149 --- /dev/null +++ b/Exporter.as @@ -0,0 +1,179 @@ +package +{ + import flash.display.*; + import flash.net.*; + import flash.events.*; + import flash.desktop.*; + import flash.errors.*; + import flash.system.*; + + public class Exporter extends MovieClip + { + public static var Instance:Exporter = null; + + public static var DefaultPort:int = 7890; + private var driver:Socket = null; + public function Exporter() + { + Instance = this; + + try + { + NativeApplication.nativeApplication.addEventListener("invoke", ApplicationInvoked); + } + catch (e) + { + // not an air runtime app + ConnectDriver(DefaultPort); // try default port + } + } + + public function ApplicationInvoked(e) + { + if (e.arguments.length == 1) + { + ConnectDriver(parseInt(e.arguments[0])); + } + else + { + ConnectDriver(DefaultPort); + } + } + + private function ConnectDriver(port) + { + Trace("Attempting to connect to driver"); + try + { + var s:Socket = new Socket(); + s.addEventListener(IOErrorEvent.IO_ERROR, DriverError); + s.addEventListener(Event.CONNECT, DriverConnected); + s.connect("localhost", port); + } + catch (e) + { + Trace("Error establishing wrapper connection"); + } + } + + private function DriverError(e) + { + Trace(" Failed to connect"); + } + + private function DriverConnected(e) + { + Trace(" Connected"); + driver = e.target as Socket; + driver.addEventListener(ProgressEvent.SOCKET_DATA, DriverRecv); + } + + private function Quit() + { + fscommand("quit"); + try + { + NativeApplication.nativeApplication.exit(); + } catch (e) + { + + } + } + + private function DispatchCommand(msg) + { + if (msg.hasOwnProperty("command")) + { + var cmd = "" + msg.command; + switch (cmd) + { + case "trace": + Trace(msg.command); + break; + case "quit": + Quit(); + break; + default: + Trace("Recv: " + JSON.stringify(msg)); + break; + } + } + } + + private function DriverRecv(e) + { + try + { + var cmd = driver.readUTF(); + DispatchCommand(JSON.parse(cmd)); + } + catch (e:EOFError) + { + // wait for more data + } + catch (e:IOError) + { + Trace("Driver IO error"); + } + catch (e) + { + Trace("Problem reading from driver"); + } + } + + private function DriverCommand(cmd:String, data = null) + { + var obj = {command:cmd}; + if (data != null) + { + for (var k in data) + { + obj[k] = data[k]; + } + } + DriverSend(JSON.stringify(obj)); + } + + private function DriverSend(str:String) + { + if (driver != null) + { + driver.writeUTF(str); + } + } + + public function Trace(str:String) + { + traceText.x = 2; + + trace(str); + traceText.width = stage.stageWidth - 4; + traceText.height = stage.stageHeight - 4; + if (traceText.text == "") + { + traceText.text = str; + } + else + { + traceText.appendText("\n" + str); + } + traceText.y = stage.height - traceText.textHeight - 2; + } + + public function Print(str:String, localTrace:Boolean = true) + { + if (localTrace || driver == null) + { + Trace(str); + } + else + { + trace(str); + } + if (driver != null) + { + DriverCommand("print", {string:str}); + } + } + } +} \ No newline at end of file diff --git a/Exporter.exe b/Exporter.exe new file mode 100644 index 0000000..829fdd0 --- /dev/null +++ b/Exporter.exe Binary files differ diff --git a/Exporter.fla b/Exporter.fla new file mode 100644 index 0000000..62c62d2 --- /dev/null +++ b/Exporter.fla Binary files differ diff --git a/Exporter.swf b/Exporter.swf new file mode 100644 index 0000000..60adb24 --- /dev/null +++ b/Exporter.swf Binary files differ diff --git a/.gitignore b/.gitignore index 5ad0b9e..d264257 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.swp RECOVER*.fla GraphicExport.app/ +Exporter.app/ *.p12 *.airi air*.tmp diff --git a/Exporter-app.xml b/Exporter-app.xml new file mode 100644 index 0000000..7deb7c5 --- /dev/null +++ b/Exporter-app.xml @@ -0,0 +1,38 @@ + + + + Exporter + 1.0 + Exporter + + Exporter + + + Exporter.swf + standard + false + true + false + portrait + auto + + + false + false + diff --git a/Exporter.as b/Exporter.as new file mode 100644 index 0000000..7a2a149 --- /dev/null +++ b/Exporter.as @@ -0,0 +1,179 @@ +package +{ + import flash.display.*; + import flash.net.*; + import flash.events.*; + import flash.desktop.*; + import flash.errors.*; + import flash.system.*; + + public class Exporter extends MovieClip + { + public static var Instance:Exporter = null; + + public static var DefaultPort:int = 7890; + private var driver:Socket = null; + public function Exporter() + { + Instance = this; + + try + { + NativeApplication.nativeApplication.addEventListener("invoke", ApplicationInvoked); + } + catch (e) + { + // not an air runtime app + ConnectDriver(DefaultPort); // try default port + } + } + + public function ApplicationInvoked(e) + { + if (e.arguments.length == 1) + { + ConnectDriver(parseInt(e.arguments[0])); + } + else + { + ConnectDriver(DefaultPort); + } + } + + private function ConnectDriver(port) + { + Trace("Attempting to connect to driver"); + try + { + var s:Socket = new Socket(); + s.addEventListener(IOErrorEvent.IO_ERROR, DriverError); + s.addEventListener(Event.CONNECT, DriverConnected); + s.connect("localhost", port); + } + catch (e) + { + Trace("Error establishing wrapper connection"); + } + } + + private function DriverError(e) + { + Trace(" Failed to connect"); + } + + private function DriverConnected(e) + { + Trace(" Connected"); + driver = e.target as Socket; + driver.addEventListener(ProgressEvent.SOCKET_DATA, DriverRecv); + } + + private function Quit() + { + fscommand("quit"); + try + { + NativeApplication.nativeApplication.exit(); + } catch (e) + { + + } + } + + private function DispatchCommand(msg) + { + if (msg.hasOwnProperty("command")) + { + var cmd = "" + msg.command; + switch (cmd) + { + case "trace": + Trace(msg.command); + break; + case "quit": + Quit(); + break; + default: + Trace("Recv: " + JSON.stringify(msg)); + break; + } + } + } + + private function DriverRecv(e) + { + try + { + var cmd = driver.readUTF(); + DispatchCommand(JSON.parse(cmd)); + } + catch (e:EOFError) + { + // wait for more data + } + catch (e:IOError) + { + Trace("Driver IO error"); + } + catch (e) + { + Trace("Problem reading from driver"); + } + } + + private function DriverCommand(cmd:String, data = null) + { + var obj = {command:cmd}; + if (data != null) + { + for (var k in data) + { + obj[k] = data[k]; + } + } + DriverSend(JSON.stringify(obj)); + } + + private function DriverSend(str:String) + { + if (driver != null) + { + driver.writeUTF(str); + } + } + + public function Trace(str:String) + { + traceText.x = 2; + + trace(str); + traceText.width = stage.stageWidth - 4; + traceText.height = stage.stageHeight - 4; + if (traceText.text == "") + { + traceText.text = str; + } + else + { + traceText.appendText("\n" + str); + } + traceText.y = stage.height - traceText.textHeight - 2; + } + + public function Print(str:String, localTrace:Boolean = true) + { + if (localTrace || driver == null) + { + Trace(str); + } + else + { + trace(str); + } + if (driver != null) + { + DriverCommand("print", {string:str}); + } + } + } +} \ No newline at end of file diff --git a/Exporter.exe b/Exporter.exe new file mode 100644 index 0000000..829fdd0 --- /dev/null +++ b/Exporter.exe Binary files differ diff --git a/Exporter.fla b/Exporter.fla new file mode 100644 index 0000000..62c62d2 --- /dev/null +++ b/Exporter.fla Binary files differ diff --git a/Exporter.swf b/Exporter.swf new file mode 100644 index 0000000..60adb24 --- /dev/null +++ b/Exporter.swf Binary files differ diff --git a/exporter.py b/exporter.py index 32dd978..2a00557 100755 --- a/exporter.py +++ b/exporter.py @@ -5,6 +5,7 @@ import errno import sys import os +import os.path import json import traceback import shlex @@ -37,6 +38,12 @@ def condition(self, make_type, condition): return lambda v: make_type(v) if condition(make_type(v)) else None + def folder(self, v): + path = os.path.abspath(os.getcwd() + "/" + v) + if os.path.isdir(path): + return path + return None + def parse_args(self, args): self.args = args self.i = 0 @@ -65,16 +72,21 @@ if msg is not None: return (msg, None) ret["scale"] = s + elif arg == "--base" or arg == "-b": + (msg, b) = self.parse_type(self.folder) + if msg is not None: + return (msg, None) + ret["base"] = b else: ret["input"].append(arg) self.i += 1 return (None, ret) def usage(): - print "usage 1: ./exporter.py [--port/-p wrapper_communication_port] [--type/-t (1,3)] [--scale/-s skeletal_scale] input_files..." + print "usage 1: ./exporter.py [--port/-p wrapper_communication_port] [--type/-t (1,3)] [--scale/-s skeletal_scale] [--base/-b base_dir] input_files..." print " Exports the given file(s) with the given settings" print - print "usage 2: ./exporter.py [--port/-p wrapper_communication_port] -" + print "usage 2: ./exporter.py [--port/-p wrapper_communication_port] [--base/-b base_dir] -" print " Reads commands (everything after --port in usage 1) as lines from stdin" print print "usage 3: ./export.py --help|-h" @@ -107,8 +119,8 @@ s = socket.socket() s.bind(("localhost", port)) -exporter_args = [os.getcwd() + "/GraphicExport.exe"] -#exporter_args = [os.getcwd() + "/GraphicExport.app/GraphicExport.exe", str(port)] +exporter_args = [os.getcwd() + "/Exporter.exe"] +#exporter_args = [os.getcwd() + "/Exporter.app/Expoter.exe", str(port)] g = subprocess.Popen(exporter_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) s.settimeout(0.5) @@ -128,7 +140,7 @@ "scale": args["scale"] if "scale" in args else 1} num_jobs_sent = 0 -def send_cmd(conn, base_cmd, in_file): +def send_job(conn, base_cmd, in_file): global num_jobs_sent num_jobs_sent += 1 cmd = dict(base_cmd) @@ -167,7 +179,7 @@ else: base_cmd = make_base_cmd(args) for i in args["input"]: - send_cmd(conn, base_cmd, i) + send_job(conn, base_cmd, i) def handle_command(msg_str): global quit @@ -215,7 +227,7 @@ else: base_cmd = make_base_cmd(line_args) for i in line_args["input"]: - send_cmd(conn, base_cmd, i) + send_job(conn, base_cmd, i) if quit: send_msg(conn, {"command":"quit"}) conn.close()