From 79bd7ac09021a9894853641d541eaabd582ff233 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Fri, 21 Aug 2009 14:27:31 -0700 Subject: [PATCH] Add an unarchiver for the delta format so that Sparkle can successfully install the delta updates. --- SUBinaryDeltaUnarchiver.h | 20 +++++++++++++ SUBinaryDeltaUnarchiver.m | 47 +++++++++++++++++++++++++++++++ SUUnarchiver.h | 5 +++- SUUnarchiver.m | 4 +-- SUUnarchiver_Private.h | 2 +- SUUnarchiver_Private.m | 7 +++-- Sparkle.xcodeproj/project.pbxproj | 8 ++++++ 7 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 SUBinaryDeltaUnarchiver.h create mode 100644 SUBinaryDeltaUnarchiver.m diff --git a/SUBinaryDeltaUnarchiver.h b/SUBinaryDeltaUnarchiver.h new file mode 100644 index 00000000..2f2e7651 --- /dev/null +++ b/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 +#import "SUUnarchiver.h" + +@interface SUBinaryDeltaUnarchiver : SUUnarchiver { +} + +@end + +#endif diff --git a/SUBinaryDeltaUnarchiver.m b/SUBinaryDeltaUnarchiver.m new file mode 100644 index 00000000..80e98f38 --- /dev/null +++ b/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 diff --git a/SUUnarchiver.h b/SUUnarchiver.h index 1b237210..74a82821 100644 --- a/SUUnarchiver.h +++ b/SUUnarchiver.h @@ -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; diff --git a/SUUnarchiver.m b/SUUnarchiver.m index 03cfaac0..bad6e195 100644 --- a/SUUnarchiver.m +++ b/SUUnarchiver.m @@ -15,14 +15,14 @@ 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; } diff --git a/SUUnarchiver_Private.h b/SUUnarchiver_Private.h index acf620ac..38427a32 100644 --- a/SUUnarchiver_Private.h +++ b/SUUnarchiver_Private.h @@ -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; diff --git a/SUUnarchiver_Private.m b/SUUnarchiver_Private.m index 26105085..e856f836 100644 --- a/SUUnarchiver_Private.m +++ b/SUUnarchiver_Private.m @@ -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]; } diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index d0c0ddb1..0296c351 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -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 = (); }; }; @@ -176,6 +178,8 @@ 5D06E8F30FD68D21005AE3F6 /* ConfigBinaryDeltaRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigBinaryDeltaRelease.xcconfig; sourceTree = ""; }; 5D06E8F90FD68D53005AE3F6 /* libxar.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxar.dylib; path = /usr/lib/libxar.dylib; sourceTree = ""; }; 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libbz2.dylib; path = /usr/lib/libbz2.dylib; sourceTree = ""; }; + 5D06E9370FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBinaryDeltaUnarchiver.h; sourceTree = ""; }; + 5D06E9380FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBinaryDeltaUnarchiver.m; sourceTree = ""; }; 610134710DD250470049ACDF /* SUUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdateDriver.h; sourceTree = ""; }; 610134720DD250470049ACDF /* SUUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdateDriver.m; sourceTree = ""; }; 610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUProbingUpdateDriver.h; sourceTree = ""; }; @@ -447,6 +451,8 @@ 5D06E8E10FD68CC7005AE3F6 /* SUBinaryDeltaCommon.h */, 5D06E8E20FD68CC7005AE3F6 /* SUBinaryDeltaCommon.m */, 5D06E8E30FD68CC7005AE3F6 /* SUBinaryDeltaTool.m */, + 5D06E9370FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h */, + 5D06E9380FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m */, ); name = "Binary Delta"; sourceTree = ""; @@ -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; }; @@ -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; };