#ifndef CFILEFACTORYIW_H_INCLUDED
#define CFILEFACTORYIW_H_INCLUDED

#include "IFileFactory.h"
#include "CWrapperMemoryReadFile.h"

typedef struct TAG_ExternFFFS
{
    void* memory_start;
    u32 len;
} ExternFFFS;

typedef bool(*FileSystemFFCallbackPtr)(const c8* , bool ,  ExternFFFS* );


extern IrrlichtDevice *device;


namespace irr
{

namespace io
{

class CFileFactoryIW : public IFileFactory
{
    public:
    CFileFactoryIW(FileSystemFFCallbackPtr callBack)
    {
        callback = callBack;
    }


     IReadFile* createAndOpenFile(const c8* filename)
     {
         if (callback)
         {
            ExternFFFS f ;//=  new ExternFFFS();
            bool ret = callback(filename, true, &f);
            if (ret)
            {

                IReadFile* irf = device->getFileSystem()->createMemoryReadFile(f.memory_start, f.len, filename, true);
//                IReadFile* irf = new CWrapperMemoryReadFile( f.memory_start, f.len, filename, true);
//                delete f;
                return irf;
            }
//            delete f;
            return NULL;
         }

        return NULL;
     }

   protected:
   FileSystemFFCallbackPtr callback;

};
}
}


#endif // CFILEFACTORYIW_H_INCLUDED
