Ok, here is the code:

BOOL                        result = NO;
    Boolean                        converted = false;
    unsigned                    i = 0;
    pid_t                        pid = -1;
    NSBundle                    *glBundle = [ NSBundle mainBundle ];
    NSDictionary                *d = nil;
    NSDictionary                *dd = nil;
    NSString                    *z = nil;
    NSString                    *zzz = nil;
    NSMutableString                *m = nil;
    NSArray                        *arr = nil;
    NSURL                        *urlRef = nil;
    NSError                        *inError = nil;
    FSRef                        exeRef;
    LSApplicationParameters        inAppParams;
    ProcessSerialNumber            outPSN;
    OSStatus                    err = noErr;
    
    memset( &exeRef, 0, sizeof( exeRef ) );
    
    memset( &inAppParams, 0, sizeof( inAppParams ) );
    
    memset( &outPSN, 0, sizeof( outPSN ) );
    
    if( glBundle )
    {
        // Get main bundle info dict...
    
        d = [ glBundle infoDictionary ];
        if( d )
        {
            // Get the GL bundle's path from the info dict...
            
            z = [ d objectForKey:kNSBundleInitialPathInfoDictKey ];
            if( z )
            {
                // Break the path up into a path component array...
                
                arr = [ z componentsSeparatedByString:kSlashStringKey ];
                
                // Make a mutable path string to manipulate...
                
                m = [ NSMutableString stringWithCapacity:0 ];
            }
        }
    }
    
    if( m && arr )
    {
        for(i=0; i<[ arr count] - 1; i++ )
        {
            [m appendString:[arr objectAtIndex:i] ];
            [m appendString:@"/" ];
        }
        
        //go up one level to get at Info.plist
        
        [m appendString:@"Info.plist" ];
        
        dd = [ NSDictionary dictionaryWithContentsOfFile:m ];
        
        zzz = [ dd valueForKey:@"CFBundleExecutable" ];
        
        //reset
        
        [ m setString:@"" ];
        
        //Loop again appening all path compoents to final file to launch...
        
        for(i=0; i<[ arr count] - 1; i++ )
        {
            [m appendString:[arr objectAtIndex:i] ];
            [m appendString:@"/" ];
        }
        
        //now get full path to the file we want to actually run...
        
        [ m appendString:zzz ];
        
        [ m appendString:@".ifn" ];
        
        urlRef = [ NSURL fileURLWithPath:m ];
        if( urlRef )
        {
            converted = CFURLGetFSRef( (CFURLRef)urlRef, &exeRef );
            if( converted )
            {
                CFURLRef    qaud = NULL;
                
                err = LSOpenCFURLRef( (CFURLRef)urlRef, &qaud );
                
                  // Setup launch param block...
                                
                inAppParams.application = &exeRef;
            
                // Launch!
                
                err = LSOpenApplication( &inAppParams, &outPSN );
                if( !err )
                {
                   err = GetProcessPID( &outPSN, &pid );
                    if( !err )
                    {
                        lppiProcInfo->dwProcessId = (DWORD)pid;
                        
                        result = YES;
                    }
                }
            }
        }




________________________________
From: Ken Thomases <k...@codeweavers.com>
To: Erg Consultant <erg_consult...@yahoo.com>
Cc: cocoa-dev@lists.apple.com
Sent: Saturday, April 25, 2009 6:12:33 PM
Subject: Re: Why is NSString->FSRef so hard?

On Apr 25, 2009, at 8:03 PM, Erg Consultant wrote:

> On Apr 25, 2009, at 7:48 PM, Stephen J. Butler wrote:
> 
>> On Sat, Apr 25, 2009 at 7:28 PM, Erg Consultant
>> <erg_consult...@yahoo.com> wrote:
>>> I was using CFURLGetFSRef passing in the NSString which works fine as long 
>>> as the path contains no special chars. If it does, CFURLGetFSRef returns 
>>> nil.
>> 
>> CFURLGetFSRef is great if what you have originally is a CF/NSURL. But
>> if you just have an NSString, you might as well use FSPathMakeRef with
>> [aString fileSystemRepresentation]. No reason to create an
>> intermediary NSURL.

> When I do that, the conversion from NSString to const UInt8 * path mangles 
> the special characters in the path.

What do you mean mangles?  I suspect you're misinterpreting "encodes" as 
mangles.  Asking a file path string for its -fileSystemRepresentation is asking 
it to encode the string into the form expected by various APIs which take file 
paths in C strings (of 8-bit characters).  Of course this won't look like the 
original Unicode string contents; Unicode can't fit into 8-bit characters 
without being encoded somehow.

But the question is, why do you care?  Did FSPathMakeRef work, when passed such 
a string?  It should, which is all you're interested in.

Regards,
Ken


      
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to