Boxer / Boxer / NSWorkspace+BXExecutableTypes.m

 Boxer is copyright 2010 Alun Bestor and contributors.
 Boxer is released under the GNU General Public License 2.0. A full copy of this license can be
 found in this XCode project at Resources/English.lproj/GNU General Public License.txt, or read
 online at [].

#import "NSWorkspace+BXExecutableTypes.h"
#import "RegexKitLite.h"

@implementation NSWorkspace (BXExecutableTypes)

- (BOOL) isWindowsOnlyExecutableAtPath: (NSString *)filePath
	//Short-circuit: only bother checking EXE files, not other types.
	if (![self file: filePath matchesTypes: [NSSet setWithObject: @""]]) return NO;
	NSPipe *outputPipe = [NSPipe pipe];
	NSTask *fileMagic = [[NSTask alloc] init];
	[fileMagic setLaunchPath: @"/usr/bin/file"];
	[fileMagic setArguments: [NSArray arrayWithObjects: @"-b", filePath, nil]];
	[fileMagic setStandardOutput: outputPipe];
	[fileMagic launch];
	[fileMagic waitUntilExit];
	int status = [fileMagic terminationStatus];
	[fileMagic release];
	if (status == 0)
		NSData *output = [[outputPipe fileHandleForReading] readDataToEndOfFile];
		NSString *outputString = [[NSString alloc] initWithData: output encoding: NSUTF8StringEncoding];
		BOOL isWindowsOnly = ([outputString rangeOfString: @"Windows"].location != NSNotFound);
		[outputString release];
		return isWindowsOnly;
	//If there was a problem, assume the file wasn't a windows executable
	//TODO: we should populate an error message
	else return NO;

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.