mirror of https://github.com/axmolengine/axmol.git
closed #3580: FileUtilsTest->TextWritePlist crashes
This commit is contained in:
parent
e860d659a4
commit
b2dc16c065
|
@ -26,6 +26,12 @@
|
|||
#include "CCString.h"
|
||||
#include "CCInteger.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "CCString.h"
|
||||
#include "CCBool.h"
|
||||
#include "CCInteger.h"
|
||||
#include "CCFloat.h"
|
||||
#include "CCDouble.h"
|
||||
#include "CCArray.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -461,15 +467,97 @@ __Dictionary* __Dictionary::createWithContentsOfFile(const char *pFileName)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static ValueMap ccdictionary_to_valuemap(__Dictionary* dict);
|
||||
|
||||
static ValueVector ccarray_to_valuevector(__Array* arr)
|
||||
{
|
||||
ValueVector ret;
|
||||
|
||||
Object* obj;
|
||||
CCARRAY_FOREACH(arr, obj)
|
||||
{
|
||||
Value arrElement;
|
||||
|
||||
__String* strVal = nullptr;
|
||||
__Dictionary* dictVal = nullptr;
|
||||
__Array* arrVal = nullptr;
|
||||
__Double* doubleVal = nullptr;
|
||||
__Bool* boolVal = nullptr;
|
||||
__Float* floatVal = nullptr;
|
||||
__Integer* intVal = nullptr;
|
||||
|
||||
if ((strVal = dynamic_cast<__String *>(obj))) {
|
||||
arrElement = Value(strVal->getCString());
|
||||
} else if ((dictVal = dynamic_cast<__Dictionary*>(obj))) {
|
||||
arrElement = ccdictionary_to_valuemap(dictVal);
|
||||
} else if ((arrVal = dynamic_cast<__Array*>(obj))) {
|
||||
arrElement = ccarray_to_valuevector(arrVal);
|
||||
} else if ((doubleVal = dynamic_cast<__Double*>(obj))) {
|
||||
arrElement = Value(doubleVal->getValue());
|
||||
} else if ((floatVal = dynamic_cast<__Float*>(obj))) {
|
||||
arrElement = Value(floatVal->getValue());
|
||||
} else if ((intVal = dynamic_cast<__Integer*>(obj))) {
|
||||
arrElement = Value(intVal->getValue());
|
||||
} else if ((boolVal = dynamic_cast<__Bool*>(obj))) {
|
||||
arrElement = boolVal->getValue() ? Value(true) : Value(false);
|
||||
} else {
|
||||
CCASSERT(false, "the type isn't suppored.");
|
||||
}
|
||||
|
||||
ret.push_back(arrElement);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ValueMap ccdictionary_to_valuemap(__Dictionary* dict)
|
||||
{
|
||||
ValueMap ret;
|
||||
DictElement* pElement = nullptr;
|
||||
CCDICT_FOREACH(dict, pElement)
|
||||
{
|
||||
Object* obj = pElement->getObject();
|
||||
|
||||
__String* strVal = nullptr;
|
||||
__Dictionary* dictVal = nullptr;
|
||||
__Array* arrVal = nullptr;
|
||||
__Double* doubleVal = nullptr;
|
||||
__Bool* boolVal = nullptr;
|
||||
__Float* floatVal = nullptr;
|
||||
__Integer* intVal = nullptr;
|
||||
|
||||
Value dictElement;
|
||||
|
||||
if ((strVal = dynamic_cast<__String *>(obj))) {
|
||||
dictElement = Value(strVal->getCString());
|
||||
} else if ((dictVal = dynamic_cast<__Dictionary*>(obj))) {
|
||||
dictElement = ccdictionary_to_valuemap(dictVal);
|
||||
} else if ((arrVal = dynamic_cast<__Array*>(obj))) {
|
||||
dictElement = ccarray_to_valuevector(arrVal);
|
||||
} else if ((doubleVal = dynamic_cast<__Double*>(obj))) {
|
||||
dictElement = Value(doubleVal->getValue());
|
||||
} else if ((floatVal = dynamic_cast<__Float*>(obj))) {
|
||||
dictElement = Value(floatVal->getValue());
|
||||
} else if ((intVal = dynamic_cast<__Integer*>(obj))) {
|
||||
dictElement = Value(intVal->getValue());
|
||||
} else if ((boolVal = dynamic_cast<__Bool*>(obj))) {
|
||||
dictElement = boolVal->getValue() ? Value(true) : Value(false);
|
||||
} else {
|
||||
CCASSERT(false, "the type isn't suppored.");
|
||||
}
|
||||
|
||||
const char* key = pElement->getStrKey();
|
||||
if (key && strlen(key) > 0)
|
||||
{
|
||||
ret[key] = dictElement;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool __Dictionary::writeToFile(const char *fullPath)
|
||||
{
|
||||
ValueMap dict;
|
||||
DictElement* element = nullptr;
|
||||
CCDICT_FOREACH(this, element)
|
||||
{
|
||||
dict[element->getStrKey()] = Value(static_cast<__String*>(element->getObject())->getCString());
|
||||
}
|
||||
|
||||
ValueMap dict = ccdictionary_to_valuemap(this);
|
||||
return FileUtils::getInstance()->writeToFile(dict, fullPath);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue