2013-02-01 11:20:46 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2013-02-01 11:20:46 +08:00
|
|
|
|
|
|
|
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_ANDROID_H__
|
|
|
|
#define __CC_FILEUTILS_ANDROID_H__
|
|
|
|
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "base/CCPlatformConfig.h"
|
2014-01-31 08:51:43 +08:00
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
|
|
|
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCPlatformMacros.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/ccTypes.h"
|
2013-02-01 11:20:46 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2013-03-08 05:56:42 +08:00
|
|
|
#include "jni.h"
|
|
|
|
#include "android/asset_manager.h"
|
|
|
|
|
2013-02-01 11:20:46 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup platform
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
//! @brief Helper class to handle file operations
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL FileUtilsAndroid : public FileUtils
|
2013-02-01 11:20:46 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
friend class FileUtils;
|
|
|
|
FileUtilsAndroid();
|
2013-02-01 11:20:46 +08:00
|
|
|
public:
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~FileUtilsAndroid();
|
2013-02-01 22:19:58 +08:00
|
|
|
|
2013-07-03 09:35:46 +08:00
|
|
|
static void setassetmanager(AAssetManager* a);
|
2014-08-06 12:36:04 +08:00
|
|
|
static AAssetManager* getAssetManager() { return assetmanager; }
|
2013-07-03 09:35:46 +08:00
|
|
|
|
2013-02-01 11:20:46 +08:00
|
|
|
/* override funtions */
|
|
|
|
bool init();
|
2013-12-18 14:58:17 +08:00
|
|
|
|
|
|
|
/** @deprecated Please use FileUtils::getDataFromFile or FileUtils::getStringFromFile instead. */
|
2013-12-25 13:57:17 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual unsigned char* getFileData(const std::string& filename, const char* mode, ssize_t * size) override;
|
2013-12-18 14:58:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets string from a file.
|
|
|
|
*/
|
|
|
|
virtual std::string getStringFromFile(const std::string& filename) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates binary data from a file.
|
|
|
|
* @return A data object.
|
|
|
|
*/
|
|
|
|
virtual Data getDataFromFile(const std::string& filename) override;
|
2013-09-07 13:52:23 +08:00
|
|
|
|
|
|
|
virtual std::string getWritablePath() const;
|
|
|
|
virtual bool isAbsolutePath(const std::string& strPath) const;
|
2013-06-18 17:10:54 +08:00
|
|
|
|
|
|
|
private:
|
2014-04-02 15:35:09 +08:00
|
|
|
virtual bool isFileExistInternal(const std::string& strFilePath) const;
|
2013-12-18 14:58:17 +08:00
|
|
|
Data getData(const std::string& filename, bool forString);
|
|
|
|
|
2013-07-03 09:35:46 +08:00
|
|
|
static AAssetManager* assetmanager;
|
2013-02-01 11:20:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// end of platform group
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2014-01-31 08:51:43 +08:00
|
|
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
|
|
|
|
|
|
|
#endif // __CC_FILEUTILS_ANDROID_H__
|