Skip to content

Commit

Permalink
Add an unarchiver for the delta format so that Sparkle can successful…
Browse files Browse the repository at this point in the history
…ly install the delta updates.
  • Loading branch information
bdash committed Aug 21, 2009
1 parent 6e648f1 commit 79bd7ac
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 6 deletions.
20 changes: 20 additions & 0 deletions SUBinaryDeltaUnarchiver.h
@@ -0,0 +1,20 @@
//
// SUBinaryDeltaUnarchiver.h
// Sparkle
//
// Created by Mark Rowe on 2009-06-03.
// Copyright 2009 Mark Rowe. All rights reserved.
//

#ifndef SUBINARYDELTAUNARCHIVER_H
#define SUBINARYDELTAUNARCHIVER_H

#import <Cocoa/Cocoa.h>
#import "SUUnarchiver.h"

@interface SUBinaryDeltaUnarchiver : SUUnarchiver {
}

@end

#endif
47 changes: 47 additions & 0 deletions SUBinaryDeltaUnarchiver.m
@@ -0,0 +1,47 @@
//
// SUBinaryDeltaUnarchiver.m
// Sparkle
//
// Created by Mark Rowe on 2009-06-03.
// Copyright 2009 Mark Rowe. All rights reserved.
//

#import "SUBinaryDeltaUnarchiver.h"
#import "SUBinaryDeltaApply.h"
#import "SUUnarchiver_Private.h"
#import "SUHost.h"
#import "NTSynchronousTask.h"

@implementation SUBinaryDeltaUnarchiver

+ (BOOL)_canUnarchivePath:(NSString *)path
{
return [[path pathExtension] isEqualToString:@"delta"];
}

- (void)start
{
[NSThread detachNewThreadSelector:@selector(_applyBinaryDelta) toTarget:self withObject:nil];
}

- (void)_applyBinaryDelta
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *sourcePath = [[updateHost bundle] bundlePath];
NSString *targetPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]];

int result = applyBinaryDelta(sourcePath, targetPath, archivePath);
if (!result)
[self performSelectorOnMainThread:@selector(_notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO];
else
[self performSelectorOnMainThread:@selector(_notifyDelegateOfFailure) withObject:nil waitUntilDone:NO];

[pool drain];
}

+ (void)load
{
[self _registerImplementation:self];
}

@end
5 changes: 4 additions & 1 deletion SUUnarchiver.h
Expand Up @@ -9,12 +9,15 @@
#ifndef SUUNARCHIVER_H
#define SUUNARCHIVER_H

@class SUHost;

@interface SUUnarchiver : NSObject {
id delegate;
NSString *archivePath;
SUHost *updateHost;
}

+ (SUUnarchiver *)unarchiverForPath:(NSString *)path;
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host;
- (void)setDelegate:delegate;

- (void)start;
Expand Down
4 changes: 2 additions & 2 deletions SUUnarchiver.m
Expand Up @@ -15,14 +15,14 @@ @implementation SUUnarchiver

extern NSMutableArray *__unarchiverImplementations;

+ (SUUnarchiver *)unarchiverForPath:(NSString *)path
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host
{
NSEnumerator *implementationEnumerator = [[self _unarchiverImplementations] objectEnumerator];
id current;
while ((current = [implementationEnumerator nextObject]))
{
if ([current _canUnarchivePath:path])
return [[[current alloc] _initWithPath:path] autorelease];
return [[[current alloc] _initWithPath:path host:host] autorelease];
}
return nil;
}
Expand Down
2 changes: 1 addition & 1 deletion SUUnarchiver_Private.h
Expand Up @@ -16,7 +16,7 @@
+ (void)_registerImplementation:(Class)implementation;
+ (NSArray *)_unarchiverImplementations;
+ (BOOL)_canUnarchivePath:(NSString *)path;
- _initWithPath:(NSString *)path;
- _initWithPath:(NSString *)path host:(SUHost *)host;

- (void)_notifyDelegateOfExtractedLength:(long)length;
- (void)_notifyDelegateOfSuccess;
Expand Down
7 changes: 5 additions & 2 deletions SUUnarchiver_Private.m
Expand Up @@ -10,16 +10,19 @@

@implementation SUUnarchiver (Private)

- _initWithPath:(NSString *)path
- _initWithPath:(NSString *)path host:(SUHost *)host
{
if ((self = [super init]))
if ((self = [super init])) {
archivePath = [path copy];
updateHost = [host retain];
}
return self;
}

- (void)dealloc
{
[archivePath release];
[updateHost release];
[super dealloc];
}

Expand Down
8 changes: 8 additions & 0 deletions Sparkle.xcodeproj/project.pbxproj
Expand Up @@ -18,6 +18,8 @@
5D06E8FF0FD68D6D005AE3F6 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */; };
5D06E9000FD68D6D005AE3F6 /* libxar.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8F90FD68D53005AE3F6 /* libxar.dylib */; };
5D06E9050FD68D7D005AE3F6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; };
5D06E9390FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D06E9370FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h */; };
5D06E93A0FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E9380FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m */; };
610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134710DD250470049ACDF /* SUUpdateDriver.h */; settings = {ATTRIBUTES = (); }; };
610134740DD250470049ACDF /* SUUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 610134720DD250470049ACDF /* SUUpdateDriver.m */; };
6101347B0DD2541A0049ACDF /* SUProbingUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */; settings = {ATTRIBUTES = (); }; };
Expand Down Expand Up @@ -176,6 +178,8 @@
5D06E8F30FD68D21005AE3F6 /* ConfigBinaryDeltaRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigBinaryDeltaRelease.xcconfig; sourceTree = "<group>"; };
5D06E8F90FD68D53005AE3F6 /* libxar.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxar.dylib; path = /usr/lib/libxar.dylib; sourceTree = "<absolute>"; };
5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbz2.dylib; path = /usr/lib/libbz2.dylib; sourceTree = "<absolute>"; };
5D06E9370FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBinaryDeltaUnarchiver.h; sourceTree = "<group>"; };
5D06E9380FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBinaryDeltaUnarchiver.m; sourceTree = "<group>"; };
610134710DD250470049ACDF /* SUUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdateDriver.h; sourceTree = "<group>"; };
610134720DD250470049ACDF /* SUUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdateDriver.m; sourceTree = "<group>"; };
610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUProbingUpdateDriver.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -447,6 +451,8 @@
5D06E8E10FD68CC7005AE3F6 /* SUBinaryDeltaCommon.h */,
5D06E8E20FD68CC7005AE3F6 /* SUBinaryDeltaCommon.m */,
5D06E8E30FD68CC7005AE3F6 /* SUBinaryDeltaTool.m */,
5D06E9370FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h */,
5D06E9380FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m */,
);
name = "Binary Delta";
sourceTree = "<group>";
Expand Down Expand Up @@ -667,6 +673,7 @@
6102FE5B0E08C7EC00F85D09 /* SUUnarchiver_Private.h in Headers */,
61EF67590E25C5B400F754E0 /* SUHost.h in Headers */,
61CFB3290E385186007A1735 /* Sparkle.pch in Headers */,
5D06E9390FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -983,6 +990,7 @@
5D06E8EB0FD68CE4005AE3F6 /* bspatch.c in Sources */,
5D06E8EC0FD68CE4005AE3F6 /* SUBinaryDeltaApply.m in Sources */,
5D06E8ED0FD68CE4005AE3F6 /* SUBinaryDeltaCommon.m in Sources */,
5D06E93A0FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 79bd7ac

Please sign in to comment.