Permalink
Browse files

Handle absence of NSJSONSerialization gracefully

  • Loading branch information...
1 parent f2b5063 commit 913fcbd98eb278facbe3bd3dd354d724217e7390 Simon Whitaker committed May 31, 2013
Showing with 21 additions and 17 deletions.
  1. +21 −17 ddcli/DDGetoptLongParser.m
View
@@ -170,23 +170,27 @@ - (NSArray *) parseOptions
NSArray * arguments = [processInfo arguments];
if (mArgumentsFilename != nil) {
- NSFileManager *fm = [NSFileManager defaultManager];
- NSString *argumentsFilePath = [[fm currentDirectoryPath] stringByAppendingPathComponent:mArgumentsFilename];
- if ([fm fileExistsAtPath:argumentsFilePath]) {
- NSError *error;
- NSArray *argumentsFromFile = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:argumentsFilePath] options:0 error:&error];
- if (argumentsFromFile != nil) {
- NSAssert([arguments count] > 0, @"Process has no arguments (not even the command). Weird.");
- NSString *command = [arguments objectAtIndex:0];
- arguments = [arguments subarrayWithRange:NSMakeRange(1, [arguments count] - 1)];
-
- NSMutableArray *mutableArguments = [NSMutableArray arrayWithObject:command];
- [mutableArguments addObjectsFromArray:argumentsFromFile];
- [mutableArguments addObjectsFromArray:arguments];
- arguments = [NSArray arrayWithArray:mutableArguments];
- } else {
- fprintf(stderr, "Error reading %s: %s\n", [mArgumentsFilename UTF8String], [[error localizedDescription] UTF8String]);
- exit(1);
+ if (NSClassFromString(@"NSJSONSerialization") == nil) {
+ fprintf(stderr, "Warning: ignoring %s, feature supported from OS X 10.7 onwards\n", [mArgumentsFilename UTF8String]);
+ } else {
+ NSFileManager *fm = [NSFileManager defaultManager];
+ NSString *argumentsFilePath = [[fm currentDirectoryPath] stringByAppendingPathComponent:mArgumentsFilename];
+ if ([fm fileExistsAtPath:argumentsFilePath]) {
+ NSError *error;
+ NSArray *argumentsFromFile = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:argumentsFilePath] options:0 error:&error];
+ if (argumentsFromFile != nil) {
+ NSAssert([arguments count] > 0, @"Process has no arguments (not even the command). Weird.");
+ NSString *command = [arguments objectAtIndex:0];
+ arguments = [arguments subarrayWithRange:NSMakeRange(1, [arguments count] - 1)];
+
+ NSMutableArray *mutableArguments = [NSMutableArray arrayWithObject:command];
+ [mutableArguments addObjectsFromArray:argumentsFromFile];
+ [mutableArguments addObjectsFromArray:arguments];
+ arguments = [NSArray arrayWithArray:mutableArguments];
+ } else {
+ fprintf(stderr, "Error reading %s: %s\n", [mArgumentsFilename UTF8String], [[error localizedDescription] UTF8String]);
+ exit(1);
+ }
}
}
}

0 comments on commit 913fcbd

Please sign in to comment.