// DlgOpt.cpp: implementation of the CDlgUpdateOptions class.
//
//////////////////////////////////////////////////////////////////////

#include "MainCPA.h"
#include "StdAfx.h"
#include "DlgOpt.h"

extern "C" tdstPreferences g_stPreferences;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

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


/*
----------------------------------------------------------------------------------------
Description   : Message Map
----------------------------------------------------------------------------------------
*/
BEGIN_MESSAGE_MAP(CDlgUpdateOptions, CDialog)
//{{AFX_MSG_MAP(CDlgUpdateOptions)
ON_BN_CLICKED(IDC_CHECK_BINARYDATA, OnCheckUseBinaryData)
//ON_BN_CLICKED(IDC_CHECK_ASK, OnCheckAskAtEachTime)
//ON_BN_CLICKED(IDC_CHECK_SAVE, OnCheckSavePrgPreferences)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/*
=======================================================================================
CUpdateOptionsDlg message handlers
=======================================================================================
*/

/*
----------------------------------------------------------------------------------------
Description   : WM_INITDIALOG
----------------------------------------------------------------------------------------
*/
BOOL CDlgUpdateOptions::OnInitDialog() 
{
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	CButton *p_oBtBinary, *p_oBtAsk, *p_oBtSave, *p_oBtBinaryDsc;
	CEdit	*p_EditDirectory;
	BOOL	bBinary, bAsk, bSave, bBinaryDsc;
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	
	CDialog::OnInitDialog();
	
	p_oBtBinary = (CButton *) GetDlgItem( IDC_CHECK_BINARYDATA );
	p_oBtAsk = (CButton *) GetDlgItem( IDC_CHECK_ASK );
	p_oBtSave = (CButton *) GetDlgItem( IDC_CHECK_SAVE );
	p_oBtBinaryDsc = (CButton *) GetDlgItem( IDC_CHECK_BINARYDSC );
	
	bBinary = (BOOL)g_stPreferences.cBinary;
	bAsk = (BOOL)g_stPreferences.cAsk;
	bSave = (BOOL)g_stPreferences.cSave;
    bBinaryDsc = (BOOL)g_stPreferences.cBinaryDsc;
	
	p_oBtBinary->SetCheck( bBinary ? 1 : 0 );
	p_oBtAsk->SetCheck( bAsk ? 1 : 0 );
	p_oBtSave->SetCheck( bSave ? 1 : 0 );
	p_oBtBinaryDsc->SetCheck( bBinaryDsc ? 1 : 0 );

	p_EditDirectory = (CEdit *) GetDlgItem( IDC_EDIT_DIRECTORY);
	if (bBinary)
		p_EditDirectory -> SetWindowText(g_stPreferences.szBinaryDirectory);
	else
		p_EditDirectory -> SetWindowText("GameData");
	
	return TRUE;  
}


/*
----------------------------------------------------------------------------------------
Description   : BN_CLICKED on IDOK button
----------------------------------------------------------------------------------------
*/
void CDlgUpdateOptions::OnOK() 
{
	g_stPreferences.cBinary =(char)((CButton *) GetDlgItem( IDC_CHECK_BINARYDATA))->GetCheck() == 1;
	g_stPreferences.cAsk = (char)((CButton *) GetDlgItem( IDC_CHECK_ASK ))->GetCheck() == 1;
	g_stPreferences.cSave = (char)((CButton *) GetDlgItem( IDC_CHECK_SAVE ))->GetCheck() == 1;
	g_stPreferences.cBinaryDsc =(char)((CButton *) GetDlgItem( IDC_CHECK_BINARYDSC))->GetCheck() == 1;

    if (g_stPreferences.cSave)
		GAM_fn_vSavePreferences();
	CDialog::OnOK();
}


/*
----------------------------------------------------------------------------------------
Description   : BN_CLICKED on IDC_CHECK_BINARYDATA
----------------------------------------------------------------------------------------
*/

void CDlgUpdateOptions::OnCheckUseBinaryData(void) 
{
	CEdit	*p_EditDirectory;
	p_EditDirectory = (CEdit *) GetDlgItem( IDC_EDIT_DIRECTORY);
	if (((CButton *) GetDlgItem( IDC_CHECK_BINARYDATA))->GetCheck() == 1)
		p_EditDirectory -> SetWindowText(g_stPreferences.szBinaryDirectory);
	else
		p_EditDirectory -> SetWindowText("GameData");

}


/*
----------------------------------------------------------------------------------------
Description   : BN_CLICKED on IDC_CHECK_ASK
----------------------------------------------------------------------------------------
*/
/*
void CDlgUpdateOptions::OnCheckAskAtEachTime(void) 
{
	g_stPreferences.cAsk = (char)((CButton *) GetDlgItem( IDC_CHECK_ASK ))->GetCheck() == 1;
}
*/
/*
----------------------------------------------------------------------------------------
Description   : BN_CLICKED on IDC_CHECK_SAVE
----------------------------------------------------------------------------------------
*/
/*
void CDlgUpdateOptions::OnCheckSavePrgPreferences(void) 
{
	g_stPreferences.cSave = (char)((CButton *) GetDlgItem( IDC_CHECK_SAVE ))->GetCheck() == 1;
}
*/