// MyFile.c
//
// Contains IO procs for the streamer and file systems


#include <am.h>

KTBOOL MyStreamIoProc(KTSTRING fileName,ACFILE * sd,KTU8 * buffer,KTU32 * size,AM_FILE_OPERATION_MODE mode);
KTBOOL MyFileIoProc(KTSTRING fileName,ACFILE * fd,KTU8 * buffer,KTU32 * size,AM_FILE_OPERATION_MODE mode);

KTBOOL MyFileIoProc(KTSTRING fileName,ACFILE * fd,KTU8 * buffer,KTU32 * size,AM_FILE_OPERATION_MODE mode)
{
ACFILE		fileDescriptor	=	0;
KTU32		fileSize		=	0;
KTU8 *	fileBuffer		=	KTNULL;

if(mode==AM_OPEN)
	{
	// open the file
	if(acFileOpen(fileName,fd)==KTFALSE)
		return KTFALSE;
	}
else if(mode==AM_CLOSE)
	{
	// close the file
	if(acFileClose(*fd)==KTFALSE)
		return KTFALSE;
	}
else if(mode==AM_READ)
	{
	// read from the file
	if(acFileRead(*fd,buffer,*size)==KTFALSE)
		return KTFALSE;
	}
else if(mode==AM_LOAD)
	{
	ACFILE gd;

	if(acFileGetSize(fileName,&fileSize)==KTFALSE)
		return KTFALSE;

	if(acFileOpen(fileName,&gd)==KTFALSE)
		return KTFALSE;

	// read from the file
	if(acFileRead(gd,buffer,fileSize)==KTFALSE)
		return KTFALSE;
	
	if(acFileClose(gd)==KTFALSE)
		return KTFALSE;
	}
else if(mode==AM_GET_SIZE)
	{
	// get the files size
	if(acFileGetSize(fileName,size)==KTFALSE)
		return KTFALSE;
	}
else if(mode==AM_REWIND)
	{
	// get the files size
	if(acFileRewind(*fd)==KTFALSE)
		return KTFALSE;
	}
else
	return KTFALSE;		// bad arg for mode, it should never come to this.

return KTTRUE;
}


KTBOOL MyStreamIoProc(KTSTRING fileName,ACFILE * sd,KTU8 * buffer,KTU32 * size,AM_FILE_OPERATION_MODE mode)
{
KTU32		fileDescriptor	=	0;
KTU32		fileSize		=	0;
KTU8 *	fileBuffer		=	KTNULL;

if(mode==AM_OPEN)
	{
	// open the file
	if(acFileOpen(fileName,(ACFILE *)sd)==KTFALSE)
		return KTFALSE;
	}
else if(mode==AM_CLOSE)
	{
	// close the file
	if(acFileClose((ACFILE)*sd)==KTFALSE)
		return KTFALSE;
	}
else if(mode==AM_READ)
	{
	// read from the file
	if(acFileRead((ACFILE)*sd,buffer,*size)==KTFALSE)
		return KTFALSE;
	}
else if(mode==AM_GET_SIZE)
	{
	// get the files size
	if(acFileGetSize(fileName,size)==KTFALSE)
		return KTFALSE;
	}
else if(mode==AM_REWIND)
	{
	// get the files size
	if(acFileRewind(*sd)==KTFALSE)
		return KTFALSE;
	}
else
	return KTFALSE;		// bad arg for mode, it should never come to this.

return KTTRUE;
}
