Have a single utility app per platform. Route zip extraction and ra package install to the .net utility app under osx.

This commit is contained in:
Paul Chote
2011-01-22 19:07:10 +13:00
parent 8e5f307ba8
commit c93bdf73aa
5 changed files with 78 additions and 16 deletions

View File

@@ -229,7 +229,7 @@ namespace OpenRA
SupportDir = args.GetValue("SupportDir", defaultSupport);
FileSystem.SpecialPackageRoot = args.GetValue("SpecialPackageRoot", "");
Utilities = new Utilities(args.GetValue("NativeUtilityPath", "."));
Utilities = new Utilities(args.GetValue("UtilityPath", "OpenRA.Utility.exe"));
Settings = new Settings(SupportDir + "settings.yaml", args);
Settings.Save();

View File

@@ -16,35 +16,34 @@ namespace OpenRA
{
public class Utilities
{
readonly string NativeUtility;
readonly string Utility = "OpenRA.Utility.exe";
readonly string Utility;
public Utilities(string nativeUtility)
public Utilities(string utility)
{
NativeUtility = nativeUtility;
Utility = utility;
}
public void ExtractZipAsync(string zipFile, string path, Action<string> parseOutput, Action onComplete)
{
ExecuteUtilityAsync(Utility, "\"--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<string> parseOutput, Action onComplete)
{
ExecuteUtilityAsync(Utility, "\"--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<string> withPath)
{
ExecuteUtility(NativeUtility,
"--filepicker --title \"{0}\" --message \"{1}\" {2} --button-text \"Select\"".F(title, message, directory ? "--require-directory" : ""),
ExecuteUtility("--display-filepicker --title \"{0}\" --message \"{1}\" {2} --button-text \"Select\""
.F(title, message, directory ? "--require-directory" : ""),
withPath);
}
void ExecuteUtility(string executable, string args, Action<string> onComplete)
void ExecuteUtility(string args, Action<string> onComplete)
{
Process p = new Process();
p.StartInfo.FileName = executable;
p.StartInfo.FileName = Utility;
p.StartInfo.Arguments = args;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
@@ -57,10 +56,10 @@ namespace OpenRA
p.Start();
}
void ExecuteUtilityAsync(string executable, string args, Action<string> parseOutput, Action onComplete)
void ExecuteUtilityAsync(string args, Action<string> parseOutput, Action onComplete)
{
Process p = new Process();
p.StartInfo.FileName = executable;
p.StartInfo.FileName = Utility;
p.StartInfo.Arguments = args;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;

View File

@@ -16,6 +16,10 @@
IBOutlet NSWindow *window;
}
- (void)launchFilePicker:(NSArray *)args;
- (void)extractZip:(NSArray *)args;
- (void)installRaPackages:(NSArray *)args;
- (void)launchMod:(NSString *)mod;
- (BOOL)initMono;
- (void)runUtilityWithArg:(NSString *)arg;
- (void)utilityResponded:(NSNotification *)n;
@end

View File

@@ -23,10 +23,10 @@
NSArray *args = [[NSProcessInfo processInfo] arguments];
// Ingame requests for native dialogs
if ([args containsObject:@"--filepicker"])
if ([args containsObject:@"--display-filepicker"])
[self launchFilePicker:args];
// Try and launch the game
if (![self initMono])
{
@@ -42,10 +42,29 @@
[[NSApplication sharedApplication] terminate:self];
}
// Extract a zip file
if ([args containsObject:@"--extract-zip"])
[self extractZip:args];
// Install ra packages from cd
if ([args containsObject:@"--install-ra-packages"])
[self installRaPackages:args];
[self launchMod:@"cnc"];
[NSApp terminate: nil];
}
- (void)extractZip:(NSArray *)args
{
[self runUtilityWithArg:[NSString stringWithFormat:@"--extract-zip=%@,%@",[args objectAtIndex:2],[args objectAtIndex:3]]];
}
- (void)installRaPackages:(NSArray *)args
{
[self runUtilityWithArg:[NSString stringWithFormat:@"--install-ra-packages=%@",[args objectAtIndex:2]]];
}
- (void)launchFilePicker:(NSArray *)args
{
[NSApp activateIgnoringOtherApps:YES];
@@ -85,7 +104,7 @@
[NSApp terminate: nil];
}
-(void) launchMod:(NSString *)mod
-(void)launchMod:(NSString *)mod
{
// Use LaunchServices because neither NSTask or NSWorkspace support Info.plist _and_ arguments pre-10.6
@@ -169,6 +188,46 @@
(major == 2 && minor == 6 && point >= 7));
}
- (void)runUtilityWithArg:(NSString *)arg
{
NSTask *task = [[[NSTask alloc] init] autorelease];
NSPipe *pipe = [NSPipe pipe];
NSMutableArray *taskArgs = [NSMutableArray arrayWithObject:@"OpenRA.Utility.exe"];
[taskArgs addObject:arg];
[task setCurrentDirectoryPath:gamePath];
[task setLaunchPath:monoPath];
[task setArguments:taskArgs];
[task setStandardOutput:pipe];
NSFileHandle *readHandle = [pipe fileHandleForReading];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(utilityResponded:)
name:NSFileHandleReadCompletionNotification
object:readHandle];
[task launch];
[readHandle readInBackgroundAndNotify];
[task waitUntilExit];
[nc removeObserver:self name:NSFileHandleReadCompletionNotification object:[[task standardOutput] fileHandleForReading]];
[nc removeObserver:self name:NSTaskDidTerminateNotification object:task];
}
- (void)utilityResponded:(NSNotification *)n
{
NSData *data = [[n userInfo] valueForKey:NSFileHandleNotificationDataItem];
NSString *response = [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
printf("%s", [response UTF8String]);
// Keep reading
if ([n object] != nil)
[[n object] readInBackgroundAndNotify];
}
- (void)dealloc
{
[monoPath release]; monoPath = nil;