Skip navigation.
 
mlI cant get my helper tool to launch
FROM : April Gendill
DATE : Tue Dec 21 23:43:06 2004

Ok I copied the example code from Apple's site and then modified it for
my app. This code is suppose to step through a list of files and remove
only files not directories.
It does not work. It races through the loop never launching the helper
app at all. What am I doing wrong???


April.

    OSStatus myStatus;
   FILE *myCommunicationsPipe=NULL;
    AuthorizationFlags myFlags = kAuthorizationFlagDefaults;
    AuthorizationRef myAuthorizationRef;
    myStatus = AuthorizationCreate(NULL,
kAuthorizationEmptyEnvironment, myFlags, &myAuthorizationRef);
   AuthorizationItem myItems = {kAuthorizationRightExecute, 0,NULL, 0};
   AuthorizationRights myRights = {1, &myItems};
   myFlags = kAuthorizationFlagDefaults | 
kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize |
  kAuthorizationFlagExtendRights;
   myStatus = AuthorizationCopyRights (myAuthorizationRef,&myRights,
NULL, myFlags, NULL );

    if (myStatus != errAuthorizationSuccess){
       [progressWindow orderOut:self];
       return;
           }
   while(current = [iter nextObject]){
       [[NSRunLoop currentRunLoop] runUntilDate:[NSDate
dateWithTimeIntervalSinceNow:0.01]];
       BOOL fileThere = [[NSFileManager defaultManager]
fileExistsAtPath:current isDirectory:&isDir];
       

        if (myStatus != errAuthorizationSuccess){
           [progressWindow orderOut:self];
           return;
           }
       
       if(fileThere && !isDir){
           
           NSString * t = [[NSBundle mainBundle]resourcePath];
           NSString * toolPath = [NSString stringWithFormat:@"%@/helper",t];

            char *myArguments[] = { [current cString], NULL };
           char * tp = [toolPath cString];
            FILE *myCommunicationsPipe = NULL;

            char myReadBuffer[128];


            myFlags = kAuthorizationFlagDefaults;
           myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef,
tp, myFlags,
                                                           myArguments,&myCommunicationsPipe);
           
           
           if (myStatus == errAuthorizationSuccess){
               [pi incrementBy:1.0];
               }
        }//end if there and not dir
       else if (!fileThere || isDir){
           [pi incrementBy:1.0];
           }
    }//end while