/*
  File: include/ioutils/Interface_DAF.h
  Description: Sonique 2 compressed package header
  Part of the Mantis project
  (c) 2002 Lycos Inc.

  This file is distributed for the sole purpose of allowing you to write
  software to interface with Sonique 2 and other Mantis programs. It is
  not to be modified or used for any other purpose without written
  authorization.

  If you redistribute this file, it must be in the original package
  complete with all other files provided, including the usage agreement.

  Do not remove this notice.
*/

#ifndef _INTERFACE_DAF_H_
#define _INTERFACE_DAF_H_

#ifdef DEBUG_INCLUDE_ORDER
#pragma message("Including " __FILE__ "\n" )
#endif


#if _MSC_VER > 1000
#pragma once
#endif


#include "mgeneric.h"
#include "filesys.h"


// {65BCBEC5-78A5-43dc-B674-D3DEBF5584E8}
DEFINE_MID(MID_PACKAGEREADER, 0x65bcbec5, 0x78a5, 0x43dc, 0xb6, 0x74, 0xd3, 0xde, 0xbf, 0x55, 0x84, 0xe8);


// {76AD8865-781D-4e33-B032-96519A00602C}
DEFINE_MID( MID_STRUCTURED_PACKAGEREADER, 0x76ad8865, 0x781d, 0x4e33, 0xb0, 0x32, 0x96, 0x51, 0x9a, 0x0, 0x60, 0x2c);


// {AE0C3DD0-018A-40a4-A244-D9E0B7B53835}
DEFINE_MID( MID_MEMORYPACKAGE, 0xae0c3dd0, 0x18a, 0x40a4, 0xa2, 0x44, 0xd9, 0xe0, 0xb7, 0xb5, 0x38, 0x35);


// {A1121DE5-DAB8-4876-81E3-52D7BA336627}
DEFINE_MID( MID_ZIPHELPER, 0xa1121de5, 0xdab8, 0x4876, 0x81, 0xe3, 0x52, 0xd7, 0xba, 0x33, 0x66, 0x27);



typedef struct PackageRecord
{
	unsigned long	lSize;				// size of resource in memory
	bool			bCompressed;		// is it compressed?
	unsigned long	lCompressedSize;	// only valid if bComprssed == true
	AString			sName;				// name of item (or number )
}DafRecord;

class MPackageVirtual : public MGeneric
{
public:
	virtual bool	__stdcall	GetRecordInfo(		const	char*	szResource,	DafRecord& drToHere ) const	=0; 
	virtual uint32	__stdcall	GetData(			const	char*	szResource, void**	ppData	)	  const	=0;
	virtual void	__stdcall	FreeData( void* pData )												  const	=0;
    virtual WString	__stdcall	GetName()            												  const	=0; // name of package, path or something like that
	
};

class MPackageMemory : public MPackageVirtual
{
public:
    // if name is set to NULL (default) a call to GetName() will return "::mem::" 
    virtual void	__stdcall	SetName( const WString& wsName )												= 0;
	virtual bool	__stdcall	SetRecord( void* pData, uint32 uiSize, char* acName, bool bCopyMem = false )	= 0;
	virtual bool	__stdcall	DelRecord( char* acName )														= 0;
	virtual bool	__stdcall	RemoveAll()																		= 0;
};

class MPackageReader : public MPackageVirtual
{
public:
    virtual void	__stdcall	SetName( const WString& wsName )										=0;

    // if the name is NULL (default) or set to NULL, then after calling Load() the name will be the path to file
	virtual	bool    __stdcall	Load( const char*		szSource	)									=0; // load from char filename
	virtual	bool    __stdcall	Load( const wchar_t*	wcSource	)									=0; // load from widechar filename
	virtual	bool    __stdcall	Load(		IOObject*	pioo		)									=0; // load from existing io object
	
	virtual bool	__stdcall	Unload()																=0; // fails if nothing was loaded

	virtual uint32	__stdcall	GetNumberRecords()	const												=0; // duh

	virtual bool	__stdcall	GetRecordInfo_Indexed(		uint32	index,		DafRecord& drToHere ) const	=0; // return true if a success
	virtual uint32	__stdcall	GetData_Indexed(	uint32  index,		void**	ppData	)	const			=0; // use not encouraged (not as flexible, unless the index has been determined in previous calls to GetRecordInfo )
	
};

class MStructuredPackageReader : public MPackageVirtual
{
public:
	virtual bool	__stdcall	InsertReader( MPackageReader* pReader, uint32 nPriority = 1000 )				=0;	// lower numbers, come first
	virtual bool	__stdcall	RemoveReader( const MPackageReader* pReader )									=0; 
	virtual bool	__stdcall	RemoveAll()																	=0; 
};

class MZipHelper : public MGeneric
{
public:
    virtual MRESULT __stdcall   ZipCompress  ( const uint8* pSource, uint32 lSourceLen, Array<uint8>& CompressedData   ) = 0;
    virtual MRESULT __stdcall   ZipUncompress( const uint8* pSource, uint32 lSourceLen, Array<uint8>& UncompressedData ) = 0;
    virtual MRESULT __stdcall   ZipUncompress( const uint8* pSource, uint32 lSourceLen, Array<uint8>& UncompressedData, uint32 UncompressedLength ) = 0;
    virtual uint32  __stdcall   CalcCRC32    ( const uint8* pSource, uint32 lSourceLen )                                 = 0;
};


#endif//_INTERFACE_DAF_H_
