Changeset 230 for trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm
- Timestamp:
- 05/25/06 17:46:45 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm
r229 r230 30 30 #import <CoreFoundation/CoreFoundation.h> 31 31 #import <ApplicationServices/ApplicationServices.h> 32 #import <Security/Authorization.h>33 32 #import <Security/AuthorizationTags.h> 34 33 … … 121 120 } 122 121 122 -(void)installFScript 123 { 124 OSStatus myStatus; 125 126 NSString *installPath = nil; 127 if([[NSFileManager defaultManager] fileExistsAtPath:@"/Library/Frameworks/FScript.framework"]) 128 installPath = @"/Library/Frameworks/FScript.framework"; 129 if([[NSFileManager defaultManager] fileExistsAtPath:[@"~/Library/Frameworks/FScript.framework" stringByExpandingTildeInPath]]) 130 installPath = [@"~/Library/Frameworks/FScript.framework" stringByExpandingTildeInPath]; 131 132 if(installPath){ 133 [[NSFileManager defaultManager] removeFileAtPath:installPath handler:nil]; 134 } 135 136 if(!installPath){ 137 switch([[NSAlert alertWithMessageText:@"Install F-Script" 138 defaultButton:@"Current User" 139 alternateButton:@"All Users" 140 otherButton:nil 141 informativeTextWithFormat:@"No previous version of F-Script found. You can choose to install for just your current user (~/Library/Frameworks) or for all users (/Library/Frameworks)."] runModal]){ 142 case NSAlertDefaultReturn: // Current user 143 installPath = [@"~/Library/Frameworks/FScript.framework" stringByExpandingTildeInPath]; 144 break; 145 case NSAlertAlternateReturn: // All users 146 installPath = @"/Library/Frameworks/FScript.framework"; 147 break; 148 default: 149 break; 150 } 151 } 152 153 NSString *fromPath = [[NSBundle mainBundle] pathForResource:@"FScript" ofType:@"framework"]; 154 if(![[NSFileManager defaultManager] fileExistsAtPath:[installPath stringByDeletingLastPathComponent]]){ 155 if ([[NSFileManager defaultManager] isWritableFileAtPath:installPath]){ 156 [[NSFileManager defaultManager] createDirectoryAtPath:[installPath stringByDeletingLastPathComponent] 157 attributes:nil]; 158 } else { 159 [self createAuthorization]; 160 NSString *myToolPath = @"/bin/mkdir"; 161 char *myArguments[] = { (char *)[[installPath stringByDeletingLastPathComponent] UTF8String], NULL }; 162 myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, [myToolPath UTF8String], 163 myFlags, myArguments, 164 NULL); 165 } 166 } 167 if([[NSFileManager defaultManager] isWritableFileAtPath:[installPath stringByDeletingLastPathComponent]]){ 168 [[NSFileManager defaultManager] copyPath:fromPath toPath:installPath handler:nil]; 169 } else { 170 [self createAuthorization]; 171 NSString *myToolPath = @"/bin/cp"; 172 char *myArguments[] = { "-r", (char *)[fromPath UTF8String], (char *)[installPath UTF8String], NULL }; 173 myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, [myToolPath UTF8String], 174 myFlags, myArguments, 175 NULL); 176 } 177 } 178 123 179 - (BOOL)_shouldContinueAfterFrameworkErrorPanelReturnedWithResult:(int)result; 124 180 { … … 126 182 case NSAlertOtherReturn: 127 183 return true; 128 case NSAlertAlternateReturn: 129 [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: FSA_FScriptURL]]; 184 case NSAlertAlternateReturn: /* Install from resources */ 185 [self installFScript]; 186 return true; 130 187 case NSAlertDefaultReturn: 131 188 default: … … 135 192 } 136 193 137 -(tDirStatus)authorizeAndAddToProcMod:(NSString *)username 138 { 194 -(BOOL)createAuthorization 195 { 196 if(myAuthorizationRef) 197 return YES; 198 139 199 OSStatus myStatus; 140 AuthorizationFlags myFlags = kAuthorizationFlagDefaults; 141 AuthorizationRef myAuthorizationRef; 200 myFlags = kAuthorizationFlagDefaults; 142 201 143 202 myStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, 144 203 myFlags, &myAuthorizationRef); 145 204 if(myStatus != errAuthorizationSuccess) 146 return eDSAuthFailed;205 return NO; 147 206 148 207 AuthorizationItem myItems = {kAuthorizationRightExecute, 0, NULL, 0}; … … 157 216 158 217 if(myStatus != errAuthorizationSuccess) 218 return NO; 219 220 myFlags = kAuthorizationFlagDefaults; 221 return YES; 222 } 223 224 -(tDirStatus)authorizeAndAddToProcMod:(NSString *)username 225 { 226 OSStatus myStatus; 227 228 if(![self createAuthorization]) 159 229 return eDSAuthFailed; 160 161 myFlags = kAuthorizationFlagDefaults;162 230 163 231 NSString *myToolPath = [[NSBundle mainBundle] pathForResource:@"AddToProcMod" ofType:@""]; … … 176 244 myReadBuffer[didRead - 1] = 0; 177 245 178 AuthorizationFree(myAuthorizationRef, kAuthorizationFlagDefaults);179 180 246 return (tDirStatus)strtol(myReadBuffer, NULL, 10); 181 247 } … … 274 340 int result = NSRunInformationalAlertPanel( 275 341 NSLocalizedString(@"F-Script Framework Not Found", "Framework not found alert title"), 276 NSLocalizedString(@"F-Script Anywhere requires the F-Script framework be installed in a Frameworks directory, such as ~/Library/Frameworks or /Library/Frameworks.\n\nTo download F-Script, please visit its Web site\n%@.\n\n If you believe this message is in error, click '%@'.",342 NSLocalizedString(@"F-Script Anywhere requires the F-Script framework be installed in a Frameworks directory, such as ~/Library/Frameworks or /Library/Frameworks.\n\nTo download F-Script, please visit its Web site\n%@.\n\nThis package also includes a copy of F-Script for your convenience that can be installed easily by clicking below. Note that there may be a more recent version of F-Script available from the F-Script web site.\n\nIf you believe this message is in error, click '%@'.", 277 343 "Framework not found alert message, F-Script Web site URL parameter, 'Continue' button parameter"), 278 344 NSLocalizedString(@"Quit", "Quit button title"), 279 NSLocalizedString(@" GetF-Script", "'Get F-Script' button title"),345 NSLocalizedString(@"Install F-Script", "'Get F-Script' button title"), 280 346 NSLocalizedString(@"Continue", "Continue button title"), 281 347 FSA_FScriptURL, NSLocalizedString(@"Continue", "")); … … 290 356 int result = NSRunInformationalAlertPanel( 291 357 NSLocalizedString(@"F-Script Framework Too Old", "Framework too old alert title"), 292 NSLocalizedString(@"F-Script Anywhere %s requires version %@ or later of the F-Script framework be installed in a Frameworks directory, such as ~/Library/Frameworks or /Library/Frameworks. The installed version is %@.\n\nTo upgrade F-Script, please visit its Web site\n%@.\n\nT o use this version of F-Script regardless of the problems you may experience, click '%@'.",358 NSLocalizedString(@"F-Script Anywhere %s requires version %@ or later of the F-Script framework be installed in a Frameworks directory, such as ~/Library/Frameworks or /Library/Frameworks. The installed version is %@.\n\nTo upgrade F-Script, please visit its Web site\n%@.\n\nThis package also includes a copy of F-Script for your convenience that can be installed easily by clicking below. Note that there may be a more recent version of F-Script available from the F-Script web site.\n\nTo use this version of F-Script regardless of the problems you may experience, click '%@'.", 293 359 "Framework too old alert message, FSA version parameter, minimum F-Script version parameter, current F-Script version parameter, F-Script Web site URL parameter, 'Continue' button parameter"), 294 360 NSLocalizedString(@"Quit", "Quit button title"), 295 NSLocalizedString(@" GetF-Script", "'Get F-Script' button title"),361 NSLocalizedString(@"Install F-Script", "'Get F-Script' button title"), 296 362 NSLocalizedString(@"Continue", "Continue button title"), 297 363 FSA_VERSION, FSA_FScriptMinimumVersion, frameworkVersion, 298 FSA_FScriptURL, NSLocalizedString(@" Continue", ""));364 FSA_FScriptURL, NSLocalizedString(@"Install F-Script", "")); 299 365 if (![self _shouldContinueAfterFrameworkErrorPanelReturnedWithResult: result]) return; 300 366 } 301 367 } 302 368 369 if(myAuthorizationRef){ 370 AuthorizationFree(myAuthorizationRef, kAuthorizationFlagDefaults); 371 myAuthorizationRef = nil; 372 } 373 303 374 NSNotificationCenter *workspaceNotificationCenter = [[NSWorkspace sharedWorkspace] notificationCenter]; 304 375 [workspaceNotificationCenter
Note:
See TracChangeset
for help on using the changeset viewer.