diff --git a/OpenRA.Game/Utilities.cs b/OpenRA.Game/Utilities.cs index 8726bd2850..abe53dba8f 100644 --- a/OpenRA.Game/Utilities.cs +++ b/OpenRA.Game/Utilities.cs @@ -25,17 +25,17 @@ namespace OpenRA public void ExtractZipAsync(string zipFile, string path, Action parseOutput, Action onComplete) { - ExecuteUtilityAsync("\"--extract-zip {0} {1}\"".F(zipFile, path), parseOutput, onComplete); + ExecuteUtilityAsync("--extract-zip \"{0}\" \"{1}\"".F(zipFile, path), parseOutput, onComplete); } public void InstallRAFilesAsync(string cdPath, Action parseOutput, Action onComplete) { - ExecuteUtilityAsync("\"--install-ra-packages {0}\"".F(cdPath), parseOutput, onComplete); + ExecuteUtilityAsync("--install-ra-packages \"{0}\"".F(cdPath), parseOutput, onComplete); } public void PromptFilepathAsync(string title, string message, bool directory, Action withPath) { - ExecuteUtility("--display-filepicker --title \"{0}\" --message \"{1}\" {2} --button-text \"Select\"" + ExecuteUtility("--display-filepicker --title \"{0}\" --message \"{1}\" \"{2}\" --button-text \"Select\"" .F(title, message, directory ? "--require-directory" : ""), withPath); } diff --git a/OpenRA.Launcher.Mac/Controller.h b/OpenRA.Launcher.Mac/Controller.h index b4e5e30a68..e91b38eb2a 100644 --- a/OpenRA.Launcher.Mac/Controller.h +++ b/OpenRA.Launcher.Mac/Controller.h @@ -17,9 +17,9 @@ } - (void)launchFilePicker:(NSArray *)args; - (void)extractZip:(NSArray *)args; -- (void)installRaPackages:(NSArray *)args; +- (void)installRAPackages:(NSArray *)args; - (void)launchMod:(NSString *)mod; - (BOOL)initMono; -- (void)runUtilityWithArg:(NSString *)arg; +- (void)runUtilityWithArgs:(NSArray *)arg; - (void)utilityResponded:(NSNotification *)n; @end diff --git a/OpenRA.Launcher.Mac/Controller.m b/OpenRA.Launcher.Mac/Controller.m index 09d05c2bdd..025782a02a 100644 --- a/OpenRA.Launcher.Mac/Controller.m +++ b/OpenRA.Launcher.Mac/Controller.m @@ -48,7 +48,7 @@ // Install ra packages from cd if ([args containsObject:@"--install-ra-packages"]) - [self installRaPackages:args]; + [self installRAPackages:args]; [self launchMod:@"cnc"]; @@ -57,12 +57,16 @@ - (void)extractZip:(NSArray *)args { - [self runUtilityWithArg:[NSString stringWithFormat:@"--extract-zip=%@,%@",[args objectAtIndex:2],[args objectAtIndex:3]]]; + // 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]; + [self runUtilityWithArgs:a]; } -- (void)installRaPackages:(NSArray *)args +- (void)installRAPackages:(NSArray *)args { - [self runUtilityWithArg:[NSString stringWithFormat:@"--install-ra-packages=%@",[args objectAtIndex:2]]]; + // 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]; + [self runUtilityWithArgs:a]; } - (void)launchFilePicker:(NSArray *)args @@ -189,13 +193,13 @@ } -- (void)runUtilityWithArg:(NSString *)arg +- (void)runUtilityWithArgs:(NSArray *)args { NSTask *task = [[[NSTask alloc] init] autorelease]; NSPipe *pipe = [NSPipe pipe]; NSMutableArray *taskArgs = [NSMutableArray arrayWithObject:@"OpenRA.Utility.exe"]; - [taskArgs addObject:arg]; + [taskArgs addObjectsFromArray:args]; [task setCurrentDirectoryPath:gamePath]; [task setLaunchPath:monoPath]; 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 e1ee1c8571..85bdff27b9 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 a47eaf4a45..c17902292f 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -22,81 +22,23 @@ namespace OpenRA.Utility { static class Command { - public static void ListMods(string _) + public static void ExtractZip(string[] args) { - var mods = Mod.AllMods; - List seen = new List(mods.Where(x => x.Value.Standalone).Select(x => x.Key)); - List remaining = new List(mods.Where(x => !x.Value.Standalone).Select(x => x.Key)); - foreach(var m in seen) - Console.WriteLine(m); - - int oldSeenSize = 0; - while (true) + if (args.Length < 3) { - foreach (var m in remaining) - { - if (seen.Contains(m)) continue; - - if (string.IsNullOrEmpty(mods[m].Requires)) - { - Console.WriteLine(m); - seen.Add(m); - continue; - } - if (seen.Contains(mods[m].Requires)) - { - Console.WriteLine(m); - seen.Add(m); - } - } - - if (oldSeenSize == seen.Count) break; - oldSeenSize = seen.Count; - } - - foreach(var m in remaining.Where(x => !seen.Contains(x))) - Console.WriteLine(m); - } - - public static void ListModInfo(string modList) - { - string[] mods = modList.Split(','); - foreach (var m in mods) - { - var mod = Mod.AllMods - .Where(x => x.Key.Equals(m)) - .Select(x => x.Value) - .FirstOrDefault(); - if (mod == null) - { - Console.WriteLine("Error: Mod `{0}` is not installed or could not be found.", m); - return; - } - - Console.WriteLine("Mod: {0}", m); - Console.WriteLine(" Title: {0}", mod.Title); - Console.WriteLine(" Version: {0}", mod.Version); - Console.WriteLine(" Author: {0}", mod.Author); - Console.WriteLine(" Description: {0}", mod.Description); - Console.WriteLine(" Requires: {0}", mod.Requires); - Console.WriteLine(" Standalone: {0}", mod.Standalone.ToString()); - } - } - - public static void ExtractZip(string argValue) - { - string[] args = argValue.Split(','); - - if (args.Length != 2) - { - Console.WriteLine("Error: invalid syntax"); + Console.WriteLine("Error: Invalid syntax"); + return; + } + + var zipFile = args[1]; + var dest = args[2]; + + if (!File.Exists(zipFile)) + { + Console.WriteLine("Error: Could not find {0}", zipFile); return; } - string zipFile = args[0]; - string path = args[1]; - if (!File.Exists(zipFile)) { Console.WriteLine("Error: Could not find {0}", zipFile); return; } - string dest = "mods{0}{1}".F(Path.DirectorySeparatorChar,path); List extracted = new List(); try { @@ -112,68 +54,15 @@ namespace OpenRA.Utility Console.WriteLine("Status: Completed"); } - public static void DownloadUrl(string argValue) + public static void InstallRAPackages(string[] args) { - string[] args = argValue.Split(','); - string url = args[0]; - WebClient wc = new WebClient(); - wc.Proxy = null; - - if (args.Length == 1) + if (args.Length < 2) { - wc.DownloadStringCompleted += DownloadStringCompleted; - wc.DownloadStringAsync(new Uri(url)); - } - else if (args.Length == 2) - { - string path = args[1].Replace("~",Environment.GetFolderPath(Environment.SpecialFolder.Personal)); - - wc.DownloadProgressChanged += DownloadProgressChanged; - wc.DownloadFileCompleted += DownloadFileCompleted; - - Console.WriteLine("Downloading {0} to {1}", url, path); - Console.WriteLine("Status: Initializing"); - - wc.DownloadFileAsync(new Uri(url), path); - } - else - { - Console.WriteLine("Error: invalid syntax"); + Console.WriteLine("Error: Invalid syntax"); return; } - - while (!completed) - Thread.Sleep(500); - } - static bool completed = false; - - static void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) - { - if (e.Error != null) - Console.WriteLine("Error: {0}", e.Error.Message); - else - Console.WriteLine(e.Result); - completed = true; - } - - static void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) - { - if (e.Error != null) - Console.WriteLine("Error: {0}", e.Error.Message); - else - Console.WriteLine("Status: Completed"); - completed = true; - } - - static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) - { - Console.WriteLine("Status: {0}% {1}/{2} bytes", e.ProgressPercentage, e.BytesReceived, e.TotalBytesToReceive); - } - - public static void InstallRAPackages(string path) - { - var basePath = "{0}{1}".F(path, Path.DirectorySeparatorChar); + var basePath = "{0}{1}".F(args[1], Path.DirectorySeparatorChar); var toPath = "mods{0}ra{0}packages{0}".F(Path.DirectorySeparatorChar); var directCopy = new string[] {"INSTALL/REDALERT.MIX"}; var extract = new string[] {"conquer.mix", "russian.mix", "allies.mix", "sounds.mix", @@ -195,9 +84,15 @@ namespace OpenRA.Utility Console.WriteLine("Status: Completed"); } - public static void InstallCncPackages(string path) + public static void InstallCncPackages(string[] args) { - var basePath = "{0}{1}".F(path, Path.DirectorySeparatorChar); + if (args.Length < 2) + { + Console.WriteLine("Error: Invalid syntax"); + return; + } + + var basePath = "{0}{1}".F(args[1], Path.DirectorySeparatorChar); var toPath = "mods{0}cnc{0}packages{0}".F(Path.DirectorySeparatorChar); var directCopy = new string[] {"CONQUER.MIX", "DESERT.MIX", "GENERAL.MIX", "SCORES.MIX", "SOUNDS.MIX", "TEMPERAT.MIX", "WINTER.MIX"}; @@ -220,13 +115,15 @@ namespace OpenRA.Utility Console.WriteLine("Status: Completed"); } - public static void Settings(string argValue) + public static void Settings(string[] args) { - string[] args = argValue.Split(','); - - if (args.Length < 2) { return; } + if (args.Length < 3) + { + Console.WriteLine("Error: Invalid syntax"); + return; + } - string expandedPath = args[0].Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal)); + string expandedPath = args[1].Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal)); string settingsFile = expandedPath + Path.DirectorySeparatorChar + "settings.yaml"; if (!File.Exists(settingsFile)) @@ -236,14 +133,14 @@ namespace OpenRA.Utility } List settingsYaml = MiniYaml.FromFile(settingsFile); - Queue settingKey = new Queue(args[1].Split('.')); + Queue settingKey = new Queue(args[2].Split('.')); string s = settingKey.Dequeue(); MiniYaml n = settingsYaml.Where(x => x.Key == s).Select(x => x.Value).FirstOrDefault(); if (n == null) { - Console.WriteLine("Error: Could not find {0} in {1}", args[1], settingsFile); + Console.WriteLine("Error: Could not find {0} in {1}", args[2], settingsFile); return; } @@ -252,7 +149,7 @@ namespace OpenRA.Utility s = settingKey.Dequeue(); if (!n.NodesDict.TryGetValue(s, out n)) { - Console.WriteLine("Error: Could not find {0} in {1}", args[1], settingsFile); + Console.WriteLine("Error: Could not find {0} in {1}", args[2], settingsFile); return; } } diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 8be5f62345..93e72739c2 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -9,6 +9,7 @@ #endregion using System; +using System.Linq; using System.Collections.Generic; using System.IO; using System.Security.Principal; @@ -19,38 +20,26 @@ namespace OpenRA.Utility { class Program { - static KeyValuePair SplitArgs(string arg) - { - int i = arg.IndexOf('='); - if (i < 0) return new KeyValuePair(arg, ""); - return new KeyValuePair(arg.Substring(0, i), arg.Substring(i + 1)); - } - - delegate void ArgCallback(string argValue); + delegate void ArgCallback(string[] args); static Dictionary argCallbacks; static void Main(string[] args) { argCallbacks = new Dictionary(); - argCallbacks.Add("--list-mods", Command.ListMods); - argCallbacks.Add("-l", Command.ListMods); - argCallbacks.Add("--mod-info", Command.ListModInfo); - argCallbacks.Add("-i", Command.ListModInfo); - argCallbacks.Add("--download-url", Command.DownloadUrl); argCallbacks.Add("--extract-zip", Command.ExtractZip); argCallbacks.Add("--install-ra-packages", Command.InstallRAPackages); argCallbacks.Add("--install-cnc-packages", Command.InstallCncPackages); argCallbacks.Add("--settings-value", Command.Settings); if (args.Length == 0) { PrintUsage(); return; } - var arg = SplitArgs(args[0]); bool piping = false; - if (args.Length > 1 && SplitArgs(args[1]).Key == "--pipe") + var i = Array.IndexOf(args, "--pipe"); + if (args.Length > 1 && i >= 0) { piping = true; - string pipename = SplitArgs(args[1]).Value; + string pipename = args[i+1]; NamedPipeServerStream pipe; var id = WindowsIdentity.GetCurrent(); var principal = new WindowsPrincipal(id); @@ -68,8 +57,8 @@ namespace OpenRA.Utility } ArgCallback callback; - if (argCallbacks.TryGetValue(arg.Key, out callback)) - callback(arg.Value); + if (argCallbacks.TryGetValue(args[0], out callback)) + callback(args); else PrintUsage(); @@ -79,15 +68,12 @@ namespace OpenRA.Utility static void PrintUsage() { - Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION]"); + Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]"); Console.WriteLine(); - Console.WriteLine(" -l,--list-mods List currently installed mods"); - Console.WriteLine(" -i=MODS,--mod-info=MODS List metadata for MODS (comma separated list of mods)"); - Console.WriteLine(" --download-url=URL,DEST Download a file from URL to DEST (omit DEST to print to stdout)"); - Console.WriteLine(" --extract-zip=ZIPFILE,PATH Extract the zip ZIPFILE to DEST (relative to openra dir)"); - Console.WriteLine(" --install-ra-packages=PATH Install required packages for RA from CD to PATH"); - Console.WriteLine(" --install-cnc-packages=PATH Install required packages for C&C from CD to PATH"); - Console.WriteLine(" --settings-value=SUPPORTDIR,KEY Get value of KEY in SUPPORTDIR/settings.yaml"); + Console.WriteLine(" --extract-zip ZIPFILE PATH Extract the zip ZIPFILE to DEST (relative to openra dir)"); + Console.WriteLine(" --install-ra-packages PATH Install required packages for RA from CD to PATH"); + Console.WriteLine(" --install-cnc-packages PATH Install required packages for C&C from CD to PATH"); + Console.WriteLine(" --settings-value SUPPORTDIR KEY Get value of KEY in SUPPORTDIR/settings.yaml"); } } } diff --git a/mods/cnc/chrome/gameinit.yaml b/mods/cnc/chrome/gameinit.yaml index 4cca7d4c2a..d5c86dab89 100644 --- a/mods/cnc/chrome/gameinit.yaml +++ b/mods/cnc/chrome/gameinit.yaml @@ -3,7 +3,7 @@ GameInitInfo@INIT_SETUP: TestFile: conquer.mix GameTitle: Command & Conquer PackageURL:http://open-ra.org/get-dependency.php?file=cnc-packages - PackagePath:cnc/packages/ + PackagePath:mods/cnc/packages/ InstallMode:cnc Delegate:GameInitDelegate diff --git a/mods/ra/chrome/gameinit.yaml b/mods/ra/chrome/gameinit.yaml index 32feaff111..801d8753bc 100644 --- a/mods/ra/chrome/gameinit.yaml +++ b/mods/ra/chrome/gameinit.yaml @@ -3,7 +3,7 @@ GameInitInfo@INIT_SETUP: TestFile: redalert.mix GameTitle: Red Alert PackageURL:http://open-ra.org/get-dependency.php?file=ra-packages - PackagePath:ra/packages/ + PackagePath:mods/ra/packages/ InstallMode:ra Delegate:GameInitDelegate