[英]C++ MAC OS X cannot write to ~/Library/Application Support/<appname>
If i save files inside the .app
bundle, it saves OK, but apple recommends saving files inside the Application Support under 如果我将文件保存在
.app
捆绑包中,则可以保存,但是Apple建议在“应用程序支持”下将文件保存在
~/Library/Application Support/appname
or 要么
~/Library/Application Support/bundleid
I tried both, but I am always getting an exception. 我都尝试过,但是总是遇到例外。 I am getting a path to the Application Support, which is
我正在找到应用程序支持的路径,这是
/Users/myname/Library/Application Support/com.company.appname/
or 要么
/Users/myname/Library/Application Support/AppName/
com.company.appname
is specified correctly inside my info.plist
, and AppName
is product AppName.app
, so the paths seems correct. com.company.appname
是在我的info.plist
正确指定的,而AppName
是product AppName.app
,因此路径似乎正确。
{
FilepathProcessor::pathForFile(fpath, "menustate", ".sav",
PATH_TO_DESTINATION_SAVE_LOAD_FOLDER);
std::ofstream file;
file.exceptions(std::ofstream::eofbit | std::ofstream::failbit |
std::ofstream::badbit);
INFO_ARG("prepare to save to '%s'", fpath.c_str());
try {
file.open(fpath.c_str(), std::ios::out | std::ios::binary |
std::ios::trunc);
ERROR_IF_ARG(!file.is_open(), "couldnt open file for saving at '%s'",
fpath.c_str(), return);
//will pass this point
//exception happens by first write
WRITE_INT_TO_BINFILE(file, episode);
//...
}
catch (std::ofstream::failure e) {
ERROR_IF_ARG(true, "exception %s", e.what(), return);
}
file.close();
}
Output : 输出:
INFO : prepare to save to '/Users/myname/Library/Application
Support/com.comapny.appname/menustate.sav' [CALLED BY : saveToFile]
ERROR!
Text : exception basic_ios::clear
The directory is not automatically created for you. 该目录不会自动为您创建。 Before saving the file, you first need to check if the directory exists, and if not, you need to create the directory.
保存文件之前,首先需要检查目录是否存在,如果不存在,则需要创建目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.