Sparkle now checks if the host app is running from a disk image and won't update if it is. This is definitely a long time coming.

This commit is contained in:
andym committed 2007-12-13 15:39:52 +00:00
1 parent acdc8eaff5
commit e119ad98cc
6 files changed
+253 -7

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
//
// NSWorkspace_RBAdditions.h
// PathProps
//
// Created by Rainer Brockerhoff on 10/04/2007.
// Copyright 2007 Rainer Brockerhoff. All rights reserved.
//
#import <Cocoa/Cocoa.h>
extern NSString* NSWorkspace_RBfstypename;
extern NSString* NSWorkspace_RBmntonname;
extern NSString* NSWorkspace_RBmntfromname;
extern NSString* NSWorkspace_RBdeviceinfo;
extern NSString* NSWorkspace_RBimagefilepath;
extern NSString* NSWorkspace_RBconnectiontype;
extern NSString* NSWorkspace_RBpartitionscheme;
extern NSString* NSWorkspace_RBserverURL;
@interface NSWorkspace (NSWorkspace_RBAdditions)
// This method will return nil if the input path is invalid. Otherwise, the returned NSDictionary may contain
// the following keys:
//- NSWorkspace_RBfstypename: will always be present.Shows the filesystem type (usually "hfs"), from statfs.
//- NSWorkspace_RBmntonname: will always be present. Shows the volume mount point.
//- NSWorkspace_RBmntfromname: will always be present. Shows the BSD device path for local volumes; info for
// remote volumes depends on the filesystem type.
//- NSWorkspace_RBconnectiontype: should always be present for local volumes. Shows the connection type ("SATA", "USB", etc.).
//- NSWorkspace_RBpartitionscheme: should always be present for local volumes. Shows the partition scheme.
//- NSWorkspace_RBdeviceinfo: should always be present for local volumes. Shows some information about the
// physical device; varies widely.
//- NSWorkspace_RBimagefilepath: should be present for disk images only. Shows the path of the disk image file.
//- NSWorkspace_RBserverURL: should be present for remote volumes only. Shows the server URL.
- (NSDictionary*)propertiesForPath:(NSString*)path;
@end
+174
View File
@@ -0,0 +1,174 @@
//
// NSWorkspace_RBAdditions.m
// PathProps
//
// Created by Rainer Brockerhoff on 10/04/2007.
// Copyright 2007 Rainer Brockerhoff. All rights reserved.
//
#import "NSWorkspace_RBAdditions.h"
#include <IOKit/IOKitLib.h>
#include <sys/mount.h>
#include <mach/mach.h>
NSString* NSWorkspace_RBfstypename = @"NSWorkspace_RBfstypename";
NSString* NSWorkspace_RBmntonname = @"NSWorkspace_RBmntonname";
NSString* NSWorkspace_RBmntfromname = @"NSWorkspace_RBmntfromname";
NSString* NSWorkspace_RBdeviceinfo = @"NSWorkspace_RBdeviceinfo";
NSString* NSWorkspace_RBimagefilepath = @"NSWorkspace_RBimagefilepath";
NSString* NSWorkspace_RBconnectiontype = @"NSWorkspace_RBconnectiontype";
NSString* NSWorkspace_RBpartitionscheme = @"NSWorkspace_RBpartitionscheme";
NSString* NSWorkspace_RBserverURL = @"NSWorkspace_RBserverURL";
// This static funtion concatenates two strings, but first checks several possibilities...
// like one or the other nil, or one containing the other already.
static NSString* AddPart(NSString* first,NSString* second) {
if (!second) {
return first;
}
second = [second stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (first) {
if ([first rangeOfString:second options:NSCaseInsensitiveSearch].location==NSNotFound) {
if ([second rangeOfString:first options:NSCaseInsensitiveSearch].location==NSNotFound) {
return [NSString stringWithFormat:@"%@; %@",first,second];
}
return second;
}
return first;
}
return second;
}
// This static functions recurses "upwards" over the IO registry. Returns strings that are concatenated
// and ultimately end up under the NSWorkspace_RBdeviceinfo key.
// This isn't too robust in that it assumes that objects returned by the objectForKey methods are
// either strings or dictionaries. A "standard" implementations would use either only CoreFoundation and
// IOKit calls for this, or do more robust type checking on the returned objects.
//
// Also notice that this works as determined experimentally in 10.4.9, there's no official docs I could find.
// YMMV, and it may stop working in any new version of Mac OS X.
static NSString* CheckParents(io_object_t thing,NSString* part,NSMutableDictionary* dict) {
NSString* result = part;
io_iterator_t parentsIterator = 0;
kern_return_t kernResult = IORegistryEntryGetParentIterator(thing,kIOServicePlane,&parentsIterator);
if ((kernResult==KERN_SUCCESS)&&parentsIterator) {
io_object_t nextParent = 0;
while ((nextParent = IOIteratorNext(parentsIterator))) {
NSDictionary* props = nil;
NSString* image = nil;
NSString* partition = nil;
NSString* connection = nil;
kernResult = IORegistryEntryCreateCFProperties(nextParent,(CFMutableDictionaryRef*)&props,kCFAllocatorDefault,0);
if (IOObjectConformsTo(nextParent,"IOApplePartitionScheme")) {
partition = [props objectForKey:@"Content Mask"];
} else if (IOObjectConformsTo(nextParent,"IOMedia")) {
partition = [props objectForKey:@"Content"];
} else if (IOObjectConformsTo(nextParent,"IODiskImageBlockStorageDeviceOutKernel")) {
NSData* data = nil;
if ((data = [[props objectForKey:@"Protocol Characteristics"] objectForKey:@"Virtual Interface Location Path"])) {
image = [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease];
}
} else if (IOObjectConformsTo(nextParent,"IOHDIXHDDriveInKernel")) {
image = [props objectForKey:@"KDIURLPath"];
}
NSDictionary* subdict;
if ((subdict = [props objectForKey:@"Protocol Characteristics"])) {
connection = [subdict objectForKey:@"Physical Interconnect"];
} else {
connection = [props objectForKey:@"Physical Interconnect"];
}
if (connection) {
[dict setObject:AddPart([dict objectForKey:NSWorkspace_RBconnectiontype],connection) forKey:NSWorkspace_RBconnectiontype];
}
if (partition) {
[dict setObject:partition forKey:NSWorkspace_RBpartitionscheme];
}
if (image) {
[dict setObject:image forKey:NSWorkspace_RBimagefilepath];
}
NSString* value;
if ((subdict = [props objectForKey:@"Device Characteristics"])) {
if ((value = [subdict objectForKey:@"Product Name"])) {
result = AddPart(result,value);
}
if ((value = [subdict objectForKey:@"Product Revision Level"])) {
result = AddPart(result,value);
}
if ((value = [subdict objectForKey:@"Vendor Name"])) {
result = AddPart(result,value);
}
}
if ((value = [props objectForKey:@"USB Serial Number"])) {
result = AddPart(result,value);
}
if ((value = [props objectForKey:@"USB Vendor Name"])) {
result = AddPart(result,value);
}
NSString* cls = [(NSString*)IOObjectCopyClass(nextParent) autorelease];
if (![cls isEqualToString:@"IOPCIDevice"]) {
// Uncomment the following line to have the device tree dumped to the console.
// NSLog(@"=================================> %@:%@\n",cls,props);
result = CheckParents(nextParent,result,dict);
}
IOObjectRelease(nextParent);
}
}
if (parentsIterator) {
IOObjectRelease(parentsIterator);
}
return result;
}
@implementation NSWorkspace (NSWorkspace_RBAdditions)
// Returns a NSDictionary with properties for the path. See details in the .h file.
// This assumes that the length of path is less than PATH_MAX (currently 1024 characters).
- (NSDictionary*)propertiesForPath:(NSString*)path {
const char* ccpath = (const char*)[path fileSystemRepresentation];
NSMutableDictionary* result = nil;
struct statfs fs;
if (!statfs(ccpath,&fs)) {
NSString* from = [NSString stringWithUTF8String:fs.f_mntfromname];
result = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithUTF8String:fs.f_fstypename],NSWorkspace_RBfstypename,
[NSString stringWithUTF8String:fs.f_mntonname],NSWorkspace_RBmntonname,
nil];
if (strncmp(fs.f_mntfromname,"/dev/",5)==0) {
// For a local volume,get the IO registry tree and search it for further info.
mach_port_t masterPort = 0;
io_iterator_t mediaIterator = 0;
kern_return_t kernResult = IOMasterPort(bootstrap_port,&masterPort);
if (kernResult==KERN_SUCCESS) {
CFMutableDictionaryRef classesToMatch = IOBSDNameMatching(masterPort,0,&fs.f_mntfromname[5]);
if (classesToMatch) {
kernResult = IOServiceGetMatchingServices(masterPort,classesToMatch,&mediaIterator);
if ((kernResult==KERN_SUCCESS)&&mediaIterator) {
io_object_t firstMedia = 0;
while ((firstMedia = IOIteratorNext(mediaIterator))) {
NSString* stuff = CheckParents(firstMedia,nil,result);
if (stuff) {
[result setObject:stuff forKey:NSWorkspace_RBdeviceinfo];
}
IOObjectRelease(firstMedia);
}
}
}
}
if (mediaIterator) {
IOObjectRelease(mediaIterator);
}
if (masterPort) {
mach_port_deallocate(mach_task_self(),masterPort);
}
}
[result setObject:from forKey:NSWorkspace_RBmntfromname];
}
return result;
}
@end
+10 -3
View File
@@ -212,7 +212,14 @@
{
if ([[utilities standardBundleDefaults] boolForKey:SUIgnoreChecksKey])
return;
if ([utilities isRunningFromDiskImage])
{
if (verbosity)
[self showUpdateErrorAlertWithInfo:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a disk image. Move %1$@ to your Applications folder, relaunch it, and try again.", nil), [utilities hostAppName]]];
return;
}
if (updateInProgress)
{
if (verbosity)
@@ -578,10 +585,10 @@
NSLog(@"Download error: %@", [error localizedDescription]);
[self showUpdateErrorAlertWithInfo:SULocalizedString(@"An error occurred while trying to download the file. Please try again later.", nil)];
}
- (IBAction)installAndRestart:sender
{
NSString *currentAppPath = [[NSBundle mainBundle] bundlePath];
NSString *currentAppPath = [utilities hostAppPath];
NSString *currentBundlePath = [updateBundle bundlePath];
NSString *newAppDownloadPath = nil;
BOOL isPackage = NO;
+2
View File
@@ -25,7 +25,9 @@
- (NSString *)hostAppVersionString;
- (NSString *)hostAppID;
- (NSImage *)hostAppIcon;
- (NSString *)hostAppPath;
- (NSString *)hostAppExtension;
- (BOOL)isRunningFromDiskImage;
- (SUBundleDefaults *)standardBundleDefaults;
@end
+11 -1
View File
@@ -9,7 +9,7 @@
#import "SUUtilities.h"
#import "SUUpdater.h"
#import "SUBundleDefaults.h"
#import "NSWorkspace_RBAdditions.h"
@implementation SUUtilities
@@ -63,6 +63,11 @@
return [self infoValueForKey:@"CFBundleVersion"];
}
- (NSString *)hostAppPath
{
return [[updater updateBundle] bundlePath] ;
}
- (NSString *)hostAppVersionString
{
NSString *shortVersionString = [self infoValueForKey:@"CFBundleShortVersionString"];
@@ -115,6 +120,11 @@
return [[defaults retain] autorelease];
}
- (BOOL)isRunningFromDiskImage
{
return [[[NSWorkspace sharedWorkspace] propertiesForPath:[self hostAppPath]] objectForKey:NSWorkspace_RBimagefilepath] != nil;
}
@end
NSString *SULocalizedString(NSString *key, NSString *comment) {
+19 -3
View File
@@ -12,6 +12,9 @@
610D5A1A0A1661B8004AAD9C /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; };
610D5A750A1670A4004AAD9C /* SUStatus.nib in Resources */ = {isa = PBXBuildFile; fileRef = 610D5A740A1670A4004AAD9C /* SUStatus.nib */; };
610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */ = {isa = PBXBuildFile; fileRef = 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */; };
611779590D1111C900749C97 /* NSWorkspace_RBAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 611779570D1111C400749C97 /* NSWorkspace_RBAdditions.h */; };
6117795A0D1111C900749C97 /* NSWorkspace_RBAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 611779560D1111C400749C97 /* NSWorkspace_RBAdditions.m */; };
61177A1F0D1112E900749C97 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6117796E0D1112E000749C97 /* IOKit.framework */; };
6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 6120721009CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h */; settings = {ATTRIBUTES = (Public, ); }; };
6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 6120721109CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m */; };
61299A2F09CA2DAB00B7442F /* NSFileManager+Verification.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A2D09CA2DAB00B7442F /* NSFileManager+Verification.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -111,6 +114,9 @@
610D5A740A1670A4004AAD9C /* SUStatus.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; path = SUStatus.nib; sourceTree = "<group>"; };
610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NTSynchronousTask.m; sourceTree = "<group>"; };
610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NTSynchronousTask.h; sourceTree = "<group>"; };
611779560D1111C400749C97 /* NSWorkspace_RBAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSWorkspace_RBAdditions.m; sourceTree = "<group>"; };
611779570D1111C400749C97 /* NSWorkspace_RBAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSWorkspace_RBAdditions.h; sourceTree = "<group>"; };
6117796E0D1112E000749C97 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; };
6120721009CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUAutomaticUpdateAlert.h; sourceTree = "<group>"; };
6120721109CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUAutomaticUpdateAlert.m; sourceTree = "<group>"; };
6129984309C9E2DA00B7442F /* NSFileManager+Authentication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+Authentication.h"; sourceTree = "<group>"; };
@@ -255,6 +261,7 @@
8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */,
61B5F8F709C4CEB300B25A18 /* Security.framework in Frameworks */,
61B5FC4C09C4FD5E00B25A18 /* WebKit.framework in Frameworks */,
61177A1F0D1112E900749C97 /* IOKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -331,6 +338,7 @@
1058C7B0FEA5585E11CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
6117796E0D1112E000749C97 /* IOKit.framework */,
61B5FC3F09C4FD4000B25A18 /* WebKit.framework */,
61B5F8F609C4CEB300B25A18 /* Security.framework */,
1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */,
@@ -400,6 +408,8 @@
61B5F8F309C4CE5900B25A18 /* Utilities */ = {
isa = PBXGroup;
children = (
611779570D1111C400749C97 /* NSWorkspace_RBAdditions.h */,
611779560D1111C400749C97 /* NSWorkspace_RBAdditions.m */,
610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */,
610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */,
D18A64E60CE2588900C49C71 /* SUBundleDefaults.h */,
@@ -456,6 +466,7 @@
6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */,
345AF9E40A5D707200D7DA6F /* SUStatusChecker.h in Headers */,
D18A64E80CE2588900C49C71 /* SUBundleDefaults.h in Headers */,
611779590D1111C900749C97 /* NSWorkspace_RBAdditions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -526,7 +537,7 @@
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "Sparkle" */;
compatibilityVersion = "Xcode 2.4";
compatibilityVersion = "Xcode 3.0";
hasScannedForEncodings = 1;
knownRegions = (
English,
@@ -651,6 +662,7 @@
345AF9E50A5D707200D7DA6F /* SUStatusChecker.m in Sources */,
D18A64E90CE2588900C49C71 /* SUBundleDefaults.m in Sources */,
610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */,
6117795A0D1111C900749C97 /* NSWorkspace_RBAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -800,8 +812,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
ppc,
ppc64,
x86_64,
);
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)";
COPY_PHASE_STRIP = NO;
@@ -835,8 +849,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
ppc,
ppc64,
x86_64,
);
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)";
COPY_PHASE_STRIP = NO;