// NewMissionDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MW4GameEd2.h"
#include "NewMissionDlg.h"
#include <Adept\Resource.hpp>
#include <GameOS\ToolOS.hpp>


/////////////////////////////////////////////////////////////////////////////
// CNewMissionDlg dialog


CNewMissionDlg::CNewMissionDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNewMissionDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNewMissionDlg)
	m_MissionName = _T("");
	m_MapName = _T("");
	//}}AFX_DATA_INIT
}


void CNewMissionDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNewMissionDlg)
	DDX_Control(pDX, IDC_MAPLIST, m_MapList);
	DDX_Text(pDX, IDC_MISSIONNAME, m_MissionName);
	DDX_LBString(pDX, IDC_MAPLIST, m_MapName);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CNewMissionDlg message handlers

BOOL CNewMissionDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_MissionName="NewMission";
UpdateData(FALSE);
	
	WIN32_FIND_DATA file_data;
	HANDLE file_find;

	file_find=FindFirstFile("Resource\\Maps\\*.mw4",&file_data);
	
	if(file_find != INVALID_HANDLE_VALUE)
	{
		CString map_name;
		do
		{
			map_name=file_data.cFileName;
			map_name=map_name.Left(map_name.ReverseFind('.'));
			m_MapList.AddString(map_name);
		}
		while (FindNextFile(file_find,&file_data));
	}

	
/*
	
	Adept::ResourceFile *res_file;
	res_file=Adept::ResourceManager::Instance->GetResourceFile(0);
	Check_Object(res_file);
	Adept::Resource curres;
	curres.First(res_file);
	
	
	CString res_name,base_name,dir_name;
	while(res_file->ReadAndNext(&curres))
	{
		res_name=(char *)curres.GetName();
		res_name.MakeLower();
		int sloc=res_name.Find("skies\\");
		
	if(sloc!=-1)
		{									// This is a Data File
			
			base_name=res_name.Mid(sloc+strlen("skies\\"));
			base_name=base_name.Left(base_name.ReverseFind('.'));
			m_SkyList.AddString(base_name);
			m_NightSkyList.AddString(base_name);
		}
	}
*/
	m_MapList.SetCurSel(0);
//	m_SkyList.SetCurSel(0);
//	m_NightSkyList.SetCurSel(0);

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

void CNewMissionDlg::OnOK() 
{
UpdateData(TRUE);


if(gos_DoesFileExist("Content\\Missions\\"+m_MissionName))
{
MessageBox("A Mission with this Name Already Exists","Mission Created Error",MB_OK);
}
else
{
	CDialog::OnOK();
}
}
