diff --git a/OpenRA.Launcher.Mac/Controller.m b/OpenRA.Launcher.Mac/Controller.m index a46d7bda12..babe4260ac 100644 --- a/OpenRA.Launcher.Mac/Controller.m +++ b/OpenRA.Launcher.Mac/Controller.m @@ -58,14 +58,14 @@ - (void)extractZip:(NSArray *)args { // Todo: check if we can write to the requested dir, escalate priviledges if required. - NSArray *a = [NSArray arrayWithObjects:@"--extract-zip", [args objectAtIndex:2], [args objectAtIndex:3], nil]; + NSArray *a = [NSArray arrayWithObjects:@"--extract-zip-inner", [args objectAtIndex:2], [args objectAtIndex:3], nil]; [self runUtilityWithArgs:a]; } - (void)installRAPackages:(NSArray *)args { // Todo: check if we can write to the requested dir, escalate priviledges if required. - NSArray *a = [NSArray arrayWithObjects:@"--install-ra-packages", [args objectAtIndex:2], nil]; + NSArray *a = [NSArray arrayWithObjects:@"--install-ra-packages-inner", [args objectAtIndex:2], nil]; [self runUtilityWithArgs:a]; } diff --git a/OpenRA.Launcher.Mac/build/Release/OpenRA.app/Contents/MacOS/OpenRA b/OpenRA.Launcher.Mac/build/Release/OpenRA.app/Contents/MacOS/OpenRA index a54d317931..ce9e955b59 100755 Binary files a/OpenRA.Launcher.Mac/build/Release/OpenRA.app/Contents/MacOS/OpenRA and b/OpenRA.Launcher.Mac/build/Release/OpenRA.app/Contents/MacOS/OpenRA differ diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index b128758620..af8488ec03 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -172,5 +172,20 @@ namespace OpenRA.Utility Console.WriteLine(n.Value); } + + public static void AuthenticateAndExtractZip(string[] args) + { + Util.CallWithAdmin("--extract-zip \"{0}\" \"{1}\"".F(args[1], args[2])); + } + + public static void AuthenticateAndInstallRAPackages(string[] args) + { + Util.CallWithAdmin("--install-ra-packages \"{0}\"".F(args[1])); + } + + public static void AuthenticateAndInstallCncPackages(string[] args) + { + Util.CallWithAdmin("--install-cnc-packages \"{0}\"".F(args[1])); + } } } diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 42b0d19b41..da7e9fa4b4 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -27,11 +27,14 @@ namespace OpenRA.Utility static void Main(string[] args) { argCallbacks = new Dictionary(); - argCallbacks.Add("--extract-zip", Command.ExtractZip); - argCallbacks.Add("--install-ra-packages", Command.InstallRAPackages); - argCallbacks.Add("--install-cnc-packages", Command.InstallCncPackages); + argCallbacks.Add("--extract-zip-inner", Command.ExtractZip); + argCallbacks.Add("--install-ra-packages-inner", Command.InstallRAPackages); + argCallbacks.Add("--install-cnc-packages-inner", Command.InstallCncPackages); argCallbacks.Add("--display-filepicker", Command.DisplayFilepicker); argCallbacks.Add("--settings-value", Command.Settings); + argCallbacks.Add("--install-ra-packages", Command.AuthenticateAndInstallRAPackages); + argCallbacks.Add("--install-cnc-packages", Command.AuthenticateAndInstallCncPackages); + argCallbacks.Add("--extract-zip", Command.AuthenticateAndExtractZip); if (args.Length == 0) { PrintUsage(); return; } diff --git a/OpenRA.Utility/Util.cs b/OpenRA.Utility/Util.cs index be35dd3231..d5885b035e 100644 --- a/OpenRA.Utility/Util.cs +++ b/OpenRA.Utility/Util.cs @@ -13,6 +13,9 @@ using System.IO; using ICSharpCode.SharpZipLib.Zip; using OpenRA.FileFormats; using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.IO.Pipes; namespace OpenRA.Utility { @@ -61,5 +64,39 @@ namespace OpenRA.Utility } z.Close(); } + + public static string GetPipeName() + { + return "OpenRA.Utility" + Guid.NewGuid().ToString(); + } + + public static void CallWithAdmin(string command) + { + string pipename = Util.GetPipeName(); + var p = new Process(); + p.StartInfo.FileName = "OpenRA.Utility.exe"; + p.StartInfo.Arguments = command + " --pipe=" + pipename; + p.StartInfo.Verb = "runas"; + + try + { + p.Start(); + } + catch (Win32Exception e) + { + if (e.NativeErrorCode == 1223) //ERROR_CANCELLED + return; + throw e; + } + + var pipe = new NamedPipeClientStream(".", pipename, PipeDirection.In); + pipe.Connect(); + + using (var reader = new StreamReader(pipe)) + { + while (!p.HasExited) + Console.Write(reader.ReadLine()); + } + } } }