/*=========================================================================
*
* DlgMain.cpp	-	implementation file for main window class
*					Main dialog functions
*
* Version			1.0
* Revision date
*
*=======================================================================*/
#include <io.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "stdafx.h"

#include "DlgMain.h"

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

#include "DlgAbout.h"

#include "IniData.h"
#include "Help.h"


//--- Global statics --------------------------------------------------------

// multitextures
BOOL g_bLevelConversion = FALSE;
BOOL g_bBankConversion  = FALSE;
BOOL g_bClassConversion = FALSE;

int	 gs_iIndex;

char g_szInitialDirectory[_MAX_PATH];

int  g_iNbConfDirs;
char g_szConfDirs[20][20];

int	 g_iNbConfOptions;
char g_szConfOptions[20][20];

int	 g_iNbConfSelects;
char g_szConfSelects[20][20];

char g_szAnimsObj[25][256];
char g_szBanksObj[25][256];
char g_szClassesObj[25][256];
char g_szFamiliesObj[25][256];
char g_szLevelsObj[25][256];
char g_szTexturesObj[25][256];

int  g_iNbAnimsObj;
int  g_iNbBanksObj;
int  g_iNbClassesObj;
int  g_iNbFamiliesObj;
int  g_iNbLevelsObj;
int  g_iNbTexturesObj;

BOOL g_bChangeComboDir = FALSE;
int	 g_iCurrentIndexDir = 0;

BOOL g_bChangeComboOption = FALSE;
int	 g_iCurrentIndexOption = 0;

BOOL g_bChangeComboSelect = FALSE;
int	 g_iCurrentIndexSelect = 0;

char g_szDirConfig[256];
char g_szSelectConfig[256];
char g_szOptionConfig[256];

char g_szRayman2[_MAX_PATH];
char g_szModifLst[_MAX_PATH];
char g_szEraseMdf[_MAX_PATH];
char g_szIgnoreZoo[_MAX_PATH];
char g_szIgnoreSct[_MAX_PATH];
char g_szIgnoreSpo[_MAX_PATH];
char g_szIgnoreGmt[_MAX_PATH];
char g_szIgnoreVmt[_MAX_PATH];
char g_szCopyAnims[_MAX_PATH];
char g_szCopyTextures[_MAX_PATH];
char g_szGenerateRLI[_MAX_PATH];
char g_szUpdateGameDSC[_MAX_PATH];
char g_szEraseDuplicated[_MAX_PATH];
char g_szEraseUnused[_MAX_PATH];
char g_szForceCommon[_MAX_PATH];
char g_szForceSpecific[_MAX_PATH];
char g_szCreateBasicFamily[_MAX_PATH];

//--- Global functions --------------------------------------------------------


/****************************************************************************
*		Description:	set the data for the GameDataPC directory
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vSetDataSpecific1()
{ 
  sprintf(g_sRawData, "%s", g_sRawData);
  SetCurrentDirectory(g_sGameSpecific1);
  
  // Create sub directories of GameSpecific1
  CreateDirectory("World", NULL);
  CreateDirectory("World\\Graphics", NULL);
  CreateDirectory("World\\Graphics\\Anims", NULL);
  CreateDirectory("World\\Graphics\\Textures", NULL);
  CreateDirectory("World\\Graphics\\Objects", NULL);
  CreateDirectory("World\\Graphics\\Objects\\Classes", NULL);
  CreateDirectory("World\\Graphics\\Objects\\Banks", NULL);
  CreateDirectory("World\\Graphics\\Visuals", NULL);
  CreateDirectory("World\\Libraries", NULL);
  CreateDirectory("World\\Libraries\\Materials", NULL);
  CreateDirectory("World\\Levels", NULL);
  CreateDirectory("World\\Levels\\_Common", NULL);
  CreateDirectory("World\\Levels\\_Common\\Families", NULL);
  
  // set the materials and textures directory
  sprintf(g_sGameTextureDirectory, "%s\\World\\Graphics\\Textures", g_sGameSpecific1);
}


/****************************************************************************
*		Description:	set the data for the GameDataN64 directory
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void MLT_vSetDataSpecific2()
{ 
  sprintf(g_sRawData, "%s", g_sRawData);
  SetCurrentDirectory(g_sGameSpecific2);
  
  // Create sub directories of GameSpecific2
  CreateDirectory("World", NULL);
  CreateDirectory("World\\Graphics", NULL);
  CreateDirectory("World\\Graphics\\Anims", NULL);
  CreateDirectory("World\\Graphics\\Textures", NULL);
  CreateDirectory("World\\Graphics\\Objects", NULL);
  CreateDirectory("World\\Graphics\\Objects\\Classes", NULL);
  CreateDirectory("World\\Graphics\\Objects\\Banks", NULL);
  CreateDirectory("World\\Graphics\\Visuals", NULL);
  CreateDirectory("World\\Libraries", NULL);
  CreateDirectory("World\\Libraries\\Materials", NULL);
  CreateDirectory("World\\Levels", NULL);
  CreateDirectory("World\\Levels\\_Common", NULL);
  CreateDirectory("World\\Levels\\_Common\\Families", NULL);
  
  // set the materials and textures directory
  sprintf(g_sGameTextureDirectory, "%s\\World\\Graphics\\Textures", g_sGameSpecific2);
}


/****************************************************************************
*		Description:	command function for richedit control
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK Command(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_LBUTTONDBLCLK)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		gs_iIndex = edit->m_oRichEditCom.LineFromChar(edit->m_oRichEditCom.LineIndex(-1));

		int iCurrentLine = edit->m_oRichEditRes.GetFirstVisibleLine();
		int iNewLine = edit->m_oRichEditRes.LineFromChar(g_iResultIndex[g_iCommandIndex[gs_iIndex]]);

		edit->m_oRichEditRes.LineScroll(iNewLine - iCurrentLine);
		edit->m_iInd = gs_iIndex;
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 

BOOL g_sBool = TRUE;
/****************************************************************************
*		Description:	command function for rawspecific1 edit button
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandRawSp1(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	
	char szName[20];
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 13) //return
		{	
			edit->m_oEditRawSp1.GetWindowText(szName, 14);
			if (strcmp(szName, ""))
			{	fn_IniData_vSetRawSp1(szName);
				strcpy(g_stInitialData.szRawSp1, szName);
			}
		}
		if (wp == 27) //escape
		{	edit->m_oEditRawSp1.SetWindowText(g_stInitialData.szRawSp1);
			strcpy(szName, "");
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 


/****************************************************************************
*		Description:	command function for rawspecific2 edit button
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandRawSp2(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	char szName[20];
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 13) //return
		{	edit->m_oEditRawSp2.GetWindowText(szName, 14);
			if (strcmp(szName, ""))
			{	fn_IniData_vSetRawSp2(szName);
				strcpy(g_stInitialData.szRawSp2, szName);
			}
		}
		if (wp == 27) //escape
		{	edit->m_oEditRawSp2.SetWindowText(g_stInitialData.szRawSp2);
			strcpy(szName, "");
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 


/****************************************************************************
*		Description:	command function for gamespecific1 edit button
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandGameSp1(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	char szName[20];
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 13) //return
		{	edit->m_oEditGameSp1.GetWindowText(szName, 14);
			if (strcmp(szName, ""))
			{	fn_IniData_vSetGameSp1(szName);
				strcpy(g_stInitialData.szGameSp1, szName);
			}
		}
		if (wp == 27) //escape
		{	edit->m_oEditGameSp1.SetWindowText(g_stInitialData.szGameSp1);
			strcpy(szName, "");
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 


/****************************************************************************
*		Description:	command function for gamespecific2 edit button
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandGameSp2(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	char szName[20];
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 13) //return
		{	edit->m_oEditGameSp2.GetWindowText(szName, 14);
			if (strcmp(szName, ""))
			{	fn_IniData_vSetGameSp2(szName);
				strcpy(g_stInitialData.szGameSp2, szName);
			}
		}
		if (wp == 27) //escape
		{	edit->m_oEditGameSp2.SetWindowText(g_stInitialData.szGameSp2);
			strcpy(szName, "");
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 


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

/****************************************************************************
*		Description:	command function for register configuration for the first panel
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandRegisterDir(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
	char szName[20];
	//int i;
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 27) //escape
		{	
			edit->m_oEditRegisterDir.SetWindowText("");
			strcpy(szName, "");
			edit->m_oEditRegisterDir.ShowWindow(FALSE);
			edit->m_oButtonRegisterDir.ShowWindow(TRUE);
		}
		if (wp == 13) //return
		{	
			strcpy(szName, "");
			edit->m_oEditRegisterDir.GetWindowText(szName, 14);
			edit->m_oEditRegisterDir.ShowWindow(FALSE);
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
}
/****************************************************************************
*		Description:	command function for create configuration for the first panel
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandCreateDir(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
	char szName[20];
	//int i;
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 27) //escape
		{	
			edit->m_oEditCreateDir.SetWindowText("");
			strcpy(szName, "");
			edit->m_oEditCreateDir.ShowWindow(FALSE);
			edit->m_oButtonCreateDir.ShowWindow(TRUE);
		}
		if (wp == 13) //return
		{	
			strcpy(szName, "");
			edit->m_oEditCreateDir.GetWindowText(szName, 14);
			edit->m_oEditCreateDir.ShowWindow(FALSE);
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
}


/****************************************************************************
*		Description:	command function for renaming configuration for the first panel
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandRenameDir(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	char szName[20];
	FILE	*fileR, *fileW;
	xString szFind, sRead, szOld;
	
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if (msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 27) //escape
		{	
			edit->m_oComboChooseDir.SetCurSel(g_iCurrentIndexDir);
			edit->m_oComboChooseDir.SetWindowText( g_szConfDirs[g_iCurrentIndexDir]);
			strcpy(szName, "");
		}
		if (wp == 13) //return
		{	
			strcpy(szName, "");
			strcpy(szOld, "");
			edit->m_oComboChooseDir.GetLBText( g_iCurrentIndexDir, szOld );
			edit->m_oComboChooseDir.GetWindowText( szName, 25 );
			if (!strcmp(szName, szOld))
				return CallWindowProc(oldproc, hwnd, msg, wp, lp);

			if (strcmp(szName, ""))
			{	
				xString szPath;
				int j1 = edit->m_oComboChooseDir.FindStringExact( -1, szName);
				if (j1 != CB_ERR)
				{	
					AfxMessageBox( "The configuration already exists or you gave the same name for it. Please select another name!", MB_OK | MB_ICONSTOP );
					edit->m_oComboChooseDir.SetCurSel(g_iCurrentIndexDir);
					return CallWindowProc(oldproc, hwnd, msg, wp, lp);
				}

				if (g_iCurrentIndexDir)
				{
					if (g_iCurrentIndexDir != -1)
						edit->m_oComboChooseDir.DeleteString(g_iCurrentIndexDir);
					edit->m_oComboChooseDir.InsertString(g_iCurrentIndexDir, szName);
					edit->m_oComboChooseDir.SetCurSel(g_iCurrentIndexDir);
					strcpy(g_szConfDirs[g_iCurrentIndexDir], szName);

					//delete the section with the previous name from the Configs.ini file
					fileR = fopen (g_szIniConfDirFile, "r");
					fileW = fopen ("New.ini", "w");
			
					strcpy(szFind, "[");
					strcat(szFind, szOld);
					strcat(szFind, "]\n");
					while (fgets(sRead, 256, fileR)!=NULL) //
						if (!stricmp(sRead, szFind))
							break;
						else
							fputs( sRead, fileW);

					fputs("[", fileW);
					fputs(szName, fileW);
					fputs("]\n", fileW);
					while (!feof(fileR))
					{	
						fgets(sRead, 256, fileR);
						if (!feof(fileR)) fputs( sRead, fileW);
					}
					fclose(fileR);
					fclose(fileW);
					remove(g_szIniConfDirFile);
					MoveFile("New.ini", g_szIniConfDirFile);
				}
				else
				{
					edit->m_oComboChooseDir.AddString(szName);
					edit->m_oComboChooseDir.SetCurSel(edit->m_oComboChooseDir.GetCount() - 1);
					g_iCurrentIndexDir = edit->m_oComboChooseDir.GetCount() - 1;
					g_iNbConfDirs++;
					strcpy(g_szConfDirs[g_iNbConfDirs-1], szName);
					edit->m_oButtonSaveDir.EnableWindow(g_iCurrentIndexDir);
					edit->m_oButtonDeleteDir.EnableWindow(g_iCurrentIndexDir);
				}

				strcpy(szPath, "");

				for (int j=1; j<g_iNbConfDirs-1; j++)
				{	
					strcat(szPath, g_szConfDirs[j]);
					strcat(szPath, ",");
				}
				if (g_iNbConfDirs) //!!!
					strcat(szPath, g_szConfDirs[g_iNbConfDirs-1]);
				fn_IniData_vSetConfigDirNames( szPath );


				//add the new name section in the .ini file
				edit->m_fn_vRegisterAllPaths(g_iCurrentIndexDir);
			}
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 



/****************************************************************************
*		Description:	command function for register configuration for the second panel button
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandRegisterOption(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	char szName[20];
	//int i;
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 27) //escape
		{	
			edit->m_oEditRegisterOption.SetWindowText("");
			strcpy(szName, "");
			edit->m_oEditRegisterOption.ShowWindow(FALSE);
			edit->m_oButtonRegisterOption.ShowWindow(TRUE);
		}
		if (wp == 13) //return
		{	
			strcpy(szName, "");
			edit->m_oEditRegisterOption.GetWindowText(szName, 14);
			edit->m_oEditRegisterOption.ShowWindow(FALSE);
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 

/****************************************************************************
*		Description:	command function for create configuration for the second panel button
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandCreateOption(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	char szName[20];
	//int i;
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 27) //escape
		{	
			edit->m_oEditCreateOption.SetWindowText("");
			strcpy(szName, "");
			edit->m_oEditCreateOption.ShowWindow(FALSE);
			edit->m_oButtonCreateOption.ShowWindow(TRUE);
		}
		if (wp == 13) //return
		{	
			strcpy(szName, "");
			edit->m_oEditCreateOption.GetWindowText(szName, 14);
			edit->m_oEditCreateOption.ShowWindow(FALSE);
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 


/****************************************************************************
*		Description:	command function for renaming configuration for the second panel
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandRenameOption(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	char szName[20];
	FILE	*fileR, *fileW;
	xString szFind, sRead, szOld;
	int i1;
	
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if (msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 27) //escape
		{	
			edit->m_oComboChooseOption.SetCurSel(g_iCurrentIndexOption);
			edit->m_oComboChooseOption.SetWindowText( g_szConfOptions[g_iCurrentIndexOption]);
			strcpy(szName, "");
		}
		if (wp == 13) //return
		{
			strcpy(szName, "");
			strcpy(szOld, "");
			edit->m_oComboChooseOption.GetLBText( g_iCurrentIndexOption, szOld );
			edit->m_oComboChooseOption.GetWindowText( szName, 25 );
			if (!strcmp(szName, szOld))
				return CallWindowProc(oldproc, hwnd, msg, wp, lp);

			if (strcmp(szName, ""))
			{	
				xString szPath;
				int j1 = edit->m_oComboChooseOption.FindStringExact( -1, szName);
				if (j1 != CB_ERR)
				{	
					AfxMessageBox( "The configuration already exists or you gave the same name for it. Please select another name!", MB_OK | MB_ICONSTOP );
					return CallWindowProc(oldproc, hwnd, msg, wp, lp);
				}
				i1 = g_iCurrentIndexOption;
				
				if (i1)
				{
					if (i1 != -1)
						edit->m_oComboChooseOption.DeleteString(i1);
					edit->m_oComboChooseOption.InsertString(i1, szName);
					edit->m_oComboChooseOption.SetCurSel(i1);
					strcpy(g_szConfOptions[i1], szName);
		
					//delete the section with the previous name from the Configs.ini file
					fileR = fopen (g_szIniConfOptionFile, "r");
					fileW = fopen ("New.ini", "w");
			
					strcpy(szFind, "[");
					strcat(szFind, szOld);
					strcat(szFind, "]\n");
					while (fgets(sRead, 256, fileR)!=NULL) //
						if (!stricmp(sRead, szFind))
							break;
						else
							fputs( sRead, fileW);

					fputs("[", fileW);
					fputs(szName, fileW);
					fputs("]\n", fileW);

					while (!feof(fileR))
					{	fgets(sRead, 256, fileR);
						if (!feof(fileR)) fputs( sRead, fileW);
					}

					fclose(fileR);
					fclose(fileW);
					remove(g_szIniConfOptionFile);
					MoveFile("New.ini", g_szIniConfOptionFile);
				}
				else
				{
					edit->m_oComboChooseOption.AddString(szName);
					edit->m_oComboChooseOption.SetCurSel(edit->m_oComboChooseOption.GetCount() - 1);
					g_iCurrentIndexOption = edit->m_oComboChooseOption.GetCount() - 1;
					g_iNbConfOptions++;
					strcpy(g_szConfOptions[g_iNbConfOptions-1], szName);
					edit->m_oButtonSaveOption.EnableWindow(g_iCurrentIndexOption);
					edit->m_oButtonDeleteOption.EnableWindow(g_iCurrentIndexOption);
				}

				strcpy(szPath, "");

				for (int j=1; j<g_iNbConfOptions-1; j++)
				{	
					strcat(szPath, g_szConfOptions[j]);
					strcat(szPath, ",");
				}
				if (g_iNbConfOptions) //!!!
					strcat(szPath, g_szConfOptions[g_iNbConfOptions-1]);
				fn_IniData_vSetOptionConfigNames( szPath );
				//add the new name section in the .ini file
				edit->m_fn_vRegisterAllOptions(i1);
			}
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 

/****************************************************************************
*		Description:	command function for register configuration for the second panel button
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandRegisterSelect(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	char szName[20];
	//int i;
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 27) //escape
		{	
			edit->m_oEditRegisterSelect.SetWindowText("");
			strcpy(szName, "");
			edit->m_oEditRegisterSelect.ShowWindow(FALSE);
			edit->m_oButtonRegisterSelect.ShowWindow(TRUE);
		}
		if (wp == 13) //return
		{	
			strcpy(szName, "");
			edit->m_oEditRegisterSelect.GetWindowText(szName, 14);
			edit->m_oEditRegisterSelect.ShowWindow(FALSE);
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 

/****************************************************************************
*		Description:	command function for create configuration for the second panel button
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandCreateSelect(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	char szName[20];
	//int i;
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if(msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 27) //escape
		{	
			edit->m_oEditCreateSelect.SetWindowText("");
			strcpy(szName, "");
			edit->m_oEditCreateSelect.ShowWindow(FALSE);
			edit->m_oButtonCreateSelect.ShowWindow(TRUE);
		}
		if (wp == 13) //return
		{	
			strcpy(szName, "");
			edit->m_oEditCreateSelect.GetWindowText(szName, 14);
			edit->m_oEditCreateSelect.ShowWindow(FALSE);
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 


/****************************************************************************
*		Description:	command function for renaming configuration for the second panel
*
*		Parameters:		
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
LRESULT CALLBACK CommandRenameSelect(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{	char szName[20];
	FILE	*fileR, *fileW;
	xString szFind, sRead, szOld;
	int i1;
	
	WNDPROC oldproc = (WNDPROC)GetProp(hwnd, "wproc");
	if (msg == WM_CHAR)
	{
		CDlgMain* edit = (CDlgMain *)GetProp(hwnd, "class");
		if (wp == 27) //escape
		{	
			edit->m_oComboChooseSelect.SetCurSel(g_iCurrentIndexSelect);
			edit->m_oComboChooseSelect.SetWindowText( g_szConfSelects[g_iCurrentIndexSelect]);
			strcpy(szName, "");
		}
		if (wp == 13) //return
		{
			strcpy(szName, "");
			strcpy(szOld, "");
			edit->m_oComboChooseSelect.GetLBText( g_iCurrentIndexSelect, szOld );
			edit->m_oComboChooseSelect.GetWindowText( szName, 25 );
			if (!strcmp(szName, szOld))
				return CallWindowProc(oldproc, hwnd, msg, wp, lp);

			if (strcmp(szName, ""))
			{	
				xString szPath;
				int j1 = edit->m_oComboChooseSelect.FindStringExact( -1, szName);
				if (j1 != CB_ERR)
				{	
					AfxMessageBox( "The configuration already exists or you gave the same name for it. Please select another name!", MB_OK | MB_ICONSTOP );
					return CallWindowProc(oldproc, hwnd, msg, wp, lp);
				}
				i1 = g_iCurrentIndexSelect;

				if (i1)
				{
					if (i1 != -1)
						edit->m_oComboChooseSelect.DeleteString(i1);
					edit->m_oComboChooseSelect.InsertString(i1, szName);
					edit->m_oComboChooseSelect.SetCurSel(i1);
					strcpy(g_szConfSelects[i1], szName);
		
					//delete the section with the previous name from the Configs.ini file
					fileR = fopen (g_szIniConfSelectFile, "r");
					fileW = fopen ("New.ini", "w");
			
					strcpy(szFind, "[");
					strcat(szFind, szOld);
					strcat(szFind, "]\n");
					while (fgets(sRead, 256, fileR)!=NULL) //
						if (!stricmp(sRead, szFind))
							break;
						else
							fputs( sRead, fileW);

					fputs("[", fileW);
					fputs(szName, fileW);
					fputs("]\n", fileW);

					while (!feof(fileR))
					{	fgets(sRead, 256, fileR);
						if (!feof(fileR)) fputs( sRead, fileW);
					}

					fclose(fileR);
					fclose(fileW);
					remove(g_szIniConfSelectFile);
					MoveFile("New.ini", g_szIniConfSelectFile);
				}
				else
				{
					edit->m_oComboChooseSelect.AddString(szName);
					edit->m_oComboChooseSelect.SetCurSel(edit->m_oComboChooseSelect.GetCount() - 1);
					g_iCurrentIndexSelect = edit->m_oComboChooseSelect.GetCount() - 1;
					g_iNbConfSelects++;
					strcpy(g_szConfSelects[g_iNbConfSelects-1], szName);
					edit->m_oButtonSaveSelect.EnableWindow(g_iCurrentIndexSelect);
					edit->m_oButtonDeleteSelect.EnableWindow(g_iCurrentIndexSelect);
				}

				strcpy(szPath, "");

				for (int j=1; j<g_iNbConfSelects-1; j++)
				{	
					strcat(szPath, g_szConfSelects[j]);
					strcat(szPath, ",");
				}
				if (g_iNbConfSelects) //!!!
					strcat(szPath, g_szConfSelects[g_iNbConfSelects-1]);
				fn_IniData_vSetSelectConfigNames( szPath );

				//add the new name section in the .ini file
				edit->m_fn_vRegisterSelections(i1);
			}
		}
	}
	return CallWindowProc(oldproc, hwnd, msg, wp, lp);
} 
//--------------------------------------------------------------------



/****************************************************************************
*		Description:	constructor
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
CDlgMain::CDlgMain(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgMain::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgMain)
		// NOTE: the ClassWizard will add member initialization here

	//}}AFX_DATA_INIT

	// initialize the values for the controls 

// FIRST PANEL

	m_a_uiGroupButtons[0] = IDC_GROUP_SOURCEDIRECTORIES;
	m_a_uiGroupButtons[1] = IDC_GROUP_DESTDIRECTORIES;
	m_a_uiGroupButtons[2] = IDC_GROUP_MAINOPTIONS;
	m_cNbGroupButtons = 3;

	m_a_uiEditControls[0] = IDC_EDIT_RAWDATA;
	m_a_uiEditControls[1] = IDC_EDIT_RAWSPECIFIC1;
	m_a_uiEditControls[2] = IDC_EDIT_RAWSPECIFIC2;
	m_a_uiEditControls[3] = IDC_EDIT_GAMEDATA;
	m_a_uiEditControls[4] = IDC_EDIT_GAMESPECIFIC1;
	m_a_uiEditControls[5] = IDC_EDIT_GAMESPECIFIC2;
	m_cNbEditControls = 6;

	m_a_uiEditNameControls[0] = IDC_EDIT_RAWSP1;
	m_a_uiEditNameControls[1] = IDC_EDIT_RAWSP2;
	m_a_uiEditNameControls[2] = IDC_EDIT_GAMESP1;
	m_a_uiEditNameControls[3] = IDC_EDIT_GAMESP2;
	m_cNbEditNameControls = 4;

	m_a_uiBrowseButtons[0]  = IDC_BROWSE_RAWDATA;
	m_a_uiBrowseButtons[1]  = IDC_BROWSE_RAWSPECIFIC1;
	m_a_uiBrowseButtons[2]  = IDC_BROWSE_RAWSPECIFIC2;
	m_a_uiBrowseButtons[3]  = IDC_BROWSE_GAMEDATA;
	m_a_uiBrowseButtons[4]  = IDC_BROWSE_GAMESPECIFIC1;
	m_a_uiBrowseButtons[5]  = IDC_BROWSE_GAMESPECIFIC2;
	m_a_uiBrowseButtons[6]  = IDC_BROWSE_ANIMS;
	m_a_uiBrowseButtons[7]  = IDC_BROWSE_BANKS;
	m_a_uiBrowseButtons[8]  = IDC_BROWSE_CLASSES;
	m_a_uiBrowseButtons[9]  = IDC_BROWSE_FAMILIES;
	m_a_uiBrowseButtons[10]  = IDC_BROWSE_LEVELS;
	m_a_uiBrowseButtons[11]  = IDC_BROWSE_TEXTURES;
	m_cNbBrowseButtons = 12;

	m_a_uiCustomConfigControls[0] = IDC_BUTTON_REGISTERCONFIGDIR;
	m_a_uiCustomConfigControls[1] = IDC_COMBO_CONFIGDIR;
	m_a_uiCustomConfigControls[2] = IDC_BUTTON_CREATECONFIGDIR;
	m_a_uiCustomConfigControls[3] = IDC_BUTTON_SAVECONFIGDIR;
	m_a_uiCustomConfigControls[4] = IDC_BUTTON_DELETECONFIGDIR;
	m_cNbCustomConfigControls = 5;

	m_a_uiCustomStaticControls[0] = IDC_STATIC_ANIMS;
	m_a_uiCustomStaticControls[1] = IDC_STATIC_BANKS;
	m_a_uiCustomStaticControls[2] = IDC_STATIC_CLASSES;
	m_a_uiCustomStaticControls[3] = IDC_STATIC_FAMILIES;
	m_a_uiCustomStaticControls[4] = IDC_STATIC_LEVELS;
	m_a_uiCustomStaticControls[5] = IDC_STATIC_TEXTURES;
	m_cNbCustomStaticControls = 6;

	m_a_uiCustomEditControls[0] = IDC_EDIT_ANIMS;
	m_a_uiCustomEditControls[1] = IDC_EDIT_BANKS;
	m_a_uiCustomEditControls[2] = IDC_EDIT_CLASSES;
	m_a_uiCustomEditControls[3] = IDC_EDIT_FAMILIES;
	m_a_uiCustomEditControls[4] = IDC_EDIT_LEVELS;
	m_a_uiCustomEditControls[5] = IDC_EDIT_TEXTURES;
	m_cNbCustomEditControls = 6;

	m_a_uiMainButtons[0] = IDC_CHECK_RAYMAN2;
    m_a_uiMainButtons[1] = IDC_CHECK_MODIFLST;
	m_a_uiMainButtons[2] = IDC_CHECK_ERASEMOD;
	m_cNbMainButtons = 3;

// SECOND PANEL
	
	m_a_uiSelectButtons[0] = IDC_BUTTON_SELECTALL;
	m_a_uiSelectButtons[1] = IDC_BUTTON_SELECTLIST;
	m_cNbSelectButtons = 2;

	m_a_uiClearButtons[0] = IDC_BUTTON_CLEARALL;
	m_a_uiClearButtons[1] = IDC_BUTTON_CLEARLIST;
	m_cNbClearButtons = 2;

    m_a_uiSelectConfigButtons[0] = IDC_BUTTON_REGISTERCONFIGSELECT;
	m_a_uiSelectConfigButtons[1] = IDC_COMBO_CONFIGSELECT;
	m_a_uiSelectConfigButtons[2] = IDC_BUTTON_CREATECONFIGSELECT;
	m_a_uiSelectConfigButtons[3] = IDC_BUTTON_SAVECONFIGSELECT;
	m_a_uiSelectConfigButtons[4] = IDC_BUTTON_DELETECONFIGSELECT;
	m_cNbSelectConfigButtons = 5;

	m_a_uiConflictStaticButtons[0] = IDC_STATIC_ZOO;
	m_a_uiConflictStaticButtons[1] = IDC_STATIC_SCT;
	m_a_uiConflictStaticButtons[2] = IDC_STATIC_SPO;
	m_a_uiConflictStaticButtons[3] = IDC_STATIC_GMT;
	m_a_uiConflictStaticButtons[4] = IDC_STATIC_VMT;
	m_cNbConflictStaticButtons = 5;

	m_a_uiConflictMaxButtons[0] = IDC_CHECK_ZOO_MAX;
	m_a_uiConflictMaxButtons[1] = IDC_CHECK_SCT_MAX;
	m_a_uiConflictMaxButtons[2] = IDC_CHECK_SPO_MAX;
	m_a_uiConflictMaxButtons[3] = IDC_CHECK_GMT_MAX;
	m_a_uiConflictMaxButtons[4] = IDC_CHECK_VMT_MAX;
	m_cNbConflictMaxButtons = 5;

	m_a_uiConflictEdsButtons[0] = IDC_CHECK_ZOO_EDS;
	m_a_uiConflictEdsButtons[1] = IDC_CHECK_SCT_EDS;
	m_a_uiConflictEdsButtons[2] = IDC_CHECK_SPO_EDS;
	m_a_uiConflictEdsButtons[3] = IDC_CHECK_GMT_EDS;
	m_a_uiConflictEdsButtons[4] = IDC_CHECK_VMT_EDS;
	m_cNbConflictEdsButtons = 5;

	m_a_uiOptionButtons[0] = IDC_CHECK_COPYTEXTURES;
	m_a_uiOptionButtons[1] = IDC_CHECK_COPYANIMS;
	m_a_uiOptionButtons[2] = IDC_CHECK_GENERATERLI;
	m_a_uiOptionButtons[3] = IDC_CHECK_UPDATEGAMEDSC;
	m_a_uiOptionButtons[4] = IDC_CHECK_BASICFAMILY;
	m_cNbOptionButtons = 5;

	m_a_uiEraseButtons[0] = IDC_CHECK_ERASEDUPLICATED;
	m_a_uiEraseButtons[1] = IDC_CHECK_ERASEUNUSED;
	m_cNbEraseButtons = 2;

	m_a_uiFamilyButtons[0] = IDC_CHECK_FORCECOMMON;
    m_a_uiFamilyButtons[1] = IDC_CHECK_FORCESPECIFIC;
	m_a_uiFamilyButtons[2] = IDC_CHECK_ASKFAMILY;
	m_cNbFamilyButtons = 3;

	m_a_uiOptionConfig[0] = IDC_BUTTON_REGISTERCONFIGOPTION;
	m_a_uiOptionConfig[1] = IDC_COMBO_CONFIGOPTION;
	m_a_uiOptionConfig[2] = IDC_BUTTON_CREATECONFIGOPTION;
	m_a_uiOptionConfig[3] = IDC_BUTTON_SAVECONFIGOPTION;
	m_a_uiOptionConfig[4] = IDC_BUTTON_DELETECONFIGOPTION;
	m_cNbOptionConfig = 5;

	// initial is FALSE, and is putting on TRUE in the function OnInitDialog
	m_bInit = FALSE;
	
	//initialize for the cross
	m_bFirstShow = TRUE;
	m_oCrossDC.CreateCompatibleDC(NULL);
	m_oCrossBitmap.LoadBitmap(IDB_BITMAP_CROSS);
	m_oCrossDC.SelectObject(m_oCrossBitmap);

	//initial the total number of selections is 0
	m_iCountOfSelections=0;
	m_iInd=0;

    m_bConversion = FALSE;

	//and there are no types
	m_p_oTypeAnims = NULL;
	m_p_oTypeBanks = NULL;
	m_p_oTypeClasses = NULL;
	m_p_oTypeFamilies = NULL;
	m_p_oTypeLevels = NULL;
	m_p_oTypeTextures = NULL;
}


/****************************************************************************
*		Description:	destructor
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
CDlgMain::~CDlgMain()
{
	//delete the cross
	m_oCrossBitmap.DeleteObject();
	m_oCrossDC.DeleteDC();
	m_fn_vFreeMemory();

	HWND hwnd = m_oRichEditCom.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oEditRawSp1.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oEditRawSp2.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oEditGameSp1.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oEditGameSp2.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oEditRegisterDir.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oEditCreateDir.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oComboChooseDir.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oEditRegisterOption.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oEditCreateOption.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oComboChooseOption.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oEditRegisterSelect.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oEditCreateSelect.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");

	hwnd = m_oComboChooseSelect.m_hWnd;
	::RemoveProp(hwnd, "class");
	SetWindowLong(hwnd, GWL_WNDPROC, (long)GetProp(hwnd, "wproc"));
	::RemoveProp(hwnd, "wproc");
}


/****************************************************************************
*		Description:	treat the mesages for the dialog
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
BOOL CDlgMain::PreTranslateMessage(MSG* pMsg)
{
    int		iIndexAction	= m_oListObject->GetCurSel();
	int		iCtrlID			= 0;
    BOOL	bResult			= FALSE;    
	
	switch (pMsg->message)
	{
        case WM_LBUTTONDOWN:
			if (pMsg->hwnd == m_oListObject->m_hWnd)
				bResult = OnLButtonDownListBoxObject(pMsg);
			break;


		case WM_RBUTTONDOWN:
			iCtrlID = ::GetDlgCtrlID(pMsg->hwnd);

			if (iCtrlID == IDC_PANELCONFIGS)
				AfxGetApp()->WinHelp(HID_PANELCONFIGS, HELP_CONTEXTPOPUP);

			else if (iCtrlID == IDC_MAINPANEL)
				AfxGetApp()->WinHelp(HID_MAINPANEL, HELP_CONTEXTPOPUP);

			if (iCtrlID == IDC_RICHEDIT_RESULT)
				AfxGetApp()->WinHelp(HID_RICHEDIT_RESULT, HELP_CONTEXTPOPUP);

			else if (iCtrlID == IDC_RICHEDIT_COMMAND)
				AfxGetApp()->WinHelp(HID_RICHEDIT_COMMAND, HELP_CONTEXTPOPUP);

			else if (iCtrlID)
			{
				CWnd *pCtrlWnd = GetDlgItem(iCtrlID);
				if (pCtrlWnd)
					AfxGetApp()->WinHelp(pCtrlWnd->GetWindowContextHelpId(), HELP_CONTEXTPOPUP);	
			}
			else
			{	
				POINT ptMousePos;

				ptMousePos.x = LOWORD(pMsg->lParam);
				ptMousePos.y = HIWORD(pMsg->lParam);
				  
				CWnd *pCtrlWnd = ChildWindowFromPoint(ptMousePos, CWP_SKIPINVISIBLE);
				if (pCtrlWnd)
					AfxGetApp()->WinHelp(pCtrlWnd->GetWindowContextHelpId(), HELP_CONTEXTPOPUP);
			}
			bResult = TRUE;
			break;
	}
	return bResult;
}


/****************************************************************************
*		Description:	data exchange
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgMain)
		// NOTE: the ClassWizard will add DDX and DDV calls here

	// panels
	DDX_Control(pDX, IDC_PANELCONFIGS, m_oConfigPanel);
	DDX_Control(pDX, IDC_MAINPANEL, m_oMainPanel);

	// directory configs
	DDX_Control(pDX, IDC_EDIT_REGISTERCONFIGDIR, m_oEditRegisterDir);
	DDX_Control(pDX, IDC_EDIT_CREATECONFIGDIR, m_oEditCreateDir);
	DDX_Control(pDX, IDC_BUTTON_REGISTERCONFIGDIR, m_oButtonRegisterDir);
	DDX_Control(pDX, IDC_BUTTON_CREATECONFIGDIR, m_oButtonCreateDir);
	DDX_Control(pDX, IDC_BUTTON_DELETECONFIGDIR, m_oButtonDeleteDir);
	DDX_Control(pDX, IDC_BUTTON_SAVECONFIGDIR, m_oButtonSaveDir);
	DDX_Control(pDX, IDC_COMBO_CONFIGDIR, m_oComboChooseDir);

	// rawdata
	DDX_Control(pDX, IDC_CHECK_RAWDATA, m_oCheckRawData);
	DDX_Control(pDX, IDC_CHECK_RAWSPECIFIC1, m_oCheckRawSP1);
	DDX_Control(pDX, IDC_CHECK_RAWSPECIFIC2, m_oCheckRawSP2);
	DDX_Control(pDX, IDC_EDIT_RAWSP1, m_oEditRawSp1);
	DDX_Control(pDX, IDC_EDIT_RAWSP2, m_oEditRawSp2);
	// gamedata
	DDX_Control(pDX, IDC_CHECK_GAMEDATA, m_oCheckGameData);
	DDX_Control(pDX, IDC_CHECK_GAMESPECIFIC1, m_oCheckGameSP1);
	DDX_Control(pDX, IDC_CHECK_GAMESPECIFIC2, m_oCheckGameSP2);
	DDX_Control(pDX, IDC_EDIT_GAMESP1, m_oEditGameSp1);
	DDX_Control(pDX, IDC_EDIT_GAMESP2, m_oEditGameSp2);
	// main options
	DDX_Control(pDX, IDC_CHECK_RAYMAN2, m_oCheckRayman2);
	DDX_Control(pDX, IDC_CHECK_MODIFLST, m_oCheckModifLst);
	DDX_Control(pDX, IDC_CHECK_ERASEMOD, m_oCheckEraseMdf);

	// selection buttons
	DDX_Control(pDX, IDC_BUTTON_SELECTLIST, m_oSelectList);
	DDX_Control(pDX, IDC_BUTTON_SELECTALL, m_oSelectAll);
	DDX_Control(pDX, IDC_BUTTON_CLEARLIST, m_oClearList);
	DDX_Control(pDX, IDC_BUTTON_CLEARALL, m_oClearAll);
	// select configs buttons
	DDX_Control(pDX, IDC_EDIT_REGISTERCONFIGSELECT, m_oEditRegisterSelect);
	DDX_Control(pDX, IDC_EDIT_CREATECONFIGSELECT, m_oEditCreateSelect);
	DDX_Control(pDX, IDC_BUTTON_REGISTERCONFIGSELECT, m_oButtonRegisterSelect);
	DDX_Control(pDX, IDC_BUTTON_CREATECONFIGSELECT, m_oButtonCreateSelect);
	DDX_Control(pDX, IDC_BUTTON_DELETECONFIGSELECT, m_oButtonDeleteSelect);
	DDX_Control(pDX, IDC_BUTTON_SAVECONFIGSELECT, m_oButtonSaveSelect);
	DDX_Control(pDX, IDC_COMBO_CONFIGSELECT, m_oComboChooseSelect);
	// conflict options
	DDX_Control(pDX, IDC_CHECK_ZOO_MAX, m_oCheckZooMax);
	DDX_Control(pDX, IDC_CHECK_SCT_MAX, m_oCheckSctMax);
	DDX_Control(pDX, IDC_CHECK_SPO_MAX, m_oCheckSpoMax);
	DDX_Control(pDX, IDC_CHECK_GMT_MAX, m_oCheckGmtMax);
	DDX_Control(pDX, IDC_CHECK_VMT_MAX, m_oCheckVmtMax);
	DDX_Control(pDX, IDC_CHECK_ZOO_EDS, m_oCheckZooEds);
	DDX_Control(pDX, IDC_CHECK_SCT_EDS, m_oCheckSctEds);
	DDX_Control(pDX, IDC_CHECK_SPO_EDS, m_oCheckSpoEds);
	DDX_Control(pDX, IDC_CHECK_GMT_EDS, m_oCheckGmtEds);
	DDX_Control(pDX, IDC_CHECK_VMT_EDS, m_oCheckVmtEds);
	// conversion options
	DDX_Control(pDX, IDC_CHECK_COPYANIMS, m_oCheckCopyAnims);
	DDX_Control(pDX, IDC_CHECK_COPYTEXTURES, m_oCheckCopyTextures);
	DDX_Control(pDX, IDC_CHECK_GENERATERLI, m_oCheckGenerateRLI);
	DDX_Control(pDX, IDC_CHECK_UPDATEGAMEDSC, m_oCheckUpdateGameDsc);
	// erase options
	DDX_Control(pDX, IDC_CHECK_ERASEDUPLICATED, m_oCheckEraseDup);
	DDX_Control(pDX, IDC_CHECK_ERASEUNUSED, m_oCheckEraseUnused);
	// family options
	DDX_Control(pDX, IDC_CHECK_ASKFAMILY, m_oCheckAskFamily);
	DDX_Control(pDX, IDC_CHECK_FORCECOMMON, m_oCheckCommon);
	DDX_Control(pDX, IDC_CHECK_FORCESPECIFIC, m_oCheckSpecific);
	// bank options
	DDX_Control(pDX, IDC_CHECK_BASICFAMILY, m_oCheckCreateFamily);
	// convert button
	DDX_Control(pDX, IDC_BUTTON_CONVERT, m_oConvert);
	
	// options config
	DDX_Control(pDX, IDC_EDIT_REGISTERCONFIGOPTION, m_oEditRegisterOption);
	DDX_Control(pDX, IDC_EDIT_CREATECONFIGOPTION, m_oEditCreateOption);
	DDX_Control(pDX, IDC_BUTTON_REGISTERCONFIGOPTION, m_oButtonRegisterOption);
	DDX_Control(pDX, IDC_BUTTON_CREATECONFIGOPTION, m_oButtonCreateOption);
	DDX_Control(pDX, IDC_BUTTON_DELETECONFIGOPTION, m_oButtonDeleteOption);
	DDX_Control(pDX, IDC_BUTTON_SAVECONFIGOPTION, m_oButtonSaveOption);
	DDX_Control(pDX, IDC_COMBO_CONFIGOPTION, m_oComboChooseOption);

	// progress bar
	DDX_Control(pDX, IDC_STATIC_PROGRESS, m_oProgress);

	//}}AFX_DATA_MAP
}


/****************************************************************************
*		Description:	treat the WM_COMMAND message
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
BOOL CDlgMain::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	switch(LOWORD(wParam))
    {
		// help menu
		case IDM_OPENHELP:	
			OnHelp();				
			break;

		case IDM_ABOUTBOX:		
			{	
				CAboutDlg dlgAbout;
				dlgAbout.DoModal();
				break;
			}
			break;

		default :
    		return CDialog::OnCommand(wParam, lParam);

    }
	return TRUE;
}


/****************************************************************************
*		Description:	message map
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
BEGIN_MESSAGE_MAP(CDlgMain, CDialog)
	//{{AFX_MSG_MAP(CDlgMain)
	// main functions
	ON_WM_PAINT()
	ON_WM_SIZE()
	ON_WM_SIZING()
	ON_WM_DESTROY()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_QUIT, OnQuit)

	// help 
	ON_WM_HELPINFO()
	ON_BN_CLICKED(IDC_BUTTON_HELP, OnCheckHelp)

	// change panel
	ON_NOTIFY(TCN_SELCHANGE, IDC_MAINPANEL, OnSelchangePanel)
	ON_NOTIFY(TCN_SELCHANGE, IDC_PANELCONFIGS, OnSelchangeTab)

	// rename directories
	ON_EN_KILLFOCUS(IDC_EDIT_RAWSP1, OnKillFocusRawSpecific1)
	ON_EN_KILLFOCUS(IDC_EDIT_RAWSP2, OnKillFocusRawSpecific2)
	ON_EN_KILLFOCUS(IDC_EDIT_GAMESP1, OnKillFocusGameSpecific1)
	ON_EN_KILLFOCUS(IDC_EDIT_GAMESP2, OnKillFocusGameSpecific2)
	// choose directories
	ON_BN_CLICKED(IDC_CHECK_GAMEDATA, OnCheckGameData)
	ON_BN_CLICKED(IDC_CHECK_GAMESPECIFIC1, OnCheckGameSpecific1)
	ON_BN_CLICKED(IDC_CHECK_GAMESPECIFIC2, OnCheckGameSpecific2)
	ON_BN_CLICKED(IDC_CHECK_RAWDATA, OnCheckRawData)
	ON_BN_CLICKED(IDC_CHECK_RAWSPECIFIC1, OnCheckRawSpecific1)
	ON_BN_CLICKED(IDC_CHECK_RAWSPECIFIC2, OnCheckRawSpecific2)
	// browse directories
	ON_BN_CLICKED(IDC_BROWSE_GAMEDATA, OnButtonBrowseGameData)
	ON_BN_CLICKED(IDC_BROWSE_GAMESPECIFIC1, OnButtonBrowseGameSpecific1)
	ON_BN_CLICKED(IDC_BROWSE_GAMESPECIFIC2, OnButtonBrowseGameSpecific2)
	ON_BN_CLICKED(IDC_BROWSE_RAWDATA, OnButtonBrowseRawData)
	ON_BN_CLICKED(IDC_BROWSE_RAWSPECIFIC1, OnButtonBrowseRawSpecific1)
	ON_BN_CLICKED(IDC_BROWSE_RAWSPECIFIC2, OnButtonBrowseRawSpecific2)

	// directory configuration
	ON_BN_CLICKED(IDC_BUTTON_REGISTERCONFIGDIR, OnRegisterConfigDir)
	ON_BN_CLICKED(IDC_BUTTON_CREATECONFIGDIR, OnCreateConfigDir)
	ON_BN_CLICKED(IDC_BUTTON_DELETECONFIGDIR, OnDeleteConfigDir)
	ON_BN_CLICKED(IDC_BUTTON_SAVECONFIGDIR, OnSaveConfigDir)
	ON_CBN_SELCHANGE(IDC_COMBO_CONFIGDIR, OnChooseConfigDir)
	ON_CBN_KILLFOCUS(IDC_COMBO_CONFIGDIR, OnKillFocusComboChooseConfigDir)
	ON_EN_KILLFOCUS(IDC_EDIT_REGISTERCONFIGDIR, OnKillFocusEditRegisterConfigDir)
	ON_EN_KILLFOCUS(IDC_EDIT_CREATECONFIGDIR, OnKillFocusEditCreateConfigDir)

	// browse custom directories
	ON_BN_CLICKED(IDC_BROWSE_ANIMS, OnButtonBrowseAnims)
	ON_BN_CLICKED(IDC_BROWSE_BANKS, OnButtonBrowseBanks)
	ON_BN_CLICKED(IDC_BROWSE_CLASSES, OnButtonBrowseClasses)
	ON_BN_CLICKED(IDC_BROWSE_FAMILIES, OnButtonBrowseFamilies)
	ON_BN_CLICKED(IDC_BROWSE_LEVELS, OnButtonBrowseLevels)
	ON_BN_CLICKED(IDC_BROWSE_TEXTURES, OnButtonBrowseTextures)

	// main options
	ON_BN_CLICKED(IDC_CHECK_RAYMAN2, OnRayman2)
	ON_BN_CLICKED(IDC_CHECK_MODIFLST, OnModifLst)
	ON_BN_CLICKED(IDC_CHECK_ERASEMOD, OnEraseMdf)

	// listbox functions
	ON_LBN_SELCHANGE(IDC_LISTBOX_TYPES, OnSelchangeListType)
	ON_WM_DRAWITEM()

	// selection buttons
	ON_BN_CLICKED(IDC_BUTTON_SELECTALL, OnSelectAll)
	ON_BN_CLICKED(IDC_BUTTON_SELECTLIST, OnSelectList)
	ON_BN_CLICKED(IDC_BUTTON_CLEARLIST, OnClearList)
	ON_BN_CLICKED(IDC_BUTTON_CLEARALL, OnClearAll)
	// select config buttons
	ON_BN_CLICKED(IDC_BUTTON_CREATECONFIGSELECT, OnCreateConfigSelect)
	ON_BN_CLICKED(IDC_BUTTON_REGISTERCONFIGSELECT, OnRegisterConfigSelect)
	ON_BN_CLICKED(IDC_BUTTON_SAVECONFIGSELECT, OnSaveConfigSelect)
	ON_BN_CLICKED(IDC_BUTTON_DELETECONFIGSELECT, OnDeleteConfigSelect)
	ON_CBN_SELCHANGE(IDC_COMBO_CONFIGSELECT, OnChooseConfigSelect)
	ON_CBN_KILLFOCUS(IDC_COMBO_CONFIGSELECT, OnKillFocusComboChooseConfigSelect)
	ON_EN_KILLFOCUS(IDC_EDIT_CREATECONFIGSELECT, OnKillFocusEditCreateConfigSelect)
	ON_EN_KILLFOCUS(IDC_EDIT_REGISTERCONFIGSELECT, OnKillFocusEditRegisterConfigSelect)
	// convert button
	ON_BN_CLICKED(IDC_BUTTON_CONVERT, OnConvert)

	// conflict options
	ON_BN_CLICKED(IDC_CHECK_ZOO_MAX, OnCheckZooMax)
	ON_BN_CLICKED(IDC_CHECK_ZOO_EDS, OnCheckZooEds)
	ON_BN_CLICKED(IDC_CHECK_SCT_MAX, OnCheckSctMax)
	ON_BN_CLICKED(IDC_CHECK_SCT_EDS, OnCheckSctEds)
	ON_BN_CLICKED(IDC_CHECK_SPO_MAX, OnCheckSpoMax)
	ON_BN_CLICKED(IDC_CHECK_SPO_EDS, OnCheckSpoEds)
	ON_BN_CLICKED(IDC_CHECK_GMT_MAX, OnCheckGmtMax)
	ON_BN_CLICKED(IDC_CHECK_GMT_EDS, OnCheckGmtEds)
	ON_BN_CLICKED(IDC_CHECK_VMT_MAX, OnCheckVmtMax)
	ON_BN_CLICKED(IDC_CHECK_VMT_EDS, OnCheckVmtEds)
	// conversion options
	ON_BN_CLICKED(IDC_CHECK_COPYANIMS, OnCopyAnims)
	ON_BN_CLICKED(IDC_CHECK_COPYTEXTURES, OnCopyTextures)
	ON_BN_CLICKED(IDC_CHECK_GENERATERLI, OnGenerateRLI)
	ON_BN_CLICKED(IDC_CHECK_UPDATEGAMEDSC, OnUpdateGameDSC)
	// erase options
	ON_BN_CLICKED(IDC_CHECK_ERASEDUPLICATED, OnEraseDuplicated)
	ON_BN_CLICKED(IDC_CHECK_ERASEUNUSED, OnEraseUnused)
	// family options
	ON_BN_CLICKED(IDC_CHECK_FORCECOMMON, OnForceCommon)
	ON_BN_CLICKED(IDC_CHECK_FORCESPECIFIC, OnForceSpecific)
	ON_BN_CLICKED(IDC_CHECK_ASKFAMILY, OnAskFamily)
	// bank option
	ON_BN_CLICKED(IDC_CHECK_BASICFAMILY, OnCreateBasicFamily)

	// option configuration
	ON_BN_CLICKED(IDC_BUTTON_CREATECONFIGOPTION, OnCreateConfigOption)
	ON_BN_CLICKED(IDC_BUTTON_REGISTERCONFIGOPTION, OnRegisterConfigOption)
	ON_BN_CLICKED(IDC_BUTTON_SAVECONFIGOPTION, OnSaveConfigOption)
	ON_BN_CLICKED(IDC_BUTTON_DELETECONFIGOPTION, OnDeleteConfigOption)
	ON_CBN_SELCHANGE(IDC_COMBO_CONFIGOPTION, OnChooseConfigOption)
	ON_CBN_KILLFOCUS(IDC_COMBO_CONFIGOPTION, OnKillFocusComboChooseConfigOption)
	ON_EN_KILLFOCUS(IDC_EDIT_CREATECONFIGOPTION, OnKillFocusEditCreateConfigOption)
	ON_EN_KILLFOCUS(IDC_EDIT_REGISTERCONFIGOPTION, OnKillFocusEditRegisterConfigOption)


	//}}AFX_MSG_MAP
END_MESSAGE_MAP()




/****************************************************************************
*		Description:	Handle function for message WM_INITDIALOG
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
BOOL CDlgMain::OnInitDialog()
{
	TC_ITEM TabCtrlItem;
	RECT	stRect;
	RECT	stDlgRect;
	long	lDlgWidth;
	long	lDlgHeight;
	char	*p_szCommanLine;
	char	szVersion[25], *p_szVersion;
	char	szAnims[_MAX_PATH];
	char	szBanks[_MAX_PATH];
	char	szClasses[_MAX_PATH];
	char	szFamilies[_MAX_PATH];
	char	szLevels[_MAX_PATH];
	char	szTextures[_MAX_PATH];

	strcpy(g_szDirConfig,"");
	strcpy(g_szSelectConfig,"");
	strcpy(g_szOptionConfig,"");

	// save initial directory
	GetCurrentDirectory(256, g_sInitialDir);

	CDialog::OnInitDialog();
		
	// obtained the height and the width of the main window
	GetClientRect( &stDlgRect );
	lDlgWidth  = stDlgRect.right - stDlgRect.left + 1;
	lDlgHeight = stDlgRect.bottom - stDlgRect.top + 1;

	// get command line
	p_szCommanLine= AfxGetApp()->m_lpCmdLine;
	p_szCommanLine= _strlwr(p_szCommanLine);
	
	GetCurrentDirectory( MAX_PATH, g_szInitialDirectory );
	// analyse command line and INI file to get all the options
	m_fn_vInitAllOptions(p_szCommanLine, szAnims, szBanks, szClasses, szFamilies, szLevels, szTextures);

	// check datas
	m_fn_bWarningUser();
	
	// init buttons for game directories
	switch(g_iData)
	{
		case 0: 
			m_oCheckGameData.SetCheck(1);
			break;
		case 1: 
			m_oCheckGameSP1.SetCheck(1);
			break;
		case 2: 
			m_oCheckGameSP2.SetCheck(1);
			break;
	}
	if (!strcmp(g_stInitialData.szGameSpecific1, ""))
		m_oCheckGameSP1.EnableWindow(FALSE);
	if (!strcmp(g_stInitialData.szGameSpecific2, ""))
		m_oCheckGameSP2.EnableWindow(FALSE);

	// init buttons for raw directories
	switch(g_iRaw)
	{
		case 0: 
			m_oCheckRawData.SetCheck(1);
			break;
		case 1: 
			m_oCheckRawSP1.SetCheck(1);
			break;
		case 2: 
			m_oCheckRawSP2.SetCheck(1);
			break;
	}
	if (!strcmp(g_stInitialData.szRawSpecific1, ""))
		m_oCheckRawSP1.EnableWindow(FALSE);
	if (!strcmp(g_stInitialData.szRawSpecific2, ""))
		m_oCheckRawSP2.EnableWindow(FALSE);
	
	// init buttons for main options
	m_oCheckRayman2.SetCheck(g_bRaymanII);
	m_oCheckModifLst.SetCheck(g_bModifLst);
	m_oCheckEraseMdf.SetCheck(g_bEraseMdf);

	// init buttons for options
	m_fn_vSetOptions();
	if (g_bAskFamily)
	{	
		m_oCheckCommon.EnableWindow(FALSE);
		m_oCheckSpecific.EnableWindow(FALSE);
	}

	// Create a richEdit control in the result panel
	GetDlgItem( IDC_STATIC_RESULTEDIT)->GetWindowRect( &stRect );
	m_oRichEditRes.Create
		( 
			WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | WS_VSCROLL |  ES_MULTILINE | ES_READONLY, 
			stRect, 
			this, 
			IDC_RICHEDIT_RESULT 
		);
	m_oRichEditRes.SetBackgroundColor( FALSE, RGB( 255, 255,255) );
	m_oRichEditRes.GetDefaultCharFormat( m_stCharFormatRes );
	m_stCharFormatRes.dwEffects = 0;
	m_stCharFormatRes.crTextColor = RGB(255,255,255);
	strcpy ( m_stCharFormatRes.szFaceName, "Arial" );
	m_stCharFormatRes.dwMask = CFM_COLOR | CFM_BOLD | CFM_FACE;
	m_oRichEditRes.SetDefaultCharFormat( m_stCharFormatRes );

	// the same for the command rich edit control 
	GetDlgItem( IDC_STATIC_COMMANDEDIT)->GetWindowRect( &stRect );
	stRect.top -= 23;
	m_oRichEditCom.Create
		( 
			WS_BORDER | WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | ES_READONLY, 
			stRect, 
			this, 
			IDC_RICHEDIT_COMMAND 
		);
	HWND hwnd = m_oRichEditCom.m_hWnd;
	::SetProp(hwnd, "class", (HANDLE)this);
	::SetProp(hwnd, "wproc", (HANDLE)SetWindowLong(hwnd, GWL_WNDPROC, (long)Command));
	m_oRichEditCom.SetBackgroundColor( FALSE, RGB( 255, 255,255) );
	m_oRichEditCom.GetDefaultCharFormat( m_stCharFormatCom );
	m_stCharFormatCom.dwEffects = 0;
	m_stCharFormatCom.crTextColor = RGB(0,0,0);
	strcpy ( m_stCharFormatCom.szFaceName, "Arial" );
	m_stCharFormatCom.dwMask = CFM_COLOR | CFM_BOLD | CFM_FACE;
	m_oRichEditCom.SetDefaultCharFormat( m_stCharFormatCom );

	HWND hwnd1 = m_oEditRawSp1.m_hWnd;
	::SetProp(hwnd1, "class", (HANDLE)this);
	::SetProp(hwnd1, "wproc", (HANDLE)SetWindowLong(hwnd1, GWL_WNDPROC, (long)CommandRawSp1));

	HWND hwnd2 = m_oEditRawSp2.m_hWnd;
	::SetProp(hwnd2, "class", (HANDLE)this);
	::SetProp(hwnd2, "wproc", (HANDLE)SetWindowLong(hwnd2, GWL_WNDPROC, (long)CommandRawSp2));

	HWND hwnd3 = m_oEditGameSp1.m_hWnd;
	::SetProp(hwnd3, "class", (HANDLE)this);
	::SetProp(hwnd3, "wproc", (HANDLE)SetWindowLong(hwnd3, GWL_WNDPROC, (long)CommandGameSp1));

	HWND hwnd4 = m_oEditGameSp2.m_hWnd;
	::SetProp(hwnd4, "class", (HANDLE)this);
	::SetProp(hwnd4, "wproc", (HANDLE)SetWindowLong(hwnd4, GWL_WNDPROC, (long)CommandGameSp2));

	hwnd1 = m_oEditRegisterDir.m_hWnd;
	::SetProp(hwnd1, "class", (HANDLE)this);
	::SetProp(hwnd1, "wproc", (HANDLE)SetWindowLong(hwnd1, GWL_WNDPROC, (long)CommandRegisterDir));

	hwnd1 = m_oEditCreateDir.m_hWnd;
	::SetProp(hwnd1, "class", (HANDLE)this);
	::SetProp(hwnd1, "wproc", (HANDLE)SetWindowLong(hwnd1, GWL_WNDPROC, (long)CommandCreateDir));

	CWnd* cwnd = m_oComboChooseDir.GetTopWindow( );
	hwnd = ((CEdit *)cwnd)->m_hWnd;
	::SetProp(hwnd, "class", (HANDLE)this);
	::SetProp(hwnd, "wproc", (HANDLE)SetWindowLong(hwnd, GWL_WNDPROC, (long)CommandRenameDir));

	hwnd1 = m_oEditRegisterOption.m_hWnd;
	::SetProp(hwnd1, "class", (HANDLE)this);
	::SetProp(hwnd1, "wproc", (HANDLE)SetWindowLong(hwnd1, GWL_WNDPROC, (long)CommandRegisterOption));

	hwnd1 = m_oEditCreateOption.m_hWnd;
	::SetProp(hwnd1, "class", (HANDLE)this);
	::SetProp(hwnd1, "wproc", (HANDLE)SetWindowLong(hwnd1, GWL_WNDPROC, (long)CommandCreateOption));

	cwnd = m_oComboChooseOption.GetTopWindow( );
	hwnd = ((CEdit *)cwnd)->m_hWnd;
	::SetProp(hwnd, "class", (HANDLE)this);
	::SetProp(hwnd, "wproc", (HANDLE)SetWindowLong(hwnd, GWL_WNDPROC, (long)CommandRenameOption));

	hwnd1 = m_oEditRegisterSelect.m_hWnd;
	::SetProp(hwnd1, "class", (HANDLE)this);
	::SetProp(hwnd1, "wproc", (HANDLE)SetWindowLong(hwnd1, GWL_WNDPROC, (long)CommandRegisterSelect));

	hwnd1 = m_oEditCreateSelect.m_hWnd;
	::SetProp(hwnd1, "class", (HANDLE)this);
	::SetProp(hwnd1, "wproc", (HANDLE)SetWindowLong(hwnd1, GWL_WNDPROC, (long)CommandCreateSelect));

	cwnd = m_oComboChooseSelect.GetTopWindow( );
	hwnd = ((CEdit *)cwnd)->m_hWnd;
	::SetProp(hwnd, "class", (HANDLE)this);
	::SetProp(hwnd, "wproc", (HANDLE)SetWindowLong(hwnd, GWL_WNDPROC, (long)CommandRenameSelect));

	// write the version in the static 
	p_szVersion = szVersion + GetDlgItem( IDC_STATIC_VERSION)->GetWindowText( szVersion, 17);
	*p_szVersion++ = ' ';
	strcpy( p_szVersion, g_fVersion );
	GetDlgItem( IDC_STATIC_VERSION)->SetWindowText( szVersion);

	m_oEditRawSp1.ShowWindow(FALSE);
	m_oEditRawSp2.ShowWindow(FALSE);
	m_oEditGameSp1.ShowWindow(FALSE);
	m_oEditGameSp2.ShowWindow(FALSE);

	//insert the panels 	
	TabCtrlItem.mask = TCIF_TEXT;
    TabCtrlItem.pszText = "Standard";
	m_oConfigPanel.InsertItem( 0, &TabCtrlItem );
    TabCtrlItem.pszText = "Custom";
	m_oConfigPanel.InsertItem( 1, &TabCtrlItem );

	//insert the panels 	
	TabCtrlItem.mask = TCIF_TEXT;
    TabCtrlItem.pszText = "Options";
	m_oMainPanel.InsertItem( 0, &TabCtrlItem );
    TabCtrlItem.pszText = "Selection";
	m_oMainPanel.InsertItem( 1, &TabCtrlItem );
    TabCtrlItem.pszText = "Result";
	m_oMainPanel.InsertItem( 2, &TabCtrlItem );


	// init list pointers
	m_oListType = (CListBox *)GetDlgItem(IDC_LISTBOX_TYPES);
	m_oListObject = (CListBox *)GetDlgItem(IDC_LISTBOX_OBJECTS);

	// init controls for configs
	m_fn_vInitDirCombo();
	m_fn_vInitSelectCombo();
	m_fn_vInitOptionCombo();

	m_oEditRegisterOption.ShowWindow(FALSE);
	m_oEditCreateOption.ShowWindow(FALSE);

	m_oEditRegisterSelect.ShowWindow(FALSE);
	m_oEditCreateSelect.ShowWindow(FALSE);

	// at initializing show only the buttons for the first panel (Directories)
	m_fn_TabC_vShowControlsPanelDir() ;

	m_oEditRawSp1.SetWindowText(g_stInitialData.szRawSp1);
	m_oEditRawSp2.SetWindowText(g_stInitialData.szRawSp2);
	m_oEditGameSp1.SetWindowText(g_stInitialData.szGameSp1);
	m_oEditGameSp2.SetWindowText(g_stInitialData.szGameSp2);

	// update all
	m_bRun = !strcmp(p_szCommanLine, "");



	// show the window with its position and size
	m_bInit = TRUE;
	MoveWindow( &g_stWinPosSize.stMainPos );
  
	// init all system
	MLT_vInitSystem();
	m_nIndexLast = m_oRichEditRes.GetLineCount();

	// check if there is something to convert
	if (!strcmp(szAnims, "") && !strcmp(szBanks, "") &&  
		!strcmp(szClasses, "") && !strcmp(szFamilies, "") &&
		!strcmp(szLevels, "") && !strcmp(szTextures, "") && 
		!strcmp(g_szSelectConfig, "") && !m_bRun)
	{
		if (AfxMessageBox( "There is nothing to convert!", MB_OK))
		{	
			OnDestroy();
			return FALSE;
		}
	}

	// check the file lists
	if (!m_bRun)
	{	
		m_fn_vSetFromFileList(szBanks, "Banks");
		m_fn_vSetFromFileList(szAnims, "Anims");
		m_fn_vSetFromFileList(szClasses, "Classes");
		m_fn_vSetFromFileList(szFamilies, "Families");
		m_fn_vSetFromFileList(szLevels, "Levels");
		m_fn_vSetFromFileList(szTextures, "Textures");
		m_fn_vConvertData() ;
		OnDestroy();
	}

	return TRUE;  
}






/****************************************************************************
*		Description:	Handle function for message WM_PAINT
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::OnPaint() 
{
	CPaintDC dc(this); 

	CDialog::OnPaint();
}



/****************************************************************************
*		Description:	Handle function for message WM_SIZE
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::OnSize(UINT nType, int cx, int cy) 
{
	RECT	stRect;
	CWnd	*p_oWnd;
	int		iWnd;
	long	lWidth, lHeight, lTop, lBottom, lLeft;

	// default sizing
	CDialog::OnSize(nType, cx, cy);
	

	if (m_bInit)
	{
		if (nType != SIZE_MINIMIZED)
		{
			// resize the main panel
			p_oWnd = GetDlgItem( IDC_MAINPANEL );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			stRect.bottom = cy - 45;
			stRect.right = cx-27; 
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize QUIT button
			p_oWnd = GetDlgItem( IDC_BUTTON_QUIT );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lWidth = stRect.right - stRect.left;
			stRect.bottom = cy - 15;
			stRect.top = stRect.bottom - 20;
			stRect.right = cx-27; 
			stRect.left = stRect.right - lWidth;
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize HELP button
			p_oWnd = GetDlgItem( IDC_BUTTON_HELP );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			stRect.bottom = cy - 15;
			stRect.top = stRect.bottom - 20;
			stRect.right = cx-117; 
			stRect.left = stRect.right - lWidth;
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize version control
			p_oWnd = GetDlgItem( IDC_STATIC_VERSION );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lWidth = stRect.right-stRect.left;
			stRect.bottom = cy - 10;
			stRect.top = stRect.bottom - 20;
			stRect.right = cx-217; 
			stRect.left = stRect.right - lWidth;
			p_oWnd->MoveWindow(&stRect, FALSE);

// FIRST PANEL
			
			// resize the groups
			for (iWnd = 0; iWnd < m_cNbGroupButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiGroupButtons[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				stRect.right = cx-68; 
				p_oWnd->MoveWindow(&stRect, FALSE);
			}

	// source directories
	// ==================

			// resize the config panel
			p_oWnd = GetDlgItem( IDC_PANELCONFIGS );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			stRect.left = 40;
			stRect.top = 70;
			stRect.right = stRect.left + (cx - 125);
			stRect.bottom = stRect.top + 185;
			p_oWnd->MoveWindow(&stRect, FALSE);

		// standard config
		//---------------
	
			// resize name controls
			for (iWnd = 0; iWnd < m_cNbEditNameControls; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiEditNameControls[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				stRect.left = 45;
				stRect.right = stRect.left + lWidth;
				p_oWnd->MoveWindow(&stRect, FALSE);
			}
			// resize edit controls
			for (iWnd = 0; iWnd < m_cNbEditControls; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiEditControls[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				stRect.right = stRect.left + (cx - 285);
				p_oWnd->MoveWindow(&stRect, FALSE);
			}
			// resize browse controls
			for (iWnd = 0; iWnd < m_cNbBrowseButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiBrowseButtons[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				stRect.right = cx-97; 
				stRect.left = stRect.right - lWidth;
				p_oWnd->MoveWindow(&stRect, FALSE);
			}

		// custom config
		//---------------

			// resize config controls
			for (iWnd = 0; iWnd < m_cNbCustomConfigControls; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiCustomConfigControls[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				stRect.left = 50;
				stRect.right = stRect.left + lWidth; 
				p_oWnd->MoveWindow(&stRect, FALSE);
				if (iWnd == 0)
				{
					p_oWnd = GetDlgItem( IDC_EDIT_REGISTERCONFIGDIR );
					p_oWnd->MoveWindow(&stRect, FALSE);
				}
				if (iWnd == 2)
				{
					p_oWnd = GetDlgItem( IDC_EDIT_CREATECONFIGDIR );
					p_oWnd->MoveWindow(&stRect, FALSE);
				}
			}
			
			// resize static controls
			for (iWnd = 0; iWnd < m_cNbCustomStaticControls; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiCustomStaticControls[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				stRect.left = 160;
				stRect.right = stRect.left + lWidth; 
				p_oWnd->MoveWindow(&stRect, FALSE);
			}
			
			// resize edit controls
			for (iWnd = 0; iWnd < m_cNbCustomEditControls; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiCustomEditControls[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				stRect.left = 210;
				stRect.right = stRect.left + (cx - 340); 
				p_oWnd->MoveWindow(&stRect, FALSE);
			}

	// main options
	// ============

			// resize main option controls
			for (iWnd = 0; iWnd < m_cNbMainButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiMainButtons[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				stRect.left = stRect.right - lWidth;
				p_oWnd->MoveWindow(&stRect, FALSE);
			}


// SECOND PANEL

	// lists
	// =====

			// resize the message
			p_oWnd = GetDlgItem( IDC_STATIC_LISTMESSAGE );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			stRect.top = 50; 
			stRect.left = 30; 
			stRect.right = 250; 
			stRect.bottom = 200;
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize the type list
			p_oWnd = GetDlgItem( IDC_LISTBOX_TYPES );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			stRect.top = 50; 
			stRect.left = 30; 
			stRect.right = 140; 
			stRect.bottom = cy - 435;
			lBottom = stRect.bottom;
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize the object list
			p_oWnd = GetDlgItem( IDC_LISTBOX_OBJECTS );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			stRect.top = 50; 
			stRect.left = 145; 
			stRect.right = cx - 290; 
			stRect.bottom = cy - 60;
			p_oWnd->MoveWindow(&stRect, FALSE);


	// selection
	// =========


		// select config controls
		// ----------------------

			// resize the group select configs
			p_oWnd = GetDlgItem( IDC_GROUP_SELECTIONCONFIG );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lWidth = stRect.bottom - stRect.top;
			lHeight = stRect.bottom - stRect.top;
			stRect.left = 30; 
			stRect.right = 140; 
			stRect.top = lBottom + 15;
			stRect.bottom = stRect.top + lHeight;
			lLeft = stRect.left;
			lTop = stRect.top;
			lBottom = lTop + lHeight;
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize the select configs buttons
			for (iWnd = 0; iWnd < m_cNbSelectConfigButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiSelectConfigButtons[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				lHeight = stRect.bottom - stRect.top;
				stRect.left = lLeft + 10;
				stRect.right = stRect.left + lWidth; 
				stRect.top = lTop + 20 + iWnd*30;
				stRect.bottom = stRect.top + lHeight; 
				p_oWnd->MoveWindow(&stRect, FALSE);
				if (iWnd == 0)
				{
					p_oWnd = GetDlgItem( IDC_EDIT_REGISTERCONFIGSELECT );
					p_oWnd->MoveWindow(&stRect, FALSE);
				}
				if (iWnd == 2)
				{
					p_oWnd = GetDlgItem( IDC_EDIT_CREATECONFIGSELECT );
					p_oWnd->MoveWindow(&stRect, FALSE);
				}
			}

		// selection controls
		// ------------------

			// resize the group selection
			p_oWnd = GetDlgItem( IDC_GROUP_SELECTION);
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lWidth = stRect.bottom - stRect.top;
			lHeight = stRect.bottom - stRect.top;
			stRect.left = 30; 
			stRect.right = 140; 
			stRect.top = lBottom + 15;
			stRect.bottom = stRect.top + lHeight;
			lLeft = stRect.left;
			lTop = stRect.top;
			lBottom = lTop + lHeight;
			p_oWnd->MoveWindow(&stRect, FALSE);
			
			// resize the selection buttons
			for (iWnd = 0; iWnd < m_cNbSelectButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiSelectButtons[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				lHeight = stRect.bottom - stRect.top;
				stRect.left = lLeft + 15;
				stRect.right = stRect.left + lWidth; 
				stRect.top = lTop + 20 + iWnd*25;
				stRect.bottom = stRect.top + lHeight; 
				p_oWnd->MoveWindow(&stRect, FALSE);
			}

			// resize the clear buttons
			for (iWnd = 0; iWnd < m_cNbClearButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiClearButtons[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				lHeight = stRect.bottom - stRect.top;
				stRect.left = lLeft + 15;
				stRect.right = stRect.left + lWidth; 
				stRect.top = lTop + 75 + iWnd*25;
				stRect.bottom = stRect.top + lHeight; 
				p_oWnd->MoveWindow(&stRect, FALSE);
			}


	// conversion
	// ==========

			// resize the convert button
			p_oWnd = GetDlgItem( IDC_BUTTON_CONVERT );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lWidth = stRect.right - stRect.left;
			lHeight = stRect.bottom - stRect.top;
			stRect.left = 40; 
			stRect.right = stRect.left + lWidth;
			stRect.top = lBottom + 15;
			stRect.bottom = stRect.top + lHeight;
			p_oWnd->MoveWindow(&stRect, FALSE);


			
	// options
	// =======

		// configurations
		// ------------

			// resize group config
			p_oWnd = GetDlgItem( IDC_GROUP_CONFIG );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lHeight = stRect.bottom - stRect.top;
			stRect.right = cx - 50; 
			stRect.left = cx - 280;
			lWidth = stRect.bottom - stRect.top;
			stRect.top = 50;
			stRect.bottom = stRect.top + lHeight;
			lLeft = stRect.left;
			lTop = stRect.top;
			lBottom = lTop + lHeight;
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize the config controls
			for (iWnd = 0; iWnd < m_cNbOptionConfig; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiOptionConfig[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				lHeight = stRect.bottom - stRect.top;
				stRect.left = (iWnd < 2) ? lLeft + 9 + iWnd*(lWidth+10) : lLeft + 9;
				stRect.top = (iWnd < 2) ? lTop + 50 : lTop + 20;
				stRect.right = stRect.left + lWidth; 
				stRect.bottom = stRect.top + lHeight; 
				p_oWnd->MoveWindow(&stRect, FALSE);
				if (iWnd == 0)
				{
					p_oWnd = GetDlgItem( IDC_EDIT_REGISTERCONFIGOPTION );
					p_oWnd->MoveWindow(&stRect, FALSE);
				}
				if (iWnd == 2)
				{
					p_oWnd = GetDlgItem( IDC_EDIT_CREATECONFIGOPTION );
					p_oWnd->MoveWindow(&stRect, FALSE);
				}
				lLeft = (iWnd < 2) ? lLeft : stRect.right;
			}
			
		// conflict options
		// ----------------

			// resize the group ignore
			p_oWnd = GetDlgItem( IDC_GROUP_CONFLICT );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lWidth = stRect.right - stRect.left;
			lHeight = stRect.bottom - stRect.top;
			stRect.right = cx-50; 
			stRect.left = stRect.right - lWidth;
			stRect.top = lBottom + 15; 
			stRect.bottom = stRect.top + lHeight;
			lLeft = stRect.left;
			lTop = stRect.top + 5;
			lBottom = lTop + lHeight;
			p_oWnd->MoveWindow(&stRect, FALSE);

			for (iWnd = 0; iWnd < m_cNbConflictStaticButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem(m_a_uiConflictStaticButtons[iWnd]);
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				lHeight = stRect.bottom - stRect.top;
				stRect.left = lLeft + 7;
				stRect.right = stRect.left + lWidth; 
				stRect.top = lTop + 20 + iWnd * 20; 
				stRect.bottom = stRect.top + lHeight; 
				p_oWnd->MoveWindow(&stRect, FALSE);
			}
			lLeft += 150; 

			for (iWnd = 0; iWnd < m_cNbConflictMaxButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem(m_a_uiConflictMaxButtons[iWnd]);
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				lHeight = stRect.bottom - stRect.top;
				stRect.left = lLeft + 7;
				stRect.right = stRect.left + lWidth; 
				stRect.top = lTop + 20 + iWnd * 20; 
				stRect.bottom = stRect.top + lHeight; 
				p_oWnd->MoveWindow(&stRect, FALSE);
			}
			lLeft += 35; 

			for (iWnd = 0; iWnd < m_cNbConflictEdsButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem(m_a_uiConflictEdsButtons[iWnd]);
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				lHeight = stRect.bottom - stRect.top;
				stRect.left = lLeft + 7;
				stRect.right = stRect.left + lWidth; 
				stRect.top = lTop + 20 + iWnd * 20; 
				stRect.bottom = stRect.top + lHeight; 
				p_oWnd->MoveWindow(&stRect, FALSE);
			}
			
		// conversion options
		// ------------------

			// resize the group options
			p_oWnd = GetDlgItem( IDC_GROUP_OPTIONS );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lWidth = stRect.right - stRect.left;
			lHeight = stRect.bottom - stRect.top;
			stRect.right = cx-50; 
			stRect.left = stRect.right - lWidth;
			stRect.top = lBottom + 10; 
			stRect.bottom = stRect.top + lHeight;
			lLeft = stRect.left;
			lTop = stRect.top;
			lBottom = lTop + lHeight;
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize the options controls
			for (iWnd = 0; iWnd < m_cNbOptionButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiOptionButtons[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				lHeight = stRect.bottom - stRect.top;
				stRect.left = lLeft + 10;
				stRect.right = stRect.left + lWidth; 
				stRect.top = lTop + 15 + iWnd * 18; 
				stRect.bottom = stRect.top + lHeight;
				p_oWnd->MoveWindow(&stRect, FALSE);
			}

		// erase options
		// -------------

			// resize the group erase
			p_oWnd = GetDlgItem( IDC_GROUP_ERASE );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lWidth = stRect.right - stRect.left;
			lHeight = stRect.bottom - stRect.top;
			stRect.right = cx-50; 
			stRect.left = stRect.right - lWidth;
			stRect.top = lBottom + 10; 
			stRect.bottom = stRect.top + lHeight;
			lLeft = stRect.left;
			lTop = stRect.top;
			lBottom = lTop + lHeight;
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize the erase controls
			for (iWnd = 0; iWnd < m_cNbEraseButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiEraseButtons[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				lHeight = stRect.bottom - stRect.top;
				stRect.left = lLeft + 10;
				stRect.right = stRect.left + lWidth; 
				stRect.top = lTop + 15 + iWnd * 18; 
				stRect.bottom = stRect.top + lHeight;
				p_oWnd->MoveWindow(&stRect, FALSE);
			}

		// family options
		// --------------

			// resize the group families
			p_oWnd = GetDlgItem( IDC_GROUP_FAMILIES );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lWidth = stRect.right - stRect.left;
			lHeight = stRect.bottom - stRect.top;
			stRect.right = cx-50; 
			stRect.left = stRect.right - lWidth;
			stRect.top = lBottom + 10; 
			stRect.bottom = stRect.top + lHeight;
			lLeft = stRect.left;
			lTop = stRect.top;
			lBottom = lTop + lHeight;
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize the family controls
			for (iWnd = 0; iWnd < m_cNbFamilyButtons; iWnd ++)
			{
				p_oWnd = GetDlgItem( m_a_uiFamilyButtons[iWnd] );
				p_oWnd->GetWindowRect( &stRect );
				ScreenToClient( &stRect );
				lWidth = stRect.right - stRect.left;
				lHeight = stRect.bottom - stRect.top;
				stRect.left = lLeft + 10;
				stRect.right = stRect.left + lWidth; 
				stRect.top = lTop + 15 + iWnd * 18; 
				stRect.bottom = stRect.top + lHeight;
				p_oWnd->MoveWindow(&stRect, FALSE);
			}


			
// THIRD PANEL
			

	// command
	// =======

			// resize the command name
			p_oWnd = GetDlgItem( IDC_STATIC_COMMAND );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			stRect.left = 25; 
			stRect.top = 50;
			stRect.right = 150; 
			stRect.bottom = stRect.top + 12;
			p_oWnd->MoveWindow(&stRect, FALSE);

			// resize the command window
			p_oWnd = GetDlgItem( IDC_RICHEDIT_COMMAND );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			stRect.left = 25; 
			stRect.top = 70;
			stRect.right = cx - 57; 
			stRect.bottom = cy/3;
			p_oWnd->MoveWindow(&stRect, FALSE);

	// result
	// ======

			// resize the result name
			p_oWnd = GetDlgItem( IDC_STATIC_RESULT );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			stRect.left = 25; 
			stRect.top = cy/3 + 15;
			stRect.right = 100; 
			stRect.bottom = stRect.top + 12;
			p_oWnd->MoveWindow(&stRect, FALSE);
			
			// resize the result window
			p_oWnd = GetDlgItem( IDC_RICHEDIT_RESULT );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			stRect.left = 25; 
			stRect.top = cy/3 + 34;
			stRect.right = cx - 57; 
			stRect.bottom = cy-65-15;
			p_oWnd->MoveWindow(&stRect, FALSE);


	// progress
	// ========

			// resize Progress Bar
			p_oWnd = GetDlgItem( IDC_STATIC_PROGRESS );
			p_oWnd->GetWindowRect( &stRect );
			ScreenToClient( &stRect );
			lWidth = stRect.right - stRect.left;
			stRect.right = cx-64; 
			stRect.left = stRect.right - lWidth;
			stRect.top=cy-75;
			stRect.bottom=cy -52;
			p_oWnd->MoveWindow(&stRect, FALSE);



			Invalidate();
		}
	}
}


/****************************************************************************
*		Description:	Handle function for message WM_SIZING
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::OnSizing( UINT nSide, LPRECT lpRect )
{
	long lWidth = lpRect->right - lpRect->left + 1;
	long lHeight= lpRect->bottom - lpRect->top + 1;

	// the width cannot be less than C_iMainWindowWidth
	if (lWidth < C_iMainWindowWidth)
	{
		switch (nSide)
		{
			case WMSZ_LEFT:
			case WMSZ_TOPLEFT:
			case WMSZ_BOTTOMLEFT:
				lpRect->left = lpRect->right - C_iMainWindowWidth;
				break;
			case WMSZ_RIGHT:
			case WMSZ_TOPRIGHT:
			case WMSZ_BOTTOMRIGHT:
				lpRect->right = lpRect->left + C_iMainWindowWidth;
				break;
		}
	}

	// the height cannot be less than C_iMainWindowHeight
	if (lHeight < C_iMainWindowHeight)
	{
		switch (nSide)
		{
			case WMSZ_BOTTOM:
			case WMSZ_BOTTOMLEFT:
			case WMSZ_BOTTOMRIGHT:
				lpRect->bottom = lpRect->top + C_iMainWindowHeight;
				break;
			case WMSZ_TOP:
			case WMSZ_TOPLEFT:
			case WMSZ_TOPRIGHT:
				lpRect->top = lpRect->bottom - C_iMainWindowHeight;
		}
	}

	CDialog::OnSizing( nSide, lpRect );
}


/****************************************************************************
*		Description:	Handle function for message WM_DESTROY
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::OnDestroy()
{
	// save new position and size of the main window
	if (m_bInit)
	{
		GetWindowRect( &g_stWinPosSize.stMainPos );
		fn_IniData_vWriteWindowPosSize();
	}
	m_fn_vFreeMemory();
    MLT_vExitSystem();

	CDialog::OnDestroy();
}


/****************************************************************************
*		Description:	Handle function for message WM_CLOSE
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::OnClose()
{
	if (!m_bConversion) 
		CDialog::OnClose();
}



/****************************************************************************
*		Description:	Handle function for message BN_CLICKED on Quit button
*---------------------------------------------------------------------------
*		Revision date:                                      Author:         
*****************************************************************************/
void CDlgMain::OnQuit() 
{
	// check if the directory configuration
	if (g_bChangeComboDir && g_iCurrentIndexDir)
	{	
		int iResult = AfxMessageBox( "The current directory configuration was changed : if you do not save it before closing the dialog, the changes will be lost!\n Do you want to save the directory configuration ?", MB_YESNOCANCEL | MB_ICONEXCLAMATION );
		switch (iResult)
		{
			case IDYES:
				OnSaveConfigDir();
				break;
			case IDNO:
				break;
			case IDCANCEL:
				return;	
		}
	}

	// check if the selection configuration
	if (g_bChangeComboSelect && g_iCurrentIndexSelect)
	{	
		int iResult = AfxMessageBox( "The current selection configuration was changed : if you do not save it before closing the dialog, the changes will be lost!\n Do you want to save the selection configuration ?", MB_YESNOCANCEL | MB_ICONEXCLAMATION );
		switch (iResult)
		{
			case IDYES:
				OnSaveConfigSelect();
				break;
			case IDNO:
				break;
			case IDCANCEL:
				return;	
		}
	}

	// check if the selection configuration
	if (g_bChangeComboOption && g_iCurrentIndexOption)
	{	
		int iResult = AfxMessageBox( "The current option configuration was changed : if you do not save it before closing the dialog, the changes will be lost!\n Do you want to save the option configuration ?", MB_YESNOCANCEL | MB_ICONEXCLAMATION );
		switch (iResult)
		{
			case IDYES:
				OnSaveConfigOption();
				break;
			case IDNO:
				break;
			case IDCANCEL:
				return;	
		}
	}

	
	// if necessary, create file
	if (_access( g_szIniFile, 2) == -1)
		_chmod ( g_szIniFile, _S_IWRITE );

	// save main options
	WritePrivateProfileString( "MainOptions", "Version",   g_bRaymanII ? "RAYMANII" : "RAYMAN", g_szIniFile );
	WritePrivateProfileString( "MainOptions", "UpdateLst", g_bModifLst ? "TRUE"		: "FALSE",  g_szIniFile );
	WritePrivateProfileString( "MainOptions", "IgnoreMdf", g_bEraseMdf ? "TRUE"		: "FALSE",  g_szIniFile );
	
	// save default option config
	if (!g_iCurrentIndexOption)
	{
		// save ignore options
		WritePrivateProfileString( "Options", "IgnoreZoo", g_bIgnoreZoo ? "TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Options", "IgnoreSct", g_bIgnoreSct ? "TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Options", "IgnoreSpo", g_bIgnoreSpo ? "TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Options", "IgnoreGmt", g_bIgnoreGmt ? "TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Options", "IgnoreTex", g_bIgnoreTex ? "TRUE" : "FALSE", g_szIniFile );
		// save conversion options
		WritePrivateProfileString( "Conversion", "CopyAnims",		  g_bCopyAnims			?	"TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Conversion", "CopyTextures",	  g_bCopyTextures		?	"TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Conversion", "GenerateRLI",		  g_bGenerateRLI		?	"TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Conversion", "UpdateGameDSC",	  g_bUpdateGameDSC		?	"TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Conversion", "CreateBasicFamily", g_bCreateBasicFamily	?	"TRUE" : "FALSE", g_szIniFile );
		// save erase options
		WritePrivateProfileString( "Erase", "EraseDuplicated",	g_bEraseDuplicated	?	"TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Erase", "EraseUnused",		g_bEraseUnused		?	"TRUE" : "FALSE", g_szIniFile );
		// save family options
		WritePrivateProfileString( "Family", "CommonFamily",	g_bCommonFamily	?	"TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Family", "SpecificFamily",	g_bSpecificFamily	?	"TRUE" : "FALSE", g_szIniFile );
		WritePrivateProfileString( "Family", "AskFamily",		g_bAskFamily	?	"TRUE" : "FALSE", g_szIniFile );
	}

	// save current configurations
	WritePrivateProfileString( "CurrentConfigs", "DirMode",		g_bStandardConfig ? "Standard" : "Custom", g_szIniFile );
	WritePrivateProfileString( "CurrentConfigs", "Directories", g_szConfDirs[g_iCurrentIndexDir], g_szIniFile );
	WritePrivateProfileString( "CurrentConfigs", "Selections",	g_szConfSelects[g_iCurrentIndexSelect], g_szIniFile );
	WritePrivateProfileString( "CurrentConfigs", "Options",		g_szConfOptions[g_iCurrentIndexOption], g_szIniFile );

	CDialog::OnCancel();
}


