// AudioGet.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "AudioGet.h"
#include "AudioGetDlg.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\\AudioGet"
#define MASTER_REGISTRY_KEY	"Sony"

/////////////////////////////////////////////////////////////////////////////
// CAudioGetApp

BEGIN_MESSAGE_MAP(CAudioGetApp, CWinApp)
	//{{AFX_MSG_MAP(CAudioGetApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAudioGetApp construction

CAudioGetApp::CAudioGetApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CAudioGetApp object

CAudioGetApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CAudioGetApp initialization

BOOL CAudioGetApp::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 the registry key
	SetRegistryKey(_T(MASTER_REGISTRY_KEY));
	m_sAiboIP = GetProfileString("", IPADDRKEY, DEFAULT_AIBOIP);
	WriteProfileString("", IPADDRKEY, m_sAiboIP);

	CAudioGetDlg 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;
}
