// DlgAddTextures.cpp : implementation file
//

#include "stdafx.h"
#include "Megatron.h"
#include "DlgAddTextures.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgAddTextures dialog


CDlgAddTextures::CDlgAddTextures(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgAddTextures::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgAddTextures)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgAddTextures::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgAddTextures)
	DDX_Control(pDX, IDC_LIST, m_wndList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgAddTextures, CDialog)
	//{{AFX_MSG_MAP(CDlgAddTextures)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgAddTextures message handlers

void CDlgAddTextures::OnOK() 
{
	if (m_pList)
	{
		int count = m_wndList.GetSelCount();
		int *items = new int[count];
		m_wndList.GetSelItems(count,items);
		for (int x=0;x<count;x++)
		{
			CString str;
			m_wndList.GetText(items[x],str);

			m_pList->AddTail(str);
		}
		delete items;
	}
	CDialog::OnOK();
}

BOOL CDlgAddTextures::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CFileFind find;
	int icount = 0;
	for (bool bmore = find.FindFile("content\\textures\\*.png");bmore;)
	{
		bmore = find.FindNextFile();
		CString str = find.GetFileTitle();
		if (m_pList)
		{
			str.MakeLower();
			POSITION pos = m_pList->Find(str);
			if (pos)
			{
				m_pList->RemoveAt(pos);
			}
			else
			{
				m_wndList.AddString(str);
			}
		}
		icount++;
	}
	find.Close();

	for (bmore = find.FindFile("content\\textures\\*.tga");bmore;)
	{
		bmore = find.FindNextFile();
		CString str = find.GetFileTitle();
		if (m_pList)
		{
			str.MakeLower();
			POSITION pos = m_pList->Find(str);
			if (pos)
			{
				m_pList->RemoveAt(pos);
			}
			else
			{
				m_wndList.AddString(str);
			}
		}
		icount++;
	}
	find.Close();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
