Esempio n. 1
0
bool
CFCBundle::GetPath (char *dst, size_t dst_len)
{
    CFBundleRef bundle = get();
    if (bundle)
    {
        CFCReleaser<CFURLRef> bundle_url (CFBundleCopyBundleURL (bundle));
        if (bundle_url.get())
        {
            Boolean resolveAgainstBase = 0;
            return ::CFURLGetFileSystemRepresentation (bundle_url.get(), resolveAgainstBase, (UInt8 *)dst, dst_len) != 0;
        }
    }
    return false;
}   
Esempio n. 2
0
//----------------------------------------------------------------------
// Set the path for a bundle by supplying a 
//----------------------------------------------------------------------
bool
CFBundle::SetPath (const char *in_path)
{
    // Release our old bundle and ULR
    reset();    // This class is a CFReleaser<CFBundleRef>
    
	if (in_path && in_path[0])
	{
		char resolved_path[PATH_MAX];
		const char *path = ::realpath(in_path, resolved_path);
		if (path == NULL)
			path = in_path;

		CFAllocatorRef alloc = kCFAllocatorDefault;
        // Make our Bundle URL
		CFReleaser<CFURLRef> bundle_url(::CFURLCreateFromFileSystemRepresentation (alloc, (const UInt8 *)path, strlen (path), false));
        if (bundle_url.get())
        {
			CFIndex last_length = LONG_MAX;
			
			while (bundle_url.get() != NULL)
			{
				// Check the Path range and make sure we didn't make it to just
				// "/", ".", or ".."
				CFRange rangeIncludingSeparators;
				CFRange range = ::CFURLGetByteRangeForComponent(bundle_url.get(), kCFURLComponentPath, &rangeIncludingSeparators);
				if (range.length > last_length)
					break;

				reset (::CFBundleCreate (alloc, bundle_url.get()));
				if (get() != NULL)
				{
					if (GetIdentifier() != NULL)
						break;
					reset();
				}
				bundle_url.reset (::CFURLCreateCopyDeletingLastPathComponent(alloc, bundle_url.get()));
				
				last_length = range.length;
			}
        }
    }
    return get() != NULL;
}
Esempio n. 3
0
//----------------------------------------------------------------------
// Set the path for a bundle by supplying a
//----------------------------------------------------------------------
bool
CFCBundle::SetPath (const char *path)
{
    CFAllocatorRef alloc = kCFAllocatorDefault;
    // Release our old bundle and URL
    reset();

    // Make a CFStringRef from the supplied path
    CFCString cf_path;
    cf_path.SetFileSystemRepresentation(path);
    if (cf_path.get())
    {
        // Make our Bundle URL
        CFCReleaser<CFURLRef> bundle_url (::CFURLCreateWithFileSystemPath (alloc, cf_path.get(), kCFURLPOSIXPathStyle, true));
        if (bundle_url.get())
            reset (::CFBundleCreate (alloc, bundle_url.get()));
    }
    return get() != NULL;
}