查找“〜/库/应用程序支持";来自C ++? [英] Finding "~/Library/Application Support" from C++?

查看:74
本文介绍了查找“〜/库/应用程序支持";来自C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个GTKmm应用程序,并且试图创建一些OS X增强功能.我想将配置文件存储在Application Support/myApp文件夹中,但是,我不知道找到该文件夹​​的正确方法.

I've written a GTKmm application and I'm trying to create some OS X enhancements. I'd like to store my configuration file in the Application Support/myApp folder, however, I can't figure out the proper way to locate this folder.

我尝试浏览Core Foundation库(我正在使用它来获取myApp.app路径),但找不到任何东西.

I've tried looking through the Core Foundation library (that I'm using to get my myApp.app path) but I can't find anything.

推荐答案

在C/C ++中执行此操作的正确方法:

Proper way to do it in C/C++:

#include <CoreServices/CoreServices.h>

FSRef ref;
OSType folderType = kApplicationSupportFolderType;
char path[PATH_MAX];

FSFindFolder( kUserDomain, folderType, kCreateFolder, &ref );

FSRefMakePath( &ref, (UInt8*)&path, PATH_MAX );

// You now have ~/Library/Application Support stored in 'path'

自然,这些都是非常古老的API,Apple不再建议使用它们.尽管如此,如果您想完全避免在代码库中使用Objective-C,就可以完成工作.

Naturally, those are very old APIs and their use is no longer recommended by Apple. Despite that it gets the job done if you want to avoid Objective-C completely in your codebase.

这篇关于查找“〜/库/应用程序支持";来自C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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