Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Read only the first few bytes of a file to check for #! #1025

Closed
wants to merge 3 commits into from

1 participant

Patrick Robertson
Patrick Robertson
Owner

Saves trying to load a potentially very large file into memory and causing all sorts of problems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 30, 2012
  1. Patrick Robertson

    Read only the first few bytes of a file to check for #!

    pjrobertson authored
    Saves trying to load a potentially very large file into memory and causing all sorts of problems
  2. Patrick Robertson
  3. Patrick Robertson

    release string when done

    pjrobertson authored
This page is out of date. Refresh to see the latest.
17 Quicksilver/Code-App/QSGrowlNotifier.h
View
@@ -0,0 +1,17 @@
+//
+// QSGrowlNotifier.h
+// QSGrowlNotifier
+//
+// Created by Nicholas Jitkoff on 7/12/04.
+// Copyright __MyCompanyName__ 2004. All rights reserved.
+//
+
+// If compiler complains that GrowlApplicaionBrid.h is not found
+// then download latest Growl source code and compile.
+#import <Growl/GrowlApplicationBridge.h>
+
+@interface QSGrowlNotifier : NSObject <GrowlApplicationBridgeDelegate>
+{
+}
+@end
+
71 Quicksilver/Code-App/QSGrowlNotifier.m
View
@@ -0,0 +1,71 @@
+//
+// QSGrowlNotifier.m
+// QSGrowlNotifier
+//
+// Created by Nicholas Jitkoff on 7/12/04.
+// Copyright __MyCompanyName__ 2004. All rights reserved.
+//
+
+#import <QSCore/QSNotifyMediator.h>
+#import "QSGrowlNotifier.h"
+#import <Growl/GrowlApplicationBridge.h>
+
+#define QSGrowlNotification @"Quicksilver Notification"
+#define QSiTunesNotification @"iTunes Notification"
+
+Class GAB;
+
+@implementation QSGrowlNotifier
++ (void) initialize {
+ [super initialize];
+ NSBundle *plugin = [NSBundle bundleForClass:self];
+ NSString *path = [[plugin privateFrameworksPath] stringByAppendingPathComponent:@"Growl.framework"];
+ NSBundle *bundle = [NSBundle bundleWithPath:path];
+ if (path && [bundle load]) {
+ GAB = NSClassFromString(@"GrowlApplicationBridge");
+ } else {
+ GAB = nil;
+ }
+}
+
+- (id) init {
+ if (self = [super init]) {
+ [GAB setGrowlDelegate:self];
+ }
+ return self;
+}
+
+- (NSDictionary *) registrationDictionaryForGrowl {
+ NSArray *notifications = [NSArray arrayWithObjects:QSGrowlNotification, QSiTunesNotification, nil];
+ return [NSDictionary dictionaryWithObjectsAndKeys:
+ notifications, GROWL_NOTIFICATIONS_ALL,
+ notifications, GROWL_NOTIFICATIONS_DEFAULT,
+ nil];
+}
+
+- (NSString *) applicationNameForGrowl {
+ return @"Quicksilver";
+}
+
+- (void) displayNotificationWithAttributes:(NSDictionary *)attributes {
+
+ NSString *type = QSGrowlNotification;
+ if ([[attributes objectForKey:QSNotifierType] isEqualToString:@"QSiTunesTrackChangeNotification"]) {
+ type = QSiTunesNotification;
+ }
+
+ NSString *text = [attributes objectForKey:QSNotifierText];
+ if (!text)
+ text = @"";
+
+ [GAB notifyWithTitle:[attributes objectForKey:QSNotifierTitle]
+ description:text
+ notificationName:type
+ iconData:[[attributes objectForKey:QSNotifierIcon] TIFFRepresentation]
+ priority:0
+ isSticky:NO
+ clickContext:nil
+ identifier:(type == QSiTunesNotification ? QSiTunesNotification : nil)];
+}
+
+@end
12 Quicksilver/PlugIns-Main/QSCorePlugIn/Code/QSShellScriptRunAction.m
View
@@ -35,10 +35,14 @@ BOOL QSPathCanBeExecuted(NSString *path, BOOL allowApps) {
return NO;
BOOL executable = [[NSFileManager defaultManager] isExecutableFileAtPath:path];
if (!executable) {
- if ([[NSString stringWithContentsOfFile:path usedEncoding:nil error:nil] hasPrefix:@"#!"]) executable = YES;
-#ifdef DEBUG
- else if (VERBOSE) NSLog(@"No Shebang found");
-#endif
+ NSFileHandle * fileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
+ // Read in the first 5 bytes of the file to see if it contains #! (5 bytes, because some files contain byte order marks (3 bytes)
+ NSData * buffer = [fileHandle readDataOfLength:5];
+ NSString *string = [[NSString alloc] initWithData:buffer encoding:NSUTF8StringEncoding];
+ if ([string containsString:@"#!"]) {
+ executable = YES;
+ }
+ [string release];
} else if (!allowApps) {
LSItemInfoRecord infoRec;
LSCopyItemInfoForURL((CFURLRef) [NSURL fileURLWithPath:path], kLSRequestBasicFlagsOnly, &infoRec);
Something went wrong with that request. Please try again.