Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Resource ID Organiser Add-In for Visual C++ 5.0/6.0/.NET

, 10 Jan 2005
An application/add-in to organise and renumber resource symbol IDs
resorg103.zip
resorg104.zip
resorgaddinsetup.zip
resorgaddin_executables.zip
resorgnetaddinsetup.zip
resorgnetaddin_executables.zip
resorgnet_executables.zip
ResOrgNET_executables
CJ609LibVc7.dll
NGLib103Vc7.dll
QHTMLight.dll
ResOrg.cnt
resorg.fts
ResOrg.hlp
ResOrgNETAddIn.dll
ResOrgNETAddInToolWindows.ocx
ResOrgNETCore.dll
resorg_demo.zip
resorg_executables.zip
resorg_src.zip
BXFileDialog
BXFileDialog.dsp
Lib
Release
Res
bitmap2.bmp
FileOpen.bmp
filesave.bmp
CJLibrary
CJLibrary
CJLibrary.def
CJLibrary.dsp
CJLibrary.dsw
CJLibrarydep.jpg
CJLibraryStatic.dsp
Debug_Unicode
Release
Release_Unicode
res
Include
res
btn_arro.bmp
btn_explorer.bmp
button_images.bmp
cj_logo.bmp
dragging.cur
handcur.cur
headerba.bmp
hsplitba.cur
icr_hand.cur
nodraggi.cur
PushPin.bmp
Toolbar.bmp
vsplitba.cur
Lib
NGLibrary
Bin
NGLibrary.def
NGLibrary.dsp
NGLibrary.dsw
Release
Res
Drives.bmp
Release
ResOrgAddIn
Release
Res
HtmlDoc.ico
ResOrg.ico
ResOrgDoc.ico
TBarLrge.bmp
TBarMedm.bmp
Toolbar.bmp
WorkspaceTabs.bmp
ResOrgAddIn.def
ResOrgAddIn.dsp
ResOrgAddIn.odl
ResOrgAddIn_Res.hm
ResOrgApp
Lint
Release
Res
HtmlDoc.ico
MAINFRAM.BMP
ResOrg.ico
ResOrgDoc.ico
TBarLrge.bmp
TBarMedm.bmp
Toolbar.bmp
workspace.ico
WorkspaceTabs.bmp
ResOrgApp.dsp
ResOrgApp_Res.hm
ResOrgApp_Res.resorg
ResOrgCore
Lint
Release
Res
Anna.bmp
BuildOptions.ico
ComCtl Version Prompt.rtf
File Reload Warning Ex.rtf
File Reload Warning.rtf
Global Next Symbol Value Warning Prompt.rtf
information.ico
Invalid Symbol Name.rtf
Mailing List Prompt.rtf
Next Symbol Value Warning Prompt.rtf
project context menu.bmp
project.ico
RenumWiz Completion.rtf
Report.ico
ResOrg Logo.bmp
ResOrg Updated.rtf
ResOrg.ico
resource file.ico
riverblade_logo.bmp
solution.ico
Symbol Delete Warning.rtf
Symbol Name Warning.rtf
Symbol Rename Warning.rtf
SymbolFile.ico
Symbols Delete Warning.rtf
sym_binary.ico
sym_bitmap.ico
sym_command.ico
sym_control.ico
sym_dialog.ico
sym_icon.ico
sym_menu.ico
sym_prompt.ico
sym_resource.ico
sym_string.ico
Toolbar.bmp
VcAddIn.ico
VersionCheck.ico
warning.ico
WizardHeader256.bmp
WizardWatermark256.bmp
ResOrgCore.def
ResOrgCore.dsp
ResOrgCore_Res.hm
ResOrgCore_Res.resorg
Xml
ProblemSymbolReportHtml.xsl
SymbolsReportHtml.xsl
ResOrgNETAddIn
AddIn.def
Release
Res
AddIn.rgs
HtmlDoc.ico
ResOrg.ico
ResOrgDoc.ico
Toolbar.bmp
WorkspaceTabs.bmp
ResOrgNETAddInSetup
Banner.jpg
Intro screen.jpg
Licence.rtf
ReadMe.rtf
Release
ResOrg.ico
ResOrgNETAddInSetup.vdproj
ResOrgNETAddInToolWindows
Release
Res
Edit.ico
Properties.ico
Renumber.ico
ResOrgNETAddInToolWindows.ico
ResOrgNETAddInToolWindowsCtrl.bmp
ResOrgNETAddInToolWindows.def
SatelliteDll
Release
res
AboutBoxCmd.bmp
OpenResOrgCmd.bmp
OptionsCmd.bmp
ViewMainToolWinCmd.bmp
/************************************************************************
 *
 *                 Resource ID Organiser Core Library
 *
 * (c) Copyright 2000-2004 by Anna-Jayne Metcalfe (resorg@annasplace.me.uk)
 *                         All rights reserved.
 *
 ************************************************************************
 *                                                                       
 *  Filename    : ResOrgXmlWriter.cpp
 *
 *  Description : CResOrgXmlWriter - class for writing XML files
 *                
 *  Compiler    : Microsoft Visual C++ 6.0, Service Pack 3 or later
 *                Microsoft Visual C++ .NET 2003
 *                                                                       
 *  Target                                                               
 *  Environment : Windows 98/NT/2000/XP
 *
 *  NOTE:
 *
 *    This software is provided "as is" free for personal use. All
 *    title and copyrights in and to the software, including but not
 *    limited to any images, text, etc. incorporated into it, are
 *    owned by Anna-Jayne Metcalfe, except where acknowledged otherwise.
 *
 *    Your may freely to use this code in your own products, PROVIDED
 *    this notice is not removed or modified.
 *
 *
 *    Visit http://www.annasplace.me.uk/resorg for latest updates
 *
 ************************************************************************
 *
 *   MODIFICATION HISTORY:
 *
 *           This is a controlled document. See project configuration
 *           control tool for latest version and full version history.
 *
 *    $Archive: /Projects/AddIns/ResOrg/ResOrgCore/ResOrgXmlWriter.cpp $
 *   $Revision: 8 $
 *       $Date: 29/08/04 21:12 $
 *     $Author: Anna $
 *
 *    $History: ResOrgXmlWriter.cpp $
 * 
 * *****************  Version 8  *****************
 * User: Anna         Date: 29/08/04   Time: 21:12
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * CResOrgXmlWriter::LoadSymbolFileConfig() now asks the associated
 * CResourceSymbolManager object to recalculate its problem symbol count
 * after loading a config file. Also guarded it against NULL
 * CResourceSymbolManager pointers
 * 
 * *****************  Version 7  *****************
 * User: Anna         Date: 29/08/04   Time: 10:49
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Added support for toolbars, accelerators and out of range symbols
 * 
 * *****************  Version 6  *****************
 * User: Anna         Date: 23/08/04   Time: 21:39
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Added support for out of range symbols
 * 
 * *****************  Version 5  *****************
 * User: Anna         Date: 27/06/03   Time: 21:12
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * CResOrgXmlWriter::SaveXml() now saves both internal and external
 * conflict counts
 * 
 * *****************  Version 4  *****************
 * User: Anna         Date: 20/04/03   Time: 15:47
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Replaced CException with CUserException to keep VS.NET happy
 * 
 * *****************  Version 3  *****************
 * User: Anna         Date: 15/04/03   Time: 20:48
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Implemented Load/SaveSymbolFileConfig()
 * 
 * *****************  Version 2  *****************
 * User: Anna         Date: 3/04/03    Time: 13:32
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Added CResOrgXmlWriter::LoadSymbolFileConfig() and
 * SaveSymbolFileConfig() [not used yet]
 * 
 * *****************  Version 1  *****************
 * User: Anna         Date: 3/03/03    Time: 20:07
 * Created in $/Projects/AddIns/ResOrg/ResOrgCore
 *
 * $Nokeywords: $
 *
 ************************************************************************/

#include "StdAfx.h"
#include <math.h>
#include "ResOrgCore_Priv.h"

#include "ResourceSymbol.h"
#include "ResourceSymbolManager.h"
#include "ResourceSymbolManagerMultiFile.h"

#include "ResOrgXmlWriter.h"



#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// CResOrgXmlWriter

CResOrgXmlWriter::CResOrgXmlWriter(void)
{
}


CResOrgXmlWriter::~CResOrgXmlWriter(void)
{
}




/////////////////////////////////////////////////////////////////////////////
// CResOrgXmlWriter implementation

static BOOL GetNodeValue(IXMLDOMNode* pParent,
						 const CString& sChildNodeName,
						 int eType,
						 _variant_t& rVal)
{
	MSXML2::IXMLDOMNodePtr ptrParent(pParent);

	if (ptrParent != NULL)
	{
		MSXML2::IXMLDOMNodePtr ptrNode = ptrParent->selectSingleNode( (LPCTSTR)sChildNodeName);

		if (ptrNode != NULL)
		{
			for (MSXML2::IXMLDOMNodePtr pChild = ptrNode->firstChild;
				 NULL != pChild;
				 pChild = pChild->nextSibling)
			{
				if (pChild->GetnodeType() == (MSXML2::tagDOMNodeType)eType)
				{
					rVal = pChild->GetnodeValue();

					return true;
				}
			}
		}
	}
	return false;
}


HRESULT CResOrgXmlWriter::LoadSymbolFileConfig(	CResourceSymbolManager* pManager,
												IXMLDOMDocument* pDOMDoc,
												CString* psErrorMsg /*= NULL*/)
{
	if (NULL == pManager)
	{
		ASSERT(false);
		return E_FAIL;
	}

	CString sErrorMsg;
	
	MSXML2::IXMLDOMDocumentPtr ptrDOMDoc(pDOMDoc);

	HRESULT hr = E_FAIL;
	try
	{
		MSXML2::IXMLDOMElementPtr ptrRoot = ptrDOMDoc->documentElement;
		if (ptrRoot == NULL)
		{   
			sErrorMsg = _T("Unable to locate the root tag");

			throw new CUserException;
		}

		_variant_t value;
 /*		if (!GetNodeValue( (IXMLDOMNode*)ptrRoot.GetInterfacePtr(),
							_T("ResOrgConfigFile"),
							MSXML2::NODE_TEXT,
							value) )
		{
			sErrorMsg = _T("Failed to detect the ResOrgConfigFile tag");

			throw new CUserException;
		}
*/
		MSXML2::IXMLDOMNodePtr ptrFile = ptrRoot->selectSingleNode( _T("File") );
		if (ptrFile == NULL)
		{
			sErrorMsg = _T("Unable to locate the File tag");

			throw new CUserException;
		}

		if (!GetNodeValue( (IXMLDOMNode*)ptrFile.GetInterfacePtr(),
							_T("PathName"),
							MSXML2::NODE_TEXT,
							value) )
		{
			sErrorMsg = _T("Unable to locate the PathName tag");

			throw new CUserException;
		}

		CString sPathName = (LPCTSTR)(_bstr_t)value;

		// TODO Check FileName NOT Pathname

		MSXML2::IXMLDOMNodePtr ptrBaseValues = ptrFile->selectSingleNode( _T("BaseValues") );
		if (ptrBaseValues != NULL)
		{
			IXMLDOMNode* pBaseValues = (IXMLDOMNode*)ptrBaseValues.GetInterfacePtr();

			if (GetNodeValue(	pBaseValues,
								_T("Resources"),
								MSXML2::NODE_TEXT,
								value) )
			{
				UINT uBaseResourceValue = (long)value;
			
				pManager->SetBaseResourceValue(uBaseResourceValue);
			}

			if (GetNodeValue(	pBaseValues,
								_T("Controls"),
								MSXML2::NODE_TEXT,
								value) )
			{
				UINT uBaseControlValue = (long)value;

				pManager->SetBaseControlValue(uBaseControlValue);
			}

			if (GetNodeValue(	pBaseValues,
								_T("Commands"),
								MSXML2::NODE_TEXT,
								value) )
			{
				UINT uBaseCommandValue = (long)value;

				pManager->SetBaseCommandValue(uBaseCommandValue);
			}
		}
		hr = S_OK;
	}
	catch(_com_error& e)
	{
		hr = e.Error();

		if (sErrorMsg.IsEmpty() )
		{
			sErrorMsg.Format("CResOrgXmlWriter::LoadSymbolFileConfig(): Exception 0x%08x", hr);
		}
	}

	catch(CUserException* e)
	{
		e->Delete();
	}

	if (NULL != psErrorMsg)
	{
		*psErrorMsg = sErrorMsg;
	}

	// As the manager's base values are likely to have changed,
	// we need to ask it to update its problem symbol counts.
	pManager->CountConflicts();

	return hr;
}


HRESULT CResOrgXmlWriter::SaveSymbolFileConfig(	CResourceSymbolManager* pManager,
												IXMLDOMDocument* pDOMDoc,
												CString* psErrorMsg /*= NULL*/)
{
	if (NULL == pManager)
	{
		return E_FAIL;
	}

	MSXML2::IXMLDOMDocumentPtr ptrDOMDoc(pDOMDoc);

	HRESULT hr = S_OK;
	try
	{
		// Create root element
		MSXML2::IXMLDOMElementPtr ptrRoot = ptrDOMDoc->createElement(_T("ResOrgConfigFile") );
		ptrDOMDoc->appendChild(ptrRoot);

		MSXML2::IXMLDOMElementPtr ptrFile = ptrDOMDoc->createElement( _T("File") );

		MSXML2::IXMLDOMAttributePtr ptrNameAttr = ptrDOMDoc->createAttribute(_T("name"));
		ptrNameAttr->value = (LPCTSTR)pManager->GetFileName();
		ptrFile->setAttributeNode(ptrNameAttr);
		
		ptrRoot->appendChild(ptrFile);

		MSXML2::IXMLDOMElementPtr ptrPathName = ptrDOMDoc->createElement( _T("PathName") );
		ptrPathName->text = (LPCTSTR)pManager->GetPathName();
		ptrFile->appendChild(ptrPathName);

		// General Resources
		MSXML2::IXMLDOMElementPtr ptrBaseValues = ptrDOMDoc->createElement( _T("BaseValues") );
		ptrFile->appendChild(ptrBaseValues);

		MSXML2::IXMLDOMElementPtr ptrBaseResourceValue = ptrDOMDoc->createElement( _T("Resources") );
		ptrBaseResourceValue->text = (LPCTSTR)::UIntToStr( pManager->GetBaseResourceValue() );
		ptrBaseValues->appendChild(ptrBaseResourceValue);

		MSXML2::IXMLDOMElementPtr ptrBaseControlValue = ptrDOMDoc->createElement( _T("Controls") );
		ptrBaseControlValue->text = (LPCTSTR)::UIntToStr( pManager->GetBaseControlValue() );
		ptrBaseValues->appendChild(ptrBaseControlValue);

		MSXML2::IXMLDOMElementPtr ptrBaseCommandValue = ptrDOMDoc->createElement( _T("Commands") );
		ptrBaseCommandValue->text = (LPCTSTR)::UIntToStr( pManager->GetBaseCommandValue() );
		ptrBaseValues->appendChild(ptrBaseCommandValue);
	}
	catch(_com_error& e)
	{
		hr = e.Error();

		if (NULL != psErrorMsg)
		{
			psErrorMsg->Format( _T("Exception 0x%08x in CResOrgXmlWriter::SaveSymbolFileConfig()"), hr);
		}
	}
	return hr;
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgXmlWriter operations

HRESULT CResOrgXmlWriter::SaveXml(	CResourceSymbolManager* pManager,
									IXMLDOMDocument* pDOMDoc,
									IXMLDOMElement* pParent,
									CString* psErrorMsg /*= NULL*/)
{
	HRESULT hResult = S_OK;

	if (pManager->IsKindOf( RUNTIME_CLASS(CResourceSymbolManagerMultiFile) ) )
	{
		CResourceSymbolManagerMultiFile* pMngr = static_cast<CResourceSymbolManagerMultiFile*>(pManager);

		for (int n = 0; n < pMngr->GetSymbolFiles().GetSize(); n++)
		{
			CResourceSymbolManager* pFile = pMngr->GetSymbolFiles()[n];
			ASSERT(NULL != pFile);

			if (NULL != pFile)
			{
				HRESULT hr = SaveSymbolFileXml(	pFile,
												pMngr,
												pDOMDoc,
												pParent,
												psErrorMsg);

				if (FAILED(hr) )
				{
					hResult = hr;
				}
			}
		}
	}
	else
	{
		hResult = SaveSymbolFileXml(pManager,
									NULL,
									pDOMDoc,
									pParent,
									psErrorMsg);
	}
	return hResult;
}


HRESULT CResOrgXmlWriter::SaveSymbolFileXml(CResourceSymbolManager* pManager,
											CResourceSymbolManagerMultiFile* pParentManager,
											IXMLDOMDocument* pDOMDoc,
											IXMLDOMElement* pParent,
											CString* psErrorMsg /*= NULL*/)
{
	if (NULL == pManager)
	{
		return E_FAIL;
	}

	MSXML2::IXMLDOMDocumentPtr ptrDOMDoc(pDOMDoc);
	MSXML2::IXMLDOMElementPtr ptrParent(pParent);

	HRESULT hr = S_OK;
	try
	{
		MSXML2::IXMLDOMElementPtr ptrFile = ptrDOMDoc->createElement( _T("File") );

		MSXML2::IXMLDOMAttributePtr ptrNameAttr = ptrDOMDoc->createAttribute(_T("name"));
		ptrNameAttr->value = (LPCTSTR)pManager->GetFileName();
		ptrFile->setAttributeNode(ptrNameAttr);
		
		MSXML2::IXMLDOMAttributePtr ptrUidAttr = ptrDOMDoc->createAttribute(_T("uid"));
		CString sValue;
		sValue.Format( _T("%lu"), (INT_PTR)pManager);

		ptrUidAttr->value = (LPCTSTR)sValue;
		ptrFile->setAttributeNode(ptrUidAttr);

		ptrParent->appendChild(ptrFile);

		MSXML2::IXMLDOMElementPtr ptrPathName = ptrDOMDoc->createElement( _T("PathName") );
		ptrPathName->text = (LPCTSTR)pManager->GetPathName();
		ptrFile->appendChild(ptrPathName);

		MSXML2::IXMLDOMElementPtr ptrResourceFile = ptrDOMDoc->createElement( _T("ResourceFile") );
		ptrResourceFile->text = (LPCTSTR)pManager->GetResourceFileName();
		ptrFile->appendChild(ptrResourceFile);

		MSXML2::IXMLDOMElementPtr ptrOptions = ptrDOMDoc->createElement( _T("Options") );
		ptrFile->appendChild(ptrOptions);

		MSXML2::IXMLDOMElementPtr ptrCheckForOutOfRangeSymbols = ptrDOMDoc->createElement( _T("CheckForOutOfRangeSymbols") );
		ptrCheckForOutOfRangeSymbols->text = (LPCTSTR)::IntToStr( pManager->CheckForOutOfRangeSymbols() );
		ptrOptions->appendChild(ptrCheckForOutOfRangeSymbols);

		MSXML2::IXMLDOMElementPtr ptrMetrics = ptrDOMDoc->createElement( _T("Metrics") );
		ptrFile->appendChild(ptrMetrics);

		// Conflicts (internal & external)
		MSXML2::IXMLDOMElementPtr ptrConflicts = ptrDOMDoc->createElement( _T("Conflicts") );

		int nOutOfRangeSymbols	= pManager->GetOutOfRangeSymbolCount();

		int nInternalConflicts	= pManager->GetConflictCount();

		int nTotalConflicts		= nInternalConflicts;
        
		int nExternalConflicts	= 0;

		if (NULL != pParentManager)
		{
			nTotalConflicts		= pParentManager->GetTotalConflictCount(pManager);

			nExternalConflicts	= nTotalConflicts - nInternalConflicts;
		}

		ptrConflicts->text = (LPCTSTR)::IntToStr(nTotalConflicts);
		ptrMetrics->appendChild(ptrConflicts);

		MSXML2::IXMLDOMElementPtr ptrInternalConflicts = ptrDOMDoc->createElement( _T("Internal") );

		ptrInternalConflicts->text = (LPCTSTR)::IntToStr(nInternalConflicts);;
		ptrConflicts->appendChild(ptrInternalConflicts);

		MSXML2::IXMLDOMElementPtr ptrExternalConflicts = ptrDOMDoc->createElement(_T("External"));

		ptrExternalConflicts->text = (LPCTSTR)::IntToStr(nExternalConflicts);
		ptrConflicts->appendChild(ptrExternalConflicts);

		MSXML2::IXMLDOMElementPtr ptrOutOfRangeSymbols = ptrDOMDoc->createElement( _T("OutOfRangeSymbols") );
		ptrOutOfRangeSymbols->text = (LPCTSTR)::IntToStr(nOutOfRangeSymbols);
		ptrMetrics->appendChild(ptrOutOfRangeSymbols);

		CResourceSymbolCounts info;
		pManager->GetSymbolCount(info);

		// Dialogs
		MSXML2::IXMLDOMElementPtr ptrDialogs = ptrDOMDoc->createElement( _T("Dialogs") );
		ptrMetrics->appendChild(ptrDialogs);

		MSXML2::IXMLDOMElementPtr ptrDialogCount = ptrDOMDoc->createElement( _T("Count") );
		ptrDialogCount->text = (LPCTSTR)::IntToStr(info.m_nDialogs);
		ptrDialogs->appendChild(ptrDialogCount);

		// General Resources
		MSXML2::IXMLDOMElementPtr ptrResources = ptrDOMDoc->createElement( _T("Resources") );
		ptrMetrics->appendChild(ptrResources);

		MSXML2::IXMLDOMElementPtr ptrResourceCount = ptrDOMDoc->createElement( _T("Count") );
		ptrResourceCount->text = (LPCTSTR)::IntToStr(info.m_nResources);
		ptrResources->appendChild(ptrResourceCount);

		MSXML2::IXMLDOMElementPtr ptrMinResourceValue = ptrDOMDoc->createElement(_T("MinValue"));
		ptrMinResourceValue->text = (LPCTSTR)::UIntToStr(info.m_uMinResource);
		ptrResources->appendChild(ptrMinResourceValue);
		
		MSXML2::IXMLDOMElementPtr ptrMaxResourceValue = ptrDOMDoc->createElement(_T("MaxValue"));
		ptrMaxResourceValue->text = (LPCTSTR)::UIntToStr(info.m_uMaxResource);
		ptrResources->appendChild(ptrMaxResourceValue);
		
		// Accelerators
		MSXML2::IXMLDOMElementPtr ptrAccelerators = ptrDOMDoc->createElement( _T("Accelerators") );
		ptrMetrics->appendChild(ptrAccelerators);

		MSXML2::IXMLDOMElementPtr ptrAcceleratorCount = ptrDOMDoc->createElement( _T("Count") );
		ptrAccelerators->text = (LPCTSTR)::IntToStr(info.m_nAccelerators);
		ptrAccelerators->appendChild(ptrAcceleratorCount);
		
		// Bitmaps
		MSXML2::IXMLDOMElementPtr ptrBitmaps = ptrDOMDoc->createElement( _T("Bitmaps") );
		ptrMetrics->appendChild(ptrBitmaps);

		MSXML2::IXMLDOMElementPtr ptrBitmapCount = ptrDOMDoc->createElement( _T("Count") );
		ptrBitmapCount->text = (LPCTSTR)::IntToStr(info.m_nBitmaps);
		ptrBitmaps->appendChild(ptrBitmapCount);

		// Icons
		MSXML2::IXMLDOMElementPtr ptrIcons = ptrDOMDoc->createElement( _T("Icons") );
		ptrMetrics->appendChild(ptrIcons);

		MSXML2::IXMLDOMElementPtr ptrIconCount = ptrDOMDoc->createElement( _T("Count") );
		ptrIconCount->text = (LPCTSTR)::IntToStr(info.m_nIcons);
		ptrIcons->appendChild(ptrIconCount);

		// Menus
		MSXML2::IXMLDOMElementPtr ptrMenus = ptrDOMDoc->createElement( _T("Menus") );
		ptrMetrics->appendChild(ptrMenus);

		MSXML2::IXMLDOMElementPtr ptrMenuCount = ptrDOMDoc->createElement( _T("Count") );
		ptrMenuCount->text = (LPCTSTR)::IntToStr(info.m_nMenus);
		ptrMenus->appendChild(ptrMenuCount);

		// Prompt Strings
		MSXML2::IXMLDOMElementPtr ptrPrompts = ptrDOMDoc->createElement( _T("Prompts") );
		ptrMetrics->appendChild(ptrPrompts);

		MSXML2::IXMLDOMElementPtr ptrPromptCount = ptrDOMDoc->createElement( _T("Count") );
		ptrPromptCount->text = (LPCTSTR)::IntToStr(info.m_nPrompts);
		ptrPrompts->appendChild(ptrPromptCount);

		// Other Strings
		MSXML2::IXMLDOMElementPtr ptrStrings = ptrDOMDoc->createElement( _T("Strings") );
		ptrMetrics->appendChild(ptrStrings);

		MSXML2::IXMLDOMElementPtr ptrStringCount = ptrDOMDoc->createElement( _T("Count") );
		ptrStringCount->text = (LPCTSTR)::IntToStr(info.m_nStrings);
		ptrStrings->appendChild(ptrStringCount);

		// Toolbars
		MSXML2::IXMLDOMElementPtr ptrToolbars = ptrDOMDoc->createElement( _T("Toolbars") );
		ptrMetrics->appendChild(ptrToolbars);

		MSXML2::IXMLDOMElementPtr ptrToolbarCount = ptrDOMDoc->createElement( _T("Count") );
		ptrToolbars->text = (LPCTSTR)::IntToStr(info.m_nToolbars);
		ptrToolbars->appendChild(ptrToolbarCount);

		// Controls
		MSXML2::IXMLDOMElementPtr ptrControls = ptrDOMDoc->createElement( _T("Controls") );
		ptrMetrics->appendChild(ptrControls);

		MSXML2::IXMLDOMElementPtr ptrControlCount = ptrDOMDoc->createElement( _T("Count") );
		ptrControlCount->text = (LPCTSTR)::IntToStr(info.m_nControls);
		ptrControls->appendChild(ptrControlCount);

		// Commands
		MSXML2::IXMLDOMElementPtr ptrCommands = ptrDOMDoc->createElement( _T("Commands") );
		ptrMetrics->appendChild(ptrCommands);

		MSXML2::IXMLDOMElementPtr ptrCommandCount = ptrDOMDoc->createElement( _T("Count") );
		ptrCommandCount->text = (LPCTSTR)::IntToStr(info.m_nCommands);
		ptrCommands->appendChild(ptrCommandCount);

		MSXML2::IXMLDOMElementPtr ptrMinCommandValue = ptrDOMDoc->createElement(_T("MinValue"));
		ptrMinCommandValue->text = (LPCTSTR)::UIntToStr(info.m_uMinCommand);
		ptrCommands->appendChild(ptrMinCommandValue);
		
		MSXML2::IXMLDOMElementPtr ptrMaxCommandValue = ptrDOMDoc->createElement(_T("MaxValue"));
		ptrMaxCommandValue->text = (LPCTSTR)::UIntToStr(info.m_uMaxCommand);
		ptrCommands->appendChild(ptrMaxCommandValue);
		
		// Next Symbol Values
		MSXML2::IXMLDOMElementPtr ptrNextSymbols = ptrDOMDoc->createElement( _T("NextSymbols") );
		ptrFile->appendChild(ptrNextSymbols);

		MSXML2::IXMLDOMElementPtr ptrNextResourceValue = ptrDOMDoc->createElement( _T("Resources") );
		ptrNextResourceValue->text = (LPCTSTR)::UIntToStr(pManager->GetNextResourceValue() );
		ptrNextSymbols->appendChild(ptrNextResourceValue);

		MSXML2::IXMLDOMElementPtr ptrNextControlValue = ptrDOMDoc->createElement( _T("Controls") );
		ptrNextControlValue->text = (LPCTSTR)::UIntToStr(pManager->GetNextControlValue() );
		ptrNextSymbols->appendChild(ptrNextControlValue);

		MSXML2::IXMLDOMElementPtr ptrNextCommandValue = ptrDOMDoc->createElement( _T("Commands") );
		ptrNextCommandValue->text = (LPCTSTR)::UIntToStr(pManager->GetNextCommandValue() );
		ptrNextSymbols->appendChild(ptrNextCommandValue);

		MSXML2::IXMLDOMElementPtr ptrNextSymedValue = ptrDOMDoc->createElement( _T("EditableSymbols") );
		ptrNextSymedValue->text = (LPCTSTR)::UIntToStr(pManager->GetNextSymedValue() );
		ptrNextSymbols->appendChild(ptrNextSymedValue);

		MSXML2::IXMLDOMElementPtr ptrSymbols = ptrDOMDoc->createElement( _T("Symbols") );
		ptrFile->appendChild(ptrSymbols);

		CResourceSymbolList listSymbols;
		pManager->GetSymbols(listSymbols);

		POSITION pos = listSymbols.GetHeadPosition();

		while (NULL != pos)
		{
			CResourceSymbol* pSymbol = listSymbols.GetNext(pos);
			if (NULL != pSymbol)
			{
				SaveSymbolXml(	pManager,
								pSymbol,
								pDOMDoc,
								(IXMLDOMElement*)ptrSymbols.GetInterfacePtr(),
								psErrorMsg);
			}
		}
	}
	catch(_com_error& e)
	{
		hr = e.Error();

		if (NULL != psErrorMsg)
		{
			psErrorMsg->Format( _T("Exception 0x%08x in CResOrgXmlWriter::SaveXml()"), hr);
		}
	}
	return hr;
}


HRESULT CResOrgXmlWriter::SaveSymbolXml(CResourceSymbolManager* pManager,
										CResourceSymbol* pSymbol,
										IXMLDOMDocument* pDOMDoc,
										IXMLDOMElement* pParent,
										CString* psErrorMsg /*= NULL*/)
{
	if (NULL == pSymbol)
	{
		return E_FAIL;
	}

	MSXML2::IXMLDOMDocumentPtr ptrDOMDoc(pDOMDoc);
	MSXML2::IXMLDOMElementPtr ptrParent(pParent);

	HRESULT hr = S_OK;
	try
	{
		MSXML2::IXMLDOMElementPtr ptrSymbol = ptrDOMDoc->createElement( _T("Symbol") );

		MSXML2::IXMLDOMAttributePtr ptrNameAttr = ptrDOMDoc->createAttribute(_T("name"));
		ptrNameAttr->value = (LPCTSTR)pSymbol->GetName();

		ptrSymbol->setAttributeNode(ptrNameAttr);

		MSXML2::IXMLDOMAttributePtr ptrUidAttr = ptrDOMDoc->createAttribute(_T("uid"));
		CString sValue;
		sValue.Format( _T("%lu"), (INT_PTR)pSymbol);

		ptrUidAttr->value = (LPCTSTR)sValue;
		ptrSymbol->setAttributeNode(ptrUidAttr);

		ptrParent->appendChild(ptrSymbol);

		//MSXML2::IXMLDOMElementPtr ptrName = ptrDOMDoc->createElement( _T("Name") );
		//ptrName->text = (LPCTSTR)m_sName;
		//ptrSymbol->appendChild(ptrName);

		MSXML2::IXMLDOMElementPtr ptrType = ptrDOMDoc->createElement( _T("Type") );
		ptrType->text = (LPCTSTR)pSymbol->GetTypeName();
		ptrSymbol->appendChild(ptrType);

		MSXML2::IXMLDOMElementPtr ptrValue = ptrDOMDoc->createElement( _T("Value") );
		ptrValue->text = (LPCTSTR)::UIntToStr(pSymbol->GetValue() );
		ptrSymbol->appendChild(ptrValue);

		MSXML2::IXMLDOMElementPtr ptrReadOnly = ptrDOMDoc->createElement( _T("ReadOnly") );
		ptrReadOnly->text = pSymbol->IsReadOnly() ? _T("1") : _T("0");
		ptrSymbol->appendChild(ptrReadOnly);

		MSXML2::IXMLDOMElementPtr ptrOutOfRange = ptrDOMDoc->createElement( _T("OutOfRange") );

		if (pManager->CheckForOutOfRangeSymbols() )
		{
			ptrOutOfRange->text = pManager->IsOutOfRange(pSymbol)  ? _T("1") : _T("0");
		}
		else
		{
			ptrOutOfRange->text = _T("n/a");
		}
		ptrSymbol->appendChild(ptrOutOfRange);

		MSXML2::IXMLDOMElementPtr ptrConflicts = ptrDOMDoc->createElement( _T("Conflicts") );
		ptrSymbol->appendChild(ptrConflicts);

		
		POSITION pos = pSymbol->GetConflicts().GetHeadPosition();

		while (NULL != pos)
		{
			CResourceSymbol* pConflictingSymbol = pSymbol->GetConflicts().GetNext(pos);
			if (NULL != pSymbol)
			{
				MSXML2::IXMLDOMElementPtr ptrConflict = ptrDOMDoc->createElement( _T("Symbol") );

				MSXML2::IXMLDOMAttributePtr ptrNameAttr = ptrDOMDoc->createAttribute(_T("name"));
				ptrNameAttr->value = (LPCTSTR)pConflictingSymbol->GetName();

				ptrConflict->setAttributeNode(ptrNameAttr);

				MSXML2::IXMLDOMAttributePtr ptrUidAttr = ptrDOMDoc->createAttribute(_T("uid"));
				CString sValue;
				sValue.Format( _T("%lu"), (INT_PTR)pConflictingSymbol);

				ptrUidAttr->value = (LPCTSTR)sValue;
				ptrConflict->setAttributeNode(ptrUidAttr);

				ptrConflicts->appendChild(ptrConflict);
			}
		}
	}
	catch(_com_error& e)
	{
		hr = e.Error();

		if (NULL != psErrorMsg)
		{
			psErrorMsg->Format( _T("Exception 0x%08x in CResourceSymbol::SaveXml()"), hr);
		}
	}
	return hr;
}


bool CResOrgXmlWriter::LoadSymbolFileConfig(CResourceSymbolManager* pManager,
											const CString& sPathName,
											CString* psErrorMsg /*= NULL*/)
{
	ASSERT(NULL != pManager);
	ASSERT(!sPathName.IsEmpty() );

	bool bResult = false;

	CString sErrorMsg;

	if (!sPathName.IsEmpty() && (NULL != pManager) )
	{
		try
		{
			MSXML2::IXMLDOMDocumentPtr ptrDOMDoc;

			// Create empty DOM
			::CoInitialize(NULL);

			HRESULT hr = ptrDOMDoc.CreateInstance("Msxml2.DOMDocument.4.0");

			if (FAILED(hr) )
			{
				sErrorMsg = _T("Failed to create XML DOM");

				throw new CUserException();
			}

			// Try to load the XML stream
			ptrDOMDoc->load( _variant_t(sPathName) );

			hr = LoadSymbolFileConfig(	pManager,
										(IXMLDOMDocument *)ptrDOMDoc.GetInterfacePtr(),
										&sErrorMsg);

			if (FAILED(hr) )
			{
//				sErrorMsg = _T("Failed to load XML stream");

				throw new CUserException();
			}

			bResult = true;
		}
		catch (CException* pError)
		{
			// Nothing to do here - we already know what's wrong
			pError->Delete();
		}
	}
	if (!bResult)
	{
		if ( (NULL != psErrorMsg) && !sErrorMsg.IsEmpty() )
		{
			*psErrorMsg = sErrorMsg;
		}
		TRACE1("ERROR in CResOrgXmlWriter::LoadSymbolFileConfig(): %s\n", sErrorMsg);
	}

	return bResult;
}


CString CResOrgXmlWriter::GetConfigFilePathName(const CString& sSymbolFilePathName)
{
	CNGSplitPath split(sSymbolFilePathName);

	CString sConfigFilePathName =	split.GetDrive() +
									split.GetDirectory() +
									split.GetFileName() +
									_T(".resorg");

	return sConfigFilePathName;
}


bool CResOrgXmlWriter::SaveSymbolFileConfig(	CResourceSymbolManager* pManager,
												const CString& sPathName,
												CString* psErrorMsg /*= NULL*/)

{
	ASSERT(!sPathName.IsEmpty() );
	ASSERT(NULL != pManager);

	bool bResult = false;

	CString sErrorMsg;

	if (!sPathName.IsEmpty() && (NULL != pManager) )
	{
		try
		{
			MSXML2::IXMLDOMDocumentPtr ptrDOMDoc;

			// Create empty DOM
			::CoInitialize(NULL);

			HRESULT hr = ptrDOMDoc.CreateInstance("Msxml2.DOMDocument.4.0");

			if (FAILED(hr) )
			{
				//sErrorMsg.LoadString(IDP_RESORG_ERR_XML_DOM_CREATE);
				sErrorMsg = _T("Failed to create XML DOM");

				throw new CUserException();
			}

			// Add xml version node
			CString sAttribs = _T("version=\"1.0\" encoding=\"iso-8859-1\"");

			MSXML2::IXMLDOMProcessingInstructionPtr ptrIns;
			ptrIns = ptrDOMDoc->createProcessingInstruction(_T("xml"), (LPCTSTR)sAttribs);
			ptrDOMDoc->appendChild(ptrIns);

			hr = SaveSymbolFileConfig(	pManager,
										(IXMLDOMDocument*)ptrDOMDoc.GetInterfacePtr(),
										&sErrorMsg);

			if (FAILED(hr) )
			{
				sErrorMsg = _T("Failed to save XML stream - ") + sErrorMsg;

				throw new CUserException();
			}

			try
			{
				 _variant_t varPathName = (LPCTSTR)sPathName;

				 ptrDOMDoc->save(varPathName);

				bResult = true;
			}
			catch(_com_error& e)
			{
				sErrorMsg = (LPCTSTR)e.Description();
			}
		}
		catch (CUserException* pError)
		{
			// Nothing to do here - we already know what's wrong
			pError->Delete();
		}
	}
	if (!bResult)
	{
		if ( (NULL != psErrorMsg) && !sErrorMsg.IsEmpty() )
		{
			*psErrorMsg = sErrorMsg;
		}
		TRACE( _T("ERROR in CResOrgXmlWriter::SaveSymbolFileConfig(): %s\n"), sErrorMsg);
	}
	return bResult;
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Anna-Jayne Metcalfe
Founder Riverblade Limited
United Kingdom United Kingdom
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing Darth Vader's Codpiece * for the UK Army in 1990).
    * Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company, Riverblade Ltd.
 
One of my personal specialities is IDE plug-in development. ResOrg was my first attempt at a plug-in, but my day to day work is with Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.
 
I love lots of things, but particularly music, photography and anything connected with history or engineering. I despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...Laugh | :laugh:
 
I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!
Follow on   Twitter

| Advertise | Privacy | Mobile
Web01 | 2.8.140718.1 | Last Updated 10 Jan 2005
Article Copyright 2001 by Anna-Jayne Metcalfe
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid