Fixes 243533 (for real this time, I hope)

I've undone all the UTI nonsense: I don't see any reason to use it if the underlying frameworks are just going to do dumber path extension comparison that what I'm already doing. I've switched back to the tried-and-true method.

I also made SUUnarchiver* path-based instead of NSURL-based because I realized that the latter didn't make any sense given that we're only unarchiving local files.
This commit is contained in:
Andy Matuschak committed 2008-07-16 22:48:10 -07:00
1 parent b815ce9db4
commit 58a05e2ee7
7 files changed
+23 -47

No files matched your search

+1 -1
View File
@@ -179,7 +179,7 @@
}
}
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForURL:[[[NSURL alloc] initFileURLWithPath:downloadPath] autorelease]];
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:downloadPath];
if (!unarchiver)
{
NSLog(@"Sparkle Error: No valid unarchiver for %@!", downloadPath);
+2 -3
View File
@@ -12,9 +12,9 @@
@implementation SUDiskImageUnarchiver
+ (BOOL)_canUnarchiveURL:(NSURL *)URL
+ (BOOL)_canUnarchivePath:(NSString *)path
{
return [URL conformsToType:@"public.disk-image"];
return [[path pathExtension] isEqualToString:@"dmg"];
}
- (void)start
@@ -25,7 +25,6 @@
- (void)_extractDMG
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *archivePath = [archiveURL path];
BOOL mountedSuccessfully = NO;
// get a unique mount point path
+9 -11
View File
@@ -11,21 +11,20 @@
@implementation SUPipedUnarchiver
+ (SEL)_selectorConformingToTypeOfURL:(NSURL *)URL
+ (SEL)_selectorConformingToTypeOfPath:(NSString *)path
{
static NSDictionary *typeSelectorDictionary;
// HACK: The UTI detector is dumb (not my fault!) and sees .tar.gz files as plain .gz files. If we see something of type .bz2 or .gz, we'll assume it's really a .tar.bz2 or .tar.gz.
if (!typeSelectorDictionary)
typeSelectorDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:@"_extractZIP", @"com.pkware.zip-archive",
@"_extractTGZ", @"org.gnu.gnu-zip-tar-archive", @"_extractTGZ", @"org.gnu.gnu-zip-archive",
@"_extractTBZ", @"org.bzip.bzip2-tar-archive", @"_extractTBZ", @"org.bzip.bzip2-archive", @"_extractTBZ", @"public.archive.bzip2",
@"_extractTAR", @"public.tar-archive", nil] retain];
typeSelectorDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:@"_extractZIP", @".zip", @"_extractTAR", @".tar",
@"_extractTGZ", @".tar.gz", @"_extractTGZ", @".tgz",
@"_extractTBZ", @".tar.bz2", @"_extractTBZ", @".tbz", nil] retain];
NSString *lastPathComponent = [path lastPathComponent];
NSEnumerator *typeEnumerator = [typeSelectorDictionary keyEnumerator];
id currentType;
while ((currentType = [typeEnumerator nextObject]))
{
if ([URL conformsToType:currentType])
if ([[lastPathComponent substringFromIndex:[lastPathComponent length] - [currentType length]] isEqualToString:currentType])
return NSSelectorFromString([typeSelectorDictionary objectForKey:currentType]);
}
return NULL;
@@ -33,19 +32,18 @@
- (void)start
{
[NSThread detachNewThreadSelector:[[self class] _selectorConformingToTypeOfURL:archiveURL] toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:[[self class] _selectorConformingToTypeOfPath:archivePath] toTarget:self withObject:nil];
}
+ (BOOL)_canUnarchiveURL:(NSURL *)URL
+ (BOOL)_canUnarchivePath:(NSString *)path
{
return ([self _selectorConformingToTypeOfURL:URL] != nil);
return ([self _selectorConformingToTypeOfPath:path] != nil);
}
// This method abstracts the types that use a command line tool piping data from stdin.
- (void)_extractArchivePipingDataToCommand:(NSString *)command
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *archivePath = [archiveURL path];
FILE *fp = NULL, *cmdFP = NULL;
// Get the file size.
+2 -2
View File
@@ -11,10 +11,10 @@
@interface SUUnarchiver : NSObject {
id delegate;
NSURL *archiveURL;
NSString *archivePath;
}
+ (SUUnarchiver *)unarchiverForURL:(NSURL *)URL;
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path;
- (void)setDelegate:delegate;
- (void)start;
+3 -3
View File
@@ -15,14 +15,14 @@
extern NSMutableArray *__unarchiverImplementations;
+ (SUUnarchiver *)unarchiverForURL:(NSURL *)URL
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path
{
NSEnumerator *implementationEnumerator = [[self _unarchiverImplementations] objectEnumerator];
id current;
while ((current = [implementationEnumerator nextObject]))
{
if ([current _canUnarchiveURL:URL])
return [[[current alloc] _initWithURL:URL] autorelease];
if ([current _canUnarchivePath:path])
return [[[current alloc] _initWithPath:path] autorelease];
}
return nil;
}
+2 -6
View File
@@ -15,16 +15,12 @@
@interface SUUnarchiver (Private)
+ (void)_registerImplementation:(Class)implementation;
+ (NSArray *)_unarchiverImplementations;
+ (BOOL)_canUnarchiveURL:(NSURL *)URL;
- _initWithURL:(NSURL *)URL;
+ (BOOL)_canUnarchivePath:(NSString *)path;
- _initWithPath:(NSString *)path;
- (void)_notifyDelegateOfExtractedLength:(long)length;
- (void)_notifyDelegateOfSuccess;
- (void)_notifyDelegateOfFailure;
@end
@interface NSURL (SUTypeDetection)
- (BOOL)conformsToType:(NSString *)type;
@end
#endif
+4 -21
View File
@@ -10,20 +10,20 @@
@implementation SUUnarchiver (Private)
- _initWithURL:(NSURL *)URL
- _initWithPath:(NSString *)path
{
if ((self = [super init]))
archiveURL = [URL copy];
archivePath = [path copy];
return self;
}
- (void)dealloc
{
[archiveURL release];
[archivePath release];
[super dealloc];
}
+ (BOOL)_canUnarchiveURL:(NSURL *)URL
+ (BOOL)_canUnarchivePath:(NSString *)path
{
return NO;
}
@@ -61,20 +61,3 @@ static NSMutableArray *__unarchiverImplementations;
}
@end
@implementation NSURL (SUTypeDetection)
- (NSString *)__UTI
{
FSRef fsRefToItem;
FSPathMakeRef((UInt8 *)[[self path] fileSystemRepresentation], &fsRefToItem, NULL );
NSString *UTI = nil;
LSCopyItemAttribute(&fsRefToItem, kLSRolesAll, kLSItemContentType, (CFTypeRef *)(&UTI));
return [UTI autorelease];
}
- (BOOL)conformsToType:(NSString *)type
{
return UTTypeConformsTo((CFStringRef)[self __UTI], (CFStringRef)type);
}
@end