【发布时间】:2014-09-04 11:45:40
【问题描述】:
我遇到了一个(过时的)代码 sn-p,它使用文件管理器功能(包含在 Carbon 中)来定位共享应用程序的 Preferences 文件夹(在大多数情况下只是“/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) 的功能。
因此我想知道:找到应用程序首选项文件夹的当前正确方法是什么(没有将“库/首选项/应用程序名称”硬连接到代码中)?谢谢
【问题讨论】:
-
还有
FSFindFolder,虽然FSSpec也被弃用了,但更容易避免使用。 -
@thakis 太久没有精通这个话题了……但我猜不是因为这个问题与python无关。
标签: c++ macos osx-mavericks