/*
**	MacSND DataType
**
**	Written by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
**		Public domain
**
** :ts=4
*/

#include "Global.h"

	// We want to use the hook data

#undef SysBase
#define SysBase	Hook -> dthc_SysBase

#undef DOSBase
#define DOSBase	Hook -> dthc_DOSBase

	/* DTHook(register __a0 struct DTHookContext *Hook):
	 *
	 *	Examine a file and return if we know its format.
	 */

BOOL __asm __saveds
DTHook(register __a0 struct DTHookContext *Hook)
{
		// Did we get everything we needed?

	if(Hook -> dthc_Lock && Hook -> dthc_FIB && Hook -> dthc_FileHandle)
	{
			// Examine the file

		if(Examine(Hook -> dthc_Lock,Hook -> dthc_FIB))
		{
				// Is this really a file?

			if(Hook -> dthc_FIB -> fib_DirEntryType < 0)
			{
					// Seek back to the beginning

				if(Seek(Hook -> dthc_FileHandle,0,OFFSET_BEGINNING) != -1)
				{
					struct SoundDataHeader	Header;
					LONG					Error;

						// Try to read the MacBinary header

					if(ReadMacBinaryHeader(Hook -> dthc_FileHandle,&Error,(struct ExecBase *)SysBase,(struct DosLibrary *)DOSBase))
					{
							// Look for a "snd " resource

						if(ScanResource(Hook -> dthc_FileHandle,&Header,&Error,(struct ExecBase *)SysBase,(struct DosLibrary *)DOSBase))
							return(TRUE);
					}

						// Seek back to the beginning

					if(Seek(Hook -> dthc_FileHandle,0,OFFSET_BEGINNING) != -1)
					{
							// Look for a "snd " resource

						if(ScanResource(Hook -> dthc_FileHandle,&Header,&Error,(struct ExecBase *)SysBase,(struct DosLibrary *)DOSBase))
							return(TRUE);
					}
				}
			}
		}
	}

		// No success

	return(FALSE);
}
