Index: trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm
===================================================================
--- trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm	(revision 229)
+++ trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm	(revision 230)
@@ -30,5 +30,4 @@
 #import <CoreFoundation/CoreFoundation.h>
 #import <ApplicationServices/ApplicationServices.h>
-#import <Security/Authorization.h>
 #import <Security/AuthorizationTags.h>
 
@@ -121,4 +120,61 @@
 }
 
+-(void)installFScript
+{
+    OSStatus myStatus;
+
+    NSString *installPath = nil;
+    if([[NSFileManager defaultManager] fileExistsAtPath:@"/Library/Frameworks/FScript.framework"])
+        installPath = @"/Library/Frameworks/FScript.framework";
+    if([[NSFileManager defaultManager] fileExistsAtPath:[@"~/Library/Frameworks/FScript.framework" stringByExpandingTildeInPath]])
+        installPath = [@"~/Library/Frameworks/FScript.framework" stringByExpandingTildeInPath];
+    
+    if(installPath){
+        [[NSFileManager defaultManager] removeFileAtPath:installPath handler:nil];
+    }
+    
+    if(!installPath){
+        switch([[NSAlert alertWithMessageText:@"Install F-Script"
+                                defaultButton:@"Current User"
+                              alternateButton:@"All Users"
+                                  otherButton:nil
+                    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]){
+            case NSAlertDefaultReturn:  // Current user
+                installPath = [@"~/Library/Frameworks/FScript.framework" stringByExpandingTildeInPath];
+                break;
+            case NSAlertAlternateReturn: // All users
+                installPath = @"/Library/Frameworks/FScript.framework";
+                break;
+            default:
+                break;
+        }        
+    }
+    
+    NSString *fromPath = [[NSBundle mainBundle] pathForResource:@"FScript" ofType:@"framework"];
+    if(![[NSFileManager defaultManager] fileExistsAtPath:[installPath stringByDeletingLastPathComponent]]){
+        if ([[NSFileManager defaultManager] isWritableFileAtPath:installPath]){
+            [[NSFileManager defaultManager] createDirectoryAtPath:[installPath stringByDeletingLastPathComponent]
+                                                       attributes:nil];
+        } else {
+            [self createAuthorization];
+            NSString *myToolPath = @"/bin/mkdir";
+            char *myArguments[] = { (char *)[[installPath stringByDeletingLastPathComponent] UTF8String], NULL };
+            myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, [myToolPath UTF8String],
+                                                          myFlags, myArguments,
+                                                          NULL);
+        }
+    }
+    if([[NSFileManager defaultManager] isWritableFileAtPath:[installPath stringByDeletingLastPathComponent]]){
+        [[NSFileManager defaultManager] copyPath:fromPath toPath:installPath handler:nil];
+    } else {
+        [self createAuthorization];
+        NSString *myToolPath = @"/bin/cp";
+        char *myArguments[] = { "-r", (char *)[fromPath UTF8String], (char *)[installPath UTF8String], NULL };
+        myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, [myToolPath UTF8String],
+                                                      myFlags, myArguments,
+                                                      NULL);
+    }    
+}
+
 - (BOOL)_shouldContinueAfterFrameworkErrorPanelReturnedWithResult:(int)result;
 {
@@ -126,6 +182,7 @@
         case NSAlertOtherReturn:
             return true;
-        case NSAlertAlternateReturn:
-            [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: FSA_FScriptURL]];
+        case NSAlertAlternateReturn: /* Install from resources */
+            [self installFScript];
+            return true;
         case NSAlertDefaultReturn:
         default:
@@ -135,14 +192,16 @@
 }
 
--(tDirStatus)authorizeAndAddToProcMod:(NSString *)username
-{
+-(BOOL)createAuthorization
+{
+    if(myAuthorizationRef)
+        return YES;
+    
     OSStatus myStatus;
-    AuthorizationFlags myFlags = kAuthorizationFlagDefaults;
-    AuthorizationRef myAuthorizationRef;
+    myFlags = kAuthorizationFlagDefaults;
     
     myStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment,
                                    myFlags, &myAuthorizationRef);
     if(myStatus != errAuthorizationSuccess)
-        return eDSAuthFailed;
+        return NO;
     
     AuthorizationItem myItems = {kAuthorizationRightExecute, 0, NULL, 0};
@@ -157,7 +216,16 @@
     
     if(myStatus != errAuthorizationSuccess) 
+        return NO;
+    
+    myFlags = kAuthorizationFlagDefaults;
+    return YES;
+}
+
+-(tDirStatus)authorizeAndAddToProcMod:(NSString *)username
+{
+    OSStatus myStatus;
+    
+    if(![self createAuthorization])
         return eDSAuthFailed;
-    
-    myFlags = kAuthorizationFlagDefaults;
     
     NSString *myToolPath = [[NSBundle mainBundle] pathForResource:@"AddToProcMod" ofType:@""];
@@ -176,6 +244,4 @@
     myReadBuffer[didRead - 1] = 0;
     
-    AuthorizationFree(myAuthorizationRef, kAuthorizationFlagDefaults);
-
     return (tDirStatus)strtol(myReadBuffer, NULL, 10);
 }
@@ -274,8 +340,8 @@
         int result = NSRunInformationalAlertPanel(
             NSLocalizedString(@"F-Script Framework Not Found", "Framework not found alert title"),
-            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\nIf you believe this message is in error, click '%@'.",
+            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 '%@'.",
                               "Framework not found alert message, F-Script Web site URL parameter, 'Continue' button parameter"),
             NSLocalizedString(@"Quit", "Quit button title"),
-            NSLocalizedString(@"Get F-Script", "'Get F-Script' button title"),
+            NSLocalizedString(@"Install F-Script", "'Get F-Script' button title"),
             NSLocalizedString(@"Continue", "Continue button title"),
             FSA_FScriptURL, NSLocalizedString(@"Continue", ""));
@@ -290,15 +356,20 @@
             int result = NSRunInformationalAlertPanel(
 		NSLocalizedString(@"F-Script Framework Too Old", "Framework too old alert title"),
-		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\nTo use this version of F-Script regardless of the problems you may experience, click '%@'.",
+		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 '%@'.",
                                   "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"),
 		NSLocalizedString(@"Quit", "Quit button title"),
-                NSLocalizedString(@"Get F-Script", "'Get F-Script' button title"),
+                NSLocalizedString(@"Install F-Script", "'Get F-Script' button title"),
                 NSLocalizedString(@"Continue", "Continue button title"),
                 FSA_VERSION, FSA_FScriptMinimumVersion, frameworkVersion,
-                FSA_FScriptURL, NSLocalizedString(@"Continue", ""));
+                FSA_FScriptURL, NSLocalizedString(@"Install F-Script", ""));
             if (![self _shouldContinueAfterFrameworkErrorPanelReturnedWithResult: result]) return;
         }
     }
 
+    if(myAuthorizationRef){
+        AuthorizationFree(myAuthorizationRef, kAuthorizationFlagDefaults);
+        myAuthorizationRef = nil;
+    }
+    
     NSNotificationCenter *workspaceNotificationCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
     [workspaceNotificationCenter
