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

CXmlProjectSettings_VC7::CXmlProjectSettings_VC7()
{
	SetDefaults();
}

CXmlProjectSettings_VC7::~CXmlProjectSettings_VC7()
{}

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

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

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

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

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

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

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

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

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

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

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

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

bool CXmlProjectSettings_VC7::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, CXmlProjectPostGen::GetXmlNodeName(), postGen_);

	return true;
}

bool CXmlProjectSettings_VC7::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);
	
	postGen_.AppendToDOMDocument(xmlDoc, newElement);

	IXMLDOMNode* newOutNode;

	if (parentElement)
		hr = parentElement->appendChild(newElement, &newOutNode);
	else
		hr = xmlDoc->appendChild(newElement, &newOutNode);
	newOutNode->Release();

	return true;
}

void CXmlProjectSettings_VC7::Clear()
{
	postBuildPath_ = _T("");
	generationPath_ = _T("");
	classPrefix_ = _T("");
}

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

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

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

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

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

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

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

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

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