Bug 634334: Check that subdir argument really is one of the two cases

we can handle. Wrap fileURLWithPath in @try/@catch so that we don't
crash when it throws.

Free bonus fix: If "en" is the language and doesn't have a translation, force the C locale.



git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19785 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
John Ralls 2010-11-09 18:50:58 +00:00
parent f0a7805f27
commit cc2c20a1de

View File

@ -285,16 +285,19 @@ gnc_gnome_help (const char *dir, const char *detail)
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *subdir = [NSString stringWithUTF8String: dir]; NSString *subdir = [NSString stringWithUTF8String: dir];
NSString *help_dir = [NSString stringWithUTF8String: HF_HELP];
NSString *tag; NSString *tag;
NSURL *url = NULL; NSURL *url = NULL;
if (detail) if (detail)
tag = [NSString stringWithUTF8String: detail]; tag = [NSString stringWithUTF8String: detail];
else if ([subdir compare: help_dir] == NSOrderedSame) else if ([subdir compare: @HF_HELP] == NSOrderedSame)
tag = @"help"; tag = @"help";
else else if ([subdir compare: @HF_GUIDE] == NSOrderedSame)
tag = @"index"; tag = @"index";
else {
PWARN("gnc_gnome_help called with unknown subdirectory %s", dir);
return;
}
if (![[NSBundle mainBundle] bundleIdentifier]) { if (![[NSBundle mainBundle] bundleIdentifier]) {
/* If bundleIdentifier is NULL, then we're running from the /* If bundleIdentifier is NULL, then we're running from the
@ -345,31 +348,54 @@ gnc_gnome_help (const char *dir, const char *detail)
fileExistsAtPath: completed_path fileExistsAtPath: completed_path
isDirectory: &dir]) isDirectory: &dir])
if (dir) { if (dir) {
url = [NSURL fileURLWithPath: @try {
[[[completed_path url = [NSURL fileURLWithPath:
stringByAppendingPathComponent: subdir] [[[completed_path
stringByAppendingPathComponent: tag] stringByAppendingPathComponent: subdir]
stringByAppendingPathExtension: @"html"]]; stringByAppendingPathComponent: tag]
stringByAppendingPathExtension: @"html"]];
}
@catch (NSException *e) {
PWARN("fileURLWithPath threw %s: %s",
[[e name] UTF8String], [[e reason] UTF8String]);
return;
}
break; break;
} }
if ([this_lang compare:@"en"] == NSOrderedSame)
break; /* Special case, forces use of "C" locale */
}
}
if (!url) {
@try {
url = [NSURL
fileURLWithPath: [[[[docs_dir
stringByAppendingPathComponent: @"C"]
stringByAppendingPathComponent: subdir]
stringByAppendingPathComponent: tag]
stringByAppendingPathExtension: @"html"]];
}
@catch (NSException *e) {
PWARN("fileURLWithPath threw %s: %s",
[[e name] UTF8String], [[e reason] UTF8String]);
return;
} }
} }
if (!url)
url = [NSURL
fileURLWithPath: [[[[docs_dir
stringByAppendingPathComponent: @"C"]
stringByAppendingPathComponent: subdir]
stringByAppendingPathComponent: tag]
stringByAppendingPathExtension: @"html"]];
} }
/* It's a lot easier in a bundle! OSX finds the best translation for us. */ /* It's a lot easier in a bundle! OSX finds the best translation for us. */
else else {
url = [NSURL fileURLWithPath: [[NSBundle mainBundle] @try {
pathForResource: tag url = [NSURL fileURLWithPath: [[NSBundle mainBundle]
ofType: @"html" pathForResource: tag
inDirectory: subdir ]]; ofType: @"html"
inDirectory: subdir ]];
}
@catch (NSException *e) {
PWARN("fileURLWithPath threw %s: %s",
[[e name] UTF8String], [[e reason] UTF8String]);
return;
}
}
/* Now just open the URL in the default app for opening URLs */ /* Now just open the URL in the default app for opening URLs */
if (url) if (url)
[[NSWorkspace sharedWorkspace] openURL: url]; [[NSWorkspace sharedWorkspace] openURL: url];