如何使用OS X api定位应用程序首选项文件夹
How to locate application preferences folder using OS X APIs?
我遇到了一个(过时的)代码片段,它使用文件管理器函数(包含在Carbon中)来定位共享的应用程序首选项文件夹(在大多数情况下只是"/Library/Preferences")。它类似于:
#include <Carbon/Carbon.h>
...
FSSpec spec = { 0 }; // data type which specifies name and location of a file or folder
FSRef ref; // data type which references in some sense a file or a folder
OSErr err = fnfErr;
// find a 'preferences' type folder (specified by kPreferencesFolderType)
// with the necessary permissions (specified by kUserDomain)
err = FindFolder(kUserDomain, ,
1, &spec.vRefNum, &spec.parID);
// operate some conversions to put the folder path inside a string where you can
// then append the app name to it.
FSpMakeFSRef(&spec, &ref);
FSRefMakePath(&ref, (UInt8*)filename, FL_PATH_MAX);
(kUserDomain
和kPreferencesFolderType
是在CarbonCore/Folders.h.中定义的枚举值)
不幸的是,许多"FS"文件管理器功能似乎被弃用了,特别是那些使用FSSpec
(https://developer.apple.com/library/mac/documentation/Carbon/reference/File_Manager/Reference/reference.html)的功能。
我因此想知道:这将是当前正确的方式来定位应用程序首选项文件夹(没有硬接线"库/首选项/AppName"到代码)?由于
我敢想象你想使用一些需要NSSearchPathDirectory
的东西-可能是NSFileManager -URLsForDirectory:inDomains:
,可能是NSLibraryDirectory
,你需要自己添加Preferences
位。基于Apple公开的这些选项,我真的不认为您打算自己从路径中读取和写入—它只是用于用户默认值,暴露的NSApplicationSupportDirectory
是您只需扔其他支持数据的地方。
相关文章:
- Bash 自动完成一个选项,而不运行应用程序
- 由于选项卡顺序的原因,鼠标光标总是得到错误的hwnd-MFC应用程序
- 如何在 DirectX 11 应用程序中提供选择图形适配器的选项?
- 相机枚举的选项和UWP应用程序的HAL(WPF/C CLI DLL)
- 如果应用程序从安装选项启动,则加载库失败,错误代码为 126
- 在任务管理器的应用程序选项卡中获取运行任务的列表
- 在C#WPF应用程序中使用C++11库的选项是什么
- 显示应用程序列表,如Win7中的alt选项卡
- Qt 应用程序在向 QTabWidget 添加选项卡后崩溃
- 如何在跨平台应用程序中存储首选项(和用户设置)
- C++ MFC 应用程序 CMFCBaseTabCtrl 选项卡不可见
- Boost选项-获取应用程序名称
- c++应用程序保存并应用首选项模式(可能是boost或其他什么)
- Visual Studio 2012 for windows 8未显示win32控制台应用程序选项
- 在终端服务服务器会话中存储用户的应用程序首选项。托管C++
- 如何使用OS X api定位应用程序首选项文件夹
- Qt Creator没有Qt应用程序的选项
- 如何为应用程序设置默认选项
- 在Windows Vista/View Studio 2005中,应用程序崩溃弹出窗口中没有JIT调试器的“调试”选项
- 正确处理全屏OpenGL应用程序中的Alt选项卡