Aún es útil poder establecer el bit del paquete mediante programación, por ejemplo, iPhoto hace esto para que la carpeta iPhoto Library aparezca como un único archivo.
Puede establecer el bit del paquete programáticamente utilizando la API de Carbon File Manager. Deberá asegurarse de que la aplicación enlaza con el marco Carbon e importar el encabezado <Carbon/Carbon.h>
. Estas llamadas son seguras a 64 bits.
- (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;
}
quiero configurar una carpeta como un paquete. entonces a través del sistema de archivos se verá como un archivo. más tarde quiero abrir ese paquete con mi aplicación. la pregunta es cómo establecer el atributo del paquete de carpetas a través de cocoa. – Remizorrr
sí. pero no necesito extensión rtfd. pero por ejemplo fbp. Y necesito hacerlo programáticamente. Para hacer que cualquier carpeta sea un paquete, puede usar un comando a través de la terminal: SetFile -a B foldername. página de manual para SetFile dice - -a atributos Establece los bits de atributos del archivo donde ... (etc.) B | b Tiene paquete. la pregunta es cómo hacer lo mismo programáticamente a través de cacao. – Remizorrr