我正在尝试检查 native 客户端中是否存在目录 file system但找不到任何功能来做到这一点。我尝试为目录创建一个 PPB_FileRef
,然后使用 PPB_FileIO::Open
打开它,然后调用 PPB_FileIO::Query
但是 PPB_FileIO::Open
返回 PP_ERROR_NOTAFILE
,然后第二次调用失败。
这是我一直在尝试的代码,为简洁起见省略了一些初始化。
PP_Instance instance; // initialised elsewhere
PPB_FileRef *fileRefInterface; // initialised elsewhere
PPB_FileIO *fileIOInterface; // initialised elsewhere
PP_Resource fileSystemResource; // initialised elsewhere
PP_Resource fileRefResource = fileRefInterface->Create(
fileSystemResource,
"/directory");
PP_Resource fileIOResource = fileIOInterface->Create(instance);
// This call is returning PP_ERROR_NOTAFILE
//
int32_t result = fileIOInterface->Open(
fileIOResource,
fileRefResource,
PP_FILEOPENFLAG_READ,
PP_BlockUntilComplete()); // this is being called from a background thread.
if (result != PP_OK)
{
return false;
}
PP_FileInfo info;
result = fileIOInterface->Query(fileIOResource, &info, PP_BlockUntilComplete());
if (result != PP_OK)
{
return info.type == PP_FILETYPE_DIRECTORY;
}
return false;
PPB_FileIO::Open
的 PP_ERROR_NOTAFILE
的返回值是有效的 PPB_FileRef
足以让我判断它是一个目录还是在那里我应该使用另一种更好的方法吗?
谢谢,詹姆斯
最佳答案
是的,目前确定 PPB_FileRef
是否引用目录的方法是尝试打开它并查找 PP_ERROR_NOTAFILE
返回值。
背景 PP_ERROR_NOTAFILE
是在 pepper_25
的分支创建之后添加的,因此在 pepper_26
在 SDK 中可用之前,应该使用pepper_canary
在 pp_errors.h
中获取它的定义。有关更多详细信息,请参阅相关的 Chrome change list ,其中特别提到尝试打开目录时会使用此返回值。
目前的行为可以说是有点不透明。有一个“开发”(实验性/未完成)接口(interface) PPB_DirectoryReader
,发布后将提供更直接的目录处理方式。
关于c++ - 检查 google-nativeclient 文件系统中是否存在目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14503920/