// XmlProjectSettings_Atl.cpp
//
#include "stdafx.h"
#include "XmlProjectSettings_Atl.h"

CXmlProjectSettings_Atl::CXmlProjectSettings_Atl()
{
	SetDefaults();
}

CXmlProjectSettings_Atl::~CXmlProjectSettings_Atl()
{}

cmString CXmlProjectSettings_Atl::GetGenerationPath() const
{
	return generationPath_;
}

void CXmlProjectSettings_Atl::SetGenerationPath(const cmString& generationPath)
{
	generationPath_ = generationPath;
}

cmString CXmlProjectSettings_Atl::GetClassPrefix() const
{
	return classPrefix_;
}

void CXmlProjectSettings_Atl::SetClassPrefix(const cmString& classPrefix)
{
	classPrefix_ = classPrefix;
}

cmString CXmlProjectSettings_Atl::GetFormPrefix() const
{
	return formPrefix_;
}

void CXmlProjectSettings_Atl::SetFormPrefix(const cmString& formPrefix)
{
	formPrefix_ = formPrefix;
}

bool CXmlProjectSettings_Atl::GetTestPrjGenerationEnabled() const
{
	return testPrjGenerationEnabled_;
}

void CXmlProjectSettings_Atl::SetTestPrjGenerationEnabled(bool testPrjGenerationEnabled)
{
	testPrjGenerationEnabled_ = testPrjGenerationEnabled;
}

bool CXmlProjectSettings_Atl::GetGUIGenerationEnabled() const
{
	return guiGenerationEnabled_;
}

void CXmlProjectSettings_Atl::SetGUIGenerationEnabled(bool GUIGenerationEnabled)
{
	guiGenerationEnabled_ = GUIGenerationEnabled;
}

bool CXmlProjectSettings_Atl::GetDeleteExistingFiles() const
{
	return deleteExistingFiles_;
}

void CXmlProjectSettings_Atl::SetDeleteExistingFiles(const bool deleteExistingFiles)
{
	deleteExistingFiles_ = deleteExistingFiles;
}

bool CXmlProjectSettings_Atl::BuildFromXml(IXMLDOMNode* node)
{
	Clear();

	ExtractMemberNode(node, _T("GenerationPath"), generationPath_);
	ExtractMemberNode(node, _T("ClassPrefix"), classPrefix_);
	ExtractMemberNode(node, _T("GenerateTestProject"), testPrjGenerationEnabled_);
	ExtractMemberNode(node, _T("DeleteExistingFiles"), deleteExistingFiles_);
	ExtractMemberNode(node, _T("GenerateGui"), guiGenerationEnabled_);
	ExtractMemberNode(node, _T("Enabled"), enabled_);
	ExtractMemberNode(node, _T("PostBuildPath"), postBuildPath_);
	ExtractMemberNode(node, _T("ResourcesOffset"), resourcesOffset_);
	ExtractMemberNode(node, _T("TypeLibraryName"), typeLibraryName_);
	ExtractMemberNode(node, _T("TypeLibraryGuid"), typeLibraryGuid_);
	ExtractMemberNode(node, _T("MainDialogClassGuid"), mainDialogClassGuid_);
	ExtractMemberNode(node, _T("MainDialogInterfaceGuid_"), mainDialogInterfaceGuid_);
	ExtractMemberNode(node, _T("DllFileNamePrefix"), dllFileNamePrefix_);
	ExtractMemberNode(node, CXmlProjectPostGen::GetXmlNodeName(), postGen_);

	return true;
}

bool CXmlProjectSettings_Atl::AppendToDOMDocument(IXMLDOMDocument2* xmlDoc, IXMLDOMElement* parentElement)
{
	IXMLDOMElement* newElement;
	HRESULT hr;

	hr = xmlDoc->createElement(CComBSTR((const TCHAR*)GetXmlNodeName()), &newElement);
   
	AppendMemberNode(_T("GenerationPath"), generationPath_, newElement, xmlDoc);
	AppendMemberNode(_T("ClassPrefix"), classPrefix_, newElement, xmlDoc);
	AppendMemberNode(_T("GenerateTestProject"), testPrjGenerationEnabled_, newElement, xmlDoc);
	AppendMemberNode(_T("DeleteExistingFiles"), deleteExistingFiles_, newElement, xmlDoc);
	AppendMemberNode(_T("GenerateGui"), guiGenerationEnabled_, newElement, xmlDoc);
	AppendMemberNode(_T("Enabled"), enabled_, newElement, xmlDoc);
	AppendMemberNode(_T("PostBuildPath"), postBuildPath_, newElement, xmlDoc);
	AppendMemberNode(_T("ResourcesOffset"), resourcesOffset_, newElement, xmlDoc);
	AppendMemberNode(_T("TypeLibraryName"), typeLibraryName_, newElement, xmlDoc);
	AppendMemberNode(_T("TypeLibraryGuid"), typeLibraryGuid_, newElement, xmlDoc);
	AppendMemberNode(_T("MainDialogClassGuid"), mainDialogClassGuid_, newElement, xmlDoc);
	AppendMemberNode(_T("MainDialogInterfaceGuid"), mainDialogInterfaceGuid_, newElement, xmlDoc);
	AppendMemberNode(_T("DllFileNamePrefix"), dllFileNamePrefix_, newElement, xmlDoc);

	postGen_.AppendToDOMDocument(xmlDoc, newElement);

	if (parentElement)
		hr = parentElement->appendChild(newElement, NULL);
	else
		hr = xmlDoc->appendChild(newElement, NULL);
	
	return true;
}

void CXmlProjectSettings_Atl::Clear()
{
	postBuildPath_ = _T("");
	generationPath_ = _T("");
	classPrefix_ = _T("");
	typeLibraryGuid_ = _T("");
	mainDialogClassGuid_ = _T("");
	mainDialogInterfaceGuid_ = _T("");
	dllFileNamePrefix_ = _T("");
}

void CXmlProjectSettings_Atl::SetDefaults()
{
	generationPath_ = _T("");
	classPrefix_ = _T("");
	dllFileNamePrefix_ = _T("");

	enabled_ = false;
	deleteExistingFiles_ = false;
	guiGenerationEnabled_ = false;
	testPrjGenerationEnabled_ = false;
	resourcesOffset_ = 10000;
}

bool CXmlProjectSettings_Atl::GetEnabled() const
{
	return enabled_;
}

void CXmlProjectSettings_Atl::SetEnabled(bool enabled)
{
	enabled_ = enabled;
}

cmString CXmlProjectSettings_Atl::GetPostBuildPath() const
{
	return postBuildPath_;
}

void CXmlProjectSettings_Atl::SetPostBuildPath(const cmString& postBuildPath)
{
	postBuildPath_ = postBuildPath;
}

int CXmlProjectSettings_Atl::GetResourcesOffset() const
{
	return resourcesOffset_;
}

void CXmlProjectSettings_Atl::SetResourcesOffset(int value)
{
	resourcesOffset_ = value;
}

cmString CXmlProjectSettings_Atl::GetTypeLibraryName() const
{
	return typeLibraryName_;
}

void CXmlProjectSettings_Atl::SetTypeLibraryName(const cmString& typeLibraryName)
{
	typeLibraryName_ = typeLibraryName;
}

cmString CXmlProjectSettings_Atl::GetTypeLibraryGuid() const
{
	return typeLibraryGuid_;
}

void CXmlProjectSettings_Atl::SetTypeLibraryGuid(const cmString& guid)
{
	typeLibraryGuid_ = guid;
}

cmString CXmlProjectSettings_Atl::GetMainDialogClassGuid() const
{
	return mainDialogClassGuid_;
}

void CXmlProjectSettings_Atl::SetMainDialogClassGuid(const cmString& guid)
{
	mainDialogClassGuid_ = guid;
}

cmString CXmlProjectSettings_Atl::GetMainDialogInterfaceGuid() const
{
	return mainDialogInterfaceGuid_;
}

void CXmlProjectSettings_Atl::SetMainDialogInterfaceGuid(const cmString& guid)
{
	mainDialogInterfaceGuid_ = guid;
}

CXmlProjectPostGen* CXmlProjectSettings_Atl::GetPostGenerationStep()
{
	return &postGen_;
}

cmString CXmlProjectSettings_Atl::GetDllFileNamePrefix() const
{
	return dllFileNamePrefix_;
}

void CXmlProjectSettings_Atl::SetDllFileNamePrefix(const cmString& prefix)
{
	dllFileNamePrefix_ = prefix;
}
