2013-02-01 11:20:46 +08:00
|
|
|
#include "CCFileUtilsBlackberry.h"
|
|
|
|
#include "platform/CCCommon.h"
|
|
|
|
#include "ccMacros.h"
|
|
|
|
#include "CCApplication.h"
|
|
|
|
#include "cocoa/CCString.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FileUtils* FileUtils::sharedFileUtils()
|
2013-02-01 11:20:46 +08:00
|
|
|
{
|
|
|
|
if (s_sharedFileUtils == NULL)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
s_sharedFileUtils = new FileUtilsBlackberry();
|
2013-02-01 11:20:46 +08:00
|
|
|
s_sharedFileUtils->init();
|
|
|
|
}
|
|
|
|
return s_sharedFileUtils;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FileUtilsBlackberry::FileUtilsBlackberry()
|
2013-02-01 11:20:46 +08:00
|
|
|
{}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool FileUtilsBlackberry::init()
|
2013-02-01 11:20:46 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_defaultResRootPath = "app/native/Resources/";
|
2013-06-20 14:13:12 +08:00
|
|
|
return FileUtils::init();
|
2013-02-01 11:20:46 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
string FileUtilsBlackberry::getWritablePath()
|
2013-02-01 11:20:46 +08:00
|
|
|
{
|
|
|
|
// Let's write it in the current working directory's data folder
|
|
|
|
char cwd[FILENAME_MAX] = {0};
|
|
|
|
|
|
|
|
getcwd(cwd, FILENAME_MAX - 1);
|
|
|
|
cwd[FILENAME_MAX-1] = '\0';
|
|
|
|
|
|
|
|
std::string path = cwd;
|
|
|
|
path += "/data/";
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool FileUtilsBlackberry::isAbsolutePath(const std::string& strPath)
|
2013-02-01 11:20:46 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (strPath[0] == '/' || strPath.find(_defaultResRootPath) == 0)
|
2013-02-01 11:20:46 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool FileUtilsBlackberry::isFileExist(const std::string& strFilePath)
|
2013-02-01 11:20:46 +08:00
|
|
|
{
|
2013-04-25 21:51:13 +08:00
|
|
|
if (0 == strFilePath.length())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-01 22:19:58 +08:00
|
|
|
std::string strPath = strFilePath;
|
|
|
|
if (strPath[0] != '/')
|
|
|
|
{ // Not absolute path, add the default root path at the beginning.
|
2013-06-15 14:03:30 +08:00
|
|
|
if (strPath.find(_defaultResRootPath) != 0)
|
2013-02-01 22:19:58 +08:00
|
|
|
{// Didn't find "assets/" at the beginning of the path, adding it.
|
2013-06-15 14:03:30 +08:00
|
|
|
strPath.insert(0, _defaultResRootPath);
|
2013-02-01 22:19:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return access(strPath.c_str(), F_OK) != -1 ? true : false;
|
2013-02-01 11:20:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|