macos Mac OS X:我应该在哪里存储常见的应用程序数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/568708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mac OS X: Where should I store common application data?
提问by Adrian Grigore
What's the standard path on MacOS X for storing application data that is to be shared by different users? I am not talking about temporary data, but data which is used by one particular program on a regular basis and belongs to no particular user. For example a game highscore table.
MacOS X 上存储不同用户共享的应用程序数据的标准路径是什么?我不是在谈论临时数据,而是一个特定程序定期使用且不属于特定用户的数据。例如游戏高分表。
Thanks,
谢谢,
Adrian
阿德里安
采纳答案by Palm
I believe you're talking about Support files - a file that supports the application but is not required to run (your highscore table for example).
我相信您在谈论支持文件 - 一个支持应用程序但不需要运行的文件(例如您的高分表)。
These files should be put in ~/Library/Application Support/YourApp or /Library/Application Support/YourApp for shared users.
对于共享用户,这些文件应该放在 ~/Library/Application Support/YourApp 或 /Library/Application Support/YourApp 中。
回答by Heng-Cheong Leong
To get the directory, you can use the function "NSSearchPathForDirectoriesInDomains", with the directory parameter being "NSApplicationSupportDirectory", and the domainMask parameter being "NSLocalDomainMask".
要获取目录,可以使用函数“NSSearchPathForDirectoriesInDomains”,目录参数为“NSApplicationSupportDirectory”,domainMask 参数为“NSLocalDomainMask”。
(NSApplicationSupportDirectory is the "Location of application support files", while NSLocalDomainMask means "Local to the current machine—the place to install items available to everyone on this machine.")
(NSApplicationSupportDirectory 是“应用程序支持文件的位置”,而 NSLocalDomainMask 的意思是“本地到当前机器——在这台机器上安装可供所有人使用的项目的地方。”)
回答by Christian Studer
Some applications put files into the /Users/Shared-directory. I know it's the standard way to share files between users, but I'm not 100% sure it's thought for application data storage.
某些应用程序将文件放入 /Users/Shared-目录中。我知道这是在用户之间共享文件的标准方式,但我不能 100% 确定它是用于应用程序数据存储的。
The there's the /Library*-folder which is thought for systemwide common data, similiar to the /Users/Usernames/Library.
有 /Library* 文件夹,它被认为是系统范围的公共数据,类似于 /Users/Usernames/Library。
But you certainly shouldn't write data to the Application.app-directory. Users without admin rights won't even have the right to write to these directories.
但是您当然不应该将数据写入 Application.app 目录。没有管理员权限的用户甚至无权写入这些目录。
* = Or /System/Library. Need to verify.