**/
/* }}} */
+#include <pthread.h>
#include <objc/runtime.h>
#include <Foundation/Foundation.h>
+@class LSDXPCServer;
+
@interface MIFileManager
+ (MIFileManager *) defaultManager;
- (NSURL *) destinationOfSymbolicLinkAtURL:(NSURL *)url error:(NSError *)error;
static Class $MIFileManager;
+static pthread_key_t key_;
+
static NSArray *(*_MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$)(MIFileManager *self, SEL _cmd, NSURL *url, BOOL ignoring, NSError *error);
static NSArray *$MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$(MIFileManager *self, SEL _cmd, NSURL *url, BOOL ignoring, NSError *error) {
[items addObject:[NSURL fileURLWithPathComponents:[prefix arrayByAddingObjectsFromArray:[components subarrayWithRange:NSMakeRange(skip, [components count] - skip)]]]];
}
- NSLog(@"items = %@", items);
return items;
}
static NSString *(*_NSURL$path)(NSURL *self, SEL _cmd);
static NSString *$NSURL$path(NSURL *self, SEL _cmd) {
- return [[_NSURL$path(self, _cmd) mutableCopy] autorelease];
+ NSString *path(_NSURL$path(self, _cmd));
+ if (pthread_getspecific(key_) != NULL)
+ path = [[path mutableCopy] autorelease];
+ return path;
}
static NSRange (*_NSString$rangeOfString$options$)(NSString *self, SEL _cmd, NSString *value, NSStringCompareOptions options);
static NSRange $NSString$rangeOfString$options$(NSString *self, SEL _cmd, NSString *value, NSStringCompareOptions options) {
- if ([value isEqualToString:@".app/"]) do {
+ do {
+ if (pthread_getspecific(key_) == NULL)
+ break;
+ if (![value isEqualToString:@".app/"])
+ break;
+
char *real(realpath("/Applications", NULL));
NSString *destiny([NSString stringWithUTF8String:real]);
free(real);
if (![self hasPrefix:destiny])
break;
- if (![self hasSuffix:@".app"])
- break;
-
BOOL directory;
if (![[NSFileManager defaultManager] fileExistsAtPath:self isDirectory:&directory])
break;
if (!directory)
break;
- NSLog(@"path = %@", self);
// the trailing / allows lsd to "restart" its verification attempt
[(NSMutableString *) self setString:[NSString stringWithFormat:@"/Applications/%@/", [self substringFromIndex:[destiny length]]]];
} while (false);
return _NSString$rangeOfString$options$(self, _cmd, value, options);
}
+static id (*_LSDXPCServer$canOpenURL$connection$)(LSDXPCServer *self, SEL _cmd, id url, id connection);
+
+static id $LSDXPCServer$canOpenURL$connection$(LSDXPCServer *self, SEL _cmd, id url, id connection) {
+ pthread_setspecific(key_, connection);
+ @try {
+ return _LSDXPCServer$canOpenURL$connection$(self, _cmd, url, connection);
+ } @finally {
+ pthread_setspecific(key_, NULL);
+ }
+}
+
__attribute__((__constructor__))
static void initialize() {
+ pthread_key_create(&key_, NULL);
+
$MIFileManager = objc_getClass("MIFileManager");
if ($MIFileManager != Nil) {
method_setImplementation(method, reinterpret_cast<IMP>(&$NSString$rangeOfString$options$));
}
}
+
+ if (Class $LSDXPCServer = objc_getClass("LSDXPCServer")) {
+ SEL sel(@selector(canOpenURL:connection:));
+ if (Method method = class_getInstanceMethod($LSDXPCServer, sel)) {
+ _LSDXPCServer$canOpenURL$connection$ = reinterpret_cast<id (*)(LSDXPCServer *, SEL, id, id)>(method_getImplementation(method));
+ method_setImplementation(method, reinterpret_cast<IMP>(&$LSDXPCServer$canOpenURL$connection$));
+ }
+ }
}