Merge pull request #1959 from minggo/tinyxml

use tinyxml2 instead of libxml2
This commit is contained in:
minggo 2013-02-06 00:43:00 -08:00
commit 7672eaba58
14 changed files with 4282 additions and 206 deletions

View File

@ -114,6 +114,7 @@ support/ccUtils.cpp \
support/CCVertex.cpp \
support/data_support/ccCArray.cpp \
support/image_support/TGAlib.cpp \
support/tinyxml2/tinyxml2.cpp \
support/zip_support/ZipUtils.cpp \
support/zip_support/ioapi.cpp \
support/zip_support/unzip.cpp \
@ -167,6 +168,5 @@ include $(BUILD_STATIC_LIBRARY)
$(call import-module,libjpeg)
$(call import-module,libpng)
$(call import-module,libxml2)
$(call import-module,libtiff)
$(call import-module,libwebp)

View File

@ -215,6 +215,7 @@ THE SOFTWARE.
#include "support/CCProfiling.h"
#include "support/CCUserDefault.h"
#include "support/CCVertex.h"
#include "support/tinyxml2/tinyxml2.h"
// text_input_node
#include "text_input_node/CCIMEDelegate.h"

View File

@ -34,10 +34,6 @@ using namespace std;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
NS_CC_BEGIN
typedef enum

View File

@ -1,6 +1,7 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org http://cocos2d-x.org
Copyright (c) 2010 Максим Аксенов
Copyright (c) 2013 Martell Malone
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -21,15 +22,70 @@
THE SOFTWARE.
****************************************************************************/
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include "CCSAXParser.h"
#include "cocoa/CCDictionary.h"
#include "CCFileUtils.h"
#include "support/tinyxml2/tinyxml2.h"
#include <vector> // because its based on windows 8 build :P
NS_CC_BEGIN
class XmlSaxHander : public tinyxml2::XMLVisitor
{
public:
XmlSaxHander():m_ccsaxParserImp(0){};
virtual bool VisitEnter( const tinyxml2::XMLElement& element, const tinyxml2::XMLAttribute* firstAttribute );
virtual bool VisitExit( const tinyxml2::XMLElement& element );
virtual bool Visit( const tinyxml2::XMLText& text );
virtual bool Visit( const tinyxml2::XMLUnknown&){ return true; }
void setCCSAXParserImp(CCSAXParser* parser)
{
m_ccsaxParserImp = parser;
}
private:
CCSAXParser *m_ccsaxParserImp;
};
bool XmlSaxHander::VisitEnter( const tinyxml2::XMLElement& element, const tinyxml2::XMLAttribute* firstAttribute )
{
//CCLog(" VisitEnter %s",element.Value());
std::vector<const char*> attsVector;
for( const tinyxml2::XMLAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() )
{
//CCLog("%s", attrib->Name());
attsVector.push_back(attrib->Name());
//CCLog("%s",attrib->Value());
attsVector.push_back(attrib->Value());
}
// nullptr is used in c++11
//attsVector.push_back(nullptr);
attsVector.push_back(NULL);
CCSAXParser::startElement(m_ccsaxParserImp, (const CC_XML_CHAR *)element.Value(), (const CC_XML_CHAR **)(&attsVector[0]));
return true;
}
bool XmlSaxHander::VisitExit( const tinyxml2::XMLElement& element )
{
//CCLog("VisitExit %s",element.Value());
CCSAXParser::endElement(m_ccsaxParserImp, (const CC_XML_CHAR *)element.Value());
return true;
}
bool XmlSaxHander::Visit( const tinyxml2::XMLText& text )
{
//CCLog("Visit %s",text.Value());
CCSAXParser::textHandler(m_ccsaxParserImp, (const CC_XML_CHAR *)text.Value(), strlen(text.Value()));
return true;
}
CCSAXParser::CCSAXParser()
{
m_pDelegator = NULL;
@ -48,37 +104,12 @@ bool CCSAXParser::init(const char *pszEncoding)
bool CCSAXParser::parse(const char* pXMLData, unsigned int uDataLength)
{
/*
* this initializes the library and checks potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
xmlSAXHandler saxHandler;
memset( &saxHandler, 0, sizeof(saxHandler) );
// Using xmlSAXVersion( &saxHandler, 2 ) generate crash as it sets plenty of other pointers...
saxHandler.initialized = XML_SAX2_MAGIC; // so we do this to force parsing as SAX2.
saxHandler.startElement = &CCSAXParser::startElement;
saxHandler.endElement = &CCSAXParser::endElement;
saxHandler.characters = &CCSAXParser::textHandler;
tinyxml2::XMLDocument tinyDoc;
tinyDoc.Parse(pXMLData);
XmlSaxHander printer;
printer.setCCSAXParserImp(this);
int result = xmlSAXUserParseMemory( &saxHandler, this, pXMLData, uDataLength );
if ( result != 0 )
{
return false;
}
/*
* Cleanup function for the XML library.
*/
xmlCleanupParser();
/*
* this is to debug memory for regression tests
*/
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
xmlMemoryDump();
#endif
return true;
return tinyDoc.Accept( &printer );
}
bool CCSAXParser::parse(const char *pszFile)

View File

@ -1 +1 @@
9c70c4fcfd0e094b9bb09f4a8e7f7a82b76caac3
81abe6adef9de3477eb86bdb9c31bd542aa0eef8

View File

@ -19,7 +19,6 @@ INCLUDES = -I.. \
-I../../external/chipmunk/include/chipmunk \
-I../../extensions/network \
-I../platform/linux \
-I../platform/third_party/linux/libxml2 \
-I../platform/third_party/linux/libpng \
-I../platform/third_party/linux/libjpeg \
-I../platform/third_party/linux/libtiff/include \
@ -113,6 +112,7 @@ OBJECTS = ../actions/CCAction.o \
../support/CCVertex.o \
../support/CCNotificationCenter.o \
../support/image_support/TGAlib.o \
../support/tinyxml2/tinyxml2.cpp \
../support/zip_support/ZipUtils.o \
../support/zip_support/ioapi.o \
../support/zip_support/unzip.o \
@ -163,7 +163,6 @@ STATICLIBS_DIR = ../platform/third_party/linux/libraries
endif
STATICLIBS =
STATICLIBS = $(STATICLIBS_DIR)/libfreetype.a \
$(STATICLIBS_DIR)/libxml2.a \
$(STATICLIBS_DIR)/libpng.a \
$(STATICLIBS_DIR)/libjpeg.a \
$(STATICLIBS_DIR)/libtiff.a \

View File

@ -1 +1 @@
302344d8d667c49b09f5f558cd10008f0864c71f
b9e66ce70e5a94fb03e1bc5ce1189d7e86f31aaa

View File

@ -16,7 +16,6 @@ subprojects
{
zlib
libpng
libxml2
freetype
libjpeg
libtiff
@ -47,6 +46,7 @@ includepaths
"../script_support"
"../sprite_nodes"
"../support"
"../support/tinyxml2"
"../text_input_node"
"../textures"
"../tileMap_parallax_nodes"
@ -179,6 +179,9 @@ files
"*.cpp" # MH: Many ccCArray linker errors without ccCArray.cpp
"*.h"
("../support/image_support")
"*.h"
"*.cpp"
("../support/tinyxml2")
"*.h"
"*.cpp"
("../support/zip_support")

View File

@ -69,7 +69,7 @@
</PreBuildEvent>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libxml2;$(ProjectDir)..\platform\third_party\win32\libwebp;$(ProjectDir)..\platform\third_party\win32\pthread;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libwebp;$(ProjectDir)..\platform\third_party\win32\pthread;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -86,7 +86,7 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
</Command>
</PreLinkEvent>
<Link>
<AdditionalDependencies>opengl32.lib;glew32.lib;libxml2.lib;libzlib.lib;libpng.lib;libjpeg.lib;libtiff.lib;libwebp.lib;libiconv.lib;pthreadVCE2.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>opengl32.lib;glew32.lib;libzlib.lib;libpng.lib;libjpeg.lib;libtiff.lib;libwebp.lib;libiconv.lib;pthreadVCE2.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
@ -107,7 +107,7 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
</Command>
</PreBuildEvent>
<ClCompile>
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libxml2;$(ProjectDir)..\platform\third_party\win32\libwebp;$(ProjectDir)..\platform\third_party\win32\pthread;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(ProjectDir)..;$(ProjectDir)..\platform\win32;$(ProjectDir)..\platform\third_party\win32\iconv;$(ProjectDir)..\platform\third_party\win32\zlib;$(ProjectDir)..\platform\third_party\win32\libpng;$(ProjectDir)..\platform\third_party\win32\libjpeg;$(ProjectDir)..\platform\third_party\win32\libtiff;$(ProjectDir)..\platform\third_party\win32\libwebp;$(ProjectDir)..\platform\third_party\win32\pthread;$(ProjectDir)..\platform\third_party\win32\OGLES;..\include;$(ProjectDir)..\kazmath\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
@ -122,7 +122,7 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
</Command>
</PreLinkEvent>
<Link>
<AdditionalDependencies>opengl32.lib;glew32.lib;libxml2.lib;libzlib.lib;libpng.lib;libjpeg.lib;libtiff.lib;libwebp.lib;libiconv.lib;pthreadVCE2.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>opengl32.lib;glew32.lib;libzlib.lib;libpng.lib;libjpeg.lib;libtiff.lib;libwebp.lib;libiconv.lib;pthreadVCE2.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries> ;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
@ -216,6 +216,7 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
<ClCompile Include="..\support\CCUserDefault.cpp" />
<ClCompile Include="..\support\ccUtils.cpp" />
<ClCompile Include="..\support\CCVertex.cpp" />
<ClCompile Include="..\support\tinyxml2\tinyxml2.cpp" />
<ClCompile Include="..\support\TransformUtils.cpp" />
<ClCompile Include="..\support\data_support\ccCArray.cpp" />
<ClCompile Include="..\support\image_support\TGAlib.cpp" />
@ -366,6 +367,7 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
<ClInclude Include="..\support\CCUserDefault.h" />
<ClInclude Include="..\support\ccUtils.h" />
<ClInclude Include="..\support\CCVertex.h" />
<ClInclude Include="..\support\tinyxml2\tinyxml2.h" />
<ClInclude Include="..\support\TransformUtils.h" />
<ClInclude Include="..\support\data_support\ccCArray.h" />
<ClInclude Include="..\support\data_support\uthash.h" />

View File

@ -94,6 +94,9 @@
<Filter Include="draw_nodes">
<UniqueIdentifier>{1179d205-d065-49f0-8457-bc4c3f1d0cb3}</UniqueIdentifier>
</Filter>
<Filter Include="support\tinyxml2">
<UniqueIdentifier>{cc25bb83-527d-4218-8d68-ebf963ce7698}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\base_nodes\CCAtlasNode.cpp">
@ -443,6 +446,7 @@
<ClCompile Include="..\platform\CCImageCommonWebp.cpp">
<Filter>platform</Filter>
</ClCompile>
<ClCompile Include="..\support\tinyxml2\tinyxml2.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\base_nodes\CCAtlasNode.h">
@ -893,5 +897,6 @@
<ClInclude Include="..\platform\win32\CCFileUtilsWin32.h">
<Filter>platform\win32</Filter>
</ClInclude>
<ClInclude Include="..\support\tinyxml2\tinyxml2.h" />
</ItemGroup>
</Project>

View File

@ -24,8 +24,7 @@ THE SOFTWARE.
#include "CCUserDefault.h"
#include "platform/CCCommon.h"
#include "platform/CCFileUtils.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "tinyxml2/tinyxml2.h"
// root name of xml
#define USERDEFAULT_ROOT_NAME "userDefaultRoot"
@ -36,16 +35,14 @@ using namespace std;
NS_CC_BEGIN
static xmlDocPtr g_sharedDoc = NULL;
/**
* define the functions here because we don't want to
* export xmlNodePtr and other types in "CCUserDefault.h"
*/
static xmlNodePtr getXMLNodeForKey(const char* pKey, xmlNodePtr *rootNode)
static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLElement** rootNode, tinyxml2::XMLDocument **doc)
{
xmlNodePtr curNode = NULL;
tinyxml2::XMLElement* curNode = NULL;
// check the key value
if (! pKey)
@ -55,76 +52,80 @@ static xmlNodePtr getXMLNodeForKey(const char* pKey, xmlNodePtr *rootNode)
do
{
tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument();
*doc = xmlDoc;
//CCFileData data(CCUserDefault::sharedUserDefault()->getXMLFilePath().c_str(),"rt");
unsigned long nSize;
const char* pXmlBuffer = (const char*)CCFileUtils::sharedFileUtils()->getFileData(CCUserDefault::sharedUserDefault()->getXMLFilePath().c_str(), "rb", &nSize);
//const char* pXmlBuffer = (const char*)data.getBuffer();
if(NULL == pXmlBuffer)
{
CCLOG("can not read xml file");
break;
}
xmlDoc->Parse(pXmlBuffer);
// get root node
*rootNode = xmlDocGetRootElement(g_sharedDoc);
*rootNode = xmlDoc->RootElement();
if (NULL == *rootNode)
{
CCLOG("read root node error");
break;
}
// find the node
curNode = (*rootNode)->xmlChildrenNode;
curNode = (*rootNode)->FirstChildElement();
while (NULL != curNode)
{
if (! xmlStrcmp(curNode->name, BAD_CAST pKey))
const char* nodeName = curNode->Value();
if (!strcmp(nodeName, pKey))
{
break;
}
curNode = curNode->next;
curNode = curNode->NextSiblingElement();
}
} while (0);
return curNode;
}
static inline const char* getValueForKey(const char* pKey)
{
const char* ret = NULL;
xmlNodePtr rootNode;
xmlNodePtr node = getXMLNodeForKey(pKey, &rootNode);
// find the node
if (node)
{
ret = (const char*)xmlNodeGetContent(node);
}
return ret;
}
static void setValueForKey(const char* pKey, const char* pValue)
{
xmlNodePtr rootNode;
xmlNodePtr node;
tinyxml2::XMLElement* rootNode;
tinyxml2::XMLDocument* doc;
tinyxml2::XMLElement* node;
// check the params
if (! pKey || ! pValue)
{
return;
}
// find the node
node = getXMLNodeForKey(pKey, &rootNode);
node = getXMLNodeForKey(pKey, &rootNode, &doc);
// if node exist, change the content
if (node)
{
xmlNodeSetContent(node, BAD_CAST pValue);
node->FirstChild()->SetValue(pValue);
}
else
{
if (rootNode)
{
// the node doesn't exist, add a new one
// libxml in android doesn't support xmlNewTextChild, so use this approach
xmlNodePtr tmpNode = xmlNewNode(NULL, BAD_CAST pKey);
xmlNodePtr content = xmlNewText(BAD_CAST pValue);
xmlAddChild(rootNode, tmpNode);
xmlAddChild(tmpNode, content);
tinyxml2::XMLElement* tmpNode = doc->NewElement(pKey);//new tinyxml2::XMLElement(pKey);
rootNode->LinkEndChild(tmpNode);
tinyxml2::XMLText* content = doc->NewText(pValue);//new tinyxml2::XMLText(pValue);
tmpNode->LinkEndChild(content);
}
}
// save file and free doc
if (doc)
{
doc->SaveFile(CCUserDefault::sharedUserDefault()->getXMLFilePath().c_str());
delete doc;
}
}
/**
@ -141,19 +142,13 @@ bool CCUserDefault::m_sbIsFilePathInitialized = false;
*/
CCUserDefault::~CCUserDefault()
{
flush();
if (g_sharedDoc)
{
xmlFreeDoc(g_sharedDoc);
g_sharedDoc = NULL;
}
CC_SAFE_DELETE(m_spUserDefault);
m_spUserDefault = NULL;
}
CCUserDefault::CCUserDefault()
{
g_sharedDoc = xmlReadFile(getXMLFilePath().c_str(), "utf-8", XML_PARSE_RECOVER);
m_spUserDefault = NULL;
}
void CCUserDefault::purgeSharedUserDefault()
@ -169,15 +164,26 @@ void CCUserDefault::purgeSharedUserDefault()
bool CCUserDefault::getBoolForKey(const char* pKey, bool defaultValue)
{
const char* value = getValueForKey(pKey);
const char* value = NULL;
tinyxml2::XMLElement* rootNode;
tinyxml2::XMLDocument* doc;
tinyxml2::XMLElement* node;
node = getXMLNodeForKey(pKey, &rootNode, &doc);
// find the node
if (node)
{
value = (const char*)(node->FirstChild()->Value());
}
bool ret = defaultValue;
if (value)
{
ret = (! strcmp(value, "true"));
xmlFree((void*)value);
}
if (doc) delete doc;
return ret;
}
@ -188,15 +194,30 @@ int CCUserDefault::getIntegerForKey(const char* pKey)
int CCUserDefault::getIntegerForKey(const char* pKey, int defaultValue)
{
const char* value = getValueForKey(pKey);
const char* value = NULL;
tinyxml2::XMLElement* rootNode;
tinyxml2::XMLDocument* doc;
tinyxml2::XMLElement* node;
node = getXMLNodeForKey(pKey, &rootNode, &doc);
// find the node
if (node)
{
value = (const char*)(node->FirstChild()->Value());
}
int ret = defaultValue;
if (value)
{
ret = atoi(value);
xmlFree((void*)value);
}
if(doc)
{
delete doc;
}
return ret;
}
@ -219,15 +240,26 @@ double CCUserDefault::getDoubleForKey(const char* pKey)
double CCUserDefault::getDoubleForKey(const char* pKey, double defaultValue)
{
const char* value = getValueForKey(pKey);
const char* value = NULL;
tinyxml2::XMLElement* rootNode;
tinyxml2::XMLDocument* doc;
tinyxml2::XMLElement* node;
node = getXMLNodeForKey(pKey, &rootNode, &doc);
// find the node
if (node)
{
value = (const char*)(node->FirstChild()->Value());
}
double ret = defaultValue;
if (value)
{
ret = atof(value);
xmlFree((void*)value);
}
if (doc) delete doc;
return ret;
}
@ -238,15 +270,26 @@ std::string CCUserDefault::getStringForKey(const char* pKey)
string CCUserDefault::getStringForKey(const char* pKey, const std::string & defaultValue)
{
const char* value = getValueForKey(pKey);
const char* value = NULL;
tinyxml2::XMLElement* rootNode;
tinyxml2::XMLDocument* doc;
tinyxml2::XMLElement* node;
node = getXMLNodeForKey(pKey, &rootNode, &doc);
// find the node
if (node)
{
value = (const char*)(node->FirstChild()->Value());
}
string ret = defaultValue;
if (value)
{
ret = string(value);
xmlFree((void*)value);
}
if (doc) delete doc;
return ret;
}
@ -358,39 +401,28 @@ void CCUserDefault::initXMLFilePath()
bool CCUserDefault::createXMLFile()
{
bool bRet = false;
xmlDocPtr doc = NULL;
do
tinyxml2::XMLDocument *pDoc = new tinyxml2::XMLDocument();
if (NULL==pDoc)
{
// new doc
doc = xmlNewDoc(BAD_CAST"1.0");
if (doc == NULL)
{
CCLOG("can not create xml doc");
break;
return false;
}
// new root node
xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST USERDEFAULT_ROOT_NAME);
if (rootNode == NULL)
tinyxml2::XMLDeclaration *pDeclaration = pDoc->NewDeclaration("1.0");
if (NULL==pDeclaration)
{
CCLOG("can not create root node");
break;
return false;
}
// set root node
xmlDocSetRootElement(doc, rootNode);
// save xml file
xmlSaveFile(m_sFilePath.c_str(), doc);
bRet = true;
} while (0);
// if doc is not null, free it
if (doc)
pDoc->LinkEndChild(pDeclaration);
tinyxml2::XMLElement *pRootEle = pDoc->NewElement(USERDEFAULT_ROOT_NAME);
if (NULL==pRootEle)
{
xmlFreeDoc(doc);
return false;
}
pDoc->LinkEndChild(pRootEle);
bRet = pDoc->SaveFile(m_sFilePath.c_str());
if(pDoc)
{
delete pDoc;
}
return bRet;
@ -403,11 +435,6 @@ const string& CCUserDefault::getXMLFilePath()
void CCUserDefault::flush()
{
// save to file
if (g_sharedDoc)
{
xmlSaveFile(CCUserDefault::sharedUserDefault()->getXMLFilePath().c_str(), g_sharedDoc);
}
}
NS_CC_END

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
e61db43bc8354b24f352187dd11c2cc4edf62ed0
f43bbe90da807bd211fb4463ea65bf0f3aa8faa4