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

CXmlProjectSettings_Cpp::CXmlProjectSettings_Cpp()
{
	SetDefaults();
}

CXmlProjectSettings_Cpp::~CXmlProjectSettings_Cpp()
{}

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

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

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

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

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

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

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

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

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

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

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

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

bool CXmlProjectSettings_Cpp::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("DllFileNamePrefix"), dllFileNamePrefix_);
	ExtractMemberNode(node, CXmlProjectPostGen::GetXmlNodeName(), postGen_);
	
	return true;
}

bool CXmlProjectSettings_Cpp::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("DllFileNamePrefix"), dllFileNamePrefix_, 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_Cpp::Clear()
{
	postBuildPath_ = _T("");
	generationPath_ = _T("");
	classPrefix_ = _T("");
	dllFileNamePrefix_ = _T("");
}

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

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

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

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

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

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

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

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

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

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

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