/*=========================================================================
*
* Families.c	- Family conversion
*
* Version			1.0
* Revision date
*
*=======================================================================*/
#include <Windows.h>

#include "Families.h"

#include "SCR.h"

#include "conventi.h"
#include "print.h"
#include "system.h"

#include "PhySave.h"
#include "ZooSave.h"

#include "SaveModifLst.h"

//--- Global defines --------------------------------------------------------

int  g_iSpecific1	= 0; 
int  g_iSpecific2	= 0;

// files
char g_szFiles[20][5];
int  g_iNbFiles = 0;


//--- header functions --------------------------------------------------------

void MLT_vSaveEmptyChlHeader (SCR_tdst_File_Description *p_stFile, char *sFileName, void *p_vPtr, SCR_tde_Ntfy_Action xAction)
{
}
void MLT_vSaveEmptyStaHeader (SCR_tdst_File_Description *p_stFile, char *sFileName, void *p_vPtr, SCR_tde_Ntfy_Action xAction)
{
}
void MLT_vSaveEmptyAceHeader (SCR_tdst_File_Description *p_stFile, char *sFileName, void *p_vPtr, SCR_tde_Ntfy_Action xAction)
{
}
void MLT_vSaveEmptyAczHeader (SCR_tdst_File_Description *p_stFile, char *sFileName, void *p_vPtr, SCR_tde_Ntfy_Action xAction)
{
}

//--------------------------------------------------------------------


/****************************************************************************
*		Description:	compute all the families found in the source directory
*
*		Parameters:		sRawData	: source directory
*						sGameData	: destination directory
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vComputeAllFamilies (char *sRawData, char *sGameData)
{
  xString			sDirectory;
  HANDLE			hHandle;
  WIN32_FIND_DATA	stFindFileData;

  // change directory
  GetCurrentDirectory(256, sDirectory);
  SetCurrentDirectory(sRawData);

  // search all the families files
  memset(&stFindFileData,0,sizeof(stFindFileData));
  hHandle = FindFirstFile("World\\Families\\*.*", &stFindFileData);
  if( hHandle == INVALID_HANDLE_VALUE)
  {
    SetCurrentDirectory(sDirectory);
    fprintf(stderr, "\nError : Can't find Family directory\n");
    return;
  }
  
  do if(stFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  {
    if(strlen(stFindFileData.cFileName) == 0) break;
    if(strcmp(stFindFileData.cFileName, ".") == 0) continue;
    if(strcmp(stFindFileData.cFileName, "..") == 0) continue;

    // compute the family
    MLT_vComputeOneFamily(stFindFileData.cFileName, sRawData, sGameData);
  }
  while(FindNextFile(hHandle, &stFindFileData));
  FindClose(hHandle);

  // restore directory
  SetCurrentDirectory(sDirectory);
}


/****************************************************************************
*		Description:	compute the specified family
*
*		Parameters:		sFamilyName	: family to convert
*						sRawData	: source directory
*						sGameData	: destination directory
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vComputeOneFamily (char *sFamilyName, char *sRawData, char *sGameData)
{
  xString			sDirectory;
  xString			sFileSearch;
  char				*sTmp;
  HANDLE			hHandle;
  WIN32_FIND_DATA	stFindFileData;

// WIN version
#ifdef _WINDOWS

  char				szInterm[50];

  if(  ((sTmp=strstr(sFamilyName, "\\")) == NULL)
    && ((sTmp=strstr(sFamilyName, "/")) == NULL) )
  {  
	 GetCurrentDirectory(256, sDirectory);
     if (g_bStandardConfig)
	 {
		 // get OBJ name
		 sprintf(sFileSearch, "World\\Families\\%s\\*.obj", sFamilyName);
		 // change directory
		 SetCurrentDirectory(sRawData);
	 }
	 else
		 sprintf(sFileSearch, "%s\\%s\\*.obj", g_szFamilies, sFamilyName);

	 // search for the family file
	 memset(&stFindFileData,0,sizeof(stFindFileData));
	 hHandle = FindFirstFile(sFileSearch, &stFindFileData);
	 if( hHandle == INVALID_HANDLE_VALUE)
	 {
		SetCurrentDirectory(sDirectory);
		sprintf(szInterm, "\nError : Can't find %s family\n", sFamilyName);
		fn_vAfxOutputStringRes( szInterm, C_ComRes_cErrorLine);
		return;
	 }
	 do
	 {
		if(strlen(stFindFileData.cFileName) == 0) break;

		// compute the OBJ file
		MLT_vComputeOneObj(sFamilyName, MLT_p_cGetFileNameWithoutExt(stFindFileData.cFileName), sRawData, sGameData);
	 }
	 while(FindNextFile(hHandle, &stFindFileData));
	 FindClose(hHandle);

	 // restore directory
     SetCurrentDirectory(sDirectory);
  }
  else
    MLT_vComputeOneObj(sFamilyName, sFamilyName, sRawData, sGameData);

// DOS version
#else

  // get OBJ name
  if(  ((sTmp=strstr(sFamilyName, "\\")) == NULL)
    && ((sTmp=strstr(sFamilyName, "/")) == NULL) )
    sprintf(sFileSearch, "World\\Families\\%s\\*.obj", sFamilyName);
  else
  {
    sprintf(sFileSearch, "World\\Families\\%s", sFamilyName);
    *sTmp = 0;
  }

  // change directory
  GetCurrentDirectory(256, sDirectory);
  SetCurrentDirectory(sRawData);

  // search for the family file
  memset(&stFindFileData,0,sizeof(stFindFileData));
  hHandle = FindFirstFile(sFileSearch, &stFindFileData);
  if( hHandle == INVALID_HANDLE_VALUE)
  {
    SetCurrentDirectory(sDirectory);
    fprintf(stderr, "\nError : Can't find %s family\n", sFamilyName);
    return;
  }
  do
  {
    if(strlen(stFindFileData.cFileName) == 0) break;
    
	// compute the OBJ file
	MLT_vComputeOneObj(sFamilyName, MLT_p_cGetFileNameWithoutExt(stFindFileData.cFileName), sRawData, sGameData);
  }
  while(FindNextFile(hHandle, &stFindFileData));
  FindClose(hHandle);

  // restore directory
  SetCurrentDirectory(sDirectory);
#endif
}


/****************************************************************************
*		Description:	compute the OBJ file in the specified family
*
*		Parameters:		sFamilyName	: family to convert
*						sObjName	: file to convert
*						sRawData	: source directory
*						sGameData	: destination directory
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vComputeOneObj (char *sFamilyName, char *sObjName, char *sRawData, char *sGameData)
{
  xString	sRowFamily, sGameFamily, sFile, sSection, sName, sGFam, sFileAll, sGam, sFileNew;
  xString	sDefaultDir;
  int		i;

  // register globals
  sprintf(g_sFileIn, "%s", sObjName);
  sprintf(g_sFileMaterial, "%s", sFamilyName);
  sprintf(g_sDirectorySave, "%s\\", sFamilyName);

  // init paths
  if (g_bStandardConfig)
	  sprintf(sRowFamily, "%s\\World\\Families\\%s", sRawData, g_sDirectorySave);
  else
	  sprintf(sRowFamily, "%s\\%s", g_szFamilies, g_sDirectorySave);

  sprintf(sGameFamily, "%s\\World\\Levels\\_Common\\Families\\%s", sGameData, g_sDirectorySave);

  // init directories
  sprintf(sGFam, "%s\\World\\Levels\\_Common\\Families\\%s", g_sGameCommon, g_sDirectorySave);
  strcpy(sGam, "");
  
  // DISPLAY
  MLT_vOutput( C_ComRes_cTitleLine, "\nFamily %s\\%s.obj",sFamilyName, sObjName);

  // change directory
  CreateDirectory(sGameFamily, NULL);
  CreateDirectory(sGFam, NULL);

  // get TBL directory
  if (MLT_bSearchExt("tbl"))
    SetCurrentDirectory(sGameFamily); 
  else
    SetCurrentDirectory(sGFam); 
  // init TBL saving functions
  MLT_vInitSaveTbl();
  // notify and save TBL file
  sprintf(sFile, "%s.tbl", g_sFileIn);
  SCR_fn_v_SvL1_RegisterNotify(sFile, MLT_vSaveTblFile, (void *)0x1, SCR_EA_Ntfy_AddOrModifySection);
  SCR_fn_v_SvL1_UpdateAllNotify();

  // get PHY directory
  if (MLT_bSearchExt("phy"))
    SetCurrentDirectory(sGameFamily); 
  else
    SetCurrentDirectory(sGFam); 
  // notify and save PHY file
  sprintf(sFile, "%s.phy", g_sFileIn);
  SCR_fn_v_SvL1_RegisterNotify(sFile, MLT_vSavePhyFile, NULL, SCR_EA_Ntfy_AddSection);
  SCR_fn_v_SvL1_UpdateAllNotify();

  // get ZOO directory
  if (g_iData)
	SetCurrentDirectory(sGFam);
  else
  {	
	// There are files in GameSpecific1 and GameSpecific2 directories
	if (g_iSpecific1 && g_iSpecific2)
	{	
		// Module Zones is not checked -> the newest ZOO file is kept 
		struct	_stat buf, buf1;
		int		fh, result;

		strcpy(sFileAll, g_sGameSpecific1);
		strcat(sFileAll, "\\World\\Levels\\_Common\\Families\\");
		strcat(sFileAll, g_sFileIn);
		strcat(sFileAll, "\\");
		strcat(sFileAll, g_sFileIn);
		strcat(sFileAll, M_FichierZOO);
	    if( (fh = _open( sFileAll, _O_RDONLY )) ==  -1) return;
		result = _fstat( fh, &buf );
		close(fh);
		strcpy(sFileAll, g_sGameSpecific2);
		strcat(sFileAll, "\\World\\Levels\\_Common\\Families\\");
		strcat(sFileAll, g_sFileIn);
		strcat(sFileAll, "\\");
		strcat(sFileAll, g_sFileIn);
		strcat(sFileAll, M_FichierZOO);
	    if( (fh = _open( sFileAll, _O_RDONLY )) ==  -1) return;
		result = _fstat( fh, &buf1 );
		close(fh);
		if (buf.st_mtime>buf1.st_mtime)
			remove(sFileAll);
		else
		{
			strcpy(sFileAll, g_sGameSpecific1);
			strcat(sFileAll, "\\World\\Levels\\_Common\\Families\\");
			strcat(sFileAll, g_sFileIn);
			strcat(sFileAll, "\\");
			strcat(sFileAll, g_sFileIn);
			strcat(sFileAll, M_FichierZOO);
			remove(sFileAll);
		}
	}
	else
	{
	  // Keep GameSpecific1 file
	  if (g_iSpecific1)
	  {	
		strcpy(sGam, g_sGameSpecific1);
	    strcat(sGam, "\\World\\Levels\\_Common\\Families\\");
	    strcat(sGam, g_sFileIn);
	    strcat(sGam, "\\");
	    SetCurrentDirectory(sGam);
	  }
	  // Keep GameSpecific2 file
	  if (g_iSpecific2)
	  {	
		strcpy(sGam, g_sGameSpecific2);
	    strcat(sGam, "\\World\\Levels\\_Common\\Families\\");
	    strcat(sGam, g_sFileIn);
	    strcat(sGam, "\\");
	    SetCurrentDirectory(sGam);
	  }
	}
  }

  // save ZOO file
  sprintf(sFile, "%s.zoo", g_sFileIn);
  // if ZOO file does not exist, create it
  if(! SCR_fn_c_RdL0_IsSectionExists(sFile))
  {  
	  if (MLT_bSearchExt("zoo"))
	    SetCurrentDirectory(sGameFamily); 
	 else
		SetCurrentDirectory(sGFam); 
	 SCR_fn_v_SvL1_RegisterNotify(sFile, MLT_vSaveZooFile, NULL, SCR_EA_Ntfy_AddSection);
  }
  // if ZOO file exists, check if it must be rebuilt
  else
  {  
	  if (g_bIgnoreZoo)
	  {	
		i = remove(sFile);
		if (!i)
		{	
			if (MLT_bSearchExt("zoo"))
				SetCurrentDirectory(sGameFamily); 
			else
				SetCurrentDirectory(sGFam); 
     		SCR_fn_v_SvL1_RegisterNotify(sFile, MLT_vSaveZooFile, NULL, SCR_EA_Ntfy_AddSection);
		}
	  }
	  else
	  {	
		 xString sSection;
		//the case when the generated file will use the .zoo file from specific directory		 
		if (g_iData)
		{	
			if (MLT_bSearchExt("zoo"))
				SetCurrentDirectory(sGameFamily); 
			else
				SetCurrentDirectory(sGFam); 
			strcpy(sFileAll, sGFam);
			strcat(sFileAll, g_sFileIn);
			strcat(sFileAll, ".zoo");
     		CopyFile(sFileAll, "temp.zoo", FALSE);
			remove(sFileAll);
			strcpy(sFileAll, sGameFamily);
			strcat(sFileAll, g_sFileIn);
			strcat(sFileAll, M_FichierZOO);
			CopyFile("temp.zoo", sFileAll, FALSE);
		}
		else
		{
			strcpy(sFileAll, sGam);
			strcat(sFileAll, g_sFileIn);
			strcat(sFileAll, ".zoo");
			strcpy(sFileNew, sGameFamily);
			strcat(sFileNew, g_sFileIn);
			strcat(sFileNew, M_FichierZOO);
     		CopyFile(sFileAll, sFileNew, FALSE);
			strcpy(sFileNew, sGameFamily);
			strcat(sFileNew, "temp.zoo");
     		CopyFile(sFileAll, sFileNew, FALSE);
			if (strcmp(sGam,""))
				remove(sFileAll);
			SetCurrentDirectory(sGameFamily);
		}

		SCR_fn_v_RdL0_ComputeSectionName(sSection, sFile, M_AllCollideSets, "");
		SCR_fn_v_SvL1_RegisterNotify(sSection/*sFile*/, MLT_vSaveAllCollideSetsSection, NULL, SCR_EA_Ntfy_RebuildSection);
	  }
  }

  // if necessary, copy the animations
  if (g_bCopyAnims)
	MLT_vCopyAnims(sFamilyName);

  // save all notified sections
  SCR_fn_v_SvL1_UpdateAllNotify();
  
  // register path for load
  SCR_fn_v_RdL0_RegisterPath(sGameFamily);

  // change directory
  SetCurrentDirectory(sGameFamily); 

  // DISPLAY
  MLT_vOutput( C_ComRes_cNormalLine, "\n\tCopy...");

  // copy CHL file
  sprintf(sFile, "%s.chl", g_sFileIn);
  strcpy(sDefaultDir, g_sGameCommon);
  strcat(sDefaultDir, "\\default");
  if (!MLT_bSearchExt("chl"))
  {  
	  SetCurrentDirectory(sGFam); 
	  MLT_vCopyFiles("*.chl", sRowFamily, sGFam);
  }
  else
  {  
	  SetCurrentDirectory(sGameFamily); 
	  MLT_vCopyFiles("*.chl", sRowFamily, sGameFamily);
  }
  SCR_fn_v_SvL1_RegisterNotify(sFile, MLT_vSaveEmptyChlHeader, NULL, SCR_EA_Ntfy_AddSection);
  SCR_fn_v_SvL1_UpdateAllNotify();

  // copy and update STA file
  if (!MLT_bSearchExt("sta"))
     SetCurrentDirectory(sGFam); 
  else
     SetCurrentDirectory(sGameFamily); 
  sprintf(sName, "%s.sta", sFamilyName);
  MLT_vCopyAndRenameFile("Default.sta", sDefaultDir, sName, ".", FALSE);
  MLT_vSubstituteAnimInStaFile(sFamilyName);
  SCR_fn_v_SvL1_RegisterNotify(sName, MLT_vSaveEmptyStaHeader, NULL, SCR_EA_Ntfy_AddSection);
  SCR_fn_v_SvL1_UpdateAllNotify();

  // copy and update ACE file
  if (!MLT_bSearchExt("ace"))
     SetCurrentDirectory(sGFam); 
  else
     SetCurrentDirectory(sGameFamily); 
  sprintf(sName, "%s.ace", sFamilyName);
  MLT_vCopyAndRenameFile("Default.ace", sDefaultDir, sName, ".", FALSE);
  SCR_fn_v_SvL1_RegisterNotify(sName, MLT_vSaveEmptyAceHeader, NULL, SCR_EA_Ntfy_AddSection);
  SCR_fn_v_SvL1_UpdateAllNotify();

  // copy and update ACZ file
  if (!MLT_bSearchExt("acz"))
     SetCurrentDirectory(sGFam); 
  else
     SetCurrentDirectory(sGameFamily); 
  sprintf(sName, "%s.acz", sFamilyName);
  MLT_vCopyAndRenameFile("Default.acz", sDefaultDir, sName, ".", FALSE);
  SCR_fn_v_SvL1_RegisterNotify(sName, MLT_vSaveEmptyAczHeader, NULL, SCR_EA_Ntfy_AddSection);
  SCR_fn_v_SvL1_UpdateAllNotify();

  
  // change directory
  SetCurrentDirectory(sRowFamily);

  // DISPLAY
  MLT_vOutput( C_ComRes_cNormalLine, "\n\tLoad...");

  // load library
  MLT_vLoadModuleLib();

  // DISPLAY
  MLT_vOutput( C_ComRes_cNormalLine, "\n\tCreate Physical...");

  // set appropriate directory
  if (MLT_bSearchExt("tbl"))
  	SetCurrentDirectory(sGameFamily); 
  else
  	SetCurrentDirectory(sGFam); 

  // DISPLAY
  MLT_vOutput( C_ComRes_cNormalLine, "\n\tSave...");

  // save all notified sections
  SCR_fn_v_SvL1_UpdateAllNotify();

  // save TBL file
  sprintf(sFile, "%s.tbl", g_sFileIn);
  SCR_fn_v_RdL0_ComputeSectionName(sSection, sFile, M_TBL_HEADER, "");
  if (MLT_bSearchExt("tbl"))
  	SetCurrentDirectory(sGameFamily); 
  else
  	SetCurrentDirectory(sGFam); 
  SCR_fn_v_SvL1_RegisterNotify(sSection, MLT_vSaveTblFile, NULL, SCR_EA_Ntfy_RebuildSection);
  SCR_fn_v_SvL1_UpdateAllNotify();

  // erase the libs
  MLT_vDeleteModuleLib();
  
  // update ModifLst file
  MLT_vUpdatePathInModifFile(sGameFamily);

  // close all opened files for ZOO
  if (!g_bIgnoreZoo)
  {	
	  SCR_fn_v_RdL0_Close();
	  strcpy (sFile, sGameFamily);
	  strcat(sFile, "temp.zoo");
	  remove(sFile);
	  MLT_vInitSystem();
  }

  // DISPLAY
  MLT_vOutput( C_ComRes_cResultLine, "\nFamily %s converted\n",sFamilyName);

  // clean all opened structures
  for (i=3; i<256; i++)
	_close((int)i);
  MLT_vInitSystem();
}

/****************************************************************************
*		Description:	copy the animations of the family from source to destination directory
*
*		Parameters:		sFamily	: name of the family
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vCopyAnims (char *sFamily)
{
  xString sRawAnim, sGameAnim;

  // get the appropriate destination directory
  switch (g_iData)
  {	
	case 0:
		sprintf(sGameAnim, "%s\\World\\Graphics\\Anims\\%s", g_sGameCommon, sFamily);
		break;

	case 1:
		sprintf(sGameAnim, "%s\\World\\Graphics\\Anims\\%s", g_sGameSpecific1, sFamily);
		break;
		
	case 2:
		sprintf(sGameAnim, "%s\\World\\Graphics\\Anims\\%s", g_sGameSpecific2, sFamily);
		break;
  }

  // get the appropriate source directory
  if (g_bStandardConfig)
  {
    switch (g_iRaw)
	{	
	  case 0: 
		sprintf(sRawAnim, "%s\\World\\Graphics\\Anims\\%s", g_sRawCommon, sFamily);
		break;
	  case 1: 
		sprintf(sRawAnim, "%s\\World\\Graphics\\Anims\\%s", g_sRawSpecific1, sFamily);
		break;
	  case 2: 
		sprintf(sRawAnim, "%s\\World\\Graphics\\Anims\\%s", g_sRawSpecific2, sFamily);
		break;
	}
  }
  else
	sprintf(sRawAnim, "%s\\%s", g_szAnims, sFamily);

  // create the destination directory
  CreateDirectory(sGameAnim, NULL);
  
  
  // DISPLAY
  MLT_vOutput( C_ComRes_cNormalLine, "\n\tCopy animations for the family %s...", sFamily);

  // copy the animations
  MLT_vCopyFiles("*.a3d", sRawAnim, sGameAnim);
}


/****************************************************************************
*		Description:	set the animation name of the default state in STA file
*
*		Parameters:		sFamily	: name of the family
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vSubstituteAnimInStaFile (char *sFamily)
{
  FILE		*fileR, *fileW;
  xString	sAnim, sName, sRead, sWrite;
  char		*sTmp;
  BOOL		bDeleteAnim=FALSE;
  BOOL		bFound = FALSE;

  // get the appropriate destination directory
  switch(g_iData)
  {
	case 0:
			MLT_vSearchInGame(sFamily, &bFound, g_sGameCommon, sAnim);
			MLT_vSearchInGame(sFamily, &bFound, g_sGameSpecific1, sAnim);
			MLT_vSearchInGame(sFamily, &bFound, g_sGameSpecific2, sAnim);
			break;
	case 1:
			MLT_vSearchInGame(sFamily, &bFound, g_sGameSpecific1, sAnim);
			MLT_vSearchInGame(sFamily, &bFound, g_sGameCommon, sAnim);
			MLT_vSearchInGame(sFamily, &bFound, g_sGameSpecific2, sAnim);
			break;
	case 2:
			MLT_vSearchInGame(sFamily, &bFound, g_sGameSpecific2, sAnim);
			MLT_vSearchInGame(sFamily, &bFound, g_sGameCommon, sAnim);
			MLT_vSearchInGame(sFamily, &bFound, g_sGameSpecific1, sAnim);
			break;
  }

  // no animation found
  if (!bFound)
  {
    MLT_vOutput( C_ComRes_cWarningLine, "\nWarning : No anims for the %s Family", sFamily);
    bDeleteAnim=TRUE;
  }
  
  // search the string to substitute
  sprintf(sName, "%s.sta", sFamily);
  rename(sName, "temp.sta");
  // open source file
  fileR = fopen("temp.sta", "rt");
  if (!fileR) 
  {
    MLT_vOutput( C_ComRes_cWarningLine, "\nWarning: The file temp.sta can't be open for reading!");
	return;
  }
  // open destination file
  fileW = fopen(sName, "wt");
  if (!fileW)
  {
    MLT_vOutput( C_ComRes_cWarningLine, "\nWarning: The file %s can't be open for reading!", sName);
	return;
  }

  // read the source file 
  while(fgets(sRead, 255, fileR) != NULL)
  {
    // search for the string to replace
	sTmp = strstr(sRead, M_NomAnim);
    if(sTmp != NULL)
    {
      xString sBuffer;

      if(bDeleteAnim)
        continue;

      *sTmp = 0;
      sprintf(sBuffer, "%s", sRead);
      sTmp += 11;
      sprintf(sWrite, "%s%s%s", sBuffer, sAnim, sTmp);
    }
    else
      sprintf(sWrite, "%s", sRead);
    // copy in destinatio file
	fputs(sWrite, fileW);
  }

  // close files
  fclose(fileR);
  fclose(fileW);
  // delete temporary file
  remove("temp.sta");
}


/****************************************************************************
*		Description:	search for the animation files in the game directory
*
*		Parameters:		sFamily		: family to convert
*						bFound		: return the result
*						sGame		: game directory
*						sAnim		: name of the animation
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vSearchInGame (char *sFamily, BOOL *bFound, xString sGame, xString sAnim)
{
  HANDLE			hHandle;
  WIN32_FIND_DATA	stFindFileData;
  xString			sName;

  if (!(*bFound) && strcmp(sGame,""))
  {
	  // search in Game directory
	  sprintf(sName, "%s\\World\\Graphics\\Anims\\%s\\*.a3d", sGame, sFamily);
	  memset(&stFindFileData,0,sizeof(stFindFileData));
	  hHandle = FindFirstFile(sName, &stFindFileData);
	  if( hHandle != INVALID_HANDLE_VALUE)
	  {
		do
		{
		  if(strlen(stFindFileData.cFileName) != 0)
		  {
			sprintf(sAnim, "%s", MLT_p_cGetFileNameWithoutExt(stFindFileData.cFileName));
			(*bFound) = TRUE;
			return;
		  }
		}
		while(FindNextFile(hHandle, &stFindFileData));
		FindClose(hHandle);
	  }
  }
}



/****************************************************************************
*		Description:	search if the extension is a specific one
*
*		Parameters:		sExt		: extension to test
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
BOOL MLT_bSearchExt (char *sExt)
{
	int i;
	for (i=0; i<g_iNbFiles+1; i++)
	{
		if (!stricmp(sExt, g_szFiles[i]))
			return TRUE;
	}
	
	return FALSE;
}

