Index: trunk/Cocoa/F-Script Anywhere/Source/F-Script Anywhere.xcodeproj/project.pbxproj
===================================================================
--- trunk/Cocoa/F-Script Anywhere/Source/F-Script Anywhere.xcodeproj/project.pbxproj	(revision 230)
+++ trunk/Cocoa/F-Script Anywhere/Source/F-Script Anywhere.xcodeproj/project.pbxproj	(revision 231)
@@ -976,13 +976,9 @@
 				GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
 				GCC_OPTIMIZATION_LEVEL = 0;
-				HEADER_SEARCH_PATHS = (
-					"$(HEADER_SEARCH_PATHS_QUOTED_1)",
-				);
+				HEADER_SEARCH_PATHS = "$(HEADER_SEARCH_PATHS_QUOTED_1)";
 				HEADER_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../Darwin source/Commands/Apple/cctools/include\"";
 				INFOPLIST_FILE = "Info-Application.plist";
 				INSTALL_PATH = /;
-				LIBRARY_SEARCH_PATHS = (
-					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
-				);
+				LIBRARY_SEARCH_PATHS = "$(LIBRARY_SEARCH_PATHS_QUOTED_1)";
 				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../Darwin source/Commands/Apple/cctools/libstuff\"";
 				OPTIMIZATION_CFLAGS = "-O0";
@@ -1020,13 +1016,9 @@
 				FRAMEWORK_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)\"";
 				GCC_ENABLE_FIX_AND_CONTINUE = NO;
-				HEADER_SEARCH_PATHS = (
-					"$(HEADER_SEARCH_PATHS_QUOTED_1)",
-				);
+				HEADER_SEARCH_PATHS = "$(HEADER_SEARCH_PATHS_QUOTED_1)";
 				HEADER_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../Darwin source/Commands/Apple/cctools/include\"";
 				INFOPLIST_FILE = "Info-Application.plist";
 				INSTALL_PATH = /;
-				LIBRARY_SEARCH_PATHS = (
-					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
-				);
+				LIBRARY_SEARCH_PATHS = "$(LIBRARY_SEARCH_PATHS_QUOTED_1)";
 				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../Darwin source/Commands/Apple/cctools/libstuff\"";
 				OTHER_CFLAGS = "-DFSA_DEBUG=0";
@@ -1058,13 +1050,9 @@
 					"$(SRCROOT)",
 				);
-				HEADER_SEARCH_PATHS = (
-					"$(HEADER_SEARCH_PATHS_QUOTED_1)",
-				);
+				HEADER_SEARCH_PATHS = "$(HEADER_SEARCH_PATHS_QUOTED_1)";
 				HEADER_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../Darwin source/Commands/Apple/cctools/include\"";
 				INFOPLIST_FILE = "Info-Application.plist";
 				INSTALL_PATH = /;
-				LIBRARY_SEARCH_PATHS = (
-					"$(LIBRARY_SEARCH_PATHS_QUOTED_1)",
-				);
+				LIBRARY_SEARCH_PATHS = "$(LIBRARY_SEARCH_PATHS_QUOTED_1)";
 				LIBRARY_SEARCH_PATHS_QUOTED_1 = "\"$(SRCROOT)/../Darwin source/Commands/Apple/cctools/libstuff\"";
 				OTHER_LDFLAGS = (
Index: trunk/Cocoa/F-Script Anywhere/Source/FSAApp.h
===================================================================
--- trunk/Cocoa/F-Script Anywhere/Source/FSAApp.h	(revision 230)
+++ trunk/Cocoa/F-Script Anywhere/Source/FSAApp.h	(revision 231)
@@ -54,4 +54,5 @@
 
 - (IBAction)installBundleInSelectedApp:(id)sender;
+- (void)installBundleInAppWithPID:(pid_t)pid;
 -(BOOL)createAuthorization;
 
Index: trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm
===================================================================
--- trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm	(revision 230)
+++ trunk/Cocoa/F-Script Anywhere/Source/FSAApp.mm	(revision 231)
@@ -31,4 +31,5 @@
 #import <ApplicationServices/ApplicationServices.h>
 #import <Security/AuthorizationTags.h>
+#include <mach/mach.h>
 
 NSString * const PatchBundleIdentifier = @"net.sabi.FScriptAnywhere";
@@ -120,16 +121,13 @@
 }
 
--(void)installFScript
+-(void)installFScriptAtPath:(NSString *)installPath
 {
     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 hasSuffix:@"FScript.framework"]){
+            installPath = [installPath stringByDeletingLastPathComponent];
+            NSLog(@"new ip %@", installPath);
+        }
     }
     
@@ -141,8 +139,8 @@
                     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];
+                installPath = [@"~/Library/Frameworks" stringByExpandingTildeInPath];
                 break;
             case NSAlertAlternateReturn: // All users
-                installPath = @"/Library/Frameworks/FScript.framework";
+                installPath = @"/Library/Frameworks";
                 break;
             default:
@@ -152,12 +150,12 @@
     
     NSString *fromPath = [[NSBundle mainBundle] pathForResource:@"FScript" ofType:@"framework"];
-    if(![[NSFileManager defaultManager] fileExistsAtPath:[installPath stringByDeletingLastPathComponent]]){
+    if(![[NSFileManager defaultManager] fileExistsAtPath:installPath]){
         if ([[NSFileManager defaultManager] isWritableFileAtPath:installPath]){
-            [[NSFileManager defaultManager] createDirectoryAtPath:[installPath stringByDeletingLastPathComponent]
+            [[NSFileManager defaultManager] createDirectoryAtPath:installPath
                                                        attributes:nil];
         } else {
             [self createAuthorization];
             NSString *myToolPath = @"/bin/mkdir";
-            char *myArguments[] = { (char *)[[installPath stringByDeletingLastPathComponent] UTF8String], NULL };
+            char *myArguments[] = { (char *)[installPath UTF8String], NULL };
             myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, [myToolPath UTF8String],
                                                           myFlags, myArguments,
@@ -165,10 +163,10 @@
         }
     }
-    if([[NSFileManager defaultManager] isWritableFileAtPath:[installPath stringByDeletingLastPathComponent]]){
-        [[NSFileManager defaultManager] copyPath:fromPath toPath:installPath handler:nil];
+    if([[NSFileManager defaultManager] isWritableFileAtPath:installPath]){
+        [[NSFileManager defaultManager] copyPath:fromPath toPath:[installPath stringByAppendingString:@"/FScript.framework"] handler:nil];
     } else {
         [self createAuthorization];
         NSString *myToolPath = @"/bin/cp";
-        char *myArguments[] = { "-r", (char *)[fromPath UTF8String], (char *)[installPath UTF8String], NULL };
+        char *myArguments[] = { "-R", "-f", (char *)[fromPath UTF8String], (char *)[installPath UTF8String], NULL };
         myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, [myToolPath UTF8String],
                                                       myFlags, myArguments,
@@ -177,13 +175,15 @@
 }
 
-- (BOOL)_shouldContinueAfterFrameworkErrorPanelReturnedWithResult:(int)result;
+- (BOOL)_shouldContinueAfterFrameworkErrorPanelReturnedWithResult:(int)result withFrameworkPath:(NSString *)frameworkPath
 {
     switch (result) {
         case NSAlertOtherReturn:
+            [self terminate: self];
+            return false;
+        case NSAlertAlternateReturn:
             return true;
-        case NSAlertAlternateReturn: /* Install from resources */
-            [self installFScript];
+        case NSAlertDefaultReturn:  /* Install from resources */
+            [self installFScriptAtPath:frameworkPath];
             return true;
-        case NSAlertDefaultReturn:
         default:
             [self terminate: self];
@@ -249,50 +249,66 @@
 - (void)finishLaunching
 {
-#ifdef __i386__
-    if(![[NSUserDefaults standardUserDefaults] objectForKey:@"doPathCheck"])
-        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"doPathCheck"];
-    
-    if([[NSUserDefaults standardUserDefaults] boolForKey:@"doPathCheck"]){
+    mach_port_t     taskOfOurProcess = mach_task_self();
+    mach_port_t     machPortForProcess;
+    
+    if(task_for_pid(taskOfOurProcess, 1, &machPortForProcess) != KERN_SUCCESS){ // launchd should always be pid 1
+        if(![[NSUserDefaults standardUserDefaults] objectForKey:@"doPathCheck"])
+            [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"doPathCheck"];
+        
+        if([[NSUserDefaults standardUserDefaults] boolForKey:@"doPathCheck"]){
 top:
-        PathManager *pm = [[PathManager alloc] initWithLocalNode];
-        [pm backupStack];
-        [pm cd:@"/Groups/procmod"];
-        CFDictionaryRef sessionInfoDict = CGSessionCopyCurrentDictionary();
-        if(sessionInfoDict){
-            CFStringRef shortUserName = (CFStringRef)CFDictionaryGetValue(sessionInfoDict, kCGSessionUserNameKey);
-            if(![[[pm lastObject] readArray:@"GroupMembership"] containsObject:(NSString *)shortUserName]){
-                switch([[NSAlert alertWithMessageText:[NSString stringWithFormat:@"User %@ not in the procmod group", shortUserName]
-                                        defaultButton:@"Add me"
-                                      alternateButton:@"Disable checking"
-                                          otherButton:@"Ignore message"
-                            informativeTextWithFormat:@"F-Script Anywhere requires that you add yourself to the procmod "
-                    "group in order for it to function properly. If you like, F-Script Anywhere can automatically add you "
-                    "to the procmod group."] runModal]){
-                    case NSAlertDefaultReturn:
-                    {
-                        tDirStatus status = [self authorizeAndAddToProcMod:(NSString *)shortUserName];
-                        if(status != eDSNoErr){
-                            [[NSAlert alertWithMessageText:@"Error adding to procmod group"
-                                             defaultButton:nil
-                                           alternateButton:nil
-                                               otherButton:nil
-                                 informativeTextWithFormat:@"There was an error (%@) adding you to the procmod group. ", [[NSClassFromString(@"DSoStatus") sharedInstance] stringForStatus:status]] runModal];
+            PathManager *pm = [[PathManager alloc] initWithLocalNode];
+            [pm backupStack];
+            @try {
+                [pm cd:@"/Groups/procmod"];
+            } @catch ( NSException *exception ) {
+                goto next;  // this means we must be on ppc 10.4 or less.
+            }
+            CFDictionaryRef sessionInfoDict = CGSessionCopyCurrentDictionary();
+            if(sessionInfoDict){
+                CFStringRef shortUserName = (CFStringRef)CFDictionaryGetValue(sessionInfoDict, kCGSessionUserNameKey);
+                if(![[[pm lastObject] readArray:@"GroupMembership"] containsObject:(NSString *)shortUserName]){
+                    switch([[NSAlert alertWithMessageText:[NSString stringWithFormat:@"User %@ not in the procmod group", shortUserName]
+                                            defaultButton:@"Add me"
+                                          alternateButton:@"Disable checking"
+                                              otherButton:@"Ignore message"
+                                informativeTextWithFormat:@"F-Script Anywhere requires that you add yourself to the procmod "
+                        "group in order for it to function properly. If you like, F-Script Anywhere can automatically add you "
+                        "to the procmod group."] runModal]){
+                        case NSAlertDefaultReturn:
+                        {
+                            tDirStatus status = [self authorizeAndAddToProcMod:(NSString *)shortUserName];
+                            if(status != eDSNoErr){
+                                [[NSAlert alertWithMessageText:@"Error adding to procmod group"
+                                                 defaultButton:nil
+                                               alternateButton:nil
+                                                   otherButton:nil
+                                     informativeTextWithFormat:@"There was an error (%@) adding you to the procmod group. ", [[NSClassFromString(@"DSoStatus") sharedInstance] stringForStatus:status]] runModal];
+                            } else {
+                                [[NSAlert alertWithMessageText:@"Adding user procmod group succeeded"
+                                                 defaultButton:nil
+                                               alternateButton:nil
+                                                   otherButton:nil
+                                     informativeTextWithFormat:@"You may have to wait a few minutes until the system updates its caches (or alternatively, reboot your machine) before things will work properly."] runModal];
+                            }
                         }
-                    }
-                        [pm restoreStack];
-                        [pm release];
-                        goto top;
-                    case NSAlertAlternateReturn:
-                        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"doPathCheck"];
-                        break;
-                    default:
-                        break;
-                }            
+                            [pm restoreStack];
+                            [pm release];
+                            goto top;
+                        case NSAlertAlternateReturn:
+                            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"doPathCheck"];
+                            break;
+                        default:
+                            break;
+                    }            
+                }
             }
-        }
-        [pm restoreStack];
-        [pm release];
-    }
-#endif
+            [pm restoreStack];
+            [pm release];
+        }
+    } else {
+        mach_port_deallocate(taskOfOurProcess, machPortForProcess);
+    }
+next:
     patchController = new FSAPatchController(self);
     patchController->AddPatch((CFStringRef)PatchBundleIdentifier, CFSTR("Contents/Resources/"),
@@ -320,5 +336,5 @@
         NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask, TRUE);
     NSString *libPath;
-    NSString *frameworkPath;
+    NSString *frameworkPath = NULL;
     CFBundleRef frameworkBundle = NULL;
     BOOL isDirectory;
@@ -342,27 +358,47 @@
             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(@"Install F-Script", "'Get F-Script' button title"),
             NSLocalizedString(@"Continue", "Continue button title"),
+            NSLocalizedString(@"Quit", "Quit button title"),
             FSA_FScriptURL, NSLocalizedString(@"Continue", ""));
-        if (![self _shouldContinueAfterFrameworkErrorPanelReturnedWithResult: result]) return;
+        if (![self _shouldContinueAfterFrameworkErrorPanelReturnedWithResult: result withFrameworkPath:nil]) return;
     } else {
+        CFBundleRef includedBundle = CFBundleCreate(kCFAllocatorDefault, (CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"FScript" ofType:@"framework"]]);
+        [(id)includedBundle autorelease];
+        UInt32 includedVersion = CFBundleGetVersionNumber(includedBundle);
         UInt32 version = CFBundleGetVersionNumber(frameworkBundle);
         FSALog(@"Framework version 0x%x", version);
-        if (version < FSA_FSCRIPT_MIN_VERSION) {
-            NSString *frameworkVersion = (NSString *)CFBundleGetValueForInfoDictionaryKey(frameworkBundle, kCFBundleVersionKey);
-            if (frameworkVersion == nil)
-                frameworkVersion = NSLocalizedString(@"unavailable", "Framework too old 'unavailable' version");
-            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\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(@"Install F-Script", "'Get F-Script' button title"),
-                NSLocalizedString(@"Continue", "Continue button title"),
-                FSA_VERSION, FSA_FScriptMinimumVersion, frameworkVersion,
-                FSA_FScriptURL, NSLocalizedString(@"Install F-Script", ""));
-            if (![self _shouldContinueAfterFrameworkErrorPanelReturnedWithResult: result]) return;
-        }
+        if(version < includedVersion){
+            if (version < FSA_FSCRIPT_MIN_VERSION){ // must force upgrade 
+                NSString *frameworkVersion = (NSString *)CFBundleGetValueForInfoDictionaryKey(frameworkBundle, kCFBundleVersionKey);
+                if (frameworkVersion == nil)
+                    frameworkVersion = NSLocalizedString(@"unavailable", "Framework too old 'unavailable' version");
+                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 to the latest version, 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(@"Install F-Script", "'Get F-Script' button title"),
+                                                          NSLocalizedString(@"Continue", "Continue button title"),
+                                                          NSLocalizedString(@"Quit", "Quit button title"),
+                                                          FSA_VERSION, FSA_FScriptMinimumVersion, frameworkVersion,
+                                                          FSA_FScriptURL, NSLocalizedString(@"Install F-Script", ""));
+                if (![self _shouldContinueAfterFrameworkErrorPanelReturnedWithResult: result withFrameworkPath:frameworkPath]) return;                
+            } else {
+                NSNumber *lastChecked = [[NSUserDefaults standardUserDefaults] objectForKey:@"LastCheckedVersion"];
+                if((version < includedVersion) && (!lastChecked || ([lastChecked unsignedIntValue] != version))){
+                    FSALog(@"Included framework in resources is newer than installed version.");
+                    int result = NSRunInformationalAlertPanel(
+                                                              NSLocalizedString(@"Newer Version of F-Script Framework Available", "Framework newer found alert title"),
+                                                              NSLocalizedString(@"F-Script Anywhere is bundled with a newer version of the F-Script framework. If you wish, F-Script Anywhere can upgrade your framework version.",
+                                                                                "Framework newer found alert message, 'Continue' button parameter"),
+                                                              NSLocalizedString(@"Upgrade F-Script Framework", "Upgrade button title"),
+                                                              NSLocalizedString(@"Continue", "Continue button title"),
+                                                              nil,
+                                                              NSLocalizedString(@"Upgrade", ""), NSLocalizedString(@"Continue", ""));
+                    if (![self _shouldContinueAfterFrameworkErrorPanelReturnedWithResult: result withFrameworkPath:frameworkPath]) return;                
+                }
+            }
+        }
+        [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithUnsignedInt:version] forKey:@"LastCheckedVersion"];
     }
 
Index: trunk/Cocoa/F-Script Anywhere/Source/SCPatch/SCPatchController/SCPatchController.h
===================================================================
--- trunk/Cocoa/F-Script Anywhere/Source/SCPatch/SCPatchController/SCPatchController.h	(revision 230)
+++ trunk/Cocoa/F-Script Anywhere/Source/SCPatch/SCPatchController/SCPatchController.h	(revision 231)
@@ -1,6 +1,7 @@
 #pragma once
+#include <Carbon/Carbon.h>
+#include <list>
 
-#include <Carbon/Carbon.h>
-#include <list.h>
+using namespace std;
 
 #include "SCPatchPrivate.h"
