diff --git a/OpenRA.Launcher/Download.cs b/OpenRA.Launcher/Download.cs index 9478d8ecd5..eb015c6bd8 100644 --- a/OpenRA.Launcher/Download.cs +++ b/OpenRA.Launcher/Download.cs @@ -108,7 +108,7 @@ namespace OpenRA.Launcher string url = args[0]; string dest = args[1]; string pipename = UtilityProgram.GetPipeName(); - var p = UtilityProgram.Call("--download-url", pipename, url, dest); + var p = UtilityProgram.Call("--download-url", pipename, null, url, dest); Regex r = new Regex(@"(\d{1,3})% (\d+)/(\d+) bytes"); NamedPipeClientStream pipe = new NamedPipeClientStream(".", pipename, PipeDirection.In); diff --git a/OpenRA.Launcher/JSBridge.cs b/OpenRA.Launcher/JSBridge.cs index bb8ad35efe..ae175f1dea 100644 --- a/OpenRA.Launcher/JSBridge.cs +++ b/OpenRA.Launcher/JSBridge.cs @@ -169,13 +169,22 @@ namespace OpenRA.Launcher public void httpRequest(string url, string callbackName) { string pipename = UtilityProgram.GetPipeName(); - var p = UtilityProgram.Call("--download-url", pipename, url); var pipe = new NamedPipeClientStream(".", pipename, PipeDirection.In); - p.Exited += (_, e) => + + var p = UtilityProgram.Call("--download-url", pipename, + (_, e) => { + using (var reader = new StreamReader(pipe)) - document.InvokeScript(callbackName, new object[] { reader.ReadToEnd() }); - }; + { + var data = reader.ReadToEnd(); + /* debug */ + MessageBox.Show( + string.Format("Finished HTTP Request -- {0},{1} => {2}", + url, callbackName, data)); + document.InvokeScript(callbackName, new object[] { data }); + } + }, url); pipe.Connect(); } diff --git a/OpenRA.Launcher/UtilityProgram.cs b/OpenRA.Launcher/UtilityProgram.cs index e62fe057c6..706d534684 100644 --- a/OpenRA.Launcher/UtilityProgram.cs +++ b/OpenRA.Launcher/UtilityProgram.cs @@ -71,13 +71,19 @@ namespace OpenRA.Launcher return arguments.ToString(); } - public static Process Call(string command, string pipename, params string[] args) + public static Process Call(string command, string pipename, EventHandler onExit, params string[] args) { Process p = new Process(); p.StartInfo.FileName = "OpenRA.Utility.exe"; p.StartInfo.Arguments = BuildArgs(command, args) + " --pipe=" + pipename; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; + + if (onExit != null) + { + p.EnableRaisingEvents = true; + p.Exited += onExit; + } p.Start(); @@ -87,7 +93,7 @@ namespace OpenRA.Launcher public static string CallSimpleResponse(string command, params string[] args) { string pipename = GetPipeName(); - Call(command, pipename, args); + Call(command, pipename, null, args); string responseString; NamedPipeClientStream pipe = new NamedPipeClientStream(".", pipename, PipeDirection.In); pipe.Connect(); diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index a05373ef59..8be5f62345 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.IO; using System.Security.Principal; using System.IO.Pipes; +using System.Security.AccessControl; namespace OpenRA.Utility { @@ -56,11 +57,11 @@ namespace OpenRA.Utility if (principal.IsInRole(WindowsBuiltInRole.Administrator)) { var ps = new PipeSecurity(); - ps.AddAccessRule(new PipeAccessRule("EVERYONE", (PipeAccessRights)2032031, System.Security.AccessControl.AccessControlType.Allow)); - pipe = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.None, 1024, 1024, ps); + ps.AddAccessRule(new PipeAccessRule("EVERYONE", (PipeAccessRights)2032031, AccessControlType.Allow)); + pipe = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.None, 1024*1024, 1024*1024, ps); } else - pipe = new NamedPipeServerStream(pipename, PipeDirection.Out); + pipe = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.None, 1024*1024,1024*1024,null); pipe.WaitForConnection(); Console.SetOut(new StreamWriter(pipe) { AutoFlush = true });