X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=blobdiff_plain;f=Categories%2FNSRunningApplication%2BNJPossibleNames.m;fp=Categories%2FNSRunningApplication%2BNJPossibleNames.m;h=a3fdaf581111c6501611033c07ce2c5db6c1436f;hp=0000000000000000000000000000000000000000;hb=7e5568674713bedf9318e83b9fb13abbd122382c;hpb=0d00fc387704e00e29c5c64669b32eb7a58ed03d diff --git a/Categories/NSRunningApplication+NJPossibleNames.m b/Categories/NSRunningApplication+NJPossibleNames.m new file mode 100644 index 0000000..a3fdaf5 --- /dev/null +++ b/Categories/NSRunningApplication+NJPossibleNames.m @@ -0,0 +1,52 @@ +// +// NSRunningApplication+NJPossibleNames.m +// Enjoyable +// +// Created by Joe Wreschnig on 3/8/13. +// +// + +#import "NSRunningApplication+NJPossibleNames.h" + +@implementation NSRunningApplication (NJPossibleNames) + +- (NSArray *)possibleMappingNames { + NSMutableArray *names = [[NSMutableArray alloc] initWithCapacity:4]; + if (self.bundleIdentifier) + [names addObject:self.bundleIdentifier]; + if (self.localizedName) + [names addObject:self.localizedName]; + if (self.bundleURL) + [names addObject:[self.bundleURL.lastPathComponent stringByDeletingPathExtension]]; + if (self.executableURL) + [names addObject:self.executableURL.lastPathComponent]; + return names; +} + +- (NSString *)bestMappingName { + // A number of Flash applications all use the generic Flash bundle + // ID and localized name, but they name their bundle file and + // executable correctly. Don't want to fall back to those IDs + // unless we absolutely have to. + NSArray *genericBundles = @[ + @"com.macromedia.Flash Player Debugger.app", + @"com.macromedia.Flash Player.app", + ]; + BOOL probablyWrong = [genericBundles containsObject:self.bundleIdentifier]; + if (!probablyWrong && self.localizedName) + return self.localizedName; + else if (!probablyWrong && self.bundleIdentifier) + return self.bundleIdentifier; + else if (self.bundleURL) + return [self.bundleURL.lastPathComponent stringByDeletingPathExtension]; + else if (self.executableURL) + return self.executableURL.lastPathComponent; + else if (self.localizedName) + return self.localizedName; + else if (self.bundleIdentifier) + return self.bundleIdentifier; + else + return @"@Application"; +} + +@end