issue #434,refactor class CCFileUtils on win32 and wophone.

This commit is contained in:
natural-law 2011-03-26 13:52:33 +08:00
parent 7e7e8e2b4c
commit 28a940ab57
21 changed files with 547 additions and 1001 deletions

View File

@ -24,7 +24,7 @@ THE SOFTWARE.
#include "CCData.h"
#include "support/file_support/FileData.h"
#include "CCFileUtils.h"
#include <stdio.h>

View File

@ -1,30 +0,0 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
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.
****************************************************************************/
#ifndef __CC_FILEUTILS_H__
#define __CC_FILEUTILS_H__
#include "platform/CCFileUtils_platform.h"
#endif // __CC_FILEUTILS_H__

View File

@ -1,64 +0,0 @@
/****************************************************************************
Copyright (c) 2010 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.
****************************************************************************/
#ifndef __SUPPORT_FILE_SUPPORT_FILEUTILS_H__
#define __SUPPORT_FILE_SUPPORT_FILEUTILS_H__
#include "CCCommon.h"
#include <string>
namespace cocos2d {
class CC_DLL FileUtils
{
public:
/**
@brief Get resource file data
@param[in] pszFileName The resource file name which contain the path
@param[in] pszMode The read mode of the file
@param[out] pSize If get the file data succeed the it will be the data size,or it will be 0
@return if success,the pointer of data will be returned,or NULL is returned
@warning If you get the file data succeed,you must delete it after used.
*/
static unsigned char* getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize);
/**
@brief Get resource file data from zip file
@param[in] pszFileName The resource file name which contain the relative path of zip file
@param[out] pSize If get the file data succeed the it will be the data size,or it will be 0
@return if success,the pointer of data will be returned,or NULL is returned
@warning If you get the file data succeed,you must delete it after used.
*/
static unsigned char* getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize);
/** removes the HD suffix from a path
@returns const char * without the HD suffix
@since v0.99.5
*/
static std::string& ccRemoveHDSuffixFromFile(std::string& path);
};
} // namespace cocos2d
#endif // __SUPPORT_FILE_SUPPORT_FILEUTILS_H__

View File

@ -31,7 +31,7 @@ THE SOFTWARE.
#include "CCSprite.h"
#include "CCPointExtension.h"
#include "support/file_support/FileData.h"
#include "CCFileUtils.h"
#include "support/data_support/uthash.h"
namespace cocos2d{

View File

@ -0,0 +1,247 @@
/****************************************************************************
Copyright (c) 2010 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 "CCFileUtils.h"
#include <stack>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include "CCLibxml2.h"
#include "CCString.h"
#include "CCSAXParser.h"
#include "support/zip_support/unzip.h"
NS_CC_BEGIN;
typedef enum
{
SAX_NONE = 0,
SAX_KEY,
SAX_DICT,
SAX_INT,
SAX_REAL,
SAX_STRING
}CCSAXState;
class CCDictMaker : public CCSAXDelegator
{
public:
CCDictionary<std::string, CCObject*> *m_pRootDict;
CCDictionary<std::string, CCObject*> *m_pCurDict;
std::stack<CCDictionary<std::string, CCObject*>*> m_tDictStack;
std::string m_sCurKey;///< parsed key
CCSAXState m_tState;
public:
CCDictMaker()
{
m_pRootDict = NULL;
m_pCurDict = NULL;
m_tState = SAX_NONE;
}
~CCDictMaker()
{
}
CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName)
{
CCSAXParser parser;
if (false == parser.init("UTF-8"))
{
return NULL;
}
parser.setDelegator(this);
parser.parse(pFileName);
return m_pRootDict;
}
void startElement(void *ctx, const char *name, const char **atts)
{
std::string sName((char*)name);
if( sName == "dict" )
{
CCDictionary<std::string, CCObject*> *pNewDict = new CCDictionary<std::string, CCObject*>();
if(! m_pRootDict)
{
m_pRootDict = pNewDict;
pNewDict->autorelease();
}
else
{
CCAssert(m_pCurDict && !m_sCurKey.empty(), "");
m_pCurDict->setObject(pNewDict, m_sCurKey);
pNewDict->release();
m_sCurKey.clear();
}
m_pCurDict = pNewDict;
m_tDictStack.push(m_pCurDict);
m_tState = SAX_DICT;
}
else if(sName == "key")
{
m_tState = SAX_KEY;
}
else if(sName == "integer")
{
m_tState = SAX_INT;
}
else if(sName == "real")
{
m_tState = SAX_REAL;
}
else if(sName == "string")
{
m_tState = SAX_STRING;
}
else
{
m_tState = SAX_NONE;
}
}
void endElement(void *ctx, const char *name)
{
std::string sName((char*)name);
if( sName == "dict" )
{
m_tDictStack.pop();
if ( !m_tDictStack.empty() )
{
m_pCurDict = (CCDictionary<std::string, CCObject*>*)(m_tDictStack.top());
}
}
m_tState = SAX_NONE;
}
void textHandler(void *ctx, const char *ch, int len)
{
if (m_tState == SAX_NONE)
{
return;
}
CCString *pText = new CCString();
pText->m_sString = std::string((char*)ch,0,len);
switch(m_tState)
{
case SAX_KEY:
m_sCurKey = pText->m_sString;
break;
case SAX_INT:
case SAX_REAL:
case SAX_STRING:
{
CCAssert(!m_sCurKey.empty(), "not found key : <integet/real>");
m_pCurDict->setObject(pText, m_sCurKey);
break;
}
}
pText->release();
}
};
std::string& CCFileUtils::ccRemoveHDSuffixFromFile(std::string& path)
{
#if CC_IS_RETINA_DISPLAY_SUPPORTED
if( CC_CONTENT_SCALE_FACTOR() == 2 )
{
std::string::size_type pos = path.rfind("/") + 1; // the begin index of last part of path
std::string::size_type suffixPos = path.rfind(CC_RETINA_DISPLAY_FILENAME_SUFFIX);
if (std::string::npos != suffixPos && suffixPos > pos)
{
CCLog("cocos2d: FilePath(%s) contains suffix(%s), remove it.", path.c_str(),
CC_RETINA_DISPLAY_FILENAME_SUFFIX);
path.replace(suffixPos, strlen(CC_RETINA_DISPLAY_FILENAME_SUFFIX), "");
}
}
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
return path;
}
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
{
CCDictMaker tMaker;
return tMaker.dictionaryWithContentsOfFile(pFileName);
}
unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize)
{
unsigned char * pBuffer = NULL;
unzFile pFile = NULL;
*pSize = 0;
do
{
CC_BREAK_IF(!pszZipFilePath || !pszFileName);
CC_BREAK_IF(strlen(pszZipFilePath) == 0);
pFile = unzOpen(pszZipFilePath);
CC_BREAK_IF(!pFile);
int nRet = unzLocateFile(pFile, pszFileName, 1);
CC_BREAK_IF(UNZ_OK != nRet);
char szFilePathA[260];
unz_file_info FileInfo;
nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0);
CC_BREAK_IF(UNZ_OK != nRet);
nRet = unzOpenCurrentFile(pFile);
CC_BREAK_IF(UNZ_OK != nRet);
pBuffer = new unsigned char[FileInfo.uncompressed_size];
int nSize = 0;
nSize = unzReadCurrentFile(pFile, pBuffer, FileInfo.uncompressed_size);
CCAssert(nSize == 0 || nSize == FileInfo.uncompressed_size, "the file size is wrong");
*pSize = FileInfo.uncompressed_size;
unzCloseCurrentFile(pFile);
} while (0);
if (pFile)
{
unzClose(pFile);
}
return pBuffer;
}
NS_CC_END;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#include "win32/CCFileUtils_win32.cpp"
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
#include "wophone/CCFileUtils_wophone.cpp"
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "android/CCFileUtils_android.cpp"
#endif

View File

@ -0,0 +1,138 @@
/****************************************************************************
Copyright (c) 2010 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.
****************************************************************************/
#ifndef __CC_FILEUTILS_PLATFORM_H__
#define __CC_FILEUTILS_PLATFORM_H__
#include <string>
#include "CCMutableDictionary.h"
NS_CC_BEGIN;
//! @brief Helper class to handle file operations
class CC_DLL CCFileUtils
{
public:
/**
@brief Get resource file data
@param[in] pszFileName The resource file name which contain the path
@param[in] pszMode The read mode of the file
@param[out] pSize If get the file data succeed the it will be the data size,or it will be 0
@return if success,the pointer of data will be returned,or NULL is returned
@warning If you get the file data succeed,you must delete it after used.
*/
static unsigned char* getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize);
/**
@brief Get resource file data from zip file
@param[in] pszFileName The resource file name which contain the relative path of zip file
@param[out] pSize If get the file data succeed the it will be the data size,or it will be 0
@return if success,the pointer of data will be returned,or NULL is returned
@warning If you get the file data succeed,you must delete it after used.
*/
static unsigned char* getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize);
/** removes the HD suffix from a path
@returns const char * without the HD suffix
@since v0.99.5
*/
static std::string& ccRemoveHDSuffixFromFile(std::string& path);
/**
@brief Generate the absolute path of the file.
@param pszRelativePath The relative path of the file.
@return The absolute path of the file.
@warning We only add the ResourcePath before the relative path of the file.
If you have not set the ResourcePath,the function add "/NEWPLUS/TDA_DATA/UserData/" as default.
You can set ResourcePath by function void setResourcePath(const char *pszResourcePath);
*/
static const char* fullPathFromRelativePath(const char *pszRelativePath);
/// @cond
static const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile);
/// @endcond
/**
@brief Set the ResourcePath,we will find resource in this path
@param pszResourcePath The absolute resource path
@warning it's only implement on win32 and android
*/
static void setResourcePath(const char *pszResourcePath);
/**
@brief Generate a CCDictionary pointer by file
@param pFileName The file name of *.plist file
@return The CCDictionary pointer generated from the file
*/
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
///////////////////////////////////////////////////
// interfaces on wophone
///////////////////////////////////////////////////
/**
@brief Set the ResourcePath and(or) the zip file name
@param pszResPath The absolute resource path
@param pszZipFileName The relative path of the .zip file
*/
static void setResource(const char* pszZipFileName, const char* pszResPath = NULL);
///////////////////////////////////////////////////
// interfaces on android
///////////////////////////////////////////////////
static const char* getResourcePath(void);
static void setRelativePath(const char* pszRelativePath);
};
class FileData
{
public:
FileData() : m_pBuffer(NULL) {}
~FileData()
{
if (m_pBuffer)
{
delete [] m_pBuffer;
m_pBuffer = NULL;
}
}
unsigned char* getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
if (m_pBuffer)
{
delete [] m_pBuffer;
m_pBuffer = NULL;
}
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, pSize);
return m_pBuffer;
}
protected:
unsigned char* m_pBuffer;
};
NS_CC_END;
#endif // end of __CC_EGLVIEW_PLATFORM_H__

View File

@ -1,43 +0,0 @@
/****************************************************************************
Copyright (c) 2010 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.
****************************************************************************/
#ifndef __CC_FILEUTILS_PLATFORM_H__
#define __CC_FILEUTILS_PLATFORM_H__
#include "CCPlatformConfig.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
#include "wophone/CCFileUtils_wophone.h"
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#include "win32/CCFileUtils_win32.h"
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "android/CCFileUtils_android.h"
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#include "ios/CCFileUtils_ios.h"
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY)
#include "airplay/CCFileUtils_airplay.h"
#else
#error
#endif // __CC_FILEUTILS_PLATFORM_H__
#endif // end of __CC_EGLVIEW_PLATFORM_H__

View File

@ -4,7 +4,7 @@
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include "CCLibxml2.h"
#include "../support/file_support/FileData.h"
#include "CCFileUtils.h"
NS_CC_BEGIN;

View File

@ -22,179 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCFileUtils_win32.h"
#include <windows.h>
#include <stack>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include "CCLibxml2.h"
#include "CCString.h"
namespace cocos2d {
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
void plist_endElement(void *ctx, const xmlChar *name);
void plist_characters(void *ctx, const xmlChar *ch, int len);
typedef enum
{
SAX_NONE = 0,
SAX_KEY,
SAX_DICT,
SAX_INT,
SAX_REAL,
SAX_STRING
}CCSAXState;
class CCDictMaker
{
public:
CCDictionary<std::string, CCObject*> *m_pRootDict;
CCDictionary<std::string, CCObject*> *m_pCurDict;
std::stack<CCDictionary<std::string, CCObject*>*> m_tDictStack;
std::string m_sCurKey;///< parsed key
CCSAXState m_tState;
public:
CCDictMaker()
{
m_pRootDict = NULL;
m_pCurDict = NULL;
m_tState = SAX_NONE;
}
~CCDictMaker()
{
}
CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName)
{
FILE *fp = NULL;
if( !(fp = fopen(pFileName, "r")) )
{
return NULL;
}
fseek(fp,0,SEEK_END);
int size = ftell(fp);
fseek(fp,0,SEEK_SET);
char *buffer = new char[size+1];
fread(buffer,sizeof(char),size,fp);
fclose(fp);
/*
* this initialize the library and check 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 = &plist_startElement;
saxHandler.endElement = &plist_endElement;
saxHandler.characters = &plist_characters;
int result = xmlSAXUserParseMemory( &saxHandler, this, buffer, size );
if ( result != 0 )
{
return NULL;
}
/*
* Cleanup function for the XML library.
*/
xmlCleanupParser();
/*
* this is to debug memory for regression tests
*/
xmlMemoryDump();
delete []buffer;
return m_pRootDict;
}
};
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts)
{
CCDictMaker *pMaker = (CCDictMaker*)(ctx);
std::string sName((char*)name);
if( sName == "dict" )
{
CCDictionary<std::string, CCObject*> *pNewDict = new CCDictionary<std::string, CCObject*>();
if(! pMaker->m_pRootDict)
{
pMaker->m_pRootDict = pNewDict;
pNewDict->autorelease();
}
else
{
CCAssert(pMaker->m_pCurDict && !pMaker->m_sCurKey.empty(), "");
pMaker->m_pCurDict->setObject(pNewDict, pMaker->m_sCurKey);
pNewDict->release();
pMaker->m_sCurKey.clear();
}
pMaker->m_pCurDict = pNewDict;
pMaker->m_tDictStack.push(pMaker->m_pCurDict);
pMaker->m_tState = SAX_DICT;
}
else if(sName == "key")
{
pMaker->m_tState = SAX_KEY;
}
else if(sName == "integer")
{
pMaker->m_tState = SAX_INT;
}
else if(sName == "real")
{
pMaker->m_tState = SAX_REAL;
}
else if(sName == "string")
{
pMaker->m_tState = SAX_STRING;
}
else
{
pMaker->m_tState = SAX_NONE;
}
}
void plist_endElement(void *ctx, const xmlChar *name)
{
CCDictMaker * pMaker = (CCDictMaker*)(ctx);
std::string sName((char*)name);
if( sName == "dict" )
{
pMaker->m_tDictStack.pop();
if ( !pMaker->m_tDictStack.empty() )
{
pMaker->m_pCurDict = (CCDictionary<std::string, CCObject*>*)(pMaker->m_tDictStack.top());
}
}
pMaker->m_tState = SAX_NONE;
}
void plist_characters(void *ctx, const xmlChar *ch, int len)
{
CCDictMaker * pMaker = (CCDictMaker*)(ctx);
if (pMaker->m_tState == SAX_NONE)
{
return;
}
CCString *pText = new CCString();
pText->m_sString = std::string((char*)ch,0,len);
switch(pMaker->m_tState)
{
case SAX_KEY:
pMaker->m_sCurKey = pText->m_sString;
break;
case SAX_INT:
case SAX_REAL:
case SAX_STRING:
{
CCAssert(!pMaker->m_sCurKey.empty(), "not found key : <integet/real>");
pMaker->m_pCurDict->setObject(pText, pMaker->m_sCurKey);
break;
}
}
pText->release();
}
NS_CC_BEGIN;
// record the resource path
static char s_pszResourcePath[MAX_PATH] = {0};
@ -285,10 +113,41 @@ const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const
return pRet->m_sString.c_str();
}
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
CCDictMaker tMaker;
return tMaker.dictionaryWithContentsOfFile(pFileName);
unsigned char * Buffer = NULL;
do
{
// read the file from hardware
FILE *fp = fopen(pszFileName, pszMode);
CC_BREAK_IF(!fp);
fseek(fp,0,SEEK_END);
*pSize = ftell(fp);
fseek(fp,0,SEEK_SET);
Buffer = new unsigned char[*pSize];
*pSize = fread(Buffer,sizeof(unsigned char), *pSize,fp);
fclose(fp);
} while (0);
return Buffer;
}
}//namespace cocos2d
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)
{
CCAssert(0, "Have not implement!");
}
const char* CCFileUtils::getResourcePath(void)
{
CCAssert(0, "Have not implement!");
return NULL;
}
void CCFileUtils::setRelativePath(const char* pszRelativePath)
{
CCAssert(0, "Have not implement!");
}
NS_CC_END;

View File

@ -1,68 +0,0 @@
/****************************************************************************
Copyright (c) 2010 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.
****************************************************************************/
#ifndef __PLATFORM_WIN32_CCFILE_UTILS_H__
#define __PLATFORM_WIN32_CCFILE_UTILS_H__
#include <string>
#include "CCMutableDictionary.h"
#include "FileUtils.h"
namespace cocos2d {
//! @brief Helper class to handle file operations
class CC_DLL CCFileUtils : public FileUtils
{
public:
/**
@brief Generate the absolute path of the file.
@param pszRelativePath The relative path of the file.
@return The absolute path of the file.
@warning We only add the ResourcePath before the relative path of the file.
If you have not set the ResourcePath,the function add "/NEWPLUS/TDA_DATA/UserData/" as default.
You can set ResourcePath by function void setResourcePath(const char *pszResourcePath);
*/
static const char* fullPathFromRelativePath(const char *pszRelativePath);
/// @cond
static const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile);
/// @endcond
/**
@brief Generate a CCDictionary pointer by file
@param pFileName The file name of *.plist file
@return The CCDictionary pointer generated from the file
*/
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
/**
@brief Set the ResourcePath,we will find resource in this path
@param pszResourcePath The absolute resource path
*/
static void setResourcePath(const char *pszResourcePath);
};
}//namespace cocos2d
#endif // __PLATFORM_WIN32_CCFILE_UTILS_H__

View File

@ -22,179 +22,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include <string>
#include <stack>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include <TG3.h>
#include "CCString.h"
#include "CCFileUtils_wophone.h"
#include "CCApplication.h"
#include "support/file_support/FileData.h"
#include "support/zip_support/unzip.h"
namespace cocos2d {
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
void plist_endElement(void *ctx, const xmlChar *name);
void plist_characters(void *ctx, const xmlChar *ch, int len);
typedef enum
{
SAX_NONE = 0,
SAX_KEY,
SAX_DICT,
SAX_INT,
SAX_REAL,
SAX_STRING
}CCSAXState;
class CCDictMaker
{
public:
CCDictionary<std::string, CCObject*> *m_pRootDict;
CCDictionary<std::string, CCObject*> *m_pCurDict;
std::stack<CCDictionary<std::string, CCObject*>*> m_tDictStack;
std::string m_sCurKey;///< parsed key
CCSAXState m_tState;
public:
CCDictMaker()
{
m_pRootDict = NULL;
m_pCurDict = NULL;
m_tState = SAX_NONE;
}
~CCDictMaker()
{
}
CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName)
{
FileData data;
unsigned long size = 0;
char *pBuffer = (char *) data.getFileData(pFileName, "r", &size);
if (!pBuffer)
{
return NULL;
}
/*
* this initialize the library and check 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 = &plist_startElement;
saxHandler.endElement = &plist_endElement;
saxHandler.characters = &plist_characters;
int result = xmlSAXUserParseMemory( &saxHandler, this, pBuffer, size );
if ( result != 0 )
{
return NULL;
}
/*
* Cleanup function for the XML library.
*/
xmlCleanupParser();
/*
* this is to debug memory for regression tests
*/
xmlMemoryDump();
return m_pRootDict;
}
};
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts)
{
CCDictMaker *pMaker = (CCDictMaker*)(ctx);
std::string sName((char*)name);
if( sName == "dict" )
{
CCDictionary<std::string, CCObject*> *pNewDict = new CCDictionary<std::string, CCObject*>();
if(! pMaker->m_pRootDict)
{
pMaker->m_pRootDict = pNewDict;
pNewDict->autorelease();
}
else
{
CCAssert(pMaker->m_pCurDict && !pMaker->m_sCurKey.empty(), "");
pMaker->m_pCurDict->setObject(pNewDict, pMaker->m_sCurKey);
pNewDict->release();
pMaker->m_sCurKey.clear();
}
pMaker->m_pCurDict = pNewDict;
pMaker->m_tDictStack.push(pMaker->m_pCurDict);
pMaker->m_tState = SAX_DICT;
}
else if(sName == "key")
{
pMaker->m_tState = SAX_KEY;
}
else if(sName == "integer")
{
pMaker->m_tState = SAX_INT;
}
else if(sName == "real")
{
pMaker->m_tState = SAX_REAL;
}
else if(sName == "string")
{
pMaker->m_tState = SAX_STRING;
}
else
{
pMaker->m_tState = SAX_NONE;
}
}
void plist_endElement(void *ctx, const xmlChar *name)
{
CCDictMaker * pMaker = (CCDictMaker*)(ctx);
std::string sName((char*)name);
if( sName == "dict" )
{
pMaker->m_tDictStack.pop();
if ( !pMaker->m_tDictStack.empty() )
{
pMaker->m_pCurDict = (CCDictionary<std::string, CCObject*>*)(pMaker->m_tDictStack.top());
}
}
pMaker->m_tState = SAX_NONE;
}
void plist_characters(void *ctx, const xmlChar *ch, int len)
{
CCDictMaker * pMaker = (CCDictMaker*)(ctx);
if (pMaker->m_tState == SAX_NONE)
{
return;
}
CCString *pText = new CCString();
pText->m_sString = std::string((char*)ch,0,len);
switch(pMaker->m_tState)
{
case SAX_KEY:
pMaker->m_sCurKey = pText->m_sString;
break;
case SAX_INT:
case SAX_REAL:
case SAX_STRING:
{
CCAssert(!pMaker->m_sCurKey.empty(), "not found key : <integet/real>");
pMaker->m_pCurDict->setObject(pText, pMaker->m_sCurKey);
break;
}
}
pText->release();
}
NS_CC_BEGIN;
// record the resource path
static char s_pszResourcePath[EOS_FILE_MAX_PATH] = {0};
@ -277,87 +109,42 @@ void setZipFilePath(const char* pZipFileName)
strcat(s_pszZipFilePath, fullPath);
}
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)
bool isResourceExist(const char* pszResName)
{
if (pszResPath != NULL && pszZipFileName != NULL)
{
// record the resource path
strcpy(s_pszResourcePath, pszResPath);
bool bRet = false;
// record the zip file path
setZipFilePath(pszZipFileName);
}
else if (pszResPath != NULL)
{
// update the zip file path
updateZipFilePath(pszResPath);
TUChar FilePath[EOS_FILE_MAX_PATH] = {0};
TUString::StrGBToUnicode(FilePath, (const Char *) pszResName);
// record the resource path
strcpy(s_pszResourcePath, pszResPath);
}
else if (pszZipFileName != NULL)
{
// record the zip file path
setZipFilePath(pszZipFileName);
}
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
// if have set the zip file path,return the relative path of zip file
if (strlen(s_pszZipFilePath) != 0)
{
return CCFileUtils::getDiffResolutionPath(pszRelativePath);
}
// if have set the zip file path,find the resource in the zip file
unzFile pZipFile = unzOpen(s_pszZipFilePath);
do
{
CC_BREAK_IF(!pZipFile);
// get the user data path and append relative path to it
if (strlen(s_pszResourcePath) == 0)
{
const char* pAppDataPath = CCApplication::sharedApplication().getAppDataPath();
strcpy(s_pszResourcePath, pAppDataPath);
}
Int32 nPos = unzLocateFile(pZipFile, pszResName, 1);
CC_BREAK_IF(nPos != UNZ_OK);
#ifndef _TRANZDA_VM_
char *pszDriver = "";
#else
char *pszDriver = "D:/Work7";
#endif
CCString * pRet = new CCString();
pRet->autorelease();
if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':'))
{
pRet->m_sString = pszRelativePath;
}
else if (strlen(pszRelativePath) > 0 && pszRelativePath[0] == '/')
{
pRet->m_sString = pszDriver;
pRet->m_sString += pszRelativePath;
bRet = true;
unzClose(pZipFile);
} while (0);
}
else
{
pRet->m_sString = pszDriver;
pRet->m_sString += s_pszResourcePath;
pRet->m_sString += pszRelativePath;
// find in the hardware
if (EOS_IsFileExist(FilePath))
{
bRet = true;
}
}
return CCFileUtils::getDiffResolutionPath(pRet->m_sString.c_str());
}
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
CCString *pRet = new CCString();
pRet->autorelease();
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
pRet->m_sString += pszFilename;
return CCFileUtils::getDiffResolutionPath(pRet->m_sString.c_str());
}
CCDictionary<std::string, CCObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
{
CCDictMaker tMaker;
return tMaker.dictionaryWithContentsOfFile(pFileName);
return bRet;
}
const char* CCFileUtils::getDiffResolutionPath(const char *pszPath)
const char* getDiffResolutionPath(const char *pszPath)
{
CCString *pRet = new CCString(pszPath);
pRet->autorelease();
@ -394,7 +181,7 @@ const char* CCFileUtils::getDiffResolutionPath(const char *pszPath)
pRet->m_sString = filePathWithoutExtension + "@WVGA" + extension;
// not find the resource of new path,use the original path
if (! CCFileUtils::isResourceExist(pRet->m_sString.c_str()))
if (! isResourceExist(pRet->m_sString.c_str()))
{
pRet->m_sString = filePath;
}
@ -409,38 +196,79 @@ const char* CCFileUtils::getDiffResolutionPath(const char *pszPath)
return pRet->m_sString.c_str();
}
bool CCFileUtils::isResourceExist(const char* pszResName)
void CCFileUtils::setResource(const char* pszZipFileName, const char* pszResPath)
{
bool bRet = false;
if (pszResPath != NULL && pszZipFileName != NULL)
{
// record the resource path
strcpy(s_pszResourcePath, pszResPath);
TUChar FilePath[EOS_FILE_MAX_PATH] = {0};
TUString::StrGBToUnicode(FilePath, (const Char *) pszResName);
// record the zip file path
setZipFilePath(pszZipFileName);
}
else if (pszResPath != NULL)
{
// update the zip file path
updateZipFilePath(pszResPath);
// record the resource path
strcpy(s_pszResourcePath, pszResPath);
}
else if (pszZipFileName != NULL)
{
// record the zip file path
setZipFilePath(pszZipFileName);
}
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
// if have set the zip file path,return the relative path of zip file
if (strlen(s_pszZipFilePath) != 0)
{
// if have set the zip file path,find the resource in the zip file
unzFile pZipFile = unzOpen(s_pszZipFilePath);
do
{
CC_BREAK_IF(!pZipFile);
return getDiffResolutionPath(pszRelativePath);
}
Int32 nPos = unzLocateFile(pZipFile, pszResName, 1);
CC_BREAK_IF(nPos != UNZ_OK);
// get the user data path and append relative path to it
if (strlen(s_pszResourcePath) == 0)
{
const char* pAppDataPath = CCApplication::sharedApplication().getAppDataPath();
strcpy(s_pszResourcePath, pAppDataPath);
}
bRet = true;
unzClose(pZipFile);
} while (0);
#ifndef _TRANZDA_VM_
char *pszDriver = "";
#else
char *pszDriver = "D:/Work7";
#endif
CCString * pRet = new CCString();
pRet->autorelease();
if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':'))
{
pRet->m_sString = pszRelativePath;
}
else if (strlen(pszRelativePath) > 0 && pszRelativePath[0] == '/')
{
pRet->m_sString = pszDriver;
pRet->m_sString += pszRelativePath;
}
else
{
// find in the hardware
if (EOS_IsFileExist(FilePath))
{
bRet = true;
}
pRet->m_sString = pszDriver;
pRet->m_sString += s_pszResourcePath;
pRet->m_sString += pszRelativePath;
}
return bRet;
return getDiffResolutionPath(pRet->m_sString.c_str());
}
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
CCString *pRet = new CCString();
pRet->autorelease();
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
pRet->m_sString += pszFilename;
return getDiffResolutionPath(pRet->m_sString.c_str());
}
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
@ -452,7 +280,7 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
if (strlen(s_pszZipFilePath) != 0)
{
// if specify the zip file,load from it first
pBuffer = FileUtils::getFileDataFromZip(s_pszZipFilePath, pszFileName, pSize);
pBuffer = getFileDataFromZip(s_pszZipFilePath, pszFileName, pSize);
CC_BREAK_IF(pBuffer);
}
@ -471,10 +299,20 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
return pBuffer;
}
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
void CCFileUtils::setResourcePath(const char *pszResourcePath)
{
///@todo
return 0;
CCAssert(0, "Have not implement!");
}
}//namespace cocos2d
const char* CCFileUtils::getResourcePath(void)
{
CCAssert(0, "Have not implement!");
return NULL;
}
void CCFileUtils::setRelativePath(const char* pszRelativePath)
{
CCAssert(0, "Have not implement!");
}
NS_CC_END;

View File

@ -1,98 +0,0 @@
/****************************************************************************
Copyright (c) 2010 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.
****************************************************************************/
#ifndef __PLATFORM_WOPHONE_CCFILE_UTILS_H__
#define __PLATFORM_WOPHONE_CCFILE_UTILS_H__
#include <string>
#include "ssFile.h"
#include "CCCommon.h"
#include "CCMutableDictionary.h"
#include "FileUtils.h"
namespace cocos2d {
//! @brief Helper class to handle file operations
class CC_DLL CCFileUtils : public FileUtils
{
public:
/**
@brief Generate the absolute path of the file.
@param pszRelativePath The relative path of the file.
@return The absolute path of the file.
@warning We only add the ResourcePath before the relative path of the file.
If you have not set the ResourcePath,the function add "/NEWPLUS/TDA_DATA/UserData/" as default.
You can set ResourcePath by function void setResourcePath(const char *pszResourcePath);
*/
static const char* fullPathFromRelativePath(const char *pszRelativePath);
/// @cond
static const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile);
static const char* getDiffResolutionPath(const char *pszPath);
/// @endcond
/**
@brief Generate a CCDictionary pointer by file
@param pFileName The file name of *.plist file
@return The CCDictionary pointer generated from the file
*/
static CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName);
/**
@brief Set the ResourcePath and(or) the zip file name
@param pszResPath The absolute resource path
@param pszZipFileName The relative path of the .zip file
*/
static void setResource(const char* pszZipFileName, const char* pszResPath = NULL);
/**
@brief Whether the resource is exist or not.The function find the resource in hardware,if not find,it will find in resource map.
@param pszResName The name of resource
@return The return value is true if exist,otherwise return false.
*/
static bool isResourceExist(const char* pszResName);
/** loads a file into memory.
the caller should release the allocated buffer.
@returns the size of the allocated buffer
@since v0.99.5
*/
static int ccLoadFileIntoMemory(const char *filename, unsigned char **out);
/**
@brief Get resource file data
@param[in] pszFileName The resource file name which contain the path
@param[in] pszMode The read mode of the file
@param[out] pSize If get the file data succeed the it will be the data size,or it will be 0
@return if success,the pointer of data will be returned,or NULL is returned
@warning If you get the file data succeed,you must delete it after used.
*/
static unsigned char* getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize);
};
}//namespace cocos2d
#endif // __PLATFORM_WOPHONE_CCFILE_UTILS_H__

View File

@ -399,10 +399,6 @@
RelativePath="..\include\CCEventDispatcher.h"
>
</File>
<File
RelativePath="..\include\CCFileUtils.h"
>
</File>
<File
RelativePath="..\include\CCGeometry.h"
>
@ -623,10 +619,6 @@
RelativePath="..\include\cocos2d.h"
>
</File>
<File
RelativePath="..\include\FileUtils.h"
>
</File>
<File
RelativePath="..\include\selector_protocol.h"
>
@ -740,7 +732,11 @@
>
</File>
<File
RelativePath="..\platform\CCFileUtils_platform.h"
RelativePath="..\platform\CCFileUtils.cpp"
>
</File>
<File
RelativePath="..\platform\CCFileUtils.h"
>
</File>
<File
@ -862,14 +858,6 @@
RelativePath="..\platform\win32\CCEGLView_win32.h"
>
</File>
<File
RelativePath="..\platform\win32\CCFileUtils_win32.cpp"
>
</File>
<File
RelativePath="..\platform\win32\CCFileUtils_win32.h"
>
</File>
<File
RelativePath="..\platform\win32\CCNS_win32.cpp"
>
@ -1003,18 +991,6 @@
>
</File>
</Filter>
<Filter
Name="file_support"
>
<File
RelativePath="..\support\file_support\FileData.h"
>
</File>
<File
RelativePath="..\support\file_support\FileUtils.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="textures"

View File

@ -78,6 +78,7 @@ OBJECTS = \
$(OBJECTS_DIR)/CCParticleSystemQuad.o \
$(OBJECTS_DIR)/CCCommon.o \
$(OBJECTS_DIR)/CCDirector_mobile.o \
$(OBJECTS_DIR)/CCFileUtils.o \
$(OBJECTS_DIR)/CCGL.o \
$(OBJECTS_DIR)/CCGrid_mobile.o \
$(OBJECTS_DIR)/CCImage.o \
@ -85,6 +86,7 @@ OBJECTS = \
$(OBJECTS_DIR)/CCMenu_mobile.o \
$(OBJECTS_DIR)/CCNode_mobile.o \
$(OBJECTS_DIR)/CCParticleSystemPoint_mobile.o \
$(OBJECTS_DIR)/CCSAXParser.o \
$(OBJECTS_DIR)/CCStdC.o \
$(OBJECTS_DIR)/CCThread.o \
$(OBJECTS_DIR)/CCTransition_mobile.o \
@ -93,7 +95,6 @@ OBJECTS = \
$(OBJECTS_DIR)/CCAccelerometer_wophone.o \
$(OBJECTS_DIR)/CCApplication_wophone.o \
$(OBJECTS_DIR)/CCEGLView_wophone.o \
$(OBJECTS_DIR)/CCFileUtils_wophone.o \
$(OBJECTS_DIR)/CCNS_wophone.o \
$(OBJECTS_DIR)/CCAnimation.o \
$(OBJECTS_DIR)/CCAnimationCache.o \
@ -107,7 +108,6 @@ OBJECTS = \
$(OBJECTS_DIR)/CCProfiling.o \
$(OBJECTS_DIR)/ccUtils.o \
$(OBJECTS_DIR)/TransformUtils.o \
$(OBJECTS_DIR)/FileUtils.o \
$(OBJECTS_DIR)/TGAlib.o \
$(OBJECTS_DIR)/ioapi.o \
$(OBJECTS_DIR)/unzip.o \
@ -121,7 +121,6 @@ OBJECTS = \
$(OBJECTS_DIR)/CCTMXObjectGroup.o \
$(OBJECTS_DIR)/CCTMXTiledMap.o \
$(OBJECTS_DIR)/CCTMXXMLParser.o \
$(OBJECTS_DIR)/CCSAXParser.o \
$(OBJECTS_DIR)/CCTouchDispatcher.o \
$(OBJECTS_DIR)/CCTouchHandler.o
@ -280,6 +279,9 @@ $(OBJECTS_DIR)/CCCommon.o : ../platform/CCCommon.cpp
$(OBJECTS_DIR)/CCDirector_mobile.o : ../platform/CCDirector_mobile.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCDirector_mobile.o ../platform/CCDirector_mobile.cpp
$(OBJECTS_DIR)/CCFileUtils.o : ../platform/CCFileUtils.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCFileUtils.o ../platform/CCFileUtils.cpp
$(OBJECTS_DIR)/CCGL.o : ../platform/CCGL.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCGL.o ../platform/CCGL.cpp
@ -328,9 +330,6 @@ $(OBJECTS_DIR)/CCApplication_wophone.o : ../platform/wophone/CCApplication_wopho
$(OBJECTS_DIR)/CCEGLView_wophone.o : ../platform/wophone/CCEGLView_wophone.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCEGLView_wophone.o ../platform/wophone/CCEGLView_wophone.cpp
$(OBJECTS_DIR)/CCFileUtils_wophone.o : ../platform/wophone/CCFileUtils_wophone.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCFileUtils_wophone.o ../platform/wophone/CCFileUtils_wophone.cpp
$(OBJECTS_DIR)/CCNS_wophone.o : ../platform/wophone/CCNS_wophone.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCNS_wophone.o ../platform/wophone/CCNS_wophone.cpp
@ -370,9 +369,6 @@ $(OBJECTS_DIR)/ccUtils.o : ../support/ccUtils.cpp
$(OBJECTS_DIR)/TransformUtils.o : ../support/TransformUtils.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/TransformUtils.o ../support/TransformUtils.cpp
$(OBJECTS_DIR)/FileUtils.o : ../support/file_support/FileUtils.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/FileUtils.o ../support/file_support/FileUtils.cpp
$(OBJECTS_DIR)/TGAlib.o : ../support/image_support/TGAlib.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/TGAlib.o ../support/image_support/TGAlib.cpp

View File

@ -62,7 +62,10 @@ EXCLUDEFILE= ./textures/CCPVRTexture.cpp
EXCLUDEFILE= ./platform/wophone/NewDeleteOp.cpp
EXCLUDEFILE= ./platform/wophone/CCImage_wophone.cpp
EXCLUDEFILE= ./platform/wophone/CCThread_wophone.cpp
EXCLUDEFILE= ./platform/wophone/CCFileUtils_wophone.cpp
EXCLUDEFILE= ./platform/win32/
EXCLUDEFILE= ./platform/android/
EXCLUDEFILE= ./platform/iphone/
EXCLUDEFILE= ./platform/mac/
EXCLUDEFILE= ./platform/airplay/
EXCLUDEFILE= ./platform/third_party/

View File

@ -368,10 +368,6 @@
RelativePath="..\include\CCEventDispatcher.h"
>
</File>
<File
RelativePath="..\include\CCFileUtils.h"
>
</File>
<File
RelativePath="..\include\CCGeometry.h"
>
@ -592,10 +588,6 @@
RelativePath="..\include\cocos2d.h"
>
</File>
<File
RelativePath="..\include\FileUtils.h"
>
</File>
<File
RelativePath="..\include\selector_protocol.h"
>
@ -808,18 +800,6 @@
>
</File>
</Filter>
<Filter
Name="file_support"
>
<File
RelativePath="..\support\file_support\FileData.h"
>
</File>
<File
RelativePath="..\support\file_support\FileUtils.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="textures"
@ -945,7 +925,11 @@
>
</File>
<File
RelativePath="..\platform\CCFileUtils_platform.h"
RelativePath="..\platform\CCFileUtils.cpp"
>
</File>
<File
RelativePath="..\platform\CCFileUtils.h"
>
</File>
<File
@ -1067,14 +1051,6 @@
RelativePath="..\platform\wophone\CCEGLView_wophone.h"
>
</File>
<File
RelativePath="..\platform\wophone\CCFileUtils_wophone.cpp"
>
</File>
<File
RelativePath="..\platform\wophone\CCFileUtils_wophone.h"
>
</File>
<File
RelativePath="..\platform\wophone\CCNS_wophone.cpp"
>

View File

@ -1,63 +0,0 @@
/****************************************************************************
Copyright (c) 2010 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.
****************************************************************************/
#ifndef __SUPPORT_DATA_SUPPORT_FILEDATA_H__
#define __SUPPORT_DATA_SUPPORT_FILEDATA_H__
#include "CCFileUtils.h"
namespace cocos2d
{
class FileData
{
public:
FileData() : m_pBuffer(NULL) {}
~FileData()
{
if (m_pBuffer)
{
delete [] m_pBuffer;
m_pBuffer = NULL;
}
}
unsigned char* getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
if (m_pBuffer)
{
delete [] m_pBuffer;
m_pBuffer = NULL;
}
m_pBuffer = CCFileUtils::getFileData(pszFileName, pszMode, pSize);
return m_pBuffer;
}
protected:
unsigned char* m_pBuffer;
};
} // namespace cocos2d
#endif // __SUPPORT_DATA_SUPPORT_FILEDATA_H__

View File

@ -1,120 +0,0 @@
/****************************************************************************
Copyright (c) 2010 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 "FileUtils.h"
#include <stdio.h>
#include "ccMacros.h"
#include "support/zip_support/unzip.h"
#include <string>
#include <assert.h>
namespace cocos2d {
unsigned char* FileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
{
unsigned char * Buffer = NULL;
do
{
// read the file from hardware
FILE *fp = fopen(pszFileName, pszMode);
CC_BREAK_IF(!fp);
fseek(fp,0,SEEK_END);
*pSize = ftell(fp);
fseek(fp,0,SEEK_SET);
Buffer = new unsigned char[*pSize];
*pSize = fread(Buffer,sizeof(unsigned char), *pSize,fp);
fclose(fp);
} while (0);
return Buffer;
}
unsigned char* FileUtils::getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize)
{
unsigned char * pBuffer = NULL;
unzFile pFile = NULL;
*pSize = 0;
do
{
CC_BREAK_IF(!pszZipFilePath || !pszFileName);
CC_BREAK_IF(strlen(pszZipFilePath) == 0);
pFile = unzOpen(pszZipFilePath);
CC_BREAK_IF(!pFile);
int nRet = unzLocateFile(pFile, pszFileName, 1);
CC_BREAK_IF(UNZ_OK != nRet);
char szFilePathA[260];
unz_file_info FileInfo;
nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0);
CC_BREAK_IF(UNZ_OK != nRet);
nRet = unzOpenCurrentFile(pFile);
CC_BREAK_IF(UNZ_OK != nRet);
pBuffer = new unsigned char[FileInfo.uncompressed_size];
int nSize = 0;
nSize = unzReadCurrentFile(pFile, pBuffer, FileInfo.uncompressed_size);
CCAssert(nSize == 0 || nSize == FileInfo.uncompressed_size, "the file size is wrong");
*pSize = FileInfo.uncompressed_size;
unzCloseCurrentFile(pFile);
} while (0);
if (pFile)
{
unzClose(pFile);
}
return pBuffer;
}
std::string& FileUtils::ccRemoveHDSuffixFromFile(std::string& path)
{
#if CC_IS_RETINA_DISPLAY_SUPPORTED
if( CC_CONTENT_SCALE_FACTOR() == 2 )
{
std::string::size_type pos = path.rfind("/") + 1; // the begin index of last part of path
std::string::size_type suffixPos = path.rfind(CC_RETINA_DISPLAY_FILENAME_SUFFIX);
if (std::string::npos != suffixPos && suffixPos > pos)
{
CCLog("cocos2d: FilePath(%s) contains suffix(%s), remove it.", path.c_str(),
CC_RETINA_DISPLAY_FILENAME_SUFFIX);
path.replace(suffixPos, strlen(CC_RETINA_DISPLAY_FILENAME_SUFFIX), "");
}
}
#endif // CC_IS_RETINA_DISPLAY_SUPPORTED
return path;
}
} //namespace cocos2d

View File

@ -26,7 +26,7 @@ THE SOFTWARE.
#include <stdlib.h>
#include "TGAlib.h"
#include "support/file_support/FileData.h"
#include "CCFileUtils.h"
namespace cocos2d {

View File

@ -34,7 +34,6 @@ THE SOFTWARE.
#include "platform/platform.h"
#include "CCFileUtils.h"
#include "CCImage.h"
#include "support/file_support/FileData.h"
namespace cocos2d {

View File

@ -27,7 +27,7 @@ THE SOFTWARE.
#include "CCTMXXMLParser.h"
#include "CCTMXTiledMap.h"
#include "ccMacros.h"
#include "support/file_support/FileData.h"
#include "CCFileUtils.h"
#include "support/zip_support/ZipUtils.h"
#include "CCPointExtension.h"
#include "support/base64.h"