Support launching an arbitrary mod. Hook up package detection for cnc.

This commit is contained in:
Paul Chote
2010-11-17 13:49:30 +13:00
parent f42f39f9c9
commit 3dc16bdbb4
15 changed files with 128 additions and 45 deletions

View File

@@ -38,7 +38,7 @@ static JSBridge *SharedInstance;
if (self != nil)
{
methods = [[NSDictionary dictionaryWithObjectsAndKeys:
@"launchCurrentMod", NSStringFromSelector(@selector(launchCurrentMod)),
@"launchMod", NSStringFromSelector(@selector(launchMod:)),
@"log", NSStringFromSelector(@selector(log:)),
@"fileExistsInMod", NSStringFromSelector(@selector(fileExists:inMod:)),
nil] retain];
@@ -59,10 +59,17 @@ static JSBridge *SharedInstance;
#pragma mark JS methods
- (void)launchCurrentMod
- (BOOL)launchMod:(NSString *)aMod
{
NSLog(@"launchcurrent");
[controller launchGame];
id mod = [[controller allMods] objectForKey:aMod];
if (mod == nil)
{
NSLog(@"Invalid or unknown mod: %@", aMod);
return NO;
}
[controller launchMod:aMod];
return YES;
}
- (void)log:(NSString *)message
@@ -72,8 +79,19 @@ static JSBridge *SharedInstance;
- (BOOL)fileExists:(NSString *)aFile inMod:(NSString *)aMod
{
NSLog(@"File %@ exists in mod %@",aFile, aMod);
return NO;
id mod = [[controller allMods] objectForKey:aMod];
if (mod == nil)
{
NSLog(@"Invalid or unknown mod: %@", aMod);
return NO;
}
// Disallow traversing up the directory tree
id path = [[[mod baseURL] absoluteString]
stringByAppendingPathComponent:[aFile stringByReplacingOccurrencesOfString:@"../"
withString:@""]];
return [[NSFileManager defaultManager] fileExistsAtPath:path];
}
@end