// BaseClient.cpp :  Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "BaseClient.h"
#include "BaseClientDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define	IPADDRKEY			"AIBO-IP"
#define	DEFAULT_AIBOIP		"10.0.1.100"
#define APPLICATION_NAME	"VirtualAIBO\\RemoteTest"
#define MASTER_REGISTRY_KEY	"Sony"

/////////////////////////////////////////////////////////////////////////////
// CBaseClientApp

BEGIN_MESSAGE_MAP(CBaseClientApp, CWinApp)
	//{{AFX_MSG_MAP(CBaseClientApp)
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBaseClientApp construction

CBaseClientApp::CBaseClientApp()
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CBaseClientApp object

CBaseClientApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CBaseClientApp initialization

BOOL CBaseClientApp::InitInstance()
{
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	// Standard initialization

	// Reset Application name
	free((void*)m_pszAppName);
	m_pszAppName=_tcsdup(_T(APPLICATION_NAME));

	// Get AIBO's IP from registory key
	SetRegistryKey(_T(MASTER_REGISTRY_KEY));
	m_sAiboIP = GetProfileString("", IPADDRKEY, DEFAULT_AIBOIP);
	WriteProfileString("", IPADDRKEY, m_sAiboIP);

	CBaseClientDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		WriteProfileString("", IPADDRKEY, m_sAiboIP);
	}
	else if (nResponse == IDCANCEL)
	{
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
