Don't tie unarchiver to host

This commit is contained in:
Kornel Lesiński committed 2015-04-23 01:21:37 +01:00
1 parent 5ba0b2d656
commit d4843c90e8
6 files changed
+14 -15

No files matched your search

+3 -4
View File
@@ -265,14 +265,13 @@
- (void)extractUpdate
{
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHost:self.host];
if (!unarchiver)
{
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:[[self.host bundle] bundlePath]];
if (!unarchiver) {
SULog(@"Error: No valid unarchiver for %@!", self.downloadPath);
[self unarchiverDidFail:nil];
return;
}
[unarchiver setDelegate:self];
unarchiver.delegate = self;
[unarchiver start];
}
+1 -1
View File
@@ -23,7 +23,7 @@
- (void)applyBinaryDelta
{
@autoreleasepool {
NSString *sourcePath = [[self.updateHost bundle] bundlePath];
NSString *sourcePath = self.updateHostBundlePath;
NSString *targetPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]];
int result = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO);
+2 -2
View File
@@ -15,10 +15,10 @@
@interface SUUnarchiver : NSObject
@property (copy, readonly) NSString *archivePath;
@property (weak, readonly) SUHost *updateHost;
@property (weak, readonly) NSString *updateHostBundlePath;
@property (weak) id<SUUnarchiverDelegate> delegate;
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host;
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHostBundlePath:(NSString *)host;
- (void)start;
@end
+5 -5
View File
@@ -18,15 +18,15 @@
@implementation SUUnarchiver
@synthesize archivePath;
@synthesize updateHost;
@synthesize updateHostBundlePath;
@synthesize delegate;
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHostBundlePath:(NSString *)hostPath
{
for (id current in [self unarchiverImplementations])
{
if ([current canUnarchivePath:path]) {
return [[current alloc] initWithPath:path host:host];
return [[current alloc] initWithPath:path hostBundlePath:hostPath];
}
}
return nil;
@@ -39,12 +39,12 @@
// No-op
}
- (instancetype)initWithPath:(NSString *)path host:(SUHost *)host
- (instancetype)initWithPath:(NSString *)path hostBundlePath:(NSString *)hostPath
{
if ((self = [super init]))
{
archivePath = [path copy];
updateHost = host;
updateHostBundlePath = hostPath;
}
return self;
}
+1 -1
View File
@@ -16,7 +16,7 @@
+ (void)registerImplementation:(Class)implementation;
+ (NSArray *)unarchiverImplementations;
+ (BOOL)canUnarchivePath:(NSString *)path;
- (instancetype)initWithPath:(NSString *)path host:(SUHost *)host;
- (instancetype)initWithPath:(NSString *)archive hostBundlePath:(NSString *)host;
- (void)notifyDelegateOfExtractedLength:(size_t)length;
- (void)notifyDelegateOfSuccess;
+2 -2
View File
@@ -50,11 +50,11 @@
NSFileManager *fm = [NSFileManager defaultManager];
NSString *testFile = [tempDestDir stringByAppendingPathComponent:@"extracted file.txt"];
[fm removeItemAtPath:testFile error:nil];
XCTAssertFalse([fm fileExistsAtPath:testFile isDirectory:nil]);
XCTAssertTrue([fm copyItemAtPath:originalArchivePath toPath:tempArchivePath error:nil]);
SUUnarchiver *unarc = [SUUnarchiver unarchiverForPath:tempArchivePath updatingHost:nil];
SUUnarchiver *unarc = [SUUnarchiver unarchiverForPath:tempArchivePath updatingHostBundlePath:nil];
XCTAssertTrue([unarc isKindOfClass:[SUPipedUnarchiver class]]);