// ProppageFolders.cpp : implementation file
//

#include "stdafx.h"
#include "dslavsplit.h"
#include "ProppageFolders.h"

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

/////////////////////////////////////////////////////////////////////////////
// CProppageFolders property page

IMPLEMENT_DYNCREATE(CProppageFolders, CPropertyPage)

CProppageFolders::CProppageFolders() : CPropertyPage(CProppageFolders::IDD)
{
	//{{AFX_DATA_INIT(CProppageFolders)
	m_strContents = _T("");
	m_strVideos = _T("");
	//}}AFX_DATA_INIT
}

CProppageFolders::~CProppageFolders()
{
}

void CProppageFolders::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProppageFolders)
	DDX_Control(pDX, IDC_BUTTON_BROWSE_VIDEO, m_btnBrouseVideos);
	DDX_Control(pDX, IDC_BUTTON_BROWSE_CONTENTS, m_btnBrowseContents);
	DDX_Control(pDX, IDC_RICHEDIT_VIDEO_FILES, m_richEditVideos);
	DDX_Control(pDX, IDC_RICHEDIT_CONTENTS_FILES, m_richEditContents);
	DDX_Text(pDX, IDC_RICHEDIT_CONTENTS_FILES, m_strContents);
	DDX_Text(pDX, IDC_RICHEDIT_VIDEO_FILES, m_strVideos);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CProppageFolders, CPropertyPage)
	//{{AFX_MSG_MAP(CProppageFolders)
	ON_BN_CLICKED(IDC_BUTTON_BROWSE_CONTENTS, OnButtonBrowseContents)
	ON_BN_CLICKED(IDC_BUTTON_BROWSE_VIDEO, OnButtonBrowseVideo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProppageFolders message handlers

BOOL CProppageFolders::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// Note CSettingsDlg::SetSettingsData() has initialized:
	//  m_strContents
	//  m_strVideos	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CProppageFolders::OnButtonBrowseContents() 
{
	BROWSEINFO bi;
	memset((LPVOID)&bi, 0, sizeof(bi));
	TCHAR szDisplayName[_MAX_PATH];
	szDisplayName[0] = '\0';
	bi.hwndOwner = GetSafeHwnd();
	bi.pidlRoot = NULL;
	bi.pszDisplayName = szDisplayName;
	bi.lpszTitle = _T("Pick a folder used for Contents file storage:");
	bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; // BIF_USENEWUI for new folder

	LPITEMIDLIST pIIL = ::SHBrowseForFolder(&bi);

	TCHAR szInitialDir[_MAX_PATH];

	BOOL bRet = ::SHGetPathFromIDList(pIIL, (LPWSTR)&szInitialDir);
	
	if(bRet)
	{
		CString str = szInitialDir;
		if(!str.IsEmpty())
		{
			// Set member.
			m_strContents = str;
			UpdateData(FALSE);
		}
		LPMALLOC pMalloc;
		HRESULT hr = SHGetMalloc(&pMalloc);
		pMalloc->Free(pIIL);
		pMalloc->Release();
	}	
}
void CProppageFolders::OnButtonBrowseVideo() 
{
	BROWSEINFO bi;
	memset((LPVOID)&bi, 0, sizeof(bi));
	TCHAR szDisplayName[_MAX_PATH];
	szDisplayName[0] = '\0';
	bi.hwndOwner = GetSafeHwnd();
	bi.pidlRoot = NULL;
	bi.pszDisplayName = szDisplayName;
	bi.lpszTitle = _T("Pick a folder used for Video file storage:");
	bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; // BIF_USENEWUI for new folder

	LPITEMIDLIST pIIL = ::SHBrowseForFolder(&bi);

	TCHAR szInitialDir[_MAX_PATH];

	BOOL bRet = ::SHGetPathFromIDList(pIIL, (LPWSTR)&szInitialDir);
	
	if(bRet)
	{
		CString str = szInitialDir;
		if(!str.IsEmpty())
		{
			// Set member.
			m_strVideos = str;
			UpdateData(FALSE);
		}
		LPMALLOC pMalloc;
		HRESULT hr = SHGetMalloc(&pMalloc);
		pMalloc->Free(pIIL);
		pMalloc->Release();
	}
}
