Skip to content

Commit

Permalink
Initial merge of SparklePlus.
Browse files Browse the repository at this point in the history
Fixes to compiling for release.
Fixes to rescheduling the updater after the initial launch.
  • Loading branch information
andym committed Dec 24, 2007
1 parent 86f8091 commit bed9e98
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 16 deletions.
4 changes: 2 additions & 2 deletions NSFileManager+Authentication.m
Expand Up @@ -96,9 +96,9 @@ - (BOOL)copyPath:(NSString *)src overPath:(NSString *)dst withAuthentication:(BO
return result;
}
else if (useAuthentication == YES)
{
return [self _copyPathWithForcedAuthentication:src toPath:dst];
}
else
return NO;
}

@end
14 changes: 14 additions & 0 deletions SUSystemProfiler.h
@@ -0,0 +1,14 @@
//
// SUSystemProfiler.h
// Sparkle
//
// Created by Andy Matuschak on 12/22/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>


@interface SUSystemProfiler : NSObject {}
+ (NSURL *)profiledURLForAppcastURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hostBundle;
@end
133 changes: 133 additions & 0 deletions SUSystemProfiler.m
@@ -0,0 +1,133 @@
//
// SUSystemProfiler.m
// Sparkle
//
// Created by Andy Matuschak on 12/22/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "SUSystemProfiler.h"
#import "NSBundle+SUAdditions.h"
#import <sys/sysctl.h>

@implementation SUSystemProfiler
+ (NSDictionary *)modelTranslationTable
{
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"SUModelTranslation" ofType:@"plist"];
return [[NSDictionary alloc] initWithContentsOfFile:path];
}

+ (NSMutableArray *)systemProfileInformationArrayWithHostBundle:(NSBundle *)hostBundle
{
NSDictionary *modelTranslation = [self modelTranslationTable];

// Gather profile information and append it to the URL.
NSMutableArray *profileArray = [NSMutableArray array];
NSArray *profileDictKeys = [NSArray arrayWithObjects:@"key", @"visibleKey", @"value", @"visibleValue", nil];
int error = 0 ;
int value = 0 ;
unsigned long length = sizeof(value) ;

// OS version (Apple recommends using SystemVersion.plist instead of Gestalt() here, don't ask me why).
NSString *currentSystemVersion = SUSystemVersionString();
if (currentSystemVersion != nil)
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"osVersion",@"OS Version",currentSystemVersion,currentSystemVersion,nil] forKeys:profileDictKeys]];

// CPU type (decoder info for values found here is in mach/machine.h)
error = sysctlbyname("hw.cputype", &value, &length, NULL, 0);
int cpuType = -1;
if (error == 0) {
cpuType = value;
NSString *visibleCPUType;
switch(value) {
case 7: visibleCPUType=@"Intel"; break;
case 18: visibleCPUType=@"PowerPC"; break;
default: visibleCPUType=@"Unknown"; break;
}
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cputype",@"CPU Type", [NSNumber numberWithInt:value], visibleCPUType,nil] forKeys:profileDictKeys]];
}
error = sysctlbyname("hw.cpusubtype", &value, &length, NULL, 0);
if (error == 0) {
NSString *visibleCPUSubType;
if (cpuType == 7) {
// Intel
visibleCPUSubType = @"Intel"; // If anyone knows how to tell a Core Duo from a Core Solo, please email tph@atomicbird.com
} else if (cpuType == 18) {
// PowerPC
switch(value) {
case 9: visibleCPUSubType=@"G3"; break;
case 10: case 11: visibleCPUSubType=@"G4"; break;
case 100: visibleCPUSubType=@"G5"; break;
default: visibleCPUSubType=@"Other"; break;
}
} else {
visibleCPUSubType = @"Other";
}
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpusubtype",@"CPU Subtype", [NSNumber numberWithInt:value], visibleCPUSubType,nil] forKeys:profileDictKeys]];
}
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)
free(cpuModel);
}

// Number of CPUs
error = sysctlbyname("hw.ncpu", &value, &length, NULL, 0);
if (error == 0)
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"ncpu",@"Number of CPUs", [NSNumber numberWithInt:value], [NSNumber numberWithInt:value],nil] forKeys:profileDictKeys]];

// User preferred language
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defs objectForKey:@"AppleLanguages"];
if (languages && ([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
NSString *appName = [hostBundle name];
if (appName)
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appName",@"Application Name", appName, appName,nil] forKeys:profileDictKeys]];
NSString *appVersion = [hostBundle version];
if (appVersion)
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appVersion",@"Application Version", appVersion, appVersion,nil] forKeys:profileDictKeys]];

// Number of displays?
// CPU speed
OSErr err;
SInt32 gestaltInfo;
err = Gestalt(gestaltProcClkSpeedMHz,&gestaltInfo);
if (err == noErr)
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpuFreqMHz",@"CPU Speed (MHz)", [NSNumber numberWithInt:gestaltInfo], [NSNumber numberWithInt:gestaltInfo],nil] forKeys:profileDictKeys]];

// amount of RAM
err = Gestalt(gestaltPhysicalRAMSizeInMegabytes,&gestaltInfo);
if (err == noErr)
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"ramMB",@"Memory (MB)", [NSNumber numberWithInt:gestaltInfo], [NSNumber numberWithInt:gestaltInfo],nil] forKeys:profileDictKeys]];

return profileArray;
}

+ (NSURL *)profiledURLForAppcastURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hostBundle
{
NSMutableArray *profileInfo = [NSMutableArray array];
NSEnumerator *profileInfoEnumerator = [[self systemProfileInformationArrayWithHostBundle:hostBundle] objectEnumerator];
NSDictionary *currentProfileInfo;
while ((currentProfileInfo = [profileInfoEnumerator nextObject])) {
[profileInfo addObject:[NSString stringWithFormat:@"%@=%@", [currentProfileInfo objectForKey:@"key"], [currentProfileInfo objectForKey:@"value"]]];
}

NSString *appcastStringWithProfile = [NSString stringWithFormat:@"%@?%@", [appcastURL absoluteString], [profileInfo componentsJoinedByString:@"&"]];

// Clean it up so it's a valid URL
return [NSURL URLWithString:[appcastStringWithProfile stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
@end
9 changes: 4 additions & 5 deletions SUUpdater.m
Expand Up @@ -34,7 +34,6 @@ - (void)showUpdateAlert;
- (void)beginDownload;
- (void)extractUpdate;
- (void)showUpdateErrorAlertWithInfo:(NSString *)info;
- (NSTimeInterval)storedCheckInterval;
- (void)abandonUpdate;
- (IBAction)installAndRestart:sender;
- (NSString *)systemVersionString;
Expand Down Expand Up @@ -119,13 +118,13 @@ - (void)applicationDidFinishLaunching:(NSNotification *)note

// Now we want to figure out how long until we check again.
NSTimeInterval delayUntilCheck;
if (intervalSinceCheck < [self storedCheckInterval])
delayUntilCheck = ([self storedCheckInterval] - intervalSinceCheck); // It hasn't been long enough.
if (intervalSinceCheck < checkInterval)
delayUntilCheck = (checkInterval - intervalSinceCheck); // It hasn't been long enough.
else
delayUntilCheck = 0; // We're overdue! Run one now.

[self performSelector:@selector(checkForUpdatesInBackground) withObject:nil afterDelay:delayUntilCheck];
[self performSelector:@selector(scheduleCheckWithIntervalObject:) withObject:[NSNumber numberWithDouble:[self storedCheckInterval]] afterDelay:delayUntilCheck];
[self performSelector:@selector(scheduleCheckWithIntervalObject:) withObject:[NSNumber numberWithDouble:checkInterval] afterDelay:delayUntilCheck];
}
}

Expand Down Expand Up @@ -492,7 +491,7 @@ - (IBAction)installAndRestart:sender
[NSApp sendEvent:event];

// Search subdirectories for the application
NSString *currentFile, *newAppDownloadPath, *bundleFileName = [[hostBundle bundlePath] lastPathComponent];
NSString *currentFile, *newAppDownloadPath = nil, *bundleFileName = [[hostBundle bundlePath] lastPathComponent];
BOOL isPackage = NO;
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:[downloadPath stringByDeletingLastPathComponent]];
while ((currentFile = [dirEnum nextObject]))
Expand Down
30 changes: 22 additions & 8 deletions Sparkle.xcodeproj/project.pbxproj
Expand Up @@ -35,6 +35,8 @@
61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */; };
61A2262B0D1C58FD00430CCD /* SUUserDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A226290D1C58FD00430CCD /* SUUserDefaults.h */; };
61A2262C0D1C58FD00430CCD /* SUUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A2262A0D1C58FD00430CCD /* SUUserDefaults.m */; };
61A2279C0D1CEE7600430CCD /* SUSystemProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 61A2279A0D1CEE7600430CCD /* SUSystemProfiler.h */; };
61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A2279B0D1CEE7600430CCD /* SUSystemProfiler.m */; };
61AAE8280A321A7F00D8810D /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; };
61AAE8290A321A8000D8810D /* SUAutomaticUpdateAlert.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8240A321A7F00D8810D /* SUAutomaticUpdateAlert.nib */; };
61AAE82A0A321A8000D8810D /* SUUpdateAlert.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8260A321A7F00D8810D /* SUUpdateAlert.nib */; };
Expand Down Expand Up @@ -136,6 +138,8 @@
61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUStandardVersionComparator.m; sourceTree = "<group>"; };
61A226290D1C58FD00430CCD /* SUUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUserDefaults.h; sourceTree = "<group>"; };
61A2262A0D1C58FD00430CCD /* SUUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUserDefaults.m; sourceTree = "<group>"; };
61A2279A0D1CEE7600430CCD /* SUSystemProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUSystemProfiler.h; sourceTree = "<group>"; };
61A2279B0D1CEE7600430CCD /* SUSystemProfiler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUSystemProfiler.m; sourceTree = "<group>"; };
61AAE8230A321A7F00D8810D /* en */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Sparkle.strings; sourceTree = "<group>"; };
61AAE8250A321A7F00D8810D /* en */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = en; path = en.lproj/SUAutomaticUpdateAlert.nib; sourceTree = "<group>"; };
61AAE8270A321A7F00D8810D /* en */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = en; path = en.lproj/SUUpdateAlert.nib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -421,6 +425,8 @@
61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */,
61A226290D1C58FD00430CCD /* SUUserDefaults.h */,
61A2262A0D1C58FD00430CCD /* SUUserDefaults.m */,
61A2279A0D1CEE7600430CCD /* SUSystemProfiler.h */,
61A2279B0D1CEE7600430CCD /* SUSystemProfiler.m */,
);
includeInIndex = 1;
name = Utilities;
Expand Down Expand Up @@ -464,6 +470,7 @@
61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */,
61A225A40D1C4AC000430CCD /* SUStandardVersionComparator.h in Headers */,
61A2262B0D1C58FD00430CCD /* SUUserDefaults.h in Headers */,
61A2279C0D1CEE7600430CCD /* SUSystemProfiler.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -659,6 +666,7 @@
61A225940D1C3ADD00430CCD /* NSBundle+SUAdditions.m in Sources */,
61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */,
61A2262C0D1C58FD00430CCD /* SUUserDefaults.m in Sources */,
61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -835,6 +843,8 @@
);
OTHER_LDFLAGS = "-lcrypto";
PRODUCT_NAME = Sparkle;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk";
"SDKROOT[arch=ppc]" = /Developer/SDKs/MacOSX10.3.9.sdk;
SKIP_INSTALL = YES;
STRIP_INSTALLED_PRODUCT = NO;
WARNING_CFLAGS = "-Wall";
Expand All @@ -855,8 +865,8 @@
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)";
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_COMPATIBILITY_VERSION = 1.5;
DYLIB_CURRENT_VERSION = 1.5;
FRAMEWORK_VERSION = A;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_ENABLE_FIX_AND_CONTINUE = NO;
Expand All @@ -865,14 +875,20 @@
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Sparkle_Prefix.pch;
GCC_REUSE_STRINGS = NO;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "@executable_path/../Frameworks";
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 10.3;
"MACOSX_DEPLOYMENT_TARGET[arch=i386]" = 10.4;
"MACOSX_DEPLOYMENT_TARGET[arch=x86_64]" = 10.5;
OTHER_LDFLAGS = "-lcrypto";
PREBINDING = YES;
PRODUCT_NAME = Sparkle;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk";
"SDKROOT[arch=ppc]" = /Developer/SDKs/MacOSX10.3.9.sdk;
"SDKROOT[arch=x86_64]" = /Developer/SDKs/MacOSX10.5.sdk;
SKIP_INSTALL = YES;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_STYLE = all;
Expand All @@ -888,20 +904,19 @@
ARCHS = (
i386,
ppc,
ppc64,
x86_64,
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.5;
MACOSX_DEPLOYMENT_TARGET = 10.4;
"MACOSX_DEPLOYMENT_TARGET[arch=i386]" = 10.4;
"MACOSX_DEPLOYMENT_TARGET[arch=ppc]" = 10.3;
OTHER_CFLAGS = "-fsingle-precision-constant";
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
"SDKROOT[arch=i386]" = /Developer/SDKs/MacOSX10.4u.sdk;
"SDKROOT[arch=ppc]" = /Developer/SDKs/MacOSX10.4u.sdk;
VALID_ARCHS = "ppc7400 ppc970 i386 x86_64 ppc";
WARNING_CFLAGS = "-wall";
};
name = Debug;
Expand All @@ -912,20 +927,19 @@
ARCHS = (
i386,
ppc,
ppc64,
x86_64,
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.5;
MACOSX_DEPLOYMENT_TARGET = 10.4;
"MACOSX_DEPLOYMENT_TARGET[arch=i386]" = 10.4;
"MACOSX_DEPLOYMENT_TARGET[arch=ppc]" = 10.3;
OTHER_CFLAGS = "-fsingle-precision-constant";
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
"SDKROOT[arch=i386]" = /Developer/SDKs/MacOSX10.4u.sdk;
"SDKROOT[arch=ppc]" = /Developer/SDKs/MacOSX10.4u.sdk;
VALID_ARCHS = "ppc7400 ppc970 i386 x86_64 ppc";
WARNING_CFLAGS = "-wall";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion en.lproj/SUUpdateAlert.nib/info.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified en.lproj/SUUpdateAlert.nib/keyedobjects.nib
Binary file not shown.

0 comments on commit bed9e98

Please sign in to comment.