OS X 上插件中资源文件夹的路径

发布于 2024-10-07 21:49:43 字数 908 浏览 4 评论 0原文

我正在为 OS X 编写 FileMaker Pro 插件,并且需要能够访问 /Applications/FileMaker Pro 11/Extensions/blah.fmplugin/Contents/Resources 目录中的文件。 (但这可能是 /apps/FileMaker Pro 11 Advanced/Extensions/xyz.fmplugin/Contents/Resources 或其他内容,具体取决于用户安装 FMP 的位置以及他们是否重命名插件等。)我无法控制用户安装 FMP 的位置,或者他们是否运行 FMP 或 FMPA,或者他们是否重命名了我的插件(尽管这比 FMP 与 FMPA 情况不太可能),我 了解插件包的路径。

我找到了这样的答案: 相对路径在 Xcode C++ 中不起作用 但这为我提供了 FileMaker.app 中的 Resources 文件夹的路径,而不是我的插件中的路径。

即我得到 /Applications/FileMaker Pro 11/FileMaker Pro.app/Contents/Resources 而不是我的插件中的 Resources 文件夹的路径。

我需要在 Xcode 中配置一些东西才能使上述解决方案起作用吗?或者还有其他方法可以到达该路径吗? CFBundleGetMainBundle() 调用听起来像是要返回应用程序本身的包而不是插件。

我根据 Bundle 编程指南和 CFBundleGetBundleWithIdentifier (由 mipadi 提到)找到了一些可能性,但我还无法确切地弄清楚我需要什么功能以及先决条件是什么。

I'm writing a FileMaker Pro plugin for OS X, and I need to be able to access a file in the /Applications/FileMaker Pro 11/Extensions/blah.fmplugin/Contents/Resources directory. (But this could be /apps/FileMaker Pro 11 Advanced/Extensions/xyz.fmplugin/Contents/Resources or something else, depending on where the user installed FMP and whether they renamed the plugin etc.) Since I can't control where the user has installed FMP, or whether they are running FMP or FMPA or whether they have renamed my plugin (although this is less likely than the FMP vs FMPA situation), I do not know the path to the plugin's bundle.

I've found answers like this: Relative Paths Not Working in Xcode C++ but that gives me the path to the Resources folder in the FileMaker.app instead of in my plugin.

i.e. I get /Applications/FileMaker Pro 11/FileMaker Pro.app/Contents/Resources instead of the path to the Resources folder in my plugin.

Is there something I need to configure in Xcode to get the above solution to work? Or is there some other way to get at the path? The CFBundleGetMainBundle() call makes it sound like it is meant to return the bundle of the app itself rather than the plugin.

I have found some possibilities based on the Bundle Programming Guide and CFBundleGetBundleWithIdentifier (mentioned by mipadi), but I haven't been able to figure out yet exactly what functions I need and what the prerequisites are.

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

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

发布评论

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

评论(2

小情绪 2024-10-14 21:49:43

这似乎可以做到。 CFBundleGetBundleWithIdentifier 应该也可以工作,但我决定使用 NSBundle 的东西而不是 CF*。我将其放入 .mm 文件中并将其包含在项目中。然后我可以调用 get_resources_path() 函数并获取字符串形式的路径。

#include <Foundation/Foundation.h>

#include <string>

std::string *get_resources_path()
{
    NSBundle *bundle;

    bundle = [NSBundle bundleWithIdentifier: @"com.example.fmplugin"];
    if (bundle == NULL) {
        // error handling
    }

    NSString *respath = [bundle resourcePath];
    if (respath == NULL) {
        // error handling
    }

    const char *path = [respath UTF8String];
    if (path == NULL) {
        // error handling
    }

    return new std::string(path);
}

This seems to do it. CFBundleGetBundleWithIdentifier should have worked too, but I decided to go with the NSBundle stuff rather than CF*. I put this in a .mm file and included it in the project. I can then call the get_resources_path() function and get the path as a string.

#include <Foundation/Foundation.h>

#include <string>

std::string *get_resources_path()
{
    NSBundle *bundle;

    bundle = [NSBundle bundleWithIdentifier: @"com.example.fmplugin"];
    if (bundle == NULL) {
        // error handling
    }

    NSString *respath = [bundle resourcePath];
    if (respath == NULL) {
        // error handling
    }

    const char *path = [respath UTF8String];
    if (path == NULL) {
        // error handling
    }

    return new std::string(path);
}
风流物 2024-10-14 21:49:43

您可以使用 CFBundleCreate(如果您知道捆绑包的路径);或者您可以通过 CFBundleGetBundleWithIdentifier 使用包标识符获取包。

You can use CFBundleCreate if you know the path to your bundle; or you can get the bundle using the bundle identifier via CFBundleGetBundleWithIdentifier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文