以编程方式make mac软件包/软件包 [英] make mac package/bundle programmatically

查看:131
本文介绍了以编程方式make mac软件包/软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

through terminal you can make it with a command - "SetFile -a B filename"

以编程方式,我想我应该设置其中的一个属性通过
[[NSFileManager defaultManager] createDirectoryAtPath:dirPath withIntermediateDirectories:NO attributes:attributes error:nil];

programmatically i think i should set one of the attributes through [[NSFileManager defaultManager] createDirectoryAtPath:dirPath withIntermediateDirectories:NO attributes:attributes error:nil];

但我找不到哪一个。

感谢

推荐答案

能够以程序方式设置bundle位, iPhoto会将 iPhoto Library 文件夹显示为单个文件。

It is still useful to be able to set the bundle bit programmatically, for instance iPhoto does this to make the iPhoto Library folder appear as a single file.

您可以使用Carbon File Manager API 。您需要确保您的应用程序链接到Carbon框架,并导入< Carbon / Carbon.h> 标题。这些调用是64位安全的。

You can set the bundle bit programmatically using the Carbon File Manager API. You'll need to make sure your app links against the Carbon framework and import the <Carbon/Carbon.h> header. These calls are 64-bit safe.

- (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;
}

这篇关于以编程方式make mac软件包/软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆