//------------------------------------------------------------------------------------
// irr::io::IFileSystem wrappers
// use irr:IrrlichtDevice.getFileSystem() to get a pointer for this.  do not delete
// or drop.
//------------------------------------------------------------------------------------

extern "C"
{
	
	IAttributes* IrrIO_IFileSystem_createEmptyAttributes(IFileSystem* file,video::IVideoDriver* driver=0)
	{
		if (file)
			return file->createEmptyAttributes(driver);
		else return 0;
	}
	
	bool IrrIO_IFileSystem_addZipFileArchive(IFileSystem* file,const c8 *filename,bool ignoreCase=true,bool ignorePaths=true)
	{
		if (file)
			return file->addZipFileArchive(filename,ignoreCase,ignorePaths);
		else
			return false;
	}
	
	bool IrrIO_IFileSystem_addPakFileArchive(IFileSystem* file,const c8 *filename,bool ignoreCase=true,bool ignorePaths=true)
	{
		if (file)
			return file->addPakFileArchive(filename,ignoreCase,ignorePaths);
		else
			return false;
	}

	bool IrrIO_IFileSystem_changeWorkingDirectoryTo(IFileSystem* file,const c8 *newDirectory)
	{
		if (file)
			return file->changeWorkingDirectoryTo(path(newDirectory));
		else
			return false;
	}
	
	// this pointer must be dropped
	IReadFile* IrrIO_IFileSystem_createAndOpenFile(IFileSystem* file,const c8 *filename)
	{
		if (file)
			return file->createAndOpenFile(path(filename));
		else
			return 0;
	}
	
	// this pointer must be dropped
	IWriteFile* IrrIO_IFileSystem_createAndWriteFile(IFileSystem* file,const c8 *filename,bool append=false)
	{
		if (file)
			return file->createAndWriteFile(path(filename),append);
		else
			return 0;
	}
	
	// this pointer must be dropped
	IFileList* IrrIO_IFileSystem_createFileList(IFileSystem* file)
	{
		if (file)
			return file->createFileList();
		else
			return 0;
	}
	
	// this pointer must be dropped
	IXMLReader* IrrIO_IFileSystem_createXMLReaderFromStream(IFileSystem* file,IReadFile* filestream)
	{
		if (file)
			return file->createXMLReader(filestream);
		else
			return 0;
	}
	
	// this pointer must be dropped
	IXMLReader* IrrIO_IFileSystem_createXMLReader(IFileSystem* file,const c8 *filename)
	{
		if (file)
			return file->createXMLReader(path(filename));
		else
			return 0;
	}
	
	// this pointer must be dropped
	IXMLReaderUTF8* IrrIO_IFileSystem_createXMLReaderUTF8FromStream(IFileSystem* file,IReadFile* filestream)
	{
		if (file)
			return file->createXMLReaderUTF8(filestream);
		else
			return 0;
	}
	
	// this pointer must be dropped
	IXMLReaderUTF8* IrrIO_IFileSystem_createXMLReaderUTF8(IFileSystem* file,const c8 *filename)
	{
		if (file)
			return file->createXMLReaderUTF8(path(filename));
		else
			return 0;
	}
	
	// this pointer must be dropped
	IXMLWriter* IrrIO_IFileSystem_createXMLWriterFromStream(IFileSystem* file,IWriteFile* filestream)
	{
		if (file)
			return file->createXMLWriter(filestream);
		else
			return 0;
	}
	
	// this pointer must be dropped
	IXMLWriter* IrrIO_IFileSystem_createXMLWriter(IFileSystem* file,const c8 *filename)
	{
		if (file)
			return file->createXMLWriter(path(filename));
		else
			return 0;
	}
	
	bool IrrIO_IFileSystem_existFile(IFileSystem* file,const c8 *filename)
	{
		if (file)
			return file->existFile(path(filename));
		else
			return false;
	}
	
	const c8* IrrIO_IFileSystem_getWorkingDirectory(IFileSystem* file)
	{
		if (file)
			return file->getWorkingDirectory().c_str();
		else
			return "";
	}

	bool IrrIO_IFileSystem_drop(IFileSystem* unk)
	{
		if (unk)
			return unk->drop();
		else return 0;
	}
	
	const c8* IrrIO_IFileSystem_getDebugName(IFileSystem* unk)
	{
		if (unk)
			return unk->getDebugName();
		else return "";
	}
	
	void IrrIO_IFileSystem_grab(IFileSystem* unk)
	{
		if (unk)
			unk->grab();
	}
	
	bool IrrIO_IFileSystem_addFolderFileArchive(IFileSystem* file,const c8* filename, bool ignoreCase = true, bool ignorePaths = true)
	{
		if (file)
			return file->addFolderFileArchive(filename,ignoreCase,ignorePaths);
		else return false;
	}
	
	const c8* IrrIO_IFileSystem_getAbsolutePath(IFileSystem* file,const c8 *filename)
	{
		if (file) {
			stringc fname=stringc(filename);
			return file->getAbsolutePath(fname).c_str();
		} else return 0;
	}

	const c8* IrrIO_IFileSystem_getFileDir(IFileSystem* file,const c8 *filename)
	{
		if (file) {
			stringc fname=stringc(filename);
			return file->getFileDir(fname).c_str();
		} else return 0;
	}
	
	IReadFile* IrrIO_IFileSystem_createMemoryReadFile(IFileSystem* file,void* memory, s32 len, const c8* fileName, bool deleteMemoryWhenDropped=false)
	{
		if (file) {
			return file->createMemoryReadFile(memory,len,path(fileName),deleteMemoryWhenDropped);
		} else return 0;	
	}
	
	const c8* IrrIO_IFileSystem_getFileBasename(IFileSystem* file, const c8* filename, bool keepExtension=true)
	{
		if (file) {
			stringc fname = stringc(filename);
			return file->getFileBasename(fname, keepExtension).c_str();
		} else return 0;
	}
	
	IReadFile* IrrIO_IFileSystem_createLimitReadFile(IFileSystem* file, const c8* fileName, IReadFile* alreadyOpenedFile, long pos, long areaSize)
	{
		if (file)
			return file->createLimitReadFile(path(fileName), alreadyOpenedFile, pos, areaSize);
		else return 0;
	}

	IWriteFile* IrrIO_IFileSystem_createMemoryWriteFile(IFileSystem* file, void* memory, s32 len, const c8* fileName, bool deleteMemoryWhenDropped=false)
	{
		if (file)
			return file->createMemoryWriteFile(memory, len, path(fileName), deleteMemoryWhenDropped);
		else return 0;
	}
	
	bool IrrIO_IFileSystem_addFileArchive(IFileSystem* file, const c8* filename, bool ignoreCase=true, bool ignorePaths=true, E_FILE_ARCHIVE_TYPE archiveType=EFAT_UNKNOWN, const c8* password="")
	{
		if (file)
			return file->addFileArchive(path(filename), ignoreCase, ignorePaths, archiveType, stringc(password));
		else return false;
	}

	void IrrIO_IFileSystem_addArchiveLoader(IFileSystem* file, IArchiveLoader* loader)
	{
		if (file)
			file->addArchiveLoader(loader);
	}

	s32 IrrIO_IFileSystem_getFileArchiveCount(IFileSystem* file)
	{
		if (file)
			return file->getFileArchiveCount();
		else return -1;
	}

	bool IrrIO_IFileSystem_removeFileArchiveByIndex(IFileSystem* file, u32 index)
	{
		if (file)
			return file->removeFileArchive(index);
		else return false;
	}

	bool IrrIO_IFileSystem_removeFileArchive(IFileSystem* file, const c8* filename)
	{
		if (file)
			return file->removeFileArchive(path(filename));
		else return false;
	}

	bool IrrIO_IFileSystem_moveFileArchive(IFileSystem* file, u32 sourceIndex, s32 relative)
	{
		if (file)
			return file->moveFileArchive(sourceIndex, relative);
		else return false;
	}

	IFileArchive* IrrIO_IFileSystem_getFileArchive(IFileSystem* file, u32 index)
	{
		if (file)
			return file->getFileArchive(index);
		else return 0;
	}
	
	// returns EFileSystemType
	s32 IrrIO_IFileSystem_setFileListSystem(IFileSystem* file, EFileSystemType listType)
	{
		if (file)
			return file->setFileListSystem(listType);
		else return -1;
	}

	IFileList* IrrIO_IFileSystem_createEmptyFileList(IFileSystem* file, const c8* fl_path, bool ignoreCase, bool ignorePaths)
	{
		if (file)
			return file->createEmptyFileList(path(fl_path), ignoreCase, ignorePaths);
		else return 0;
	}
}
