2013-03-06 16:36:44 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
#include "CCUserDefault.h"
|
|
|
|
#include "platform/CCPlatformConfig.h"
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
2013-03-11 16:45:20 +08:00
|
|
|
#include "platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
|
2013-03-06 16:36:44 +08:00
|
|
|
|
|
|
|
// root name of xml
|
|
|
|
#define USERDEFAULT_ROOT_NAME "userDefaultRoot"
|
|
|
|
|
|
|
|
#define XML_FILE_NAME "UserDefault.xml"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* implements of CCUserDefault
|
|
|
|
*/
|
|
|
|
|
|
|
|
CCUserDefault* CCUserDefault::m_spUserDefault = 0;
|
|
|
|
string CCUserDefault::m_sFilePath = string("");
|
|
|
|
bool CCUserDefault::m_sbIsFilePathInitialized = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the user invoke delete CCUserDefault::sharedUserDefault(), should set m_spUserDefault
|
|
|
|
* to null to avoid error when he invoke CCUserDefault::sharedUserDefault() later.
|
|
|
|
*/
|
|
|
|
CCUserDefault::~CCUserDefault()
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(m_spUserDefault);
|
|
|
|
m_spUserDefault = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCUserDefault::CCUserDefault()
|
|
|
|
{
|
|
|
|
m_spUserDefault = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCUserDefault::purgeSharedUserDefault()
|
|
|
|
{
|
|
|
|
m_spUserDefault = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCUserDefault::getBoolForKey(const char* pKey)
|
|
|
|
{
|
|
|
|
return getBoolForKey(pKey, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCUserDefault::getBoolForKey(const char* pKey, bool defaultValue)
|
|
|
|
{
|
2013-03-11 16:45:20 +08:00
|
|
|
return getBoolForKeyJNI(pKey, defaultValue);
|
2013-03-06 16:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int CCUserDefault::getIntegerForKey(const char* pKey)
|
|
|
|
{
|
|
|
|
return getIntegerForKey(pKey, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCUserDefault::getIntegerForKey(const char* pKey, int defaultValue)
|
|
|
|
{
|
2013-03-11 16:45:20 +08:00
|
|
|
return getIntegerForKeyJNI(pKey, defaultValue);
|
2013-03-06 16:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float CCUserDefault::getFloatForKey(const char* pKey)
|
|
|
|
{
|
|
|
|
return getFloatForKey(pKey, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
float CCUserDefault::getFloatForKey(const char* pKey, float defaultValue)
|
|
|
|
{
|
2013-03-11 16:45:20 +08:00
|
|
|
return getFloatForKeyJNI(pKey, defaultValue);
|
2013-03-06 16:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
double CCUserDefault::getDoubleForKey(const char* pKey)
|
|
|
|
{
|
|
|
|
return getDoubleForKey(pKey, 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
double CCUserDefault::getDoubleForKey(const char* pKey, double defaultValue)
|
|
|
|
{
|
2013-03-11 16:45:20 +08:00
|
|
|
return getDoubleForKeyJNI(pKey, defaultValue);
|
2013-03-06 16:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CCUserDefault::getStringForKey(const char* pKey)
|
|
|
|
{
|
|
|
|
return getStringForKey(pKey, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
string CCUserDefault::getStringForKey(const char* pKey, const std::string & defaultValue)
|
|
|
|
{
|
2013-03-11 16:45:20 +08:00
|
|
|
return getStringForKeyJNI(pKey, defaultValue.c_str());
|
2013-03-06 16:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCUserDefault::setBoolForKey(const char* pKey, bool value)
|
|
|
|
{
|
2013-03-11 16:45:20 +08:00
|
|
|
return setBoolForKeyJNI(pKey, value);
|
2013-03-06 16:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCUserDefault::setIntegerForKey(const char* pKey, int value)
|
|
|
|
{
|
2013-03-11 16:45:20 +08:00
|
|
|
return setIntegerForKeyJNI(pKey, value);
|
2013-03-06 16:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCUserDefault::setFloatForKey(const char* pKey, float value)
|
|
|
|
{
|
2013-03-11 16:45:20 +08:00
|
|
|
return setFloatForKeyJNI(pKey, value);
|
2013-03-06 16:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCUserDefault::setDoubleForKey(const char* pKey, double value)
|
|
|
|
{
|
2013-03-11 16:45:20 +08:00
|
|
|
return setDoubleForKeyJNI(pKey, value);
|
2013-03-06 16:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCUserDefault::setStringForKey(const char* pKey, const std::string & value)
|
|
|
|
{
|
2013-03-11 16:45:20 +08:00
|
|
|
return setStringForKeyJNI(pKey, value.c_str());
|
2013-03-06 16:36:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCUserDefault* CCUserDefault::sharedUserDefault()
|
|
|
|
{
|
|
|
|
if (! m_spUserDefault)
|
|
|
|
{
|
|
|
|
m_spUserDefault = new CCUserDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_spUserDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCUserDefault::isXMLFileExist()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCUserDefault::initXMLFilePath()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// create new xml file
|
|
|
|
bool CCUserDefault::createXMLFile()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const string& CCUserDefault::getXMLFilePath()
|
|
|
|
{
|
|
|
|
return m_sFilePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCUserDefault::flush()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|