Ответ 1
По-прежнему полезно иметь возможность устанавливать бит пакета программно, например, iPhoto делает это, чтобы папка iPhoto Library отображалась как один файл.
Вы можете установить бит пакета программно, используя API-интерфейс Carbon File Manager. Вам нужно будет убедиться, что ваши приложения связаны с каркасом Carbon и импортируют заголовок <Carbon/Carbon.h>
. Эти вызовы являются 64-битными.
- (void)setBundleBitOfFile:(NSString*)path toBool:(BOOL)newValue
{
const char* pathFSR = [path fileSystemRepresentation];
FSRef ref;
OSStatus err = FSPathMakeRef((const UInt8*)pathFSR, &ref, /*isDirectory*/ NULL);
if (err == noErr)
{
struct FSCatalogInfo catInfo;
union FinderInfoTransmuter finderInfoPointers = { .bytes = catInfo.finderInfo };
err = FSGetCatalogInfo(&ref,
kFSCatInfoFinderInfo,
&catInfo,
/*outName*/ NULL,
/*FSSpec*/ NULL,
/*parentRef*/ NULL);
if (err == noErr)
{
if (newValue)
finderInfoPointers.finderInfo->finderFlags |= kHasBundle;
else
finderInfoPointers.finderInfo->finderFlags &= ~kHasBundle;
FSSetCatalogInfo(&ref,
kFSCatInfoFinderInfo,
&catInfo);
}
}
}
- (BOOL)bundleBitOfFile:(NSString*)path
{
BOOL value = NO;
const char* pathFSR = [path fileSystemRepresentation];
FSRef ref;
OSStatus err = FSPathMakeRef((const UInt8*)pathFSR, &ref, /*isDirectory*/ NULL);
if (err == noErr)
{
struct FSCatalogInfo catInfo;
union FinderInfoTransmuter finderInfoPointers = { .bytes = catInfo.finderInfo };
err = FSGetCatalogInfo(&ref,
kFSCatInfoFinderInfo,
&catInfo,
/*outName*/ NULL,
/*FSSpec*/ NULL,
/*parentRef*/ NULL);
if (err == noErr)
{
value = (BOOL)(((finderInfoPointers.finderInfo->finderFlags) & kHasBundle) == kHasBundle);
}
}
return value;
}