diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index 2563b492..d16f241e 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -14,6 +14,7 @@ GCC_DEBUGGING_SYMBOLS = full GCC_PRECOMPILE_PREFIX_HEADER = YES GCC_PREFIX_HEADER = $(SDKROOT)/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h GCC_FAST_OBJC_DISPATCH = YES +GCC_ENABLE_PASCAL_STRINGS = NO ARCHS = ppc i386 x86_64 // Enable warnings @@ -36,4 +37,15 @@ GCC_WARN_UNKNOWN_PRAGMAS = YES GCC_WARN_UNUSED_VARIABLE = YES GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES -WARNING_CFLAGS = -Wall +GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES +GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES +GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES +GCC_WARN_UNUSED_FUNCTION = YES +GCC_WARN_UNUSED_LABEL = YES +GCC_WARN_UNUSED_VALUE = YES +GCC_WARN_UNUSED_PARAMETER = YES +GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES +WARNING_CFLAGS = -Wall -Wundef -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-noreturn -Wmissing-format-attribute -Wpacked -Wredundant-decls -Winline -Wdisabled-optimization -Wformat=2 -Wlarger-than-32768 -Winvalid-pch + +// TODO: +// GCC_WARN_UNDECLARED_SELECTOR = YES only 7 warnings diff --git a/Configurations/ConfigCommonDebug.xcconfig b/Configurations/ConfigCommonDebug.xcconfig index fdf006d6..36003c98 100644 --- a/Configurations/ConfigCommonDebug.xcconfig +++ b/Configurations/ConfigCommonDebug.xcconfig @@ -3,5 +3,8 @@ GCC_OPTIMIZATION_LEVEL = 0 DEBUG_INFORMATION_FORMAT = dwarf GCC_GENERATE_DEBUGGING_SYMBOLS = YES -SPARKLE_EXTRA_DEBUG = -DDEBUG -fstack-protector -D_FORTIFY_SOURCE=2 -OTHER_CFLAGS = $(SPARKLE_EXTRA_DEBUG) \ No newline at end of file +SPARKLE_EXTRA_DEBUG_10_5_ONLY = -fstack-protector -D_FORTIFY_SOURCE=2 +SPARKLE_EXTRA_DEBUG = -DDEBUG +OTHER_CFLAGS = $(SPARKLE_EXTRA_DEBUG) + +// Add $(SPARKLE_EXTRA_DEBUG_10_5_ONLY) to SPARKLE_EXTRA_DEBUG if your deployment is 10.5 or greater. \ No newline at end of file diff --git a/Configurations/ConfigUnitTest.xcconfig b/Configurations/ConfigUnitTest.xcconfig new file mode 100644 index 00000000..ab0124b0 --- /dev/null +++ b/Configurations/ConfigUnitTest.xcconfig @@ -0,0 +1,9 @@ +// Unit Test only + +INFOPLIST_FILE = Tests/Sparkle Unit Tests-Info.plist +OTHER_LDFLAGS = -framework Cocoa -framework SenTestingKit +PRODUCT_NAME = Sparkle Unit Tests +WRAPPER_EXTENSION = octest +FRAMEWORK_SEARCH_PATHS = $(DEVELOPER_LIBRARY_DIR)/Frameworks +GCC_PREFIX_HEADER = $(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h +GCC_PRECOMPILE_PREFIX_HEADER = YES diff --git a/Configurations/ConfigUnitTestDebug.xcconfig b/Configurations/ConfigUnitTestDebug.xcconfig new file mode 100644 index 00000000..354e9361 --- /dev/null +++ b/Configurations/ConfigUnitTestDebug.xcconfig @@ -0,0 +1,3 @@ +#include "ConfigCommon.xcconfig" +#include "ConfigCommonDebug.xcconfig" +#include "ConfigUnitTest.xcconfig" diff --git a/Configurations/ConfigUnitTestRelease.xcconfig b/Configurations/ConfigUnitTestRelease.xcconfig new file mode 100644 index 00000000..53dd6b93 --- /dev/null +++ b/Configurations/ConfigUnitTestRelease.xcconfig @@ -0,0 +1,3 @@ +#include "ConfigCommon.xcconfig" +#include "ConfigCommonRelease.xcconfig" +#include "ConfigUnitTest.xcconfig" diff --git a/Configurations/ConfigUnitTestReleaseGCSupport.xcconfig b/Configurations/ConfigUnitTestReleaseGCSupport.xcconfig new file mode 100644 index 00000000..1b648d16 --- /dev/null +++ b/Configurations/ConfigUnitTestReleaseGCSupport.xcconfig @@ -0,0 +1,3 @@ +#include "ConfigUnitTestRelease.xcconfig" + +GCC_ENABLE_OBJC_GC = required \ No newline at end of file diff --git a/NTSynchronousTask.h b/NTSynchronousTask.h index 1cf5c04e..e1e32bee 100644 --- a/NTSynchronousTask.h +++ b/NTSynchronousTask.h @@ -11,6 +11,7 @@ @interface NTSynchronousTask : NSObject { +@private NSTask *mv_task; NSPipe *mv_outputPipe; NSPipe *mv_inputPipe; diff --git a/NTSynchronousTask.m b/NTSynchronousTask.m index d506cad5..5a46105c 100644 --- a/NTSynchronousTask.m +++ b/NTSynchronousTask.m @@ -56,10 +56,10 @@ { [[NSNotificationCenter defaultCenter] removeObserver:self]; - [self setTask:nil]; - [self setOutputPipe:nil]; - [self setInputPipe:nil]; - [self setOutput:nil]; + [mv_task release]; + [mv_outputPipe release]; + [mv_inputPipe release]; + [mv_output release]; [super dealloc]; } @@ -70,7 +70,7 @@ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSData* result=nil; - NS_DURING + @try { NTSynchronousTask* task = [[NTSynchronousTask alloc] init]; @@ -81,8 +81,7 @@ [task release]; } - NS_HANDLER; - NS_ENDHANDLER; + @catch (NSException *localException) { } [pool drain]; @@ -92,10 +91,6 @@ return result; } -@end - -@implementation NTSynchronousTask (Private) - - (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input; { BOOL success = NO; @@ -118,12 +113,12 @@ [[[self outputPipe] fileHandleForReading] readToEndOfFileInBackgroundAndNotifyForModes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSModalPanelRunLoopMode, NSEventTrackingRunLoopMode, nil]]; - NS_DURING + @try + { [[self task] launch]; success = YES; - NS_HANDLER - ; - NS_ENDHANDLER + } + @catch (NSException *localException) { } if (success) { diff --git a/SUAppcast.h b/SUAppcast.h index a29492c5..f5762cc4 100644 --- a/SUAppcast.h +++ b/SUAppcast.h @@ -10,7 +10,9 @@ #define SUAPPCAST_H @class SUAppcastItem; -@interface SUAppcast : NSObject { +@interface SUAppcast : NSObject +{ +@private NSArray *items; NSString *userAgentString; id delegate; diff --git a/SUAppcast.m b/SUAppcast.m index 4a5a3433..b79f8690 100644 --- a/SUAppcast.m +++ b/SUAppcast.m @@ -40,8 +40,12 @@ - (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename { - NSString *destinationFilename = [NSTemporaryDirectory() stringByAppendingPathComponent:filename]; - [download setDestination:destinationFilename allowOverwrite:NO]; + NSString* destinationFilename = NSTemporaryDirectory(); + if (destinationFilename) + { + destinationFilename = [destinationFilename stringByAppendingPathComponent:filename]; + [download setDestination:destinationFilename allowOverwrite:NO]; + } } - (void)download:(NSURLDownload *)download didCreateDestination:(NSString *)path @@ -52,7 +56,8 @@ - (void)downloadDidFinish:(NSURLDownload *)download { - CFRelease(download); + if (download) + CFRelease(download); NSError *error = nil; NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:downloadFilename] options:0 error:&error]; @@ -62,7 +67,7 @@ #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 [[NSFileManager defaultManager] removeFileAtPath:downloadFilename handler:nil]; #else - [[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:NULL]; + [[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:nil]; #endif [downloadFilename release]; downloadFilename = nil; @@ -179,13 +184,14 @@ - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error { - CFRelease(download); + if (download) + CFRelease(download); if (downloadFilename) { #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 [[NSFileManager defaultManager] removeFileAtPath:downloadFilename handler:nil]; #else - [[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:NULL]; + [[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:nil]; #endif } [downloadFilename release]; @@ -219,7 +225,7 @@ NSXMLElement *node; NSMutableArray *languages = [NSMutableArray array]; NSString *lang; - NSInteger i; + NSUInteger i; while ((node = [nodeEnum nextObject])) { lang = [[node attributeForName:@"xml:lang"] stringValue]; diff --git a/SUAppcastItem.h b/SUAppcastItem.h index 010c892a..f3e01763 100644 --- a/SUAppcastItem.h +++ b/SUAppcastItem.h @@ -9,7 +9,9 @@ #ifndef SUAPPCASTITEM_H #define SUAPPCASTITEM_H -@interface SUAppcastItem : NSObject { +@interface SUAppcastItem : NSObject +{ +@private NSString *title; NSDate *date; NSString *itemDescription; diff --git a/SUAppcastItem.m b/SUAppcastItem.m index f17ce493..ba88d2f5 100644 --- a/SUAppcastItem.m +++ b/SUAppcastItem.m @@ -185,14 +185,14 @@ - (void)dealloc { - [self setTitle:nil]; - [self setDate:nil]; - [self setItemDescription:nil]; - [self setReleaseNotesURL:nil]; - [self setDSASignature:nil]; - [self setFileURL:nil]; - [self setVersionString:nil]; - [self setDisplayVersionString:nil]; + [title release]; + [date release]; + [itemDescription release]; + [releaseNotesURL release]; + [DSASignature release]; + [fileURL release]; + [versionString release]; + [displayVersionString release]; [propertiesDictionary release]; [super dealloc]; } diff --git a/SUAutomaticUpdateDriver.h b/SUAutomaticUpdateDriver.h index f63c194e..266f6b69 100644 --- a/SUAutomaticUpdateDriver.h +++ b/SUAutomaticUpdateDriver.h @@ -13,7 +13,9 @@ #import "SUBasicUpdateDriver.h" @class SUAutomaticUpdateAlert; -@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver { +@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver +{ +@private BOOL postponingInstallation, showErrors; SUAutomaticUpdateAlert *alert; } diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 6f109ea9..483cda73 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -94,7 +94,7 @@ } updateItem = [item retain]; - CFRelease(ac); // Remember that we're explicitly managing the memory of the appcast. + if (ac) { CFRelease(ac); } // Remember that we're explicitly managing the memory of the appcast. if (updateItem == nil) { [self didNotFindUpdate]; return; } if ([self itemContainsValidUpdate:updateItem]) @@ -105,7 +105,7 @@ - (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error { - CFRelease(ac); // Remember that we're explicitly managing the memory of the appcast. + if (ac) { CFRelease(ac); } // Remember that we're explicitly managing the memory of the appcast. [self abortUpdateWithError:error]; } @@ -139,27 +139,31 @@ // We create a temporary directory in /tmp and stick the file there. // Not using a GUID here because hdiutil (for DMGs) for some reason chokes on GUIDs. Too long? I really have no idea. NSString *prefix = [NSString stringWithFormat:@"%@ %@ Update", [host name], [host version]]; - NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:prefix]; - int cnt=1; - while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999) + NSString *tempDir = NSTemporaryDirectory(); + if (tempDir) { - tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", prefix, cnt++]]; - } + tempDir = [tempDir stringByAppendingPathComponent:prefix]; + unsigned int cnt=1; + while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999) + { + tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %u", prefix, cnt++]]; + } #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 - BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir attributes:nil]; + BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir attributes:nil]; #else - BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL]; + BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:nil]; #endif - if (!success) - { - // Okay, something's really broken with /tmp - [download cancel]; - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.",tempDir] forKey:NSLocalizedDescriptionKey]]]; + if (!success) + { + // Okay, something's really broken with /tmp + [download cancel]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.",tempDir] forKey:NSLocalizedDescriptionKey]]]; + } + + downloadPath = [[tempDir stringByAppendingPathComponent:name] retain]; + [download setDestination:downloadPath allowOverwrite:YES]; } - - downloadPath = [[tempDir stringByAppendingPathComponent:name] retain]; - [download setDestination:downloadPath allowOverwrite:YES]; } - (void)downloadDidFinish:(NSURLDownload *)d @@ -226,8 +230,9 @@ { if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdate:)]) [[updater delegate] updater:updater willInstallUpdate:updateItem]; + // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. - NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""]; + NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""]; NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. NSError *error = nil; @@ -235,7 +240,7 @@ [[NSFileManager defaultManager] removeFileAtPath:targetPath handler:nil]; if ([[NSFileManager defaultManager] copyPath:relaunchPathToCopy toPath:targetPath handler:nil]) #else - [[NSFileManager defaultManager] removeItemAtPath:targetPath error:NULL]; + [[NSFileManager defaultManager] removeItemAtPath:targetPath error:nil]; if ([[NSFileManager defaultManager] copyItemAtPath:relaunchPathToCopy toPath:targetPath error:&error]) #endif relaunchPath = [targetPath retain]; @@ -292,7 +297,7 @@ #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 [[NSFileManager defaultManager] removeFileAtPath:[downloadPath stringByDeletingLastPathComponent] handler:nil]; #else - [[NSFileManager defaultManager] removeItemAtPath:[downloadPath stringByDeletingLastPathComponent] error:NULL]; + [[NSFileManager defaultManager] removeItemAtPath:[downloadPath stringByDeletingLastPathComponent] error:nil]; #endif } diff --git a/SUConstants.h b/SUConstants.h index e9d8e958..4a807d38 100644 --- a/SUConstants.h +++ b/SUConstants.h @@ -11,26 +11,26 @@ #define SUCONSTANTS_H -extern NSString *SUUpdaterWillRestartNotification; -extern NSString *SUTechnicalErrorInformationKey; +extern NSString *const SUUpdaterWillRestartNotification; +extern NSString *const SUTechnicalErrorInformationKey; -extern NSString *SUFeedURLKey; -extern NSString *SUHasLaunchedBeforeKey; -extern NSString *SUShowReleaseNotesKey; -extern NSString *SUSkippedVersionKey; -extern NSString *SUScheduledCheckIntervalKey; -extern NSString *SULastCheckTimeKey; -extern NSString *SUPublicDSAKeyKey; -extern NSString *SUPublicDSAKeyFileKey; -extern NSString *SUAutomaticallyUpdateKey; -extern NSString *SUAllowsAutomaticUpdatesKey; -extern NSString *SUEnableAutomaticChecksKey; -extern NSString *SUEnableAutomaticChecksKeyOld; -extern NSString *SUEnableSystemProfilingKey; -extern NSString *SUSendProfileInfoKey; -extern NSString *SULastProfileSubmitDateKey; +extern NSString *const SUFeedURLKey; +extern NSString *const SUHasLaunchedBeforeKey; +extern NSString *const SUShowReleaseNotesKey; +extern NSString *const SUSkippedVersionKey; +extern NSString *const SUScheduledCheckIntervalKey; +extern NSString *const SULastCheckTimeKey; +extern NSString *const SUPublicDSAKeyKey; +extern NSString *const SUPublicDSAKeyFileKey; +extern NSString *const SUAutomaticallyUpdateKey; +extern NSString *const SUAllowsAutomaticUpdatesKey; +extern NSString *const SUEnableAutomaticChecksKey; +extern NSString *const SUEnableAutomaticChecksKeyOld; +extern NSString *const SUEnableSystemProfilingKey; +extern NSString *const SUSendProfileInfoKey; +extern NSString *const SULastProfileSubmitDateKey; -extern NSString *SUSparkleErrorDomain; +extern NSString *const SUSparkleErrorDomain; // Appcast phase errors. extern OSStatus SUAppcastParseError; extern OSStatus SUNoUpdateError; diff --git a/SUConstants.m b/SUConstants.m index ae91584f..5f06311f 100644 --- a/SUConstants.m +++ b/SUConstants.m @@ -9,27 +9,27 @@ #import "Sparkle.h" #import "SUConstants.h" -NSString *SUUpdaterWillRestartNotification = @"SUUpdaterWillRestartNotificationName"; -NSString *SUTechnicalErrorInformationKey = @"SUTechnicalErrorInformation"; +NSString *const SUUpdaterWillRestartNotification = @"SUUpdaterWillRestartNotificationName"; +NSString *const SUTechnicalErrorInformationKey = @"SUTechnicalErrorInformation"; -NSString *SUHasLaunchedBeforeKey = @"SUHasLaunchedBefore"; -NSString *SUFeedURLKey = @"SUFeedURL"; -NSString *SUShowReleaseNotesKey = @"SUShowReleaseNotes"; -NSString *SUSkippedVersionKey = @"SUSkippedVersion"; -NSString *SUScheduledCheckIntervalKey = @"SUScheduledCheckInterval"; -NSString *SULastCheckTimeKey = @"SULastCheckTime"; -NSString *SUExpectsDSASignatureKey = @"SUExpectsDSASignature"; -NSString *SUPublicDSAKeyKey = @"SUPublicDSAKey"; -NSString *SUPublicDSAKeyFileKey = @"SUPublicDSAKeyFile"; -NSString *SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate"; -NSString *SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates"; -NSString *SUEnableSystemProfilingKey = @"SUEnableSystemProfiling"; -NSString *SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks"; -NSString *SUEnableAutomaticChecksKeyOld = @"SUCheckAtStartup"; -NSString *SUSendProfileInfoKey = @"SUSendProfileInfo"; -NSString *SULastProfileSubmitDateKey = @"SULastProfileSubmissionDate"; +NSString *const SUHasLaunchedBeforeKey = @"SUHasLaunchedBefore"; +NSString *const SUFeedURLKey = @"SUFeedURL"; +NSString *const SUShowReleaseNotesKey = @"SUShowReleaseNotes"; +NSString *const SUSkippedVersionKey = @"SUSkippedVersion"; +NSString *const SUScheduledCheckIntervalKey = @"SUScheduledCheckInterval"; +NSString *const SULastCheckTimeKey = @"SULastCheckTime"; +NSString *const SUExpectsDSASignatureKey = @"SUExpectsDSASignature"; +NSString *const SUPublicDSAKeyKey = @"SUPublicDSAKey"; +NSString *const SUPublicDSAKeyFileKey = @"SUPublicDSAKeyFile"; +NSString *const SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate"; +NSString *const SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates"; +NSString *const SUEnableSystemProfilingKey = @"SUEnableSystemProfiling"; +NSString *const SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks"; +NSString *const SUEnableAutomaticChecksKeyOld = @"SUCheckAtStartup"; +NSString *const SUSendProfileInfoKey = @"SUSendProfileInfo"; +NSString *const SULastProfileSubmitDateKey = @"SULastProfileSubmissionDate"; -NSString *SUSparkleErrorDomain = @"SUSparkleErrorDomain"; +NSString *const SUSparkleErrorDomain = @"SUSparkleErrorDomain"; OSStatus SUAppcastParseError = 1000; OSStatus SUNoUpdateError = 1001; OSStatus SUAppcastError = 1002; diff --git a/SUDSAVerifier.m b/SUDSAVerifier.m index e9ee03e5..d827ac7d 100644 --- a/SUDSAVerifier.m +++ b/SUDSAVerifier.m @@ -17,7 +17,7 @@ #import #import -long b64decode(unsigned char* str) +static long b64decode(unsigned char* str) { unsigned char *cur, *start; int d, dlast, phase; @@ -41,12 +41,12 @@ long b64decode(unsigned char* str) -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 /* F0-FF */ }; - d = dlast = phase = 0; + dlast = phase = 0; start = str; for (cur = str; *cur != '\0'; ++cur ) { if(*cur == '\n' || *cur == '\r'){phase = dlast = 0; continue;} - d = table[(int)*cur]; + d = table[(unsigned int)*cur]; if(d != -1) { switch(phase) @@ -77,26 +77,30 @@ long b64decode(unsigned char* str) return str - start; } -EVP_PKEY* load_dsa_key(char *key) +static EVP_PKEY* load_dsa_key(char *key) { EVP_PKEY* pkey = NULL; - BIO *bio; - if((bio = BIO_new_mem_buf(key, (int)strlen(key)))) + size_t keylen = strlen(key); + if (keylen <= INT_MAX) { - DSA* dsa_key = 0; - if(PEM_read_bio_DSA_PUBKEY(bio, &dsa_key, NULL, NULL)) + BIO *bio; + if((bio = BIO_new_mem_buf(key, (int)keylen))) { - if((pkey = EVP_PKEY_new())) + DSA* dsa_key = 0; + if(PEM_read_bio_DSA_PUBKEY(bio, &dsa_key, NULL, NULL)) { - if(EVP_PKEY_assign_DSA(pkey, dsa_key) != 1) + if((pkey = EVP_PKEY_new())) { - DSA_free(dsa_key); - EVP_PKEY_free(pkey); - pkey = NULL; + if(EVP_PKEY_assign_DSA(pkey, dsa_key) != 1) + { + DSA_free(dsa_key); + EVP_PKEY_free(pkey); + pkey = NULL; + } } } + BIO_free(bio); } - BIO_free(bio); } return pkey; } @@ -119,12 +123,15 @@ EVP_PKEY* load_dsa_key(char *key) } pkeyString = [pkeyTrimmedLines componentsJoinedByString:@"\n"]; // Put them back together. + NSMutableData* pkeyData = [[[pkeyString dataUsingEncoding:NSUTF8StringEncoding] mutableCopy] autorelease]; + void *pkeyBytes = [pkeyData mutableBytes]; EVP_PKEY* pkey = NULL; - pkey = load_dsa_key((char *)[pkeyString UTF8String]); + pkey = load_dsa_key(pkeyBytes); if (!pkey) { return NO; } // Now, the signature is in base64; we have to decode it into a binary stream. - unsigned char *signature = (unsigned char *)[encodedSignature UTF8String]; + NSMutableData* signatureData = [[[encodedSignature dataUsingEncoding:NSUTF8StringEncoding] mutableCopy] autorelease]; + void *signature = [signatureData mutableBytes]; long length = b64decode(signature); // Decode the signature in-place and get the new length of the signature string. // We've got the signature, now get the file data. @@ -140,10 +147,17 @@ EVP_PKEY* load_dsa_key(char *key) if(EVP_VerifyInit(&ctx, EVP_dss1()) == 1) // We're using DSA keys. { EVP_VerifyUpdate(&ctx, md, SHA_DIGEST_LENGTH); + if ((length < 0) || (length > 0x7FFFFFFF)) { return NO; } // test before cast below result = (EVP_VerifyFinal(&ctx, signature, (unsigned int)length, pkey) == 1); } EVP_PKEY_free(pkey); + + // Prevent these from being collected earlier than we want (our only reference is an inner pointer). + [pkeyData self]; + [signatureData self]; + [pathData self]; + return result; } diff --git a/SUDiskImageUnarchiver.m b/SUDiskImageUnarchiver.m index a7c5f633..96ba8bd7 100644 --- a/SUDiskImageUnarchiver.m +++ b/SUDiskImageUnarchiver.m @@ -35,14 +35,13 @@ do { CFUUIDRef uuid = CFUUIDCreate(NULL); - mountPointName = (NSString *)CFUUIDCreateString(NULL, uuid); - CFRelease(uuid); -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4 - [NSMakeCollectable((CFStringRef)mountPointName) autorelease]; -#else - [mountPointName autorelease]; -#endif - mountPoint = [@"/Volumes" stringByAppendingPathComponent:mountPointName]; + if (uuid) + { + CFStringRef uuidString = CFUUIDCreateString(NULL, uuid); + CFRelease(uuid); + mountPoint = [@"/Volumes" stringByAppendingPathComponent:(NSString*)uuidString]; + CFRelease(uuidString); + } } while (noErr == FSPathMakeRefWithOptions((UInt8 *)[mountPoint fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &tmpRef, NULL)); @@ -57,7 +56,7 @@ // Now that we've mounted it, we need to copy out its contents. FSRef srcRef, dstRef; - OSErr err; + OSStatus err; err = FSPathMakeRef((UInt8 *)[mountPoint fileSystemRepresentation], &srcRef, NULL); if (err != noErr) goto reportError; err = FSPathMakeRef((UInt8 *)[[archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], &dstRef, NULL); diff --git a/SUHost.h b/SUHost.h index f8f8203f..c43b4041 100644 --- a/SUHost.h +++ b/SUHost.h @@ -9,6 +9,7 @@ @interface SUHost : NSObject { +@private NSBundle *bundle; } diff --git a/SUHost.m b/SUHost.m index d86be234..2c95414b 100644 --- a/SUHost.m +++ b/SUHost.m @@ -14,9 +14,9 @@ - (id)initWithBundle:(NSBundle *)aBundle { - if (aBundle == nil) aBundle = [NSBundle mainBundle]; if ((self = [super init])) { + if (aBundle == nil) aBundle = [NSBundle mainBundle]; bundle = [aBundle retain]; if (![bundle bundleIdentifier]) NSLog(@"Sparkle Error: the bundle being updated at %@ has no CFBundleIdentifier! This will cause preference read/write to not work properly.", bundle); @@ -114,7 +114,7 @@ // More likely, we've got a reference to a Resources file by filename: NSString *keyFilename = [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey]; if (!keyFilename) { return nil; } - NSError *ignoreErr; + NSError *ignoreErr = nil; return [NSString stringWithContentsOfFile:[bundle pathForResource:keyFilename ofType:nil] encoding:NSASCIIStringEncoding error: &ignoreErr]; } @@ -135,18 +135,14 @@ - (id)objectForUserDefaultsKey:(NSString *)defaultName { - // Under Tiger, CFPreferencesCopyAppValue doesn't get values from NSRegistratioDomain, so anything + // Under Tiger, CFPreferencesCopyAppValue doesn't get values from NSRegistrationDomain, so anything // passed into -[NSUserDefaults registerDefaults:] is ignored. The following line falls // back to using NSUserDefaults, but only if the host bundle is the main bundle. if (bundle == [NSBundle mainBundle]) return [[NSUserDefaults standardUserDefaults] objectForKey:defaultName]; CFPropertyListRef obj = CFPreferencesCopyAppValue((CFStringRef)defaultName, (CFStringRef)[bundle bundleIdentifier]); -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4 - return [NSMakeCollectable(obj) autorelease]; -#else - return [(id)obj autorelease]; -#endif + return [(id)CFMakeCollectable(obj) autorelease]; } - (void)setObject:(id)value forUserDefaultsKey:(NSString *)defaultName; diff --git a/SUInstaller.m b/SUInstaller.m index 870663c4..f2967db1 100644 --- a/SUInstaller.m +++ b/SUInstaller.m @@ -118,7 +118,7 @@ + (void)_finishInstallationWithResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate { - if (result == YES) + if (result) { [self _mdimportHost:host]; if ([delegate respondsToSelector:@selector(installerFinishedForHost:)]) diff --git a/SUPipedUnarchiver.m b/SUPipedUnarchiver.m index db7ffc99..dbe8a7a7 100644 --- a/SUPipedUnarchiver.m +++ b/SUPipedUnarchiver.m @@ -49,9 +49,9 @@ // Get the file size. #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 - NSNumber *fs = [[[NSFileManager defaultManager] fileAttributesAtPath:archivePath traverseLink:NO] objectForKey:NSFileSize]; + NSNumber *fs = [[[NSFileManager defaultManager] fileAttributesAtPath:archivePath traverseLink:NO] objectForKey:NSFileSize]; #else - NSNumber *fs = [[[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:NULL] objectForKey:NSFileSize]; + NSNumber *fs = [[[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:nil] objectForKey:NSFileSize]; #endif if (fs == nil) goto reportError; @@ -62,11 +62,11 @@ setenv("DESTINATION", [[archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], 1); cmdFP = popen([command fileSystemRepresentation], "w"); - long written; + size_t written; if (!cmdFP) goto reportError; char buf[32*1024]; - long len; + size_t len; while((len = fread(buf, 1, 32*1024, fp))) { written = fwrite(buf, 1, len, cmdFP); @@ -76,7 +76,7 @@ goto reportError; } - [self performSelectorOnMainThread:@selector(_notifyDelegateOfExtractedLength:) withObject:[NSNumber numberWithLong:len] waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(_notifyDelegateOfExtractedLength:) withObject:[NSNumber numberWithUnsignedLong:len] waitUntilDone:NO]; } pclose(cmdFP); diff --git a/SUPlainInstaller.m b/SUPlainInstaller.m index 2586addd..b1ecebeb 100644 --- a/SUPlainInstaller.m +++ b/SUPlainInstaller.m @@ -9,13 +9,13 @@ #import "SUPlainInstaller.h" #import "SUPlainInstallerInternals.h" -NSString *SUInstallerPathKey = @"SUInstallerPath"; -NSString *SUInstallerTargetPathKey = @"SUInstallerTargetPath"; -NSString *SUInstallerTempNameKey = @"SUInstallerTempName"; -NSString *SUInstallerHostKey = @"SUInstallerHost"; -NSString *SUInstallerDelegateKey = @"SUInstallerDelegate"; -NSString *SUInstallerResultKey = @"SUInstallerResult"; -NSString *SUInstallerErrorKey = @"SUInstallerError"; +static NSString * const SUInstallerPathKey = @"SUInstallerPath"; +static NSString * const SUInstallerTargetPathKey = @"SUInstallerTargetPath"; +static NSString * const SUInstallerTempNameKey = @"SUInstallerTempName"; +static NSString * const SUInstallerHostKey = @"SUInstallerHost"; +static NSString * const SUInstallerDelegateKey = @"SUInstallerDelegate"; +static NSString * const SUInstallerResultKey = @"SUInstallerResult"; +static NSString * const SUInstallerErrorKey = @"SUInstallerError"; @implementation SUPlainInstaller diff --git a/SUPlainInstallerInternals.m b/SUPlainInstallerInternals.m index 719089b6..ada13d00 100644 --- a/SUPlainInstallerInternals.m +++ b/SUPlainInstallerInternals.m @@ -79,9 +79,9 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza NSString *prefix = [[path stringByDeletingPathExtension] stringByAppendingFormat:@" (%@)", postFix]; NSString *tempDir = [prefix stringByAppendingPathExtension:[path pathExtension]]; // Now let's make sure we get a unique path. - int cnt=2; + unsigned int cnt=2; while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999) - tempDir = [NSString stringWithFormat:@"%@ %d.%@", prefix, cnt++, [path pathExtension]]; + tempDir = [NSString stringWithFormat:@"%@ %u.%@", prefix, cnt++, [path pathExtension]]; return [tempDir lastPathComponent]; } @@ -136,7 +136,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza }; // Process the commands up until the first NULL - int commandIndex = 0; + unsigned int commandIndex = 0; for (; executables[commandIndex] != NULL; ++commandIndex) { if (res) res = AuthorizationExecuteWithPrivilegesAndWait(auth, executables[commandIndex], kAuthorizationFlagDefaults, argumentLists[commandIndex]); @@ -173,13 +173,13 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza { // Something went wrong somewhere along the way, but we're not sure exactly where. NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file copy from %@ to %@ failed.", src, dst]; - if (error != NULL) + if (error != nil) *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; } } else { - if (error != NULL) + if (error != nil) *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:@"Couldn't get permission to authenticate." forKey:NSLocalizedDescriptionKey]]; } return res; @@ -195,13 +195,13 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza + (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp error:(NSError **)error { FSRef srcRef, dstRef, targetRef, movedRef; - OSErr err; + OSStatus err; err = FSPathMakeRefWithOptions((UInt8 *)[dst fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &dstRef, NULL); if (err != noErr) { NSString *errorMessage = [NSString stringWithFormat:@"Couldn't copy %@ over %@ because there is no file at %@.", src, dst, dst]; - if (error != NULL) + if (error != nil) *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; return NO; } @@ -216,7 +216,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza err = FSMoveObjectSync(&dstRef, &targetRef, (CFStringRef)tmp, &movedRef, 0); if (err != noErr) { - if (error != NULL) + if (error != nil) *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]]; return NO; } @@ -227,7 +227,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza { // We better move the old version back to its old location FSMoveObjectSync(&movedRef, &targetRef, (CFStringRef)[dst lastPathComponent], &movedRef, 0); - if (error != NULL) + if (error != nil) *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't copy %@ to %@.", src, dst] forKey:NSLocalizedDescriptionKey]]; return NO; } @@ -258,9 +258,9 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza @end -#include -#include -#include +#import +#import +#import @implementation SUPlainInstaller (MMExtendedAttributes) @@ -308,8 +308,11 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // Only recurse if it's actually a directory. Don't recurse into a // root-level symbolic link. - NSDictionary* rootAttributes = - [[NSFileManager defaultManager] fileAttributesAtPath:root traverseLink:NO]; +#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 + NSDictionary* rootAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:root traverseLink:NO]; +#else + NSDictionary* rootAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:root error:nil]; +#endif NSString* rootType = [rootAttributes objectForKey:NSFileType]; if (rootType == NSFileTypeDirectory) { diff --git a/SUScheduledUpdateDriver.h b/SUScheduledUpdateDriver.h index 892a6a74..64b8022d 100644 --- a/SUScheduledUpdateDriver.h +++ b/SUScheduledUpdateDriver.h @@ -12,7 +12,9 @@ #import #import "SUUIBasedUpdateDriver.h" -@interface SUScheduledUpdateDriver : SUUIBasedUpdateDriver { +@interface SUScheduledUpdateDriver : SUUIBasedUpdateDriver +{ +@private BOOL showErrors; } diff --git a/SUStandardVersionComparator.m b/SUStandardVersionComparator.m index 03c0c0d7..8332760f 100644 --- a/SUStandardVersionComparator.m +++ b/SUStandardVersionComparator.m @@ -40,7 +40,8 @@ typedef enum { { NSString *character; NSMutableString *s; - NSInteger i, n, oldType, newType; + NSUInteger i, n; + SUCharacterType oldType, newType; NSMutableArray *parts = [NSMutableArray array]; if ([version length] == 0) { // Nothing to do here @@ -76,8 +77,10 @@ typedef enum { NSArray *partsB = [self splitVersionString:versionB]; NSString *partA, *partB; - NSInteger i, n, typeA, typeB, intA, intB; - + NSUInteger i, n; + int intA, intB; + SUCharacterType typeA, typeB; + n = MIN([partsA count], [partsB count]); for (i = 0; i < n; ++i) { partA = [partsA objectAtIndex:i]; diff --git a/SUStatusController.h b/SUStatusController.h index c73ea5b8..5dfd9775 100644 --- a/SUStatusController.h +++ b/SUStatusController.h @@ -12,7 +12,9 @@ #import "SUWindowController.h" @class SUHost; -@interface SUStatusController : SUWindowController { +@interface SUStatusController : SUWindowController +{ +@private double progressValue, maxProgressValue; NSString *title, *statusText, *buttonTitle; IBOutlet NSButton *actionButton; diff --git a/SUStatusController.m b/SUStatusController.m index 16774c0a..eea47609 100644 --- a/SUStatusController.m +++ b/SUStatusController.m @@ -111,10 +111,10 @@ - (void)setMaxProgressValue:(double)value { - if (value < 0) value = 0; + if (value < 0.0) value = 0.0; maxProgressValue = value; - [self setProgressValue:0]; - [progressBar setIndeterminate:(value == 0)]; + [self setProgressValue:0.0]; + [progressBar setIndeterminate:(value == 0.0)]; [progressBar startAnimation:self]; } diff --git a/SUSystemProfiler.m b/SUSystemProfiler.m index 47d5909c..0fde4a18 100644 --- a/SUSystemProfiler.m +++ b/SUSystemProfiler.m @@ -34,9 +34,9 @@ // Gather profile information and append it to the URL. NSMutableArray *profileArray = [NSMutableArray array]; NSArray *profileDictKeys = [NSArray arrayWithObjects:@"key", @"displayKey", @"value", @"displayValue", nil]; - int error = 0 ; - int value = 0 ; - unsigned long length = sizeof(value) ; + int error = 0; + int value = 0; + size_t length = sizeof(value); // OS version NSString *currentSystemVersion = [SUHost systemVersionString]; @@ -89,18 +89,18 @@ } error = sysctlbyname("hw.model", NULL, &length, NULL, 0); if (error == 0) { - char *cpuModel; - cpuModel = (char *)malloc(sizeof(char) * length); - error = sysctlbyname("hw.model", cpuModel, &length, NULL, 0); - if (error == 0) { - NSString *rawModelName = [NSString stringWithUTF8String:cpuModel]; - NSString *visibleModelName = [modelTranslation objectForKey:rawModelName]; - if (visibleModelName == nil) - visibleModelName = rawModelName; - [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"model",@"Mac Model", rawModelName, visibleModelName, nil] forKeys:profileDictKeys]]; - } - if (cpuModel != NULL) + char *cpuModel = (char *)malloc(sizeof(char) * length); + if (cpuModel != NULL) { + error = sysctlbyname("hw.model", cpuModel, &length, NULL, 0); + if (error == 0) { + NSString *rawModelName = [NSString stringWithUTF8String:cpuModel]; + NSString *visibleModelName = [modelTranslation objectForKey:rawModelName]; + if (visibleModelName == nil) + visibleModelName = rawModelName; + [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"model",@"Mac Model", rawModelName, visibleModelName, nil] forKeys:profileDictKeys]]; + } free(cpuModel); + } } // Number of CPUs @@ -111,7 +111,7 @@ // User preferred language NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; NSArray *languages = [defs objectForKey:@"AppleLanguages"]; - if (languages && ([languages count] > 0)) + if ([languages count] > 0) [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"lang",@"Preferred Language", [languages objectAtIndex:0], [languages objectAtIndex:0],nil] forKeys:profileDictKeys]]; // Application sending the request @@ -124,9 +124,8 @@ // Number of displays? // CPU speed - OSErr err; SInt32 gestaltInfo; - err = Gestalt(gestaltProcClkSpeedMHz,&gestaltInfo); + OSErr err = Gestalt(gestaltProcClkSpeedMHz,&gestaltInfo); if (err == noErr) [profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpuFreqMHz",@"CPU Speed (GHz)", [NSNumber numberWithInt:gestaltInfo], [NSNumber numberWithDouble:gestaltInfo/1000.0],nil] forKeys:profileDictKeys]]; diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index 3fe001ed..f8625d3c 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -61,7 +61,7 @@ { case SUInstallUpdateChoice: statusController = [[SUStatusController alloc] initWithHost:host]; - [statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0 statusText:nil]; + [statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil]; [statusController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelDownload:) isDefault:NO]; [statusController showWindow:self]; [self downloadUpdate]; @@ -82,22 +82,22 @@ - (NSString *)_humanReadableSizeFromDouble:(double)value { - if (value < 1024) + if (value < 1000) return [NSString stringWithFormat:@"%.0lf %@", value, SULocalizedString(@"B", @"the unit for bytes")]; - if (value < 1024 * 1024) - return [NSString stringWithFormat:@"%.0lf %@", value / 1024.0, SULocalizedString(@"KB", @"the unit for kilobytes")]; + if (value < 1000 * 1000) + return [NSString stringWithFormat:@"%.0lf %@", value / 1000.0, SULocalizedString(@"KB", @"the unit for kilobytes")]; - if (value < 1024 * 1024 * 1024) - return [NSString stringWithFormat:@"%.1lf %@", value / 1024.0 / 1024.0, SULocalizedString(@"MB", @"the unit for megabytes")]; + if (value < 1000 * 1000 * 1000) + return [NSString stringWithFormat:@"%.1lf %@", value / 1000.0 / 1000.0, SULocalizedString(@"MB", @"the unit for megabytes")]; - return [NSString stringWithFormat:@"%.2lf %@", value / 1024.0 / 1024.0 / 1024.0, SULocalizedString(@"GB", @"the unit for gigabytes")]; + return [NSString stringWithFormat:@"%.2lf %@", value / 1000.0 / 1000.0 / 1000.0, SULocalizedString(@"GB", @"the unit for gigabytes")]; } - (void)download:(NSURLDownload *)download didReceiveDataOfLength:(NSUInteger)length { - [statusController setProgressValue:[statusController progressValue] + length]; - if ([statusController maxProgressValue] > 0) + [statusController setProgressValue:[statusController progressValue] + (double)length]; + if ([statusController maxProgressValue] > 0.0) [statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ of %@", nil), [self _humanReadableSizeFromDouble:[statusController progressValue]], [self _humanReadableSizeFromDouble:[statusController maxProgressValue]]]]; else [statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ downloaded", nil), [self _humanReadableSizeFromDouble:[statusController progressValue]]]]; @@ -113,27 +113,31 @@ - (void)extractUpdate { // Now we have to extract the downloaded archive. - [statusController beginActionWithTitle:SULocalizedString(@"Extracting update...", @"Take care not to overflow the status window.") maxProgressValue:0 statusText:nil]; + [statusController beginActionWithTitle:SULocalizedString(@"Extracting update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil]; [statusController setButtonEnabled:NO]; [super extractUpdate]; } -- (void)unarchiver:(SUUnarchiver *)ua extractedLength:(long)length +- (void)unarchiver:(SUUnarchiver *)ua extractedLength:(unsigned long)length { // We do this here instead of in extractUpdate so that we only have a determinate progress bar for archives with progress. - if ([statusController maxProgressValue] == 0) + if ([statusController maxProgressValue] == 0.0) + { + NSDictionary * attributes; #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 - [statusController setMaxProgressValue:[[[[NSFileManager defaultManager] fileAttributesAtPath:downloadPath traverseLink:NO] objectForKey:NSFileSize] doubleValue]]; + attributes = [[NSFileManager defaultManager] fileAttributesAtPath:downloadPath traverseLink:NO]; #else - [statusController setMaxProgressValue:[[[[NSFileManager defaultManager] attributesOfItemAtPath:downloadPath error:NULL] objectForKey:NSFileSize] doubleValue]]; + attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:downloadPath error:nil]; #endif - [statusController setProgressValue:[statusController progressValue] + length]; + [statusController setMaxProgressValue:[[attributes objectForKey:NSFileSize] doubleValue]]; + } + [statusController setProgressValue:[statusController progressValue] + (double)length]; } - (void)unarchiverDidFinish:(SUUnarchiver *)ua { - [statusController beginActionWithTitle:SULocalizedString(@"Ready to Install", nil) maxProgressValue:1 statusText:nil]; - [statusController setProgressValue:1]; // Fill the bar. + [statusController beginActionWithTitle:SULocalizedString(@"Ready to Install", nil) maxProgressValue:1.0 statusText:nil]; + [statusController setProgressValue:1.0]; // Fill the bar. [statusController setButtonEnabled:YES]; [statusController setButtonTitle:SULocalizedString(@"Install and Relaunch", nil) target:self action:@selector(installAndRestart:) isDefault:YES]; [NSApp requestUserAttention:NSInformationalRequest]; @@ -143,7 +147,7 @@ - (void)installUpdate { - [statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"Take care not to overflow the status window.") maxProgressValue:0 statusText:nil]; + [statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil]; [statusController setButtonEnabled:NO]; [super installUpdate]; diff --git a/SUUnarchiver.h b/SUUnarchiver.h index 1b237210..3e388e92 100644 --- a/SUUnarchiver.h +++ b/SUUnarchiver.h @@ -22,7 +22,7 @@ @end @interface NSObject (SUUnarchiverDelegate) -- (void)unarchiver:(SUUnarchiver *)unarchiver extractedLength:(long)length; +- (void)unarchiver:(SUUnarchiver *)unarchiver extractedLength:(unsigned long)length; - (void)unarchiverDidFinish:(SUUnarchiver *)unarchiver; - (void)unarchiverDidFail:(SUUnarchiver *)unarchiver; @end diff --git a/SUUnarchiver_Private.m b/SUUnarchiver_Private.m index ead77eeb..afe93399 100644 --- a/SUUnarchiver_Private.m +++ b/SUUnarchiver_Private.m @@ -31,7 +31,7 @@ - (void)_notifyDelegateOfExtractedLength:(NSNumber *)length { if ([delegate respondsToSelector:@selector(unarchiver:extractedLength:)]) - [delegate unarchiver:self extractedLength:[length longValue]]; + [delegate unarchiver:self extractedLength:[length unsignedLongValue]]; } - (void)_notifyDelegateOfSuccess diff --git a/SUUpdateAlert.m b/SUUpdateAlert.m index 08fa2792..607e37ab 100644 --- a/SUUpdateAlert.m +++ b/SUUpdateAlert.m @@ -182,7 +182,7 @@ - (void)webView:sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:frame decisionListener:listener { - if (webViewFinishedLoading == YES) { + if (webViewFinishedLoading) { [[NSWorkspace sharedWorkspace] openURL:[request URL]]; [listener ignore]; diff --git a/SUUpdateDriver.h b/SUUpdateDriver.h index 5d181647..1a305d11 100644 --- a/SUUpdateDriver.h +++ b/SUUpdateDriver.h @@ -11,7 +11,7 @@ #import -extern NSString *SUUpdateDriverFinishedNotification; +extern NSString * const SUUpdateDriverFinishedNotification; @class SUHost, SUUpdater; @interface SUUpdateDriver : NSObject diff --git a/SUUpdateDriver.m b/SUUpdateDriver.m index a3ccdd32..6b8e2bf5 100644 --- a/SUUpdateDriver.m +++ b/SUUpdateDriver.m @@ -8,7 +8,7 @@ #import "SUUpdateDriver.h" -NSString *SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; +NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; @implementation SUUpdateDriver - initWithUpdater:(SUUpdater *)anUpdater diff --git a/SUUpdatePermissionPrompt.m b/SUUpdatePermissionPrompt.m index a6277a50..d54ce20c 100644 --- a/SUUpdatePermissionPrompt.m +++ b/SUUpdatePermissionPrompt.m @@ -39,7 +39,7 @@ // the user would not know why the application was paused. if ([aHost isBackgroundApplication]) { [NSApp activateIgnoringOtherApps:YES]; } - id prompt = [[[self class] alloc] initWithHost:aHost systemProfile:profile delegate:d]; + id prompt = [[[[self class] alloc] initWithHost:aHost systemProfile:profile delegate:d] autorelease]; [NSApp runModalForWindow:[prompt window]]; } diff --git a/SUUpdater.h b/SUUpdater.h index 0ed3a2d4..6874871e 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -12,7 +12,9 @@ #import @class SUUpdateDriver, SUAppcastItem, SUHost, SUAppcast; -@interface SUUpdater : NSObject { +@interface SUUpdater : NSObject +{ +@private NSTimer *checkTimer; SUUpdateDriver *driver; diff --git a/SUUpdater.m b/SUUpdater.m index 6c907f94..e9629c99 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -34,7 +34,7 @@ #pragma mark Initialization static NSMutableDictionary *sharedUpdaters = nil; -static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext"; +static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext"; + (SUUpdater *)sharedUpdater { @@ -351,7 +351,7 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv parameters = [parameters arrayByAddingObjectsFromArray:[host systemProfile]]; [host setObject:[NSDate date] forUserDefaultsKey:SULastProfileSubmitDateKey]; } - if (parameters == nil || [parameters count] == 0) { return baseFeedURL; } + if ([parameters count] == 0) { return baseFeedURL; } // Build up the parameterized URL. NSMutableArray *parameterStrings = [NSMutableArray array]; diff --git a/SUUserInitiatedUpdateDriver.h b/SUUserInitiatedUpdateDriver.h index 9d9a3041..8df5f89d 100644 --- a/SUUserInitiatedUpdateDriver.h +++ b/SUUserInitiatedUpdateDriver.h @@ -12,7 +12,9 @@ #import #import "SUUIBasedUpdateDriver.h" -@interface SUUserInitiatedUpdateDriver : SUUIBasedUpdateDriver { +@interface SUUserInitiatedUpdateDriver : SUUIBasedUpdateDriver +{ +@private SUStatusController *checkingController; BOOL isCanceled; } diff --git a/SUUserInitiatedUpdateDriver.m b/SUUserInitiatedUpdateDriver.m index 92ad3f2e..9ed50e49 100644 --- a/SUUserInitiatedUpdateDriver.m +++ b/SUUserInitiatedUpdateDriver.m @@ -17,7 +17,7 @@ { checkingController = [[SUStatusController alloc] initWithHost:aHost]; [[checkingController window] center]; // Force the checking controller to load its window. - [checkingController beginActionWithTitle:SULocalizedString(@"Checking for updates...", nil) maxProgressValue:0 statusText:nil]; + [checkingController beginActionWithTitle:SULocalizedString(@"Checking for updates...", nil) maxProgressValue:0.0 statusText:nil]; [checkingController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelCheckForUpdates:) isDefault:NO]; [checkingController showWindow:self]; [super checkForUpdatesAtURL:URL host:aHost]; diff --git a/SUWindowController.m b/SUWindowController.m index c1c5d713..038900ac 100644 --- a/SUWindowController.m +++ b/SUWindowController.m @@ -20,7 +20,8 @@ NSBundle *framework = [NSBundle bundleWithPath:frameworkPath]; path = [framework pathForResource:nibName ofType:@"nib"]; } - return [super initWithWindowNibPath:path owner:self]; + self = [super initWithWindowNibPath:path owner:self]; + return self; } @end diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 0c276081..28a4eed4 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -92,6 +92,8 @@ DAAEFC9B0DA5722F0051E0D0 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; DAAEFD4E0DA572330051E0D0 /* relaunch.m in Sources */ = {isa = PBXBuildFile; fileRef = 613242130CD06CEF00106AA4 /* relaunch.m */; }; DAAEFD510DA572550051E0D0 /* relaunch in Resources */ = {isa = PBXBuildFile; fileRef = DAAEFC960DA571DF0051E0D0 /* relaunch */; }; + FA8342D2104A4B1F001FE2FF /* SUStandardVersionComparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */; }; + FA8342DE104A4B54001FE2FF /* SUStandardVersionComparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */; }; FAEFA2F70D94AA7500472538 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; }; FAEFA2F80D94AA7900472538 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; FAEFA3040D94AB3400472538 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; @@ -309,6 +311,10 @@ FA1941D30D94A70100DD942E /* ConfigRelaunchDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigRelaunchDebug.xcconfig; sourceTree = ""; }; FA1941D40D94A70100DD942E /* ConfigRelaunchRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigRelaunchRelease.xcconfig; sourceTree = ""; }; FA1941D50D94A70100DD942E /* ConfigFrameworkRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigFrameworkRelease.xcconfig; sourceTree = ""; }; + FA302AFD109D13190060F891 /* ConfigUnitTestReleaseGCSupport.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigUnitTestReleaseGCSupport.xcconfig; sourceTree = ""; }; + FA3AAF391050B273004B3130 /* ConfigUnitTestRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigUnitTestRelease.xcconfig; sourceTree = ""; }; + FA3AAF3A1050B273004B3130 /* ConfigUnitTestDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigUnitTestDebug.xcconfig; sourceTree = ""; }; + FA3AAF3B1050B273004B3130 /* ConfigUnitTest.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigUnitTest.xcconfig; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -580,6 +586,10 @@ FA1941CE0D94A70100DD942E /* ConfigRelaunch.xcconfig */, FA1941D30D94A70100DD942E /* ConfigRelaunchDebug.xcconfig */, FA1941D40D94A70100DD942E /* ConfigRelaunchRelease.xcconfig */, + FA3AAF3B1050B273004B3130 /* ConfigUnitTest.xcconfig */, + FA3AAF3A1050B273004B3130 /* ConfigUnitTestDebug.xcconfig */, + FA3AAF391050B273004B3130 /* ConfigUnitTestRelease.xcconfig */, + FA302AFD109D13190060F891 /* ConfigUnitTestReleaseGCSupport.xcconfig */, ); path = Configurations; sourceTree = ""; @@ -867,6 +877,7 @@ buildActionMask = 2147483647; files = ( 61227A160DB548B800AB99EA /* SUVersionComparisonTest.m in Sources */, + FA8342DE104A4B54001FE2FF /* SUStandardVersionComparator.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -875,6 +886,7 @@ buildActionMask = 2147483647; files = ( 61B5F93009C4CFDC00B25A18 /* main.m in Sources */, + FA8342D2104A4B1F001FE2FF /* SUStandardVersionComparator.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1103,7 +1115,6 @@ isa = XCBuildConfiguration; baseConfigurationReference = 61072EB20DF2640C008FE88B /* ConfigFrameworkReleaseGCSupport.xcconfig */; buildSettings = { - INSTALL_PATH = "@loader_path/../Frameworks"; }; name = "Release (GC dual-mode; 10.5-only)"; }; @@ -1123,87 +1134,22 @@ }; 61072EB10DF263BD008FE88B /* Release (GC dual-mode; 10.5-only) */ = { isa = XCBuildConfiguration; + baseConfigurationReference = FA302AFD109D13190060F891 /* ConfigUnitTestReleaseGCSupport.xcconfig */; buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(NATIVE_ARCH)"; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; - GCC_ENABLE_FIX_AND_CONTINUE = NO; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_MODEL_TUNING = G5; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h"; - INFOPLIST_FILE = "Tests/Sparkle Unit Tests-Info.plist"; - INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles"; - OTHER_LDFLAGS = ( - "-framework", - Cocoa, - "-framework", - SenTestingKit, - ); - PREBINDING = NO; - PRODUCT_NAME = "Sparkle Unit Tests"; - WARNING_CFLAGS = ""; - WRAPPER_EXTENSION = octest; - ZERO_LINK = NO; }; name = "Release (GC dual-mode; 10.5-only)"; }; 612279DB0DB5470300AB99EA /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = FA3AAF3A1050B273004B3130 /* ConfigUnitTestDebug.xcconfig */; buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(NATIVE_ARCH_ACTUAL)"; - COPY_PHASE_STRIP = NO; - FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; - GCC_DYNAMIC_NO_PIC = NO; - GCC_ENABLE_FIX_AND_CONTINUE = NO; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_MODEL_TUNING = G5; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h"; - INFOPLIST_FILE = "Tests/Sparkle Unit Tests-Info.plist"; - INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles"; - OTHER_LDFLAGS = ( - "-framework", - Cocoa, - "-framework", - SenTestingKit, - ); - PREBINDING = NO; - PRODUCT_NAME = "Sparkle Unit Tests"; - WRAPPER_EXTENSION = octest; - ZERO_LINK = NO; }; name = Debug; }; 612279DC0DB5470300AB99EA /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = FA3AAF391050B273004B3130 /* ConfigUnitTestRelease.xcconfig */; buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(NATIVE_ARCH)"; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; - GCC_ENABLE_FIX_AND_CONTINUE = NO; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_MODEL_TUNING = G5; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h"; - INFOPLIST_FILE = "Tests/Sparkle Unit Tests-Info.plist"; - INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles"; - OTHER_LDFLAGS = ( - "-framework", - Cocoa, - "-framework", - SenTestingKit, - ); - PREBINDING = NO; - PRODUCT_NAME = "Sparkle Unit Tests"; - WRAPPER_EXTENSION = octest; - ZERO_LINK = NO; }; name = Release; }; diff --git a/relaunch.m b/relaunch.m index e693e377..fc04c732 100644 --- a/relaunch.m +++ b/relaunch.m @@ -1,15 +1,16 @@ #import -#include +#import @interface TerminationListener : NSObject { +@private const char *executablePath; pid_t parentProcessId; } -- (void) relaunch; +- (void)relaunch __dead2; @end @@ -39,11 +40,16 @@ - (void) relaunch { [[NSWorkspace sharedWorkspace] openFile:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:executablePath length:strlen(executablePath)]]; + NSString* path = NSTemporaryDirectory(); + if (path) + { + path = [path stringByAppendingPathComponent:@"relaunch"]; #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 - [[NSFileManager defaultManager] removeFileAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"relaunch"] handler:nil]; + [[NSFileManager defaultManager] removeFileAtPath:path handler:nil]; #else - [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"relaunch"] error:NULL]; + [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; #endif + } exit(0); }