/*=========================================================================
*
* DlgMain4.cpp	-	implementation file for main window class
*					Configuration functions
*
* Version			1.0
* Revision date
*
*=======================================================================*/
#include <io.h>
#include <fcntl.h>
#include "stdafx.h"

#include "DlgMain.h"

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

#include "IniData.h"

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


//==================================================//
//				DIRECTORIES CONFIGS					//
//==================================================//

/****************************************************************************
*		Description:	
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vInitDirCombo ()
{
	xString sIdent;
	char	*p_Char1;
	int		i, j=0;

	// init directory combo
	strcpy(g_szConfDirs[0], "Default");
	strcpy(sIdent, g_stInitialData.szConfDirs);
	if (strcmp(sIdent, "")) 
	{	
		p_Char1=sIdent;
		j=1;
		while( (*p_Char1 != ',') && (*p_Char1 != 0))
		{
			i=0;
			while( (*p_Char1 != ',') && (*p_Char1 != 0))
			{	
				g_szConfDirs[j][i]=*p_Char1;
				p_Char1++;
				i++;
			}
			g_szConfDirs[j][i] = '\0';
			if (*p_Char1 == 0) break;
			p_Char1++;
			j++;
		}
		g_iNbConfDirs = j+1;
	}
	else
		g_iNbConfDirs = 1;

	for (i=0; i<g_iNbConfDirs; i++)
		m_oComboChooseDir.AddString(_T(g_szConfDirs[i]));

	if (!strcmp(g_szDirConfig, ""))
	{
		// find current config
		GetPrivateProfileString("CurrentConfigs", "Directories", "", sIdent, 100, g_szIniFile);
		i = m_oComboChooseDir.FindStringExact(-1, sIdent);
		
		g_iCurrentIndexDir = (i != -1) ? i : 0;
		m_oComboChooseDir.SetCurSel(g_iCurrentIndexDir);

		// directory config
		GetPrivateProfileString( "CurrentConfigs", "DirMode", "Standard", sIdent, 10, g_szIniFile );
		g_bStandardConfig = stricmp(sIdent, "Custom");
	}
	else
	{
		g_bStandardConfig = !strcmp(g_szDirConfig, "Default");
		i = m_oComboChooseDir.FindStringExact(-1, g_szDirConfig);
		
		g_iCurrentIndexDir = (i != -1) ? i : 0;
		m_oComboChooseDir.SetCurSel(g_iCurrentIndexDir);
	}


	m_fn_vUpdateForDirConfig();
}

/****************************************************************************
*		Description:	Set the default directory configuration	
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vSetDefaultDirConfig() 
{
	xString sRaw;
	
	switch (g_iRaw)
	{
		case 0:
			strcpy(sRaw, g_stInitialData.szRawData);
			break;
		case 1:
			strcpy(sRaw, g_stInitialData.szRawSpecific1);
			break;
		case 2:
			strcpy(sRaw, g_stInitialData.szRawSpecific2);
			break;
	}
	sprintf(g_stInitialDirData.szAnims, "%s\\World\\Graphics\\Anims", sRaw);
	sprintf(g_stInitialDirData.szBanks, "%s\\World\\Graphics\\Objects\\Banks", sRaw);
	sprintf(g_stInitialDirData.szClasses, "%s\\World\\Graphics\\Objects\\Classes", sRaw);
	sprintf(g_stInitialDirData.szFamilies, "%s\\World\\Families", sRaw);
	sprintf(g_stInitialDirData.szLevels, "%s\\World\\Levels", sRaw);
	sprintf(g_stInitialDirData.szTextures, "%s\\World\\Textures", sRaw);
	
	m_fn_vUpdateDirectories() ;
	m_fn_vResetSelection();
}

/****************************************************************************
*		Description:	set the window text for the types and the global variables for types
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vUpdateForDirConfig() 
{
	char szDir1[_MAX_PATH];

	// update directory panel
	m_oConfigPanel.SetCurSel((g_bStandardConfig) ? 0 : 1);

	g_iCurrentIndexDir = m_oComboChooseDir.GetCurSel();

	if (g_iCurrentIndexDir)
	{
		if (strcmp(g_stInitialData.szConfDirs, ""))
		{	
			GetCurrentDirectory( MAX_PATH, szDir1 );
			SetCurrentDirectory( g_szInitialDirectory );
			//read the Configs.ini file
			fn_IniData_vGetDatasFromConfigDirsFile( TRUE, g_szConfDirs[g_iCurrentIndexDir] );

			m_fn_vUpdateDirectories() ;
			SetCurrentDirectory( szDir1 );
			m_fn_vResetSelection();
		}
	}
	else
		m_fn_vSetDefaultDirConfig();
}

/****************************************************************************
*		Description:	set the window text for the types and the global variables for types
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vUpdateDirectories() 
{
	GetDlgItem(IDC_EDIT_ANIMS)->SetWindowText(g_stInitialDirData.szAnims);
	GetDlgItem(IDC_EDIT_BANKS)->SetWindowText(g_stInitialDirData.szBanks);
	GetDlgItem(IDC_EDIT_CLASSES)->SetWindowText(g_stInitialDirData.szClasses);
	GetDlgItem(IDC_EDIT_FAMILIES)->SetWindowText(g_stInitialDirData.szFamilies);
	GetDlgItem(IDC_EDIT_LEVELS)->SetWindowText(g_stInitialDirData.szLevels);
	GetDlgItem(IDC_EDIT_TEXTURES)->SetWindowText(g_stInitialDirData.szTextures);

	strcpy(g_szAnims, g_stInitialDirData.szAnims);
	strcpy(g_szBanks, g_stInitialDirData.szBanks);
	strcpy(g_szClasses, g_stInitialDirData.szClasses);
	strcpy(g_szFamilies, g_stInitialDirData.szFamilies);
	strcpy(g_szLevels, g_stInitialDirData.szLevels);
	strcpy(g_szTextures, g_stInitialDirData.szTextures);
}

/****************************************************************************
*		Description:	
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vRegisterAllPaths (int iNumConfig)
{
	fn_IniData_vSetConfigDirPath( g_szConfDirs[iNumConfig], "Anims",	g_szAnims);
	fn_IniData_vSetConfigDirPath( g_szConfDirs[iNumConfig], "Banks",	g_szBanks);
	fn_IniData_vSetConfigDirPath( g_szConfDirs[iNumConfig], "Classes",  g_szClasses);
	fn_IniData_vSetConfigDirPath( g_szConfDirs[iNumConfig], "Families", g_szFamilies);
	fn_IniData_vSetConfigDirPath( g_szConfDirs[iNumConfig], "Levels",	g_szLevels);
	fn_IniData_vSetConfigDirPath( g_szConfDirs[iNumConfig], "Textures", g_szTextures);
}


//==================================================//
//				SELECTIONS CONFIGS					//
//==================================================//

/****************************************************************************
*		Description:	
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vInitSelectCombo ()
{
	xString sIdent;
	char	*p_Char1;
	int		i, j=0;

	// init selection combo
	strcpy(g_szConfSelects[0], "Default");
	strcpy(sIdent, g_stInitialData.szConfSelects);
	if (strcmp(sIdent, "")) 
	{	
		p_Char1=sIdent;
		j=1;
		while( (*p_Char1 != ',') && (*p_Char1 != 0))
		{
			i=0;
			while( (*p_Char1 != ',') && (*p_Char1 != 0))
			{	
				g_szConfSelects[j][i]=*p_Char1;
				p_Char1++;
				i++;
			}
			g_szConfSelects[j][i] = '\0';
			if (*p_Char1 == 0) break;
			p_Char1++;
			j++;
		}
		g_iNbConfSelects = j+1;
	}
	else
		g_iNbConfSelects = 1;

	for (i=0; i<g_iNbConfSelects; i++)
		m_oComboChooseSelect.AddString(_T(g_szConfSelects[i]));

	// find current config
	if (!strcmp(g_szSelectConfig, ""))
		GetPrivateProfileString("CurrentConfigs", "Selections", "", sIdent, 100, g_szIniFile);
	else
		strcpy(sIdent, g_szSelectConfig); 
	i = m_oComboChooseSelect.FindStringExact(-1, sIdent);
	
	g_iCurrentIndexSelect = (i != -1) ? i : 0;
	m_oComboChooseSelect.SetCurSel(g_iCurrentIndexSelect);

	m_fn_vUpdateForSelectConfig();
}
	
/****************************************************************************
*		Description:	Set the default selection configuration	
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vSetDefaultSelectConfig() 
{
	m_fn_vResetSelection();
}

/****************************************************************************
*		Description:	
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vUpdateForSelectConfig() 
{
	OnClearAll();
	
	g_iNbAnimsObj = 0;
	g_iNbBanksObj = 0;
	g_iNbClassesObj = 0;
	g_iNbFamiliesObj = 0;
	g_iNbLevelsObj = 0;
	g_iNbTexturesObj = 0;
	g_bChangeComboSelect = FALSE;

	if (strcmp(g_stInitialData.szConfSelects, ""))
	{	
		GI_Type *p_oType;
		xString szDir1;

		GetCurrentDirectory( MAX_PATH, szDir1 );
		SetCurrentDirectory( g_szInitialDirectory );

		g_iCurrentIndexSelect = m_oComboChooseSelect.GetCurSel();

		if (g_iCurrentIndexSelect)
		{
			//read the ConfigControls.ini file
			fn_IniData_vGetDatasFromConfigSelectFile( TRUE, g_szConfSelects[g_iCurrentIndexSelect] );

			//update the selection
			m_fn_vUpdateSelectLists();
			m_fn_vUpdateSelections();
		}
		else
			m_fn_vSetDefaultSelectConfig();

		// update buttons state
		m_fn_vEnableButtonAll();
		m_fn_vEnableButtonConvert();
		// update type list
		m_oListType->SetCurSel(0);
		OnSelchangeListType() ;
		// update selection buttons
		p_oType = (m_oListType->GetCount() > 0) ? (GI_Type *)m_oListType->GetItemData(0) : NULL;
		m_oSelectList.EnableWindow(p_oType && (p_oType->m_iSelected!=m_oListObject->GetCount()));
		m_oClearList.EnableWindow(p_oType && (p_oType->m_iSelected>0));
		// update object list
		m_oListObject->Invalidate(TRUE);

		SetCurrentDirectory( szDir1 );
	}
}

/****************************************************************************
*		Description:	set all objects
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vUpdateSelectLists() 
{
	m_fn_vUpdateSelectListForType("Anims",		g_stInitialSelectData.szAnims,	  &g_iNbAnimsObj);
	m_fn_vUpdateSelectListForType("Banks",		g_stInitialSelectData.szBanks,	  &g_iNbBanksObj);
	m_fn_vUpdateSelectListForType("Classes",	g_stInitialSelectData.szClasses,  &g_iNbClassesObj);
	m_fn_vUpdateSelectListForType("Families",	g_stInitialSelectData.szFamilies, &g_iNbFamiliesObj);
	m_fn_vUpdateSelectListForType("Levels",		g_stInitialSelectData.szLevels,   &g_iNbLevelsObj);
	m_fn_vUpdateSelectListForType("Textures",	g_stInitialSelectData.szTextures, &g_iNbTexturesObj);
}

/****************************************************************************
*		Description:	Select all types
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vUpdateSelections()
{
	m_fn_vUpdateSelectionForType("Anims",	 g_iNbAnimsObj);
	m_fn_vUpdateSelectionForType("Banks",	 g_iNbBanksObj);
	m_fn_vUpdateSelectionForType("Classes",  g_iNbClassesObj);
	m_fn_vUpdateSelectionForType("Families", g_iNbFamiliesObj);
	m_fn_vUpdateSelectionForType("Levels",	 g_iNbLevelsObj);
	m_fn_vUpdateSelectionForType("Textures", g_iNbTexturesObj);
}

/****************************************************************************
*		Description:	set all selections and types from the second panel
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vRegisterSelections (int iNumConfig) 
{
	m_fn_vRegisterSelectionForType(g_szConfSelects[iNumConfig], "Anims");
	m_fn_vRegisterSelectionForType(g_szConfSelects[iNumConfig], "Banks");
	m_fn_vRegisterSelectionForType(g_szConfSelects[iNumConfig], "Classes");
	m_fn_vRegisterSelectionForType(g_szConfSelects[iNumConfig], "Families");
	m_fn_vRegisterSelectionForType(g_szConfSelects[iNumConfig], "Levels");
	m_fn_vRegisterSelectionForType(g_szConfSelects[iNumConfig], "Textures");
}

/****************************************************************************
*		Description:	update the selection list for the given type
*
*		Parameters:		szObjects	: the string with all the objects separated by ,
*						szType		: type
*						iNbObjects	: the number of the objects for the type
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vUpdateSelectListForType (char *szType, char *szObjects, int  *iNbObjects)
{
	int i, j;
	char *p_Char1, sIdent[256];

	strcpy(sIdent, szObjects);
	
	if (strcmp(sIdent, "")) 
	{	
		p_Char1=sIdent;
		j=0;
		while( (*p_Char1 != ',') && (*p_Char1 != 0))
		{	
			i=0;
			while( (*p_Char1 != ',') && (*p_Char1 != 0))
			{	
				if (!stricmp(szType, "Anims"))
					g_szAnimsObj[j][i]=*p_Char1;
				if (!stricmp(szType, "Banks"))
					g_szBanksObj[j][i]=*p_Char1;
				if (!stricmp(szType, "Classes"))
					g_szClassesObj[j][i]=*p_Char1;
				if (!stricmp(szType, "Families"))
					g_szFamiliesObj[j][i]=*p_Char1;
				if (!stricmp(szType, "Levels"))
					g_szLevelsObj[j][i]=*p_Char1;
				if (!stricmp(szType, "Textures"))
					g_szTexturesObj[j][i]=*p_Char1;
				p_Char1++;
				i++;
			}
			if (!stricmp(szType, "Anims"))
				g_szAnimsObj[j][i]='\0';
			if (!stricmp(szType, "Banks"))
				g_szBanksObj[j][i]='\0';
			if (!stricmp(szType, "Classes"))
				g_szClassesObj[j][i]='\0';
			if (!stricmp(szType, "Families"))
				g_szFamiliesObj[j][i]='\0';
			if (!stricmp(szType, "Levels"))
				g_szLevelsObj[j][i]='\0';
			if (!stricmp(szType, "Textures"))
				g_szTexturesObj[j][i]='\0';

			if (*p_Char1 == 0) break;
			p_Char1++;
			j++;
		}
		*iNbObjects = j+1;
	}
}

/****************************************************************************
*		Description:	Select the objects for the type
*
*		Parameters:		szType	: type
*						g_iNb	: number of objects
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vUpdateSelectionForType (char *szType, int g_iNb )
{	
	int			j;
	int			i, iIndex;
	GI_Item		*p_oItem;
	GI_Type		*p_oType;

	iIndex= m_oListType->FindStringExact( -1, szType );
	if (iIndex != CB_ERR) 
	{
		m_oListType->SetCurSel(iIndex);
		p_oType = (GI_Type *)m_oListType->GetItemData( iIndex );
		OnSelchangeListType() ;

		j=0;
		for (i=0; i<g_iNb; i++)
		{	
			if (!stricmp(szType, "Anims"))
				iIndex= m_oListObject->FindStringExact( -1, g_szAnimsObj[i] );
			if (!stricmp(szType, "Banks"))
				iIndex= m_oListObject->FindStringExact( -1, g_szBanksObj[i] );
			if (!stricmp(szType, "Classes"))
				iIndex= m_oListObject->FindStringExact( -1, g_szClassesObj[i] );
			if (!stricmp(szType, "Families"))
				iIndex= m_oListObject->FindStringExact( -1, g_szFamiliesObj[i] );
			if (!stricmp(szType, "Levels"))
				iIndex= m_oListObject->FindStringExact( -1, g_szLevelsObj[i] );
			if (!stricmp(szType, "Textures"))
				iIndex= m_oListObject->FindStringExact( -1, g_szTexturesObj[i] );
			
			if (iIndex == LB_ERR)
			{	j++;
				continue;
			}
			p_oItem = (GI_Item *)m_oListObject->GetItemData( iIndex );
			if (!p_oItem->m_bActived)
			{	
				p_oType->m_iSelected++;
				m_iCountOfSelections++;
			}
			p_oItem->m_bActived = TRUE;
		}
	}
}

/****************************************************************************
*		Description:	Get the selection list for the given type
*
*		Parameters:		szType		: name of configuration
*						szName		: type
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vRegisterSelectionForType (char *szName, char *szType) 
{
	xString szPath;
	strcpy(szPath, "");

	// read the current selection
	m_fn_vReadCurrentSelection();

	if (!stricmp(szType, "Anims") && g_iNbAnimsObj) 
	{	
		for (int i=0; i<g_iNbAnimsObj-1; i++)
		{	strcat(szPath, g_szAnimsObj[i]);
			if (g_iNbAnimsObj != 1) strcat(szPath, ",");
		}
		if (g_iNbAnimsObj != -1) strcat(szPath, g_szAnimsObj[g_iNbAnimsObj-1]);
	}
	if (!stricmp(szType, "Banks") && g_iNbBanksObj) 
	{	
		for (int i=0; i<g_iNbBanksObj-1; i++)
		{	strcat(szPath, g_szBanksObj[i]);
			if (g_iNbBanksObj != 1) strcat(szPath, ",");
		}
		if (g_iNbBanksObj != -1) strcat(szPath, g_szBanksObj[g_iNbBanksObj-1]);
	}
	if (!stricmp(szType, "Classes") && g_iNbClassesObj) 
	{	
		for (int i=0; i<g_iNbClassesObj-1; i++)
		{	strcat(szPath, g_szClassesObj[i]);
			if (g_iNbClassesObj != 1) strcat(szPath, ",");
		}
		if (g_iNbClassesObj != -1) strcat(szPath, g_szClassesObj[g_iNbClassesObj-1]);
	}
	if (!stricmp(szType, "Families") && g_iNbFamiliesObj) 
	{	
		for (int i=0; i<g_iNbFamiliesObj-1; i++)
		{	strcat(szPath, g_szFamiliesObj[i]);
			if (g_iNbFamiliesObj != 1) strcat(szPath, ",");
		}
		if (g_iNbFamiliesObj != -1) strcat(szPath, g_szFamiliesObj[g_iNbFamiliesObj-1]);
	}
	if (!stricmp(szType, "Levels") && g_iNbLevelsObj) 
	{	
		for (int i=0; i<g_iNbLevelsObj-1; i++)
		{	strcat(szPath, g_szLevelsObj[i]);
			if (g_iNbLevelsObj != 1) strcat(szPath, ",");
		}
		if (g_iNbLevelsObj != -1) strcat(szPath, g_szLevelsObj[g_iNbLevelsObj-1]);
	}
	if (!stricmp(szType, "Textures") && g_iNbTexturesObj) 
	{	
		for (int i=0; i<g_iNbTexturesObj-1; i++)
		{	strcat(szPath, g_szTexturesObj[i]);
			if (g_iNbTexturesObj != 1) strcat(szPath, ",");
		}
		if (g_iNbTexturesObj != -1) strcat(szPath, g_szTexturesObj[g_iNbTexturesObj-1]);
	}
	fn_IniData_vSetSelectConfigValues( szName, szType, szPath );
}


/****************************************************************************
*		Description:	Read the current selection and update the lists
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vReadCurrentSelection () 
{
	int i;

	g_iNbAnimsObj=0;
	g_iNbBanksObj=0;
	g_iNbClassesObj=0;
	g_iNbFamiliesObj=0;
	g_iNbLevelsObj=0;
	g_iNbTexturesObj=0;

	// anims
	if (m_p_oTypeAnims && m_p_oTypeAnims->m_iSelected)
	{   
		for (i=0; i<m_p_oTypeAnims->m_oList.GetCount(); i++)
		{	
			GI_Item * p_oItem = m_p_oTypeAnims->m_oList.RemoveHead();
			if (p_oItem->m_bActived)
			{	strcpy(g_szAnimsObj[g_iNbAnimsObj], p_oItem->m_fn_p_oGetName());
				g_iNbAnimsObj++;
			}
			m_p_oTypeAnims->m_oList.AddTail(p_oItem);
		}
	}
	// banks
	if (m_p_oTypeBanks && m_p_oTypeBanks->m_iSelected)
	{   
		for (i=0; i<m_p_oTypeBanks->m_oList.GetCount(); i++)
		{	
			GI_Item * p_oItem = m_p_oTypeBanks->m_oList.RemoveHead();
			if (p_oItem->m_bActived)
			{	strcpy(g_szBanksObj[g_iNbBanksObj], p_oItem->m_fn_p_oGetName());
				g_iNbBanksObj++;
			}
			m_p_oTypeBanks->m_oList.AddTail(p_oItem);
		}
	}
	// classes
	if (m_p_oTypeClasses && m_p_oTypeClasses->m_iSelected)
	{   
		for (i=0; i<m_p_oTypeClasses->m_oList.GetCount(); i++)
		{	
			GI_Item * p_oItem = m_p_oTypeClasses->m_oList.RemoveHead();
			if (p_oItem->m_bActived)
			{	strcpy(g_szClassesObj[g_iNbClassesObj], p_oItem->m_fn_p_oGetName());
				g_iNbClassesObj++;
			}
			m_p_oTypeClasses->m_oList.AddTail(p_oItem);
		}
	}
	// families
	if (m_p_oTypeFamilies && m_p_oTypeFamilies->m_iSelected)
	{   
		for (i=0; i<m_p_oTypeFamilies->m_oList.GetCount(); i++)
		{	
			GI_Item * p_oItem = m_p_oTypeFamilies->m_oList.RemoveHead();
			if (p_oItem->m_bActived)
			{	strcpy(g_szFamiliesObj[g_iNbFamiliesObj], p_oItem->m_fn_p_oGetName());
				g_iNbFamiliesObj++;
			}
			m_p_oTypeFamilies->m_oList.AddTail(p_oItem);
		}
	}
	// levels
	if (m_p_oTypeLevels && m_p_oTypeLevels->m_iSelected)
	{   
		for (i=0; i<m_p_oTypeLevels->m_oList.GetCount(); i++)
		{	
			GI_Item * p_oItem = m_p_oTypeLevels->m_oList.RemoveHead();
			if (p_oItem->m_bActived)
			{	strcpy(g_szLevelsObj[g_iNbLevelsObj], p_oItem->m_fn_p_oGetName());
				g_iNbLevelsObj++;
			}
			m_p_oTypeLevels->m_oList.AddTail(p_oItem);
		}
	}
	// textures
	if (m_p_oTypeTextures && m_p_oTypeTextures->m_iSelected)
	{   
		for (i=0; i<m_p_oTypeTextures->m_oList.GetCount(); i++)
		{
			GI_Item * p_oItem = m_p_oTypeTextures->m_oList.RemoveHead();
			if (p_oItem->m_bActived)
			{	strcpy(g_szTexturesObj[g_iNbTexturesObj], p_oItem->m_fn_p_oGetName());
				g_iNbTexturesObj++;
			}
			m_p_oTypeTextures->m_oList.AddTail(p_oItem);
		}
	}
}


//==================================================//
//				OPTIONS CONFIGS						//
//==================================================//

/****************************************************************************
*		Description:	
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vInitOptionCombo ()
{
	xString sIdent;
	char	*p_Char1;
	int		i, j=0;

	// init option combo
	strcpy(g_szConfOptions[0], "Default");
	strcpy(sIdent, g_stInitialData.szConfOptions);
	if (strcmp(sIdent, "")) 
	{	
		p_Char1=sIdent;
		j=1;
		while( (*p_Char1 != ',') && (*p_Char1 != 0))
		{	
			i=0;
			while( (*p_Char1 != ',') && (*p_Char1 != 0))
			{	
				g_szConfOptions[j][i]=*p_Char1;
				p_Char1++;
				i++;
			}
			g_szConfOptions[j][i] = '\0';
			if (*p_Char1 == 0) break;
			p_Char1++;
			j++;
		}
		g_iNbConfOptions = j+1;
	}
	else
		g_iNbConfOptions = 1;

	for (i=0; i<g_iNbConfOptions; i++)
		m_oComboChooseOption.AddString(_T(g_szConfOptions[i]));

	// find current config
	if (!strcmp(g_szOptionConfig, ""))
		GetPrivateProfileString("CurrentConfigs", "Options", "", sIdent, 100, g_szIniFile);
	else
		strcpy(sIdent, g_szOptionConfig); 
	i = m_oComboChooseOption.FindStringExact(-1, sIdent);
	
	g_iCurrentIndexOption = (i != -1) ? i : 0;
	m_oComboChooseOption.SetCurSel(g_iCurrentIndexOption);

	m_fn_vUpdateForOptionConfig();
}

/****************************************************************************
*		Description:	
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vSetDefaultOptionConfig() 
{
	char szOption[10];

	// conflict options
	if (!strcmp(g_szIgnoreZoo, ""))
		GetPrivateProfileString( "Options", "IgnoreZoo", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szIgnoreZoo, "1") ? "FALSE" : "TRUE");
	g_bIgnoreZoo = stricmp(szOption, "FALSE");

	if (!strcmp(g_szIgnoreSct, ""))
		GetPrivateProfileString( "Options", "IgnoreSct", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szIgnoreSct, "1") ? "FALSE" : "TRUE");
	g_bIgnoreSct = stricmp(szOption, "FALSE");

	if (!strcmp(g_szIgnoreSpo, ""))
		GetPrivateProfileString( "Options", "IgnoreSpo", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szIgnoreSpo, "1") ? "FALSE" : "TRUE");
	g_bIgnoreSpo = stricmp(szOption, "FALSE");

	if (!strcmp(g_szIgnoreGmt, ""))
		GetPrivateProfileString( "Options", "IgnoreGmt", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szIgnoreGmt, "1") ? "FALSE" : "TRUE");
	g_bIgnoreGmt = stricmp(szOption, "FALSE");

	if (!strcmp(g_szIgnoreVmt, ""))
		GetPrivateProfileString( "Options", "IgnoreTex", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szIgnoreVmt, "1") ? "FALSE" : "TRUE");
	g_bIgnoreTex = stricmp(szOption, "FALSE");


	// conversion options
	if (!strcmp(g_szCopyAnims, ""))
		GetPrivateProfileString( "Conversion", "CopyAnims", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szCopyAnims, "1") ? "FALSE" : "TRUE");
	g_bCopyAnims = stricmp(szOption, "FALSE");

	if (!strcmp(g_szCopyTextures, ""))
		GetPrivateProfileString( "Conversion", "CopyTextures", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szCopyTextures, "1") ? "FALSE" : "TRUE");
	g_bCopyTextures = stricmp(szOption, "FALSE");

	if (!strcmp(g_szGenerateRLI, ""))
		GetPrivateProfileString( "Conversion", "GenerateRLI", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szGenerateRLI, "1") ? "FALSE" : "TRUE");
	g_bGenerateRLI = stricmp(szOption, "FALSE");

	if (!strcmp(g_szUpdateGameDSC, ""))
		GetPrivateProfileString( "Conversion", "UpdateGameDSC", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szUpdateGameDSC, "1") ? "FALSE" : "TRUE");
	g_bUpdateGameDSC = stricmp(szOption, "FALSE");

	if (!strcmp(g_szCreateBasicFamily, ""))
		GetPrivateProfileString( "Conversion", "CreateBasicFamily", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szCreateBasicFamily, "1") ? "FALSE" : "TRUE");
	g_bCreateBasicFamily = !stricmp(szOption, "TRUE");

	// erase options
	if (!strcmp(g_szEraseDuplicated, ""))
		GetPrivateProfileString( "Erase", "EraseDuplicated", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szEraseDuplicated, "1") ? "FALSE" : "TRUE");
	g_bEraseDuplicated = !stricmp(szOption, "TRUE");

	if (!strcmp(g_szEraseUnused, ""))
		GetPrivateProfileString( "Erase", "EraseUnused", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szEraseUnused, "1") ? "FALSE" : "TRUE");
	g_bEraseUnused = !stricmp(szOption, "TRUE");

	// family options
	if (!strcmp(g_szForceCommon, ""))
		GetPrivateProfileString( "Family", "CommonFamily", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szForceCommon, "1") ? "FALSE" : "TRUE");
	g_bCommonFamily = stricmp(szOption, "FALSE");

	if (!strcmp(g_szForceSpecific, ""))
		GetPrivateProfileString( "Family", "SpecificFamily", "TRUE", szOption, 10, g_szIniFile );
	else
		strcpy(szOption, strcmp(g_szForceSpecific, "1") ? "FALSE" : "TRUE");
	g_bSpecificFamily = stricmp(szOption, "FALSE");

	GetPrivateProfileString( "Family", "AskFamily", "TRUE", szOption, 10, g_szIniFile );
	g_bAskFamily = stricmp(szOption, "FALSE");

	m_fn_vSetOptions();
}

/****************************************************************************
*		Description:	
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vUpdateForOptionConfig() 
{
	g_bChangeComboOption = FALSE;

	if (strcmp(g_stInitialData.szConfOptions, ""))
	{	
		xString szDir1;
		GetCurrentDirectory( MAX_PATH, szDir1 );
		SetCurrentDirectory( g_szInitialDirectory );
		
		g_iCurrentIndexOption = m_oComboChooseOption.GetCurSel();

		if (g_iCurrentIndexOption)
		{
			//read the ConfigControls.ini file
			fn_IniData_vGetDatasFromConfigOptionsFile(TRUE, g_szConfOptions[g_iCurrentIndexOption]);
			m_fn_vSetOptions();
		}
		else
			m_fn_vSetDefaultOptionConfig();

		SetCurrentDirectory( szDir1 );
	}
}

/****************************************************************************
*		Description:	set all options and types from the second panel
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::m_fn_vRegisterAllOptions (int iNumConfig) 
{
	fn_IniData_vSetOptionConfigValues( g_bIgnoreZoo, "IgnoreZoo", g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bIgnoreSct, "IgnoreSct", g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bIgnoreSpo, "IgnoreSpo", g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bIgnoreGmt, "IgnoreGmt", g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bIgnoreTex, "IgnoreTex", g_szConfOptions[iNumConfig]);

	fn_IniData_vSetOptionConfigValues( g_bCopyAnims,		 "CopyAnims",			g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bCopyTextures,		 "CopyTextures",		g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bGenerateRLI,	 	 "GenerateRLI",			g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bUpdateGameDSC,	 "UpdateGameDSC",		g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bCreateBasicFamily, "CreateBasicFamily",	g_szConfOptions[iNumConfig]);

	fn_IniData_vSetOptionConfigValues( g_bEraseDuplicated,  "EraseDuplicated",	g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bEraseUnused,		"EraseUnused",		g_szConfOptions[iNumConfig]);

	fn_IniData_vSetOptionConfigValues( g_bSpecificFamily,	"SpecificFamily",	g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bCommonFamily,		"CommonFamily",		g_szConfOptions[iNumConfig]);
	fn_IniData_vSetOptionConfigValues( g_bAskFamily,		"AskFamily",		g_szConfOptions[iNumConfig]);
}

