// FdbProjectDialog.cpp : _xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgFiBfLiDfGiDiHiDjD_xHqqkZx_ _xZkqqHx_iDhEiDeAiDeDiDiL_xHqqkZx_
//

#include "stdafx.h"
#include "UtilFile.h"			// For FFGetFileExtension.
#include "UtilErr.h"			// For FFDebugTrace.
#include "FdbProjectDialog.h"	// This header.

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

/////////////////////////////////////////////////////////////////////////////
// FCFdbProjectDialog

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCFdbProjectDialog::FCFdbProjectDialog
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDfIiDgHiDiJiDeOiDfOiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	lpszDefExt		:_xZkqqHx_iDgGiDhEiDeIiDiLiDgHiCmMiKgHjCkDiOhBiCpAiOhHjCoIiBeC_xHqqkZx_
 *			lpszFileName	:_xZkqqHx_iDgGiDhEiDeIiDiLiDgHiCmMiDhEiDeAiDeDiDiLjGlMiCpAiOhHjCoIiBeC_xHqqkZx_
 *			dwFlags			:_xZkqqHx_iDfPiDeDiDeBiDiNiDePiDhEiDiJiDePiCpAiOhHjCoIiBeC_xHqqkZx_
 *			lpszFilter		:_xZkqqHx_iDhEiDeCiDiLiDfOiCpAiOhHjCoIiBeC_xHqqkZx_
 *			wcpMarkFile		:_xZkqqHx_iDgGiDeCiDiMiDeOiDgHiDiKiCkKiMjPiNpFjBmOiPnLiCmFiCkAiCoJiCkJjClCiCnHiCoJiClNiCnPiCmM_xHqqkZx_
 *							 _xZkqqHx_iDhEiDeAiDeDiDiLiCpAiOhHjCoIiBeC_xHqqkZx_
 *			pParentWnd		:_xZkqqHx_jAgFiDeFiDeCiDjDiDgIiDeFiCpAiOhHjCoIiBeC_xHqqkZx_
 *			wcpTitle		:_xZkqqHx_iDeFiDeCiDjDiDgIiDeFiDfOiDeDiDgHiDiLiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	_xZkqqHx_jHoBiCkGiCmOiBeBiDhEiDeCiDiLiDfOiCmJ_xHqqkZx_ "*.mdpj" _xZkqqHx_iCkKiOhHjCoIiClDiCoKiCmEiCkCiClNiCmGiClFiCmEiBeB_xHqqkZx_
 *			_xZkqqHx_iDgGiDeCiDiMiDeOiDgHiDiKiBhF_xHqqkZx_C:\Document\a.mdpj_xZkqqHx_iBhGiCpAiKeKiCkNiPoKiNiHiCpAiNgMiCkGiCoJiBeC_xHqqkZx_
 *			wcpMarkFile = "project.mdpj" _xZkqqHx_iCkKiOhHjCoIiClDiCoKiCmEiCkCiCoJiPoKiNiHiBeB_xHqqkZx_
 *			_xZkqqHx_iBhF_xHqqkZx_C:\Document\a.mdpj\project.mdpj_xZkqqHx_iBhGiCkKiDhEiDeAiDeDiDiLiCmGiClFiCmEjBlGiNnNiClFiCmEiCkCiCoKiCmO_xHqqkZx_
 *			_xZkqqHx_iDgGiDeCiDiMiDeOiDgHiDiKiBhF_xHqqkZx_C:\Document\a.mdpj_xZkqqHx_iBhGiCmNiDhBiDgCiDgHiClFiClNiCoAiCmMiCmGiClFiCmE_xHqqkZx_
 *			_xZkqqHx_iIlFiCoNiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.10.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
FCFdbProjectDialog::FCFdbProjectDialog (BOOL bOpenFileDialog,
										const wchar_t* wcpDefExt,
										const wchar_t* wcpFileName,
										DWORD dwFlags,
										const wchar_t* wcpFilter,
										const wchar_t* wcpMarkFile,
										HWND hwndParent,
										const wchar_t* wcpTitle,
										const DWORD* pCtrlIdArray,
										const wchar_t** pCtrlTextArray,
										size_t szCtrlTextCount,
										BOOL bIsJustifyWindow)
				: BASE_CLASS(	bOpenFileDialog,
								wcpDefExt,
								wcpFileName,
								dwFlags,
								wcpFilter,
								hwndParent,
								wcpTitle,
								pCtrlIdArray,
								pCtrlTextArray,
								szCtrlTextCount,
								bIsJustifyWindow)
{
	if (wcpMarkFile != NULL)
		m_wstrMarkFile = wcpMarkFile;
} // FCFdbProjectDialog::FCFdbProjectDialog.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCFdbProjectDialog::DoModal
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfPiDeDiDeBiDiNiDePiDeFiDeCiDjDiDgIiDeFiCpAiDiCiBfLiDfPiDiLiCmFjFfMiOkGiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iPeJjHlJiOjOiCmJiJjPiClDiCoKiClNiDhLiDfOiDjDiCmM_xHqqkZx_ID_xZkqqHx_iBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.10.15 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
DWORD FCFdbProjectDialog::DoModal ()
{
	// _xZkqqHx_jDmGiOkJiDhAiDfIjGlMiCmMjFmPjAjEiCpAiPiJiKpKiJlLiBeC_xHqqkZx_
	m_wstrPathName.Empty();

	// DoModal_xZkqqHx_iOjOiCmMiDgGiDeCiDiMiDeOiDgHiDiKiInKjDkOiCmF_xHqqkZx_OnFolderChanged_xZkqqHx_iKnGjAjEiCkKiMmEiCmOiCoKiCoJiCkKiBeB_xHqqkZx_
	// _xZkqqHx_iPiJiKpKiDgGiDeCiDiMiDeOiDgHiDiKiCkKiDhEiDeCiDiLiDfOiCmMiDhBiDgCiDgHjBmOiPnLiClOiCmGiClLiCmMiCnMiCnMiCgOiCgKiPeJjHlJiClFiCmEiClFiCnMiCkEiBeC_xHqqkZx_
	// _xZkqqHx_iClBiCoKiCpAjGgIiCkOiClNiCnPiCmJiBeBiPiJiKpKiDgGiDeCiDiMiDeOiDgHiDiKiCkKiDhEiDeCiDiLiDfOiCmMiDhBiDgCiDgHjBmOiPnLiCmMiPoKiNiHiCmN_xHqqkZx_
	// _xZkqqHx_iPiJiKpKiDgGiDeCiDiMiDeOiDgHiDiKiCpAiPoDiImKiCmJiInKjDkOiClHiCoJiPiIjHjNiCpAiNhDiCkEiBeC_xHqqkZx_

	if (m_ofn.lpstrFile == &m_vFileName.at(0))
	//----- _xZkqqHx_iDiBiDjDiDgPiBfLjFmPjAjEiCkKiDgPiDgCiDhEiDeAiCmGiClFiCmEiOgHiCoNiCoKiCmEiCkCiCoJiPoKiNiH_xHqqkZx_ -----
	{
		// _xZkqqHx_iPiJiKpKiDhEiDeAiDeDiDiLiCmMiDhEiDiLiDhAiDfIiBeCjHoBiBhF_xHqqkZx_C:\Document\*.doc_xZkqqHx_iBhGiCmIiCmHiBeC_xHqqkZx_
		WString wstrFilePath = TStrToWStr(m_ofn.lpstrFile);
		// _xZkqqHx_iDgGiDeCiDiMiDeOiDgHiDiKiDhAiDfIiBeCiDiPiBfLiDeOiCmGiClFiCmEiOgHiCkEiBeC_xHqqkZx_
		WString wstrDirPath = wstrFilePath;
		// _xZkqqHx_iPiJiKpKiDhEiDeAiDeDiDiLiCmMiDhEiDeAiDeDiDiLjGlMiCmMiCnNiBeCjHoBiBhF_xHqqkZx_*.doc_xZkqqHx_iBhGiCmIiCmHiBeC_xHqqkZx_
		WString wstrFileName = FFGetFileName(wstrFilePath);
		BOOL bHit;
		do
		{
			// _xZkqqHx_iDhEiDeCiDiLiDfOiCmJiDhBiDgCiDgHiClFiCmEiCkCiCoJiCkJiBeI_xHqqkZx_
			bHit = FALSE;
			// _xZkqqHx_iDgGiDeCiDiMiDeOiDgHiDiKiBeC_xHqqkZx_
			wstrDirPath = FFGetFileDirectory(wstrDirPath, TRUE);
			// _xZkqqHx_iDgGiDeCiDiMiDeOiDgHiDiKiCmMiKgHjCkDiOhBiBeC_xHqqkZx_
			WString wstrDirExt = FFGetFileExtension(wstrDirPath);
			long lIndex;
			for (lIndex = 0; !bHit; lIndex++)
			{
				WString wstrFilterExt;
				// _xZkqqHx_iOhHjCoIiDeDiDjDiDgGiDgCiDeOiDfIiCmMiDhEiDeCiDiLiDfOiCmMiDhEiDeAiDeDiDiLiKgHjCkDiOhBiCpAiOoGjDlOiBeC_xHqqkZx_
				if (!GetFilterFileExt(wstrFilterExt, lIndex)) break;
				if (wstrDirExt == wstrFilterExt)
				//----- _xZkqqHx_iDhEiDeCiDiLiDfOiCmMiKgHjCkDiOhBiCmGiDgGiDeCiDiMiDeOiDgHiDiKiCmMiKgHjCkDiOhBiCkKiIoKjChGiClHiCoJiPoKiNiH_xHqqkZx_ -----
				{
					if (!m_wstrMarkFile.IsEmpty() &&
						FFIsThereFile(wstrDirPath + L'\\' + m_wstrMarkFile) == FD_FILE_32)
					//----- _xZkqqHx_iDhGiDiNiDfHiDeGiDeOiDgHiDhEiDeAiDeDiDiLiCkKjCmKiPoNiDhEiDeAiDeDiDiLiCmGiClFiCmEjBlGiNnNiClHiCoJiPoKiNiH_xHqqkZx_ -----
					{
						// _xZkqqHx_iDhEiDeCiDiLiDfOiCmJiDhBiDgCiDgHiClFiCmEiCkCiCoJiBeC_xHqqkZx_
						bHit = TRUE;
					}
				}
			}
		} while (bHit);
		// _xZkqqHx_iDgPiDgCiDhEiDeAiCmJiPiJiKpKiDhEiDeAiDeDiDiLiCpAiLeMjIfOiBeC_xHqqkZx_
		_tcscpy(&m_vFileName.at(0), WStrToTStr(wstrDirPath + L'\\' + wstrFileName));
	}
	// Baseclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	return BASE_CLASS::DoModal();
} // FCFdbProjectDialog::DoModal.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCFdbProjectDialog::GetPathName
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfPiDeDiDeBiDiNiDePjFfMiOkGiOjOiCmNiBeBiMlLiNnNiDhEiDeAiDeDiDiLiDiKiDfIiDgHiCmFjBeJjBpAiClDiCoKiCmEiCkCiCoJiDhEiDeAiDeDiDiL_xHqqkZx_
 *			_xZkqqHx_iIlNiCkCiCmNiDgGiDeCiDiMiDeOiDgHiDiKiCmMiDhEiDiLiDhAiDfIiCpAjFnEiClHiBeC_xHqqkZx_
 *			_xZkqqHx_iDfPiDeDiDeBiDiNiDePiCmMiPeJjHlJiOjOiCmNiBeBjDlOiCoHiCoKiClNiDhEiDeAiDeDiDiLiIlNiCkCiCmNiDgGiDeCiDiMiDeOiDgHiDiKiCmM_xHqqkZx_
 *			_xZkqqHx_iDhEiDiLiDhAiDfIiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iDhEiDeAiDeDiDiLiCmMiDhEiDiLiDhAiDfIjGlMiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	06.01.23 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
WString FCFdbProjectDialog::GetPathName () const
{
	if (!::IsWindow(m_hWnd) && !m_wstrPathName.IsEmpty())
	//----- _xZkqqHx_iDfPiDeDiDeBiDiNiDePjEpBjFfMiOkGiOjOiBjFjDmGiOkJiDhAiDfIiCkKjAnNjCoIiClDiCoKiCmEiCkCiCoJiPoKiNiH_xHqqkZx_ -----
	{
		// _xZkqqHx_jDmGiOkJiDhAiDfIjGlMiCmMjFmPjAjEiCpAjFnEiClHiBeC_xHqqkZx_
		return m_wstrPathName;
	} else
	{
		// Baseclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
		return BASE_CLASS::GetPathName();
	}
} // FCFdbProjectDialog::GetPathName.

/////////////////////////////////////////////////////////////////////////////
// _xZkqqHx_iDiGiBfLiDfFiKnGjAjEiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCFdbProjectDialog::OnOK
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	OK_xZkqqHx_iDhLiDfOiDjDiCkKiJjPiClDiCoKiClNiCmGiCkLiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jCiNiInD_xHqqkZx_>	_xZkqqHx_jCmKiPoNiCmMiDfPiDeDiDeBiDiNiDePiCmM_xHqqkZx_OnOK_xZkqqHx_iCmGiCmNiIoBiCkEiBeCiDiGiBfLiDfFjCoIiLgAiCmM_xHqqkZx_virtual_xZkqqHx_iKnGjAjEiCmFiCkAiCoIiBeB_xHqqkZx_
 *			myDlgProc_xZkqqHx_iCkJiCoHiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.10.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCFdbProjectDialog::OnOK ()
{
	// Superclass_xZkqqHx_iKnGjAjEiBeC_xHqqkZx_
	BASE_CLASS::OnOK();
} // FCFdbProjectDialog::OnOK.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCFdbProjectDialog::OnFileSelchanged
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhEiDeAiDeDiDiLiCmMiDiKiDfIiDgHiDfCiDjDiDgHiDiNiBfLiDiLiCmMjBeJjBpAiCkKjFmPiNfIiClDiCoKiClNiCmGiCkLiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.10.13 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCFdbProjectDialog::OnFileSelchanged ()
{
	// _xZkqqHx_iMlLiNnNiCmMiDhEiDeCiDiLiDfOiBfLiCmMiDhEiDeAiDeDiDiLiKgHjCkDiOhBiCpAiOoGjDlOiBeC_xHqqkZx_
	WString wstrExt;
	GetFilterFileExt(wstrExt, GetCurrentFilterIndex());
	// _xZkqqHx_iDhEiDeAiDeDiDiLiCmMiKgHjCkDiOhBiCpAiDgAiDeGiDgCiDeOiBeC_xHqqkZx_
	if (GetPathName().Find(L'*') == -1 &&
		FFGetFileExtension(GetPathName()) == wstrExt)
	{
		if (FFIsThereFile(GetPathName()) == FD_FILE_DIRECTORY)
		//----- _xZkqqHx_iDgGiDeCiDiMiDeOiDgHiDiKiCkKjBlGiNnNiClHiCoJ_xHqqkZx_ -----
		{
			if (!m_wstrMarkFile.IsEmpty() &&
				FFIsThereFile(GetPathName() + L'\\' + m_wstrMarkFile) == FD_FILE_32)
			//----- _xZkqqHx_iDhGiDiNiDfHiDeGiDeOiDgHiDhEiDeAiDeDiDiLiCkKjCmKiPoNiDhEiDeAiDeDiDiLiCmGiClFiCmEjBlGiNnNiClHiCoJiPoKiNiH_xHqqkZx_ -----
			{
				// _xZkqqHx_iDhEiDeAiDeDiDiLjGlMiCmMiDeHiDgGiDeCiDgCiDgHiDhLiDgCiDeOiDfIiCpAiPeDjAlDiBeC_xHqqkZx_
				SetFileName(FFGetFileName(GetPathName()));
			}
		}
	}
	// Baseclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnFileSelchanged();
} // FCFdbProjectDialog::OnFileSelchanged.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCFdbProjectDialog::OnFolderChanged
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhEiDeIiDiLiDfPiCkKjFmPiNfIiClDiCoKiClNiCmGiCkLiCmJiOmAiNhDiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	05.10.14 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCFdbProjectDialog::OnFolderChanged ()
{
	FFDebugTrace(L"FCFdbProjectDialog::OnFolderChanged %s %s %s\n",
			(const wchar_t*)GetFolderPath(),
			(const wchar_t*)GetFileName(),
			(const wchar_t*)GetPathName());

	// _xZkqqHx_iMlLiNnNiCmMiDhEiDeCiDiLiDfOiBfLiCmMiDhEiDeAiDeDiDiLiKgHjCkDiOhBiCpAiOoGjDlOiBeC_xHqqkZx_
	WString wstrExt;
	GetFilterFileExt(wstrExt, GetCurrentFilterIndex());
	// _xZkqqHx_iDhEiDeIiDiLiDfPiCmMiKgHjCkDiOhBiCpAiDgAiDeGiDgCiDeOiBeC_xHqqkZx_
	if (GetFolderPath().Find(L'*') == -1 &&
		FFGetFileExtension(GetFolderPath()) == wstrExt)
	{
		if (!m_wstrMarkFile.IsEmpty() &&
			FFIsThereFile(GetFolderPath() + L'\\' + m_wstrMarkFile) == FD_FILE_32)
		//----- _xZkqqHx_iDhGiDiNiDfHiDeGiDeOiDgHiDhEiDeAiDeDiDiLiCkKjCmKiPoNiDhEiDeAiDeDiDiLiCmGiClFiCmEjBlGiNnNiClHiCoJiPoKiNiH_xHqqkZx_ -----
		{
			// _xZkqqHx_jDmGiOkJiDhAiDfIjGlMiCpAjAnNjCoIiBeC_xHqqkZx_
			m_wstrPathName = GetFolderPath();
//----- 06.04.20 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//			// OK_xZkqqHx_iDhLiDfOiDjDiPiIjHjNiBeC_xHqqkZx_
//			TwPostMessage(WM_COMMAND, IDOK, 0L);
//----- 06.04.20 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
			// _xZkqqHx_iDfPiDeDiDeBiDiNiDePiCpAjChIiJiEiPeJjHlJiClDiClJiCoJiBeC_xHqqkZx_
			EndDialog(TwGetHwnd(), IDOK);
//----- 06.04.20 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
		}
	}
	// Baseclass_xZkqqHx_iKnGjAjEiOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnFolderChanged();
} // FCFdbProjectDialog::OnFolderChanged.

