0

我正在使用 FlasCC+Swig 在 Adob​​e Air 应用程序中调用我的 C 函数。

C函数:

int file_exists(const char filename[]) {
    struct stat stbuf;
    if (stat(filename, &stbuf) == -1) {
        return (0);
    }
    return (1);
}

在我的普通命令行中(当然,首先编译一个main.cpp),如果我提供“/tmp/test.txt”(文件存在),函数file_exists返回1,这是预期的。

但是,我用FlasCC+Swig编译这个C函数file_exists,生成一个swc库,把这个库添加到我的Adobe Air应用程序中运行后,总是返回0,这是不正确的。

我检查了errno,它的值是ENOENT (2)

路径的组件没有命名现有文件或路径是空字符串。

http://pubs.opengroup.org/onlinepubs/7908799/xsh/stat.html

你能给我一些想法吗?

顺便说一句,在我的 Adob​​e Air 应用程序中:

var file:File = File.applicationDirectory.resolvePath(path);
trace(file.exists); // returns true

所以 Adob​​e Air 确实可以访问本地文件系统。

4

1 回答 1

0

事实证明,低级 c 代码将无法看到真正的本地文件系统。我们需要使用 Adob​​e 虚拟文件系统。

CModule.vfs.addDirectory("/MyPath/");
CModule.vfs.addFile("/MyPath/MyFile.txt", data);

我们设置好上面的VFS之后,我们的C文件读取函数就可以看到文件了/MyPath/MyFile.txt

于 2014-02-25T17:16:59.340 回答