objective-c - 以编程方式制作 mac 包/包

标签 objective-c cocoa macos filesystems

通过终端,您可以使用命令 - “SetFile -a B 文件名”

以编程方式,我认为我应该通过 [[NSFileManager defaultManager] createDirectoryAtPath:dirPath withIntermediateDirectories:NO attributes:attributes error:nil];

但我找不到哪个。

谢谢

最佳答案

能够以编程方式设置捆绑位仍然很有用,例如 iPhoto 这样做是为了使 iPhoto Library 文件夹显示为单个文件。

您可以使用 Carbon 文件管理器 API 以编程方式设置捆绑位。您需要确保您的应用链接到 Carbon 框架并导入 <Carbon/Carbon.h> header 。这些调用是 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;
}

关于objective-c - 以编程方式制作 mac 包/包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2009687/

相关文章:

xcode - 使用 NSValueTransformer 进行 NSComboBox 自动补全

objective-c - CFUserNotificationCreate 创建的弹出窗口不会出现在前面

ios - Objective-c 如何对 textField 进行验证

iphone - Authorize.net ios Sdk 错误

objective-c - UIViewController 被置空后仍保持状态

iphone - 链接文件所有者和 View Controller [iPhone SDK]

cocoa - 如何在 cocoa 应用程序中实现NSForm?

python - 如何使用 python 在 Mac OS X 中获取环境变量?

objective-c - 在内容为通过特定对象属性获取 Core Data 对象的 NSArray 中搜索

ios - 在 XCode 4+ 中创建/编辑子类模板