~tcurdt/sparkle/devel

« back to all changes in this revision

Viewing changes to SUUnarchiver_Private.m

  • Committer: Andy Matuschak
  • Date: 2008-06-19 05:53:16 UTC
  • Revision ID: andy@andymatuschak.org-20080619055316-zktlbz5mxa9ezvs5
Fixes 236695

Refactored Sparkle's unarchiving system into SUUnarchiver, a factory for SUPipedUnarchiver and SUDiskImageUnarchiver. I removed that nasty cleanUp call by now copying out the contents of the DMG into the /tmp directory and unmounting. Nice!

This changed a fair amount so please test with your build and let me know if it explodes things. Works in my tests, though.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
//  SUUnarchiver_Private.m
 
3
//  Sparkle
 
4
//
 
5
//  Created by Andy Matuschak on 6/17/08.
 
6
//  Copyright 2008 Andy Matuschak. All rights reserved.
 
7
//
 
8
 
 
9
#import "SUUnarchiver_Private.h"
 
10
 
 
11
@implementation SUUnarchiver (Private)
 
12
 
 
13
- _initWithURL:(NSURL *)URL
 
14
{
 
15
        if ((self = [super init]))
 
16
                archiveURL = [URL copy];
 
17
        return self;
 
18
}
 
19
 
 
20
- (void)dealloc
 
21
{
 
22
        [archiveURL release];
 
23
        [super dealloc];
 
24
}
 
25
 
 
26
+ (BOOL)_canUnarchiveURL:(NSURL *)URL
 
27
{
 
28
        return NO;
 
29
}
 
30
 
 
31
- (void)_notifyDelegateOfExtractedLength:(long)length
 
32
{
 
33
        if ([delegate respondsToSelector:@selector(unarchiver:extractedLength:)])
 
34
                [delegate unarchiver:self extractedLength:length];
 
35
}
 
36
 
 
37
- (void)_notifyDelegateOfSuccess
 
38
{
 
39
        if ([delegate respondsToSelector:@selector(unarchiverDidFinish:)])
 
40
                [delegate performSelector:@selector(unarchiverDidFinish:) withObject:self];
 
41
}
 
42
 
 
43
- (void)_notifyDelegateOfFailure
 
44
{
 
45
        if ([delegate respondsToSelector:@selector(unarchiverDidFail:)])
 
46
                [delegate performSelector:@selector(unarchiverDidFail:) withObject:self];
 
47
}
 
48
 
 
49
static NSMutableArray *__unarchiverImplementations;
 
50
 
 
51
+ (void)_registerImplementation:(Class)implementation
 
52
{
 
53
        if (!__unarchiverImplementations)
 
54
                __unarchiverImplementations = [[NSMutableArray array] retain];
 
55
        [__unarchiverImplementations addObject:implementation];
 
56
}
 
57
 
 
58
+ (NSArray *)_unarchiverImplementations
 
59
{
 
60
        //return [NSArray arrayWithObjects:NSClassFromString(@"SUPipedUnarchiver"), NSClassFromString(@"SUDiskImageUnarchiver"), nil];
 
61
        return [NSArray arrayWithArray:__unarchiverImplementations];
 
62
}
 
63
 
 
64
@end
 
65
 
 
66
@implementation NSURL (SUTypeDetection)
 
67
- (NSString *)__UTI
 
68
{
 
69
        FSRef fsRefToItem;
 
70
        FSPathMakeRef((UInt8 *)[[self path] UTF8String], &fsRefToItem, NULL );
 
71
        
 
72
        NSString *UTI = nil;
 
73
        LSCopyItemAttribute(&fsRefToItem, kLSRolesAll, kLSItemContentType, (CFTypeRef *)(&UTI));
 
74
        return [UTI autorelease];
 
75
}
 
76
 
 
77
- (BOOL)conformsToType:(NSString *)type
 
78
{
 
79
        return UTTypeConformsTo((CFStringRef)[self __UTI], (CFStringRef)type);
 
80
}
 
81
@end