以编程方式设置类型/创建者代码

发布于 2024-10-18 12:20:56 字数 379 浏览 5 评论 0原文

我正在尝试设置类型/创建者代码,如下所示,但这会导致查找器标志和标签变得混乱。

FSCatalogInfo catInfo;
FSGetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL);
FileInfo *info = (FileInfo*)catInfo.finderInfo;
info->fileCreator = 'ar12';
info->fileType = 'rsrc';
FSSetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &catInfo);

我做错了什么,我应该怎么做?

I am trying to set the type/creator codes as shown below, but this causes the finder flags and label to get messed up.

FSCatalogInfo catInfo;
FSGetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL);
FileInfo *info = (FileInfo*)catInfo.finderInfo;
info->fileCreator = 'ar12';
info->fileType = 'rsrc';
FSSetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &catInfo);

What am I doing wrong, and how should I be doing it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初心未许 2024-10-25 12:20:56

你的代码片段对我来说效果很好。标签和查找器标志未更改。

g5:fileinfotest toby$ touch the-file
g5:fileinfotest toby$ GetFileInfo the-file
file: "/Volumes/data/Users/toby/Documents/workspace/fileinfotest/the-file"
type: ""
creator: ""
attributes: avbstclinmedz
created: 02/23/2011 14:29:15
modified: 02/23/2011 14:29:15

g5:fileinfotest toby$ ./build/Debug/fileinfotest.app/Contents/MacOS/fileinfotest 

g5:fileinfotest toby$ GetFileInfo the-file
file: "/Volumes/data/Users/toby/Documents/workspace/fileinfotest/the-file"
type: "EFGh"
creator: "ABCd"
attributes: avbstclinmedz
created: 02/23/2011 14:29:15
modified: 02/23/2011 14:29:15

代码:

FSCatalogInfo catInfo;
FSRef ref;

if(!FSPathMakeRef (
               "/Volumes/data/Users/toby/Documents/workspace/fileinfotest/the-file",
               &ref,
               false
                   ))
{
    FSGetCatalogInfo(&ref, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL);
    FileInfo *info = (FileInfo*)catInfo.finderInfo;
    info->fileCreator = 'ABCd';
    info->fileType = 'EFGh';
    FSSetCatalogInfo(&ref, kFSCatInfoFinderInfo, &catInfo);
}

Your code snippet works fine for me. Label and finder flags are not changed.

g5:fileinfotest toby$ touch the-file
g5:fileinfotest toby$ GetFileInfo the-file
file: "/Volumes/data/Users/toby/Documents/workspace/fileinfotest/the-file"
type: ""
creator: ""
attributes: avbstclinmedz
created: 02/23/2011 14:29:15
modified: 02/23/2011 14:29:15

g5:fileinfotest toby$ ./build/Debug/fileinfotest.app/Contents/MacOS/fileinfotest 

g5:fileinfotest toby$ GetFileInfo the-file
file: "/Volumes/data/Users/toby/Documents/workspace/fileinfotest/the-file"
type: "EFGh"
creator: "ABCd"
attributes: avbstclinmedz
created: 02/23/2011 14:29:15
modified: 02/23/2011 14:29:15

Code:

FSCatalogInfo catInfo;
FSRef ref;

if(!FSPathMakeRef (
               "/Volumes/data/Users/toby/Documents/workspace/fileinfotest/the-file",
               &ref,
               false
                   ))
{
    FSGetCatalogInfo(&ref, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL);
    FileInfo *info = (FileInfo*)catInfo.finderInfo;
    info->fileCreator = 'ABCd';
    info->fileType = 'EFGh';
    FSSetCatalogInfo(&ref, kFSCatInfoFinderInfo, &catInfo);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文