diff --git a/NSWorkspace_RBAdditions.h b/NSWorkspace_RBAdditions.h deleted file mode 100644 index bd50fb13..00000000 --- a/NSWorkspace_RBAdditions.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// NSWorkspace_RBAdditions.h -// PathProps -// -// Created by Rainer Brockerhoff on 10/04/2007. -// Copyright 2007 Rainer Brockerhoff. All rights reserved. -// - -#ifndef NSWORKSPACE_RBADDITIONS_H -#define NSWORKSPACE_RBADDITIONS_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 - -#endif diff --git a/NSWorkspace_RBAdditions.m b/NSWorkspace_RBAdditions.m deleted file mode 100644 index 1ffac239..00000000 --- a/NSWorkspace_RBAdditions.m +++ /dev/null @@ -1,177 +0,0 @@ -// -// NSWorkspace_RBAdditions.m -// PathProps -// -// Created by Rainer Brockerhoff on 10/04/2007. -// Copyright 2007 Rainer Brockerhoff. All rights reserved. -// - -#import "Sparkle.h" -#import "NSWorkspace_RBAdditions.h" - -#include -#include -#include - -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); - } - io_name_t ts; // char[128] - NSString* cls = ( IOObjectGetClass (nextParent, ts) == KERN_SUCCESS ) ? [NSString stringWithUTF8String:ts ] : nil; - 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); - } - if (props) { CFRelease(props); } - 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 = [path fileSystemRepresentation]; - NSMutableDictionary* result = nil; - struct statfs fs = {}; - if (!statfs(ccpath,&fs)) { - NSString* from = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:fs.f_mntfromname length:strlen(fs.f_mntfromname)]; - result = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithUTF8String:fs.f_fstypename], NSWorkspace_RBfstypename, [[NSFileManager defaultManager] stringWithFileSystemRepresentation:fs.f_mntonname length:strlen(fs.f_mntonname)], NSWorkspace_RBmntonname, nil]; - const char* devstring = "/dev/"; - size_t devstringlen = 5; - if (strncmp(fs.f_mntfromname,devstring,devstringlen)==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[devstringlen]); - 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 diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 21a20a5d..0199eb10 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -14,9 +14,9 @@ - (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)aHost { [super checkForUpdatesAtURL:appcastURL host:aHost]; - if ([aHost isRunningFromDiskImage]) + if ([aHost isRunningOnReadOnlyVolume]) { - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a disk image. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]] forKey:NSLocalizedDescriptionKey]]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]] forKey:NSLocalizedDescriptionKey]]]; return; } diff --git a/SUHost.h b/SUHost.h index d2e769fc..832327b8 100644 --- a/SUHost.h +++ b/SUHost.h @@ -19,7 +19,7 @@ - (NSString *)version; - (NSString *)displayVersion; - (NSImage *)icon; -- (BOOL)isRunningFromDiskImage; +- (BOOL)isRunningOnReadOnlyVolume; - (NSString *)publicDSAKey; - (NSArray *)systemProfile; diff --git a/SUHost.m b/SUHost.m index c35c86a2..e5a17096 100644 --- a/SUHost.m +++ b/SUHost.m @@ -6,6 +6,7 @@ // #import "Sparkle.h" +#import // For statfs for isRunningOnReadOnlyVolume @implementation SUHost @@ -77,16 +78,11 @@ return icon; } -- (BOOL)isRunningFromDiskImage +- (BOOL)isRunningOnReadOnlyVolume { - // This check causes crashes on 10.3; for now, we'll just skip it. - if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_4) - return NO; - - NSDictionary *pathProperties = [[NSWorkspace sharedWorkspace] propertiesForPath:[bundle bundlePath]]; - BOOL isDiskImage = [pathProperties objectForKey:NSWorkspace_RBimagefilepath] != nil; - BOOL isFileVault = [[pathProperties objectForKey:NSWorkspace_RBmntonname] hasPrefix:@"/Users/"]; - return isDiskImage && !isFileVault; + struct statfs statfs_info; + statfs([[bundle bundlePath] fileSystemRepresentation], &statfs_info); + return (statfs_info.f_flags & MNT_RDONLY); } - (NSString *)publicDSAKey diff --git a/SUUserInitiatedUpdateDriver.m b/SUUserInitiatedUpdateDriver.m index c64d5e60..8ba7a573 100644 --- a/SUUserInitiatedUpdateDriver.m +++ b/SUUserInitiatedUpdateDriver.m @@ -18,7 +18,7 @@ [checkingController beginActionWithTitle:SULocalizedString(@"Checking for updates\u2026", nil) maxProgressValue:0 statusText:nil]; [checkingController setButtonTitle:SULocalizedString(@"Cancel", nil) target:self action:@selector(cancelCheckForUpdates:) isDefault:NO]; [checkingController showWindow:self]; - [super checkForUpdatesAtURL:appcastURL hostBundle:hb]; + [super checkForUpdatesAtURL:appcastURL host:hb]; } - (void)closeCheckingWindow diff --git a/Sparkle.h b/Sparkle.h index 4d0b1091..c76dfe82 100644 --- a/Sparkle.h +++ b/Sparkle.h @@ -28,7 +28,6 @@ #import "NSFileManager+Aliases.h" #import "NSFileManager+Authentication.h" #import "NSFileManager+Verification.h" -#import "NSWorkspace_RBAdditions.h" #import "NSWorkspace+SystemVersion.h" #import "NTSynchronousTask.h" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index d9b1399b..587a9a04 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -22,8 +22,6 @@ 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 */; settings = {ATTRIBUTES = (Public, ); }; }; - 6117795A0D1111C900749C97 /* NSWorkspace_RBAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 611779560D1111C400749C97 /* NSWorkspace_RBAdditions.m */; }; 61177A1F0D1112E900749C97 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6117796E0D1112E000749C97 /* IOKit.framework */; }; 61180BCA0D64138900B4E0D1 /* SUWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = 61180BC80D64138900B4E0D1 /* SUWindowController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61180BCB0D64138900B4E0D1 /* SUWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61180BC90D64138900B4E0D1 /* SUWindowController.m */; }; @@ -167,8 +165,6 @@ 610D5A740A1670A4004AAD9C /* SUStatus.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; path = SUStatus.nib; sourceTree = ""; }; 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NTSynchronousTask.m; sourceTree = ""; }; 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NTSynchronousTask.h; sourceTree = ""; }; - 611779560D1111C400749C97 /* NSWorkspace_RBAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSWorkspace_RBAdditions.m; sourceTree = ""; }; - 611779570D1111C400749C97 /* NSWorkspace_RBAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSWorkspace_RBAdditions.h; sourceTree = ""; }; 6117796E0D1112E000749C97 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = ""; }; 61180BC80D64138900B4E0D1 /* SUWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUWindowController.h; sourceTree = ""; }; 61180BC90D64138900B4E0D1 /* SUWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUWindowController.m; sourceTree = ""; }; @@ -474,8 +470,6 @@ children = ( 61EF67580E25C5B400F754E0 /* SUHost.h */, 61EF67550E25B58D00F754E0 /* SUHost.m */, - 611779570D1111C400749C97 /* NSWorkspace_RBAdditions.h */, - 611779560D1111C400749C97 /* NSWorkspace_RBAdditions.m */, 610134750DD252E60049ACDF /* NSWorkspace+SystemVersion.h */, 610134760DD252E60049ACDF /* NSWorkspace+SystemVersion.m */, 61299B3509CB04E000B7442F /* Sparkle.h */, @@ -559,7 +553,6 @@ 61299A8D09CA790200B7442F /* SUUnarchiver.h in Headers */, 61299B3609CB04E000B7442F /* Sparkle.h in Headers */, 6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */, - 611779590D1111C900749C97 /* NSWorkspace_RBAdditions.h in Headers */, 61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */, 61A225A40D1C4AC000430CCD /* SUStandardVersionComparator.h in Headers */, 61A2279C0D1CEE7600430CCD /* SUSystemProfiler.h in Headers */, @@ -820,7 +813,6 @@ 61299A8E09CA790200B7442F /* SUUnarchiver.m in Sources */, 6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */, 610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */, - 6117795A0D1111C900749C97 /* NSWorkspace_RBAdditions.m in Sources */, 61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */, 61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */, 612DCBB00D488BC60015DBEA /* SUUpdatePermissionPrompt.m in Sources */, diff --git a/en.lproj/Sparkle.strings b/en.lproj/Sparkle.strings index 7165acdf..f8f89008 100644 Binary files a/en.lproj/Sparkle.strings and b/en.lproj/Sparkle.strings differ