#ifndef CCALLBACKFILESYSTEM_H_INCLUDED
#define CCALLBACKFILESYSTEM_H_INCLUDED

#include "IExternFileSystem.h"
typedef struct TAG_ExternFS
{
    void* memory_start;
    u32 len;
} ExternFS;

extern IrrlichtDevice *device;
extern IVideoDriver* driver;
extern ISceneManager* smgr;
extern IGUIEnvironment* guienv;


typedef bool(*FileSystemCallbackPtr)(const c8* , bool ,  ExternFS* );

namespace irr
{
namespace io
{
class CCallbackFileSystem : public IExternFileSystem
{
   public:
    //! constructor
   CCallbackFileSystem(FileSystemCallbackPtr callBack) :
   callback(callBack)
   {
   }

    //! opens a file by file name
    IReadFile* openFile(const c8* filename) {
        ExternFS* f =  new ExternFS();
        bool ret = callback(filename, true, f);
        if (ret)
        {
            IReadFile* irf = device->getFileSystem()->createMemoryReadFile( f->memory_start, f->len, filename, true);
            delete f;
            return irf;
        }
        delete f;
        return NULL;
    }

    //! returns fileindex
    s32 findFile(const c8* filename)
    {
        bool ret = callback(filename, false, NULL);
        if (ret)
            return true;
        return -1;
    }


   protected:
   FileSystemCallbackPtr callback;

};

} // end namespace scene
} // end namespace irr




#endif // CCALLBACKFILESYSTEM_H_INCLUDED
