Example #1
0
bool InStream::open(const char *fn)
{
    ttvfs::VFSFile *vf = vfs.GetFile(fn);
    if(vf)
    {
        vf->open("r");
        str((char*)vf->getBuf()); // stringstream will always make a copy
        vf->close();
        vf->dropBuf(true);
        return true;
    }
    setstate(std::ios_base::failbit);
    return false;
}
Example #2
0
VFILE *vfopen(const char *fn, const char *mode)
{
    if (strchr(mode, 'w'))
    {
        fprintf(stderr, "FileAPI.h: File writing via VFS not yet supported!");
        return NULL;
    }

    VFILE *vf = vfs.GetFile(fn);
    if (!vf || !vf->open(mode))
        return NULL;
    ++(vf->ref); // keep the file alive until closed.
    return vf;
}
Example #3
0
static void PrintFile(const char *fn)
{
    ttvfs::VFSFile *vf = vfs.GetFile(fn);
    std::cout << "Open file " << fn << ": ";
    if(vf)
    {
        vf->open("r"); // force text mode
        std::cout << (const char*)vf->getBuf() << std::endl;
        vf->dropBuf(true); // no longer needed
        vf->close();
    }
    else
    {
        std::cout << "FILE OPEN ERROR!" << std::endl;
    }
}