r19785 - gnucash/trunk/src/gnome-utils - Bug 634334: Check that subdir argument really is one of the two cases
John Ralls
jralls at code.gnucash.org
Tue Nov 9 13:50:58 EST 2010
Author: jralls
Date: 2010-11-09 13:50:58 -0500 (Tue, 09 Nov 2010)
New Revision: 19785
Trac: http://svn.gnucash.org/trac/changeset/19785
Modified:
gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
Log:
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.
Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c 2010-11-09 17:55:30 UTC (rev 19784)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c 2010-11-09 18:50:58 UTC (rev 19785)
@@ -285,16 +285,19 @@
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *subdir = [NSString stringWithUTF8String: dir];
- NSString *help_dir = [NSString stringWithUTF8String: HF_HELP];
NSString *tag;
NSURL *url = NULL;
if (detail)
tag = [NSString stringWithUTF8String: detail];
- else if ([subdir compare: help_dir] == NSOrderedSame)
+ else if ([subdir compare: @HF_HELP] == NSOrderedSame)
tag = @"help";
- else
+ else if ([subdir compare: @HF_GUIDE] == NSOrderedSame)
tag = @"index";
+ else {
+ PWARN("gnc_gnome_help called with unknown subdirectory %s", dir);
+ return;
+ }
if (![[NSBundle mainBundle] bundleIdentifier]) {
/* If bundleIdentifier is NULL, then we're running from the
@@ -345,31 +348,54 @@
fileExistsAtPath: completed_path
isDirectory: &dir])
if (dir) {
- url = [NSURL fileURLWithPath:
- [[[completed_path
- stringByAppendingPathComponent: subdir]
- stringByAppendingPathComponent: tag]
- stringByAppendingPathExtension: @"html"]];
+ @try {
+ url = [NSURL fileURLWithPath:
+ [[[completed_path
+ stringByAppendingPathComponent: subdir]
+ stringByAppendingPathComponent: tag]
+ stringByAppendingPathExtension: @"html"]];
+ }
+ @catch (NSException *e) {
+ PWARN("fileURLWithPath threw %s: %s",
+ [[e name] UTF8String], [[e reason] UTF8String]);
+ return;
+ }
break;
}
+ if ([this_lang compare:@"en"] == NSOrderedSame)
+ break; /* Special case, forces use of "C" locale */
}
}
- if (!url)
- url = [NSURL
- fileURLWithPath: [[[[docs_dir
- stringByAppendingPathComponent: @"C"]
- stringByAppendingPathComponent: subdir]
- stringByAppendingPathComponent: tag]
- stringByAppendingPathExtension: @"html"]];
-
+ 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;
+ }
+ }
}
/* It's a lot easier in a bundle! OSX finds the best translation for us. */
- else
- url = [NSURL fileURLWithPath: [[NSBundle mainBundle]
- pathForResource: tag
- ofType: @"html"
- inDirectory: subdir ]];
-
+ else {
+ @try {
+ url = [NSURL fileURLWithPath: [[NSBundle mainBundle]
+ pathForResource: tag
+ 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 */
if (url)
[[NSWorkspace sharedWorkspace] openURL: url];
More information about the gnucash-changes
mailing list