mirror of https://github.com/axmolengine/axmol.git
Restructure CCFileUtils class, move platform related functions to CCFileUtilsXXX.
Add TestIsDirectoryExist and TestUnicodePath in cpp-tests FileUtil test.
This commit is contained in:
commit
0589c14302
|
@ -41,24 +41,12 @@ THE SOFTWARE.
|
||||||
#endif
|
#endif
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
NS_CC_BEGIN
|
||||||
#include <regex>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
// Implement DictMaker
|
||||||
#include <ftw.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC)
|
||||||
|
|
||||||
NS_CC_BEGIN
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
SAX_NONE = 0,
|
SAX_NONE = 0,
|
||||||
|
@ -81,17 +69,17 @@ class DictMaker : public SAXDelegator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SAXResult _resultType;
|
SAXResult _resultType;
|
||||||
ValueMap _rootDict;
|
ValueMap _rootDict;
|
||||||
ValueVector _rootArray;
|
ValueVector _rootArray;
|
||||||
|
|
||||||
std::string _curKey; ///< parsed key
|
std::string _curKey; ///< parsed key
|
||||||
std::string _curValue; // parsed value
|
std::string _curValue; // parsed value
|
||||||
SAXState _state;
|
SAXState _state;
|
||||||
|
|
||||||
ValueMap* _curDict;
|
ValueMap* _curDict;
|
||||||
ValueVector* _curArray;
|
ValueVector* _curArray;
|
||||||
|
|
||||||
std::stack<ValueMap*> _dictStack;
|
std::stack<ValueMap*> _dictStack;
|
||||||
std::stack<ValueVector*> _arrayStack;
|
std::stack<ValueVector*> _arrayStack;
|
||||||
std::stack<SAXState> _stateStack;
|
std::stack<SAXState> _stateStack;
|
||||||
|
|
||||||
|
@ -114,20 +102,20 @@ public:
|
||||||
parser.setDelegator(this);
|
parser.setDelegator(this);
|
||||||
|
|
||||||
parser.parse(fileName);
|
parser.parse(fileName);
|
||||||
return _rootDict;
|
return _rootDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueMap dictionaryWithDataOfFile(const char* filedata, int filesize)
|
ValueMap dictionaryWithDataOfFile(const char* filedata, int filesize)
|
||||||
{
|
{
|
||||||
_resultType = SAX_RESULT_DICT;
|
_resultType = SAX_RESULT_DICT;
|
||||||
SAXParser parser;
|
SAXParser parser;
|
||||||
|
|
||||||
CCASSERT(parser.init("UTF-8"), "The file format isn't UTF-8");
|
CCASSERT(parser.init("UTF-8"), "The file format isn't UTF-8");
|
||||||
parser.setDelegator(this);
|
parser.setDelegator(this);
|
||||||
|
|
||||||
parser.parse(filedata, filesize);
|
parser.parse(filedata, filesize);
|
||||||
return _rootDict;
|
return _rootDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueVector arrayWithContentsOfFile(const std::string& fileName)
|
ValueVector arrayWithContentsOfFile(const std::string& fileName)
|
||||||
{
|
{
|
||||||
|
@ -138,7 +126,7 @@ public:
|
||||||
parser.setDelegator(this);
|
parser.setDelegator(this);
|
||||||
|
|
||||||
parser.parse(fileName);
|
parser.parse(fileName);
|
||||||
return _rootArray;
|
return _rootArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
void startElement(void *ctx, const char *name, const char **atts)
|
void startElement(void *ctx, const char *name, const char **atts)
|
||||||
|
@ -148,7 +136,7 @@ public:
|
||||||
const std::string sName(name);
|
const std::string sName(name);
|
||||||
if( sName == "dict" )
|
if( sName == "dict" )
|
||||||
{
|
{
|
||||||
if(_resultType == SAX_RESULT_DICT && _rootDict.empty())
|
if(_resultType == SAX_RESULT_DICT && _rootDict.empty())
|
||||||
{
|
{
|
||||||
_curDict = &_rootDict;
|
_curDict = &_rootDict;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +153,7 @@ public:
|
||||||
{
|
{
|
||||||
// add a new dictionary into the array
|
// add a new dictionary into the array
|
||||||
_curArray->push_back(Value(ValueMap()));
|
_curArray->push_back(Value(ValueMap()));
|
||||||
_curDict = &(_curArray->rbegin())->asValueMap();
|
_curDict = &(_curArray->rbegin())->asValueMap();
|
||||||
}
|
}
|
||||||
else if (SAX_DICT == preState)
|
else if (SAX_DICT == preState)
|
||||||
{
|
{
|
||||||
|
@ -173,7 +161,7 @@ public:
|
||||||
CCASSERT(! _dictStack.empty(), "The state is wrong!");
|
CCASSERT(! _dictStack.empty(), "The state is wrong!");
|
||||||
ValueMap* preDict = _dictStack.top();
|
ValueMap* preDict = _dictStack.top();
|
||||||
(*preDict)[_curKey] = Value(ValueMap());
|
(*preDict)[_curKey] = Value(ValueMap());
|
||||||
_curDict = &(*preDict)[_curKey].asValueMap();
|
_curDict = &(*preDict)[_curKey].asValueMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// record the dict state
|
// record the dict state
|
||||||
|
@ -200,9 +188,9 @@ public:
|
||||||
{
|
{
|
||||||
_state = SAX_ARRAY;
|
_state = SAX_ARRAY;
|
||||||
|
|
||||||
if (_resultType == SAX_RESULT_ARRAY && _rootArray.empty())
|
if (_resultType == SAX_RESULT_ARRAY && _rootArray.empty())
|
||||||
{
|
{
|
||||||
_curArray = &_rootArray;
|
_curArray = &_rootArray;
|
||||||
}
|
}
|
||||||
SAXState preState = SAX_NONE;
|
SAXState preState = SAX_NONE;
|
||||||
if (! _stateStack.empty())
|
if (! _stateStack.empty())
|
||||||
|
@ -213,14 +201,14 @@ public:
|
||||||
if (preState == SAX_DICT)
|
if (preState == SAX_DICT)
|
||||||
{
|
{
|
||||||
(*_curDict)[_curKey] = Value(ValueVector());
|
(*_curDict)[_curKey] = Value(ValueVector());
|
||||||
_curArray = &(*_curDict)[_curKey].asValueVector();
|
_curArray = &(*_curDict)[_curKey].asValueVector();
|
||||||
}
|
}
|
||||||
else if (preState == SAX_ARRAY)
|
else if (preState == SAX_ARRAY)
|
||||||
{
|
{
|
||||||
CCASSERT(! _arrayStack.empty(), "The state is wrong!");
|
CCASSERT(! _arrayStack.empty(), "The state is wrong!");
|
||||||
ValueVector* preArray = _arrayStack.top();
|
ValueVector* preArray = _arrayStack.top();
|
||||||
preArray->push_back(Value(ValueVector()));
|
preArray->push_back(Value(ValueVector()));
|
||||||
_curArray = &(_curArray->rbegin())->asValueVector();
|
_curArray = &(_curArray->rbegin())->asValueVector();
|
||||||
}
|
}
|
||||||
// record the array state
|
// record the array state
|
||||||
_stateStack.push(_state);
|
_stateStack.push(_state);
|
||||||
|
@ -370,8 +358,12 @@ static tinyxml2::XMLElement* generateElementForDict(const ValueMap& dict, tinyxm
|
||||||
*/
|
*/
|
||||||
bool FileUtils::writeToFile(ValueMap& dict, const std::string &fullPath)
|
bool FileUtils::writeToFile(ValueMap& dict, const std::string &fullPath)
|
||||||
{
|
{
|
||||||
//CCLOG("tinyxml2 Dictionary %d writeToFile %s", dict->_ID, fullPath.c_str());
|
return writeValueMapToFile(dict, fullPath);
|
||||||
tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument();
|
}
|
||||||
|
|
||||||
|
bool FileUtils::writeValueMapToFile(ValueMap& dict, const std::string& fullPath)
|
||||||
|
{
|
||||||
|
tinyxml2::XMLDocument *doc = new (std::nothrow)tinyxml2::XMLDocument();
|
||||||
if (nullptr == doc)
|
if (nullptr == doc)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -396,7 +388,47 @@ bool FileUtils::writeToFile(ValueMap& dict, const std::string &fullPath)
|
||||||
doc->LinkEndChild(rootEle);
|
doc->LinkEndChild(rootEle);
|
||||||
|
|
||||||
tinyxml2::XMLElement *innerDict = generateElementForDict(dict, doc);
|
tinyxml2::XMLElement *innerDict = generateElementForDict(dict, doc);
|
||||||
if (nullptr == innerDict )
|
if (nullptr == innerDict)
|
||||||
|
{
|
||||||
|
delete doc;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
rootEle->LinkEndChild(innerDict);
|
||||||
|
|
||||||
|
bool ret = tinyxml2::XML_SUCCESS == doc->SaveFile(getSuitableFOpen(fullPath).c_str());
|
||||||
|
|
||||||
|
delete doc;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtils::writeValueVectorToFile(ValueVector vecData, const std::string& fullPath)
|
||||||
|
{
|
||||||
|
tinyxml2::XMLDocument *doc = new (std::nothrow)tinyxml2::XMLDocument();
|
||||||
|
if (nullptr == doc)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
tinyxml2::XMLDeclaration *declaration = doc->NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\"");
|
||||||
|
if (nullptr == declaration)
|
||||||
|
{
|
||||||
|
delete doc;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
doc->LinkEndChild(declaration);
|
||||||
|
tinyxml2::XMLElement *docType = doc->NewElement("!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
|
||||||
|
doc->LinkEndChild(docType);
|
||||||
|
|
||||||
|
tinyxml2::XMLElement *rootEle = doc->NewElement("plist");
|
||||||
|
rootEle->SetAttribute("version", "1.0");
|
||||||
|
if (nullptr == rootEle)
|
||||||
|
{
|
||||||
|
delete doc;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
doc->LinkEndChild(rootEle);
|
||||||
|
|
||||||
|
tinyxml2::XMLElement *innerDict = generateElementForArray(vecData, doc);
|
||||||
|
if (nullptr == innerDict)
|
||||||
{
|
{
|
||||||
delete doc;
|
delete doc;
|
||||||
return false;
|
return false;
|
||||||
|
@ -443,8 +475,8 @@ static tinyxml2::XMLElement* generateElementForObject(const Value& value, tinyxm
|
||||||
|
|
||||||
//object is bool
|
//object is bool
|
||||||
if (value.getType() == Value::Type::BOOLEAN) {
|
if (value.getType() == Value::Type::BOOLEAN) {
|
||||||
tinyxml2::XMLElement* node = doc->NewElement(value.asString().c_str());
|
tinyxml2::XMLElement* node = doc->NewElement(value.asString().c_str());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
// object is Array
|
// object is Array
|
||||||
|
@ -496,7 +528,6 @@ static tinyxml2::XMLElement* generateElementForArray(const ValueVector& array, t
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
NS_CC_BEGIN
|
|
||||||
|
|
||||||
/* The subclass FileUtilsApple should override these two method. */
|
/* The subclass FileUtilsApple should override these two method. */
|
||||||
ValueMap FileUtils::getValueMapFromFile(const std::string& filename) {return ValueMap();}
|
ValueMap FileUtils::getValueMapFromFile(const std::string& filename) {return ValueMap();}
|
||||||
|
@ -506,6 +537,7 @@ bool FileUtils::writeToFile(ValueMap& dict, const std::string &fullPath) {return
|
||||||
|
|
||||||
#endif /* (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC) */
|
#endif /* (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC) */
|
||||||
|
|
||||||
|
// Implement FileUtils
|
||||||
FileUtils* FileUtils::s_sharedFileUtils = nullptr;
|
FileUtils* FileUtils::s_sharedFileUtils = nullptr;
|
||||||
|
|
||||||
void FileUtils::destroyInstance()
|
void FileUtils::destroyInstance()
|
||||||
|
@ -530,7 +562,38 @@ FileUtils::~FileUtils()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileUtils::writeStringToFile(std::string dataStr, const std::string& fullPath)
|
||||||
|
{
|
||||||
|
Data retData;
|
||||||
|
retData.copy((unsigned char*)dataStr.c_str(), dataStr.size());
|
||||||
|
|
||||||
|
return writeDataToFile(retData, fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtils::writeDataToFile(Data retData, const std::string& fullPath)
|
||||||
|
{
|
||||||
|
size_t size = 0;
|
||||||
|
const char* mode = "wb";
|
||||||
|
|
||||||
|
CCASSERT(!fullPath.empty() && retData.getSize() != 0, "Invalid parameters.");
|
||||||
|
|
||||||
|
auto fileutils = FileUtils::getInstance();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
// Read the file from hardware
|
||||||
|
FILE *fp = fopen(fileutils->getSuitableFOpen(fullPath).c_str(), mode);
|
||||||
|
CC_BREAK_IF(!fp);
|
||||||
|
size = retData.getSize();
|
||||||
|
|
||||||
|
fwrite(retData.getBytes(), size, 1, fp);
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool FileUtils::init()
|
bool FileUtils::init()
|
||||||
{
|
{
|
||||||
|
@ -608,7 +671,7 @@ std::string FileUtils::getStringFromFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
Data data = getData(filename, true);
|
Data data = getData(filename, true);
|
||||||
if (data.isNull())
|
if (data.isNull())
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
std::string ret((const char*)data.getBytes());
|
std::string ret((const char*)data.getBytes());
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -756,7 +819,7 @@ std::string FileUtils::fullPathForFilename(const std::string &filename) const
|
||||||
// Get the new file name.
|
// Get the new file name.
|
||||||
const std::string newFilename( getNewFilename(filename) );
|
const std::string newFilename( getNewFilename(filename) );
|
||||||
|
|
||||||
std::string fullpath;
|
std::string fullpath;
|
||||||
|
|
||||||
for (const auto& searchIt : _searchPathArray)
|
for (const auto& searchIt : _searchPathArray)
|
||||||
{
|
{
|
||||||
|
@ -941,23 +1004,6 @@ std::string FileUtils::getFullPathForDirectoryAndFilename(const std::string& dir
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FileUtils::searchFullPathForFilename(const std::string& filename) const
|
|
||||||
{
|
|
||||||
if (isAbsolutePath(filename))
|
|
||||||
{
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
std::string path = fullPathForFilename(filename);
|
|
||||||
if (0 == path.compare(filename))
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileUtils::isFileExist(const std::string& filename) const
|
bool FileUtils::isFileExist(const std::string& filename) const
|
||||||
{
|
{
|
||||||
if (isAbsolutePath(filename))
|
if (isAbsolutePath(filename))
|
||||||
|
@ -966,7 +1012,7 @@ bool FileUtils::isFileExist(const std::string& filename) const
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string fullpath = searchFullPathForFilename(filename);
|
std::string fullpath = fullPathForFilename(filename);
|
||||||
if (fullpath.empty())
|
if (fullpath.empty())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
|
@ -979,29 +1025,6 @@ bool FileUtils::isAbsolutePath(const std::string& path) const
|
||||||
return (path[0] == '/');
|
return (path[0] == '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileUtils::isDirectoryExistInternal(const std::string& dirPath) const
|
|
||||||
{
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
|
||||||
std::wstring wdirPath(dirPath.begin(), dirPath.end());
|
|
||||||
if (GetFileAttributesEx(wdirPath.c_str(), GetFileExInfoStandard, &wfad))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
#elif (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
|
||||||
struct stat st;
|
|
||||||
if (stat(dirPath.c_str(), &st) == 0)
|
|
||||||
{
|
|
||||||
return S_ISDIR(st.st_mode);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
CCASSERT(false, "FileUtils not support isDirectoryExistInternal");
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileUtils::isDirectoryExist(const std::string& dirPath) const
|
bool FileUtils::isDirectoryExist(const std::string& dirPath) const
|
||||||
{
|
{
|
||||||
CCASSERT(!dirPath.empty(), "Invalid path");
|
CCASSERT(!dirPath.empty(), "Invalid path");
|
||||||
|
@ -1018,7 +1041,7 @@ bool FileUtils::isDirectoryExist(const std::string& dirPath) const
|
||||||
return isDirectoryExistInternal(cacheIter->second);
|
return isDirectoryExistInternal(cacheIter->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string fullpath;
|
std::string fullpath;
|
||||||
for (const auto& searchIt : _searchPathArray)
|
for (const auto& searchIt : _searchPathArray)
|
||||||
{
|
{
|
||||||
for (const auto& resolutionIt : _searchResolutionsOrderArray)
|
for (const auto& resolutionIt : _searchResolutionsOrderArray)
|
||||||
|
@ -1032,7 +1055,60 @@ bool FileUtils::isDirectoryExist(const std::string& dirPath) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||||
|
// windows os implement should override in platform specific FileUtiles class
|
||||||
|
bool FileUtils::isDirectoryExistInternal(const std::string& dirPath) const
|
||||||
|
{
|
||||||
|
CCASSERT(false, "FileUtils not support isDirectoryExistInternal");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtils::createDirectory(const std::string& path)
|
||||||
|
{
|
||||||
|
CCASSERT(false, "FileUtils not support createDirectory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtils::removeDirectory(const std::string& path)
|
||||||
|
{
|
||||||
|
CCASSERT(false, "FileUtils not support removeDirectory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtils::removeFile(const std::string &path)
|
||||||
|
{
|
||||||
|
CCASSERT(false, "FileUtils not support removeFile");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtils::renameFile(const std::string &path, const std::string &oldname, const std::string &name)
|
||||||
|
{
|
||||||
|
CCASSERT(false, "FileUtils not support renameFile");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FileUtils::getSuitableFOpen(const std::string& filenameUtf8) const
|
||||||
|
{
|
||||||
|
CCASSERT(false, "getSuitableFOpen should be override by platform FileUtils");
|
||||||
|
return filenameUtf8;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
// default implements for unix like os
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
bool FileUtils::isDirectoryExistInternal(const std::string& dirPath) const
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (stat(dirPath.c_str(), &st) == 0)
|
||||||
|
{
|
||||||
|
return S_ISDIR(st.st_mode);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1069,29 +1145,6 @@ bool FileUtils::createDirectory(const std::string& path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
|
||||||
std::wstring wpath(path.begin(), path.end());
|
|
||||||
if (!(GetFileAttributesEx(wpath.c_str(), GetFileExInfoStandard, &wfad)))
|
|
||||||
{
|
|
||||||
subpath = "";
|
|
||||||
for(unsigned int i = 0 ; i < dirs.size() ; ++i)
|
|
||||||
{
|
|
||||||
subpath += dirs[i];
|
|
||||||
if (i > 0 && !isDirectoryExist(subpath))
|
|
||||||
{
|
|
||||||
std::wstring wsubpath(subpath.begin(), subpath.end());
|
|
||||||
BOOL ret = CreateDirectory(wsubpath.c_str(), NULL);
|
|
||||||
if (!ret && ERROR_ALREADY_EXISTS != GetLastError())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
#elif (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
|
||||||
DIR *dir = NULL;
|
DIR *dir = NULL;
|
||||||
|
|
||||||
// Create path recursively
|
// Create path recursively
|
||||||
|
@ -1120,25 +1173,8 @@ bool FileUtils::createDirectory(const std::string& path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
#else
|
|
||||||
CCASSERT(false, "FileUtils not support createDirectory");
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
|
||||||
static int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
|
|
||||||
{
|
|
||||||
auto ret = remove(fpath);
|
|
||||||
if (ret)
|
|
||||||
{
|
|
||||||
log("Fail to remove: %s ",fpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool FileUtils::removeDirectory(const std::string& path)
|
bool FileUtils::removeDirectory(const std::string& path)
|
||||||
{
|
{
|
||||||
if (path.size() > 0 && path[path.size() - 1] != '/')
|
if (path.size() > 0 && path[path.size() - 1] != '/')
|
||||||
|
@ -1147,49 +1183,6 @@ bool FileUtils::removeDirectory(const std::string& path)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove downloaded files
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
std::wstring wpath = std::wstring(path.begin(), path.end());
|
|
||||||
std::wstring files = wpath + L"*.*";
|
|
||||||
WIN32_FIND_DATA wfd;
|
|
||||||
HANDLE search = FindFirstFileEx(files.c_str(), FindExInfoStandard, &wfd, FindExSearchNameMatch, NULL, 0);
|
|
||||||
bool ret=true;
|
|
||||||
if (search!=INVALID_HANDLE_VALUE)
|
|
||||||
{
|
|
||||||
BOOL find=true;
|
|
||||||
while (find)
|
|
||||||
{
|
|
||||||
//. ..
|
|
||||||
if(wfd.cFileName[0]!='.')
|
|
||||||
{
|
|
||||||
std::wstring temp = wpath + wfd.cFileName;
|
|
||||||
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
||||||
{
|
|
||||||
temp += '/';
|
|
||||||
ret = ret && this->removeDirectory(std::string(temp.begin(), temp.end()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetFileAttributes(temp.c_str(), FILE_ATTRIBUTE_NORMAL);
|
|
||||||
ret = ret && DeleteFile(temp.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
find = FindNextFile(search, &wfd);
|
|
||||||
}
|
|
||||||
FindClose(search);
|
|
||||||
}
|
|
||||||
if (ret && RemoveDirectory(wpath.c_str()))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
|
||||||
if (nftw(path.c_str(),unlink_cb, 64, FTW_DEPTH | FTW_PHYS))
|
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
#elif (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
|
||||||
std::string command = "rm -r ";
|
std::string command = "rm -r ";
|
||||||
// Path may include space.
|
// Path may include space.
|
||||||
command += "\"" + path + "\"";
|
command += "\"" + path + "\"";
|
||||||
|
@ -1197,33 +1190,15 @@ bool FileUtils::removeDirectory(const std::string& path)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
#else
|
|
||||||
CCASSERT(false, "FileUtils not support removeDirectory");
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileUtils::removeFile(const std::string &path)
|
bool FileUtils::removeFile(const std::string &path)
|
||||||
{
|
{
|
||||||
// Remove downloaded file
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
std::wstring wpath(path.begin(), path.end());
|
|
||||||
if (DeleteFile(wpath.c_str()))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
#elif (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
|
||||||
if (remove(path.c_str())) {
|
if (remove(path.c_str())) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
CCASSERT(false, "FileUtils not support removeFile");
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileUtils::renameFile(const std::string &path, const std::string &oldname, const std::string &name)
|
bool FileUtils::renameFile(const std::string &path, const std::string &oldname, const std::string &name)
|
||||||
|
@ -1232,19 +1207,6 @@ bool FileUtils::renameFile(const std::string &path, const std::string &oldname,
|
||||||
std::string oldPath = path + oldname;
|
std::string oldPath = path + oldname;
|
||||||
std::string newPath = path + name;
|
std::string newPath = path + name;
|
||||||
|
|
||||||
// Rename a file
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
std::regex pat("\\/");
|
|
||||||
std::string _old = std::regex_replace(oldPath, pat, "\\");
|
|
||||||
std::string _new = std::regex_replace(newPath, pat, "\\");
|
|
||||||
if (MoveFileEx(std::wstring(_old.begin(), _old.end()).c_str(),
|
|
||||||
std::wstring(_new.begin(), _new.end()).c_str(),
|
|
||||||
MOVEFILE_REPLACE_EXISTING & MOVEFILE_WRITE_THROUGH))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
#elif (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
|
||||||
int errorCode = rename(oldPath.c_str(), newPath.c_str());
|
int errorCode = rename(oldPath.c_str(), newPath.c_str());
|
||||||
|
|
||||||
if (0 != errorCode)
|
if (0 != errorCode)
|
||||||
|
@ -1253,12 +1215,15 @@ bool FileUtils::renameFile(const std::string &path, const std::string &oldname,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
#else
|
|
||||||
CCASSERT(false, "FileUtils not support renameFile");
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string FileUtils::getSuitableFOpen(const std::string& filenameUtf8) const
|
||||||
|
{
|
||||||
|
return filenameUtf8;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
long FileUtils::getFileSize(const std::string &filepath)
|
long FileUtils::getFileSize(const std::string &filepath)
|
||||||
{
|
{
|
||||||
CCASSERT(!filepath.empty(), "Invalid path");
|
CCASSERT(!filepath.empty(), "Invalid path");
|
||||||
|
@ -1266,7 +1231,7 @@ long FileUtils::getFileSize(const std::string &filepath)
|
||||||
std::string fullpath = filepath;
|
std::string fullpath = filepath;
|
||||||
if (!isAbsolutePath(filepath))
|
if (!isAbsolutePath(filepath))
|
||||||
{
|
{
|
||||||
fullpath = searchFullPathForFilename(filepath);
|
fullpath = fullPathForFilename(filepath);
|
||||||
if (fullpath.empty())
|
if (fullpath.empty())
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1302,67 +1267,5 @@ bool FileUtils::isPopupNotify() const
|
||||||
return s_popupNotify;
|
return s_popupNotify;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
||||||
static std::wstring StringUtf8ToWideChar(const std::string& strUtf8)
|
|
||||||
{
|
|
||||||
std::wstring ret;
|
|
||||||
if (!strUtf8.empty())
|
|
||||||
{
|
|
||||||
int nNum = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, nullptr, 0);
|
|
||||||
if (nNum)
|
|
||||||
{
|
|
||||||
WCHAR* wideCharString = new WCHAR[nNum + 1];
|
|
||||||
wideCharString[0] = 0;
|
|
||||||
|
|
||||||
nNum = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, wideCharString, nNum + 1);
|
|
||||||
|
|
||||||
ret = wideCharString;
|
|
||||||
delete[] wideCharString;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CCLOG("Wrong convert to WideChar code:0x%x", GetLastError());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string UTF8StringToMultiByte(const std::string& strUtf8)
|
|
||||||
{
|
|
||||||
std::string ret;
|
|
||||||
if (!strUtf8.empty())
|
|
||||||
{
|
|
||||||
std::wstring strWideChar = StringUtf8ToWideChar(strUtf8);
|
|
||||||
int nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE);
|
|
||||||
if (nNum)
|
|
||||||
{
|
|
||||||
char* ansiString = new char[nNum + 1];
|
|
||||||
ansiString[0] = 0;
|
|
||||||
|
|
||||||
nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, ansiString, nNum + 1, nullptr, FALSE);
|
|
||||||
|
|
||||||
ret = ansiString;
|
|
||||||
delete[] ansiString;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CCLOG("Wrong convert to Ansi code:0x%x", GetLastError());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string FileUtils::getSuitableFOpen(const std::string& filenameUtf8) const
|
|
||||||
{
|
|
||||||
return UTF8StringToMultiByte(filenameUtf8);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
std::string FileUtils::getSuitableFOpen(const std::string& filenameUtf8) const
|
|
||||||
{
|
|
||||||
return filenameUtf8;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
|
|
|
@ -497,7 +497,7 @@ protected:
|
||||||
* @param dirPath The directory (with absolute path) to look up for
|
* @param dirPath The directory (with absolute path) to look up for
|
||||||
* @return Returns true if the directory found at the given absolute path, otherwise returns false
|
* @return Returns true if the directory found at the given absolute path, otherwise returns false
|
||||||
*/
|
*/
|
||||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const = 0;
|
virtual bool isDirectoryExistInternal(const std::string& dirPath) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets full path for filename, resolution directory and search path.
|
* Gets full path for filename, resolution directory and search path.
|
||||||
|
|
|
@ -57,7 +57,8 @@ public:
|
||||||
void setBundle(NSBundle* bundle);
|
void setBundle(NSBundle* bundle);
|
||||||
private:
|
private:
|
||||||
virtual bool isFileExistInternal(const std::string& filePath) const override;
|
virtual bool isFileExistInternal(const std::string& filePath) const override;
|
||||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
virtual bool removeDirectory(const std::string& dirPath) override;
|
||||||
|
|
||||||
NSBundle* getBundle() const;
|
NSBundle* getBundle() const;
|
||||||
NSBundle* _bundle;
|
NSBundle* _bundle;
|
||||||
};
|
};
|
||||||
|
|
|
@ -394,14 +394,29 @@ bool FileUtilsApple::isFileExistInternal(const std::string& filePath) const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileUtilsApple::isDirectoryExistInternal(const std::string& dirPath) const
|
static int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
|
||||||
{
|
{
|
||||||
struct stat st;
|
auto ret = remove(fpath);
|
||||||
if (stat(dirPath.c_str(), &st) == 0)
|
if (ret)
|
||||||
{
|
{
|
||||||
return S_ISDIR(st.st_mode);
|
log("Fail to remove: %s ",fpath);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtilsApple::removeDirectory(const std::string& path)
|
||||||
|
{
|
||||||
|
if (path.size() > 0 && path[path.size() - 1] != '/')
|
||||||
|
{
|
||||||
|
CCLOGERROR("Fail to remove directory, path must termniate with '/': %s", path.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nftw(path.c_str(),unlink_cb, 64, FTW_DEPTH | FTW_PHYS))
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FileUtilsApple::getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename) const
|
std::string FileUtilsApple::getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename) const
|
||||||
|
|
|
@ -122,16 +122,6 @@ bool FileUtilsLinux::isFileExistInternal(const std::string& strFilePath) const
|
||||||
return (stat(strPath.c_str(), &sts) != -1) ? true : false;
|
return (stat(strPath.c_str(), &sts) != -1) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileUtilsLinux::isDirectoryExistInternal(const std::string& dirPath) const
|
|
||||||
{
|
|
||||||
struct stat st;
|
|
||||||
if (stat(dirPath.c_str(), &st) == 0)
|
|
||||||
{
|
|
||||||
return S_ISDIR(st.st_mode);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
|
||||||
|
|
|
@ -53,7 +53,6 @@ public:
|
||||||
virtual std::string getWritablePath() const;
|
virtual std::string getWritablePath() const;
|
||||||
private:
|
private:
|
||||||
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of platform group
|
// end of platform group
|
||||||
|
|
|
@ -106,6 +106,32 @@ static std::string StringWideCharToUtf8(const std::wstring& strWideChar)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string UTF8StringToMultiByte(const std::string& strUtf8)
|
||||||
|
{
|
||||||
|
std::string ret;
|
||||||
|
if (!strUtf8.empty())
|
||||||
|
{
|
||||||
|
std::wstring strWideChar = StringUtf8ToWideChar(strUtf8);
|
||||||
|
int nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE);
|
||||||
|
if (nNum)
|
||||||
|
{
|
||||||
|
char* ansiString = new char[nNum + 1];
|
||||||
|
ansiString[0] = 0;
|
||||||
|
|
||||||
|
nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, ansiString, nNum + 1, nullptr, FALSE);
|
||||||
|
|
||||||
|
ret = ansiString;
|
||||||
|
delete[] ansiString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOG("Wrong convert to Ansi code:0x%x", GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void _checkPath()
|
static void _checkPath()
|
||||||
{
|
{
|
||||||
if (0 == s_resourcePath.length())
|
if (0 == s_resourcePath.length())
|
||||||
|
@ -160,6 +186,11 @@ bool FileUtilsWin32::isDirectoryExistInternal(const std::string& dirPath) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string FileUtilsWin32::getSuitableFOpen(const std::string& filenameUtf8) const
|
||||||
|
{
|
||||||
|
return UTF8StringToMultiByte(filenameUtf8);
|
||||||
|
}
|
||||||
|
|
||||||
bool FileUtilsWin32::isFileExistInternal(const std::string& strFilePath) const
|
bool FileUtilsWin32::isFileExistInternal(const std::string& strFilePath) const
|
||||||
{
|
{
|
||||||
if (0 == strFilePath.length())
|
if (0 == strFilePath.length())
|
||||||
|
@ -179,17 +210,6 @@ bool FileUtilsWin32::isFileExistInternal(const std::string& strFilePath) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileUtilsWin32::isDirectoryExistInternal(const std::string& dirPath) const
|
|
||||||
{
|
|
||||||
unsigned long fAttrib = GetFileAttributesA(dirPath.c_str());
|
|
||||||
if (fAttrib != INVALID_FILE_ATTRIBUTES &&
|
|
||||||
(fAttrib & FILE_ATTRIBUTE_DIRECTORY))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const
|
bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const
|
||||||
{
|
{
|
||||||
if ( (strPath.length() > 2
|
if ( (strPath.length() > 2
|
||||||
|
|
|
@ -51,6 +51,7 @@ public:
|
||||||
bool init();
|
bool init();
|
||||||
virtual std::string getWritablePath() const override;
|
virtual std::string getWritablePath() const override;
|
||||||
virtual bool isAbsolutePath(const std::string& strPath) const override;
|
virtual bool isAbsolutePath(const std::string& strPath) const override;
|
||||||
|
virtual std::string getSuitableFOpen(const std::string& filenameUtf8) const override;
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||||
|
@ -105,7 +106,7 @@ protected:
|
||||||
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
||||||
* @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
* @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
||||||
*/
|
*/
|
||||||
virtual unsigned char* getFileData(const std::string& filename, const char* mode, ssize_t * size) override;
|
CC_DEPRECATED_ATTRIBUTE virtual unsigned char* getFileData(const std::string& filename, const char* mode, ssize_t * size) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets string from a file.
|
* Gets string from a file.
|
||||||
|
|
|
@ -23,9 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "CCFileUtilsWinRT.h"
|
#include "CCFileUtilsWinRT.h"
|
||||||
|
#include <regex>
|
||||||
#include "CCWinRTUtils.h"
|
#include "CCWinRTUtils.h"
|
||||||
#include "platform/CCCommon.h"
|
#include "platform/CCCommon.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
@ -47,6 +47,80 @@ static inline std::string convertPathFormatToUnixStyle(const std::string& path)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::wstring StringUtf8ToWideChar(const std::string& strUtf8)
|
||||||
|
{
|
||||||
|
std::wstring ret;
|
||||||
|
if (!strUtf8.empty())
|
||||||
|
{
|
||||||
|
int nNum = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, nullptr, 0);
|
||||||
|
if (nNum)
|
||||||
|
{
|
||||||
|
WCHAR* wideCharString = new WCHAR[nNum + 1];
|
||||||
|
wideCharString[0] = 0;
|
||||||
|
|
||||||
|
nNum = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, wideCharString, nNum + 1);
|
||||||
|
|
||||||
|
ret = wideCharString;
|
||||||
|
delete[] wideCharString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOG("Wrong convert to WideChar code:0x%x", GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string StringWideCharToUtf8(const std::wstring& strWideChar)
|
||||||
|
{
|
||||||
|
std::string ret;
|
||||||
|
if (!strWideChar.empty())
|
||||||
|
{
|
||||||
|
int nNum = WideCharToMultiByte(CP_UTF8, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE);
|
||||||
|
if (nNum)
|
||||||
|
{
|
||||||
|
char* utf8String = new char[nNum + 1];
|
||||||
|
utf8String[0] = 0;
|
||||||
|
|
||||||
|
nNum = WideCharToMultiByte(CP_UTF8, 0, strWideChar.c_str(), -1, utf8String, nNum + 1, nullptr, FALSE);
|
||||||
|
|
||||||
|
ret = utf8String;
|
||||||
|
delete[] utf8String;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOG("Wrong convert to Utf8 code:0x%x", GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string UTF8StringToMultiByte(const std::string& strUtf8)
|
||||||
|
{
|
||||||
|
std::string ret;
|
||||||
|
if (!strUtf8.empty())
|
||||||
|
{
|
||||||
|
std::wstring strWideChar = StringUtf8ToWideChar(strUtf8);
|
||||||
|
int nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE);
|
||||||
|
if (nNum)
|
||||||
|
{
|
||||||
|
char* ansiString = new char[nNum + 1];
|
||||||
|
ansiString[0] = 0;
|
||||||
|
|
||||||
|
nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, ansiString, nNum + 1, nullptr, FALSE);
|
||||||
|
|
||||||
|
ret = ansiString;
|
||||||
|
delete[] ansiString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOG("Wrong convert to Ansi code:0x%x", GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void _checkPath()
|
static void _checkPath()
|
||||||
{
|
{
|
||||||
|
@ -72,7 +146,6 @@ FileUtils* FileUtils::getInstance()
|
||||||
return s_sharedFileUtils;
|
return s_sharedFileUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CCFileUtilsWinRT::CCFileUtilsWinRT()
|
CCFileUtilsWinRT::CCFileUtilsWinRT()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -100,6 +173,11 @@ std::string CCFileUtilsWinRT::getFullPathForDirectoryAndFilename(const std::stri
|
||||||
return FileUtils::getFullPathForDirectoryAndFilename(unixDirectory, unixFilename);
|
return FileUtils::getFullPathForDirectoryAndFilename(unixDirectory, unixFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CCFileUtilsWinRT::getSuitableFOpen(const std::string& filenameUtf8) const
|
||||||
|
{
|
||||||
|
return UTF8StringToMultiByte(filenameUtf8);
|
||||||
|
}
|
||||||
|
|
||||||
bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const
|
bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
@ -132,6 +210,99 @@ bool CCFileUtilsWinRT::isDirectoryExistInternal(const std::string& dirPath) cons
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CCFileUtilsWinRT::createDirectory(const std::string& path)
|
||||||
|
{
|
||||||
|
CCASSERT(!path.empty(), "Invalid path");
|
||||||
|
|
||||||
|
if (isDirectoryExist(path))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Split the path
|
||||||
|
size_t start = 0;
|
||||||
|
size_t found = path.find_first_of("/\\", start);
|
||||||
|
std::string subpath;
|
||||||
|
std::vector<std::string> dirs;
|
||||||
|
|
||||||
|
if (found != std::string::npos)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
subpath = path.substr(start, found - start + 1);
|
||||||
|
if (!subpath.empty())
|
||||||
|
dirs.push_back(subpath);
|
||||||
|
start = found + 1;
|
||||||
|
found = path.find_first_of("/\\", start);
|
||||||
|
if (found == std::string::npos)
|
||||||
|
{
|
||||||
|
if (start < path.length())
|
||||||
|
{
|
||||||
|
dirs.push_back(path.substr(start));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
||||||
|
std::wstring wpath(path.begin(), path.end());
|
||||||
|
if (!(GetFileAttributesEx(wpath.c_str(), GetFileExInfoStandard, &wfad)))
|
||||||
|
{
|
||||||
|
subpath = "";
|
||||||
|
for (unsigned int i = 0; i < dirs.size(); ++i)
|
||||||
|
{
|
||||||
|
subpath += dirs[i];
|
||||||
|
if (i > 0 && !isDirectoryExist(subpath))
|
||||||
|
{
|
||||||
|
std::wstring wsubpath(subpath.begin(), subpath.end());
|
||||||
|
BOOL ret = CreateDirectory(wsubpath.c_str(), NULL);
|
||||||
|
if (!ret && ERROR_ALREADY_EXISTS != GetLastError())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCFileUtilsWinRT::removeDirectory(const std::string& path)
|
||||||
|
{
|
||||||
|
std::wstring wpath = std::wstring(path.begin(), path.end());
|
||||||
|
std::wstring files = wpath + L"*.*";
|
||||||
|
WIN32_FIND_DATA wfd;
|
||||||
|
HANDLE search = FindFirstFileEx(files.c_str(), FindExInfoStandard, &wfd, FindExSearchNameMatch, NULL, 0);
|
||||||
|
bool ret = true;
|
||||||
|
if (search != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
BOOL find = true;
|
||||||
|
while (find)
|
||||||
|
{
|
||||||
|
//. ..
|
||||||
|
if (wfd.cFileName[0] != '.')
|
||||||
|
{
|
||||||
|
std::wstring temp = wpath + wfd.cFileName;
|
||||||
|
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
|
temp += '/';
|
||||||
|
ret = ret && this->removeDirectory(std::string(temp.begin(), temp.end()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetFileAttributes(temp.c_str(), FILE_ATTRIBUTE_NORMAL);
|
||||||
|
ret = ret && DeleteFile(temp.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
find = FindNextFile(search, &wfd);
|
||||||
|
}
|
||||||
|
FindClose(search);
|
||||||
|
}
|
||||||
|
if (ret && RemoveDirectory(wpath.c_str()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CCFileUtilsWinRT::isAbsolutePath(const std::string& strPath) const
|
bool CCFileUtilsWinRT::isAbsolutePath(const std::string& strPath) const
|
||||||
{
|
{
|
||||||
if ( strPath.length() > 2
|
if ( strPath.length() > 2
|
||||||
|
@ -143,6 +314,34 @@ bool CCFileUtilsWinRT::isAbsolutePath(const std::string& strPath) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CCFileUtilsWinRT::removeFile(const std::string &path)
|
||||||
|
{
|
||||||
|
std::wstring wpath(path.begin(), path.end());
|
||||||
|
if (DeleteFile(wpath.c_str()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCFileUtilsWinRT::renameFile(const std::string &path, const std::string &oldname, const std::string &name)
|
||||||
|
{
|
||||||
|
CCASSERT(!path.empty(), "Invalid path");
|
||||||
|
std::string oldPath = path + oldname;
|
||||||
|
std::string newPath = path + name;
|
||||||
|
|
||||||
|
std::regex pat("\\/");
|
||||||
|
std::string _old = std::regex_replace(oldPath, pat, "\\");
|
||||||
|
std::string _new = std::regex_replace(newPath, pat, "\\");
|
||||||
|
if (MoveFileEx(std::wstring(_old.begin(), _old.end()).c_str(),
|
||||||
|
std::wstring(_new.begin(), _new.end()).c_str(),
|
||||||
|
MOVEFILE_REPLACE_EXISTING & MOVEFILE_WRITE_THROUGH))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static Data getData(const std::string& filename, bool forString)
|
static Data getData(const std::string& filename, bool forString)
|
||||||
{
|
{
|
||||||
if (filename.empty())
|
if (filename.empty())
|
||||||
|
|
|
@ -49,14 +49,55 @@ public:
|
||||||
bool init();
|
bool init();
|
||||||
virtual std::string getWritablePath() const;
|
virtual std::string getWritablePath() const;
|
||||||
virtual bool isAbsolutePath(const std::string& strPath) const;
|
virtual bool isAbsolutePath(const std::string& strPath) const;
|
||||||
virtual std::string getPathForFilename(const std::string& filename, const std::string& resolutionDirectory, const std::string& searchPath) const override;
|
virtual std::string getPathForFilename(const std::string& filename, const std::string& resolutionDirectory, const std::string& searchPath) const override;
|
||||||
virtual std::string getFullPathForDirectoryAndFilename(const std::string& strDirectory, const std::string& strFilename) const override;
|
virtual std::string getFullPathForDirectoryAndFilename(const std::string& strDirectory, const std::string& strFilename) const override;
|
||||||
virtual std::string getStringFromFile(const std::string& filename) override;
|
virtual std::string getStringFromFile(const std::string& filename) override;
|
||||||
|
virtual std::string getSuitableFOpen(const std::string& filenameUtf8) const override;
|
||||||
static std::string getAppPath();
|
static std::string getAppPath();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renames a file under the given directory.
|
||||||
|
*
|
||||||
|
* @param path The parent directory path of the file, it must be an absolute path.
|
||||||
|
* @param oldname The current name of the file.
|
||||||
|
* @param name The new name of the file.
|
||||||
|
* @return True if the file have been renamed successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool renameFile(const std::string &path, const std::string &oldname, const std::string &name) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a directory exists without considering search paths and resolution orders.
|
||||||
|
* @param dirPath The directory (with absolute path) to look up for
|
||||||
|
* @return Returns true if the directory found at the given absolute path, otherwise returns false
|
||||||
|
*/
|
||||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a file.
|
||||||
|
*
|
||||||
|
* @param filepath The full path of the file, it must be an absolute path.
|
||||||
|
* @return True if the file have been removed successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool removeFile(const std::string &filepath) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a directory.
|
||||||
|
*
|
||||||
|
* @param dirPath The path of the directory, it must be an absolute path.
|
||||||
|
* @return True if the directory have been created successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool createDirectory(const std::string& dirPath) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a directory.
|
||||||
|
*
|
||||||
|
* @param dirPath The full path of the directory, it must be an absolute path.
|
||||||
|
* @return True if the directory have been removed successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool removeDirectory(const std::string& dirPath) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of platform group
|
// end of platform group
|
||||||
|
|
|
@ -8,6 +8,7 @@ FileUtilsTests::FileUtilsTests()
|
||||||
ADD_TEST_CASE(TestSearchPath);
|
ADD_TEST_CASE(TestSearchPath);
|
||||||
ADD_TEST_CASE(TestFilenameLookup);
|
ADD_TEST_CASE(TestFilenameLookup);
|
||||||
ADD_TEST_CASE(TestIsFileExist);
|
ADD_TEST_CASE(TestIsFileExist);
|
||||||
|
ADD_TEST_CASE(TestIsDirectoryExist);
|
||||||
ADD_TEST_CASE(TestFileFuncs);
|
ADD_TEST_CASE(TestFileFuncs);
|
||||||
ADD_TEST_CASE(TestDirectoryFuncs);
|
ADD_TEST_CASE(TestDirectoryFuncs);
|
||||||
ADD_TEST_CASE(TextWritePlist);
|
ADD_TEST_CASE(TextWritePlist);
|
||||||
|
@ -15,6 +16,7 @@ FileUtilsTests::FileUtilsTests()
|
||||||
ADD_TEST_CASE(TestWriteData);
|
ADD_TEST_CASE(TestWriteData);
|
||||||
ADD_TEST_CASE(TestWriteValueMap);
|
ADD_TEST_CASE(TestWriteValueMap);
|
||||||
ADD_TEST_CASE(TestWriteValueVector);
|
ADD_TEST_CASE(TestWriteValueVector);
|
||||||
|
ADD_TEST_CASE(TestUnicodePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestResolutionDirectories
|
// TestResolutionDirectories
|
||||||
|
@ -122,7 +124,7 @@ void TestSearchPath::onEnter()
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
char szReadBuf[100] = {0};
|
char szReadBuf[100] = {0};
|
||||||
size_t read = fread(szReadBuf, 1, strlen(szBuf), fp);
|
size_t read = fread(szReadBuf, 1, strlen(szReadBuf), fp);
|
||||||
if (read > 0)
|
if (read > 0)
|
||||||
log("The content of file from writable path: %s", szReadBuf);
|
log("The content of file from writable path: %s", szReadBuf);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -232,6 +234,61 @@ std::string TestIsFileExist::subtitle() const
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestIsDirectoryExist
|
||||||
|
|
||||||
|
void TestIsDirectoryExist::onEnter()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onEnter();
|
||||||
|
auto s = Director::getInstance()->getWinSize();
|
||||||
|
auto util = FileUtils::getInstance();
|
||||||
|
int x = s.width/2, y = s.height/3;
|
||||||
|
|
||||||
|
Label* label = nullptr;
|
||||||
|
std::string dir;
|
||||||
|
char msg[512];
|
||||||
|
auto getMsg = [&dir, &msg](bool b)->const char *
|
||||||
|
{
|
||||||
|
snprintf((char *)msg, 512, "%s for dir: \"%s\"", b ? "success" : "failed", dir.c_str());
|
||||||
|
return msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
dir = "Images";
|
||||||
|
label = Label::createWithSystemFont(getMsg(util->isDirectoryExist(dir)), "", 20);
|
||||||
|
label->setPosition(x, y * 2);
|
||||||
|
this->addChild(label);
|
||||||
|
|
||||||
|
dir = util->getWritablePath();
|
||||||
|
label = Label::createWithSystemFont(getMsg(util->isDirectoryExist(dir)), "", 20);
|
||||||
|
label->setPosition(x, y * 1);
|
||||||
|
this->addChild(label);
|
||||||
|
|
||||||
|
dir = util->getWritablePath();
|
||||||
|
label = Label::createWithSystemFont(getMsg(util->isDirectoryExist(dir)), "", 20);
|
||||||
|
label->setPosition(x, y * 1);
|
||||||
|
this->addChild(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestIsDirectoryExist::onExit()
|
||||||
|
{
|
||||||
|
|
||||||
|
FileUtils *sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
|
// reset filename lookup
|
||||||
|
sharedFileUtils->purgeCachedEntries();
|
||||||
|
|
||||||
|
FileUtilsDemo::onExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestIsDirectoryExist::title() const
|
||||||
|
{
|
||||||
|
return "FileUtils: check whether the directory exists";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestIsDirectoryExist::subtitle() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
// TestFileFuncs
|
// TestFileFuncs
|
||||||
|
|
||||||
void TestFileFuncs::onEnter()
|
void TestFileFuncs::onEnter()
|
||||||
|
@ -801,3 +858,101 @@ std::string TestWriteValueVector::subtitle() const
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestUnicodePath
|
||||||
|
|
||||||
|
void TestUnicodePath::onEnter()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onEnter();
|
||||||
|
auto s = Director::getInstance()->getWinSize();
|
||||||
|
auto util = FileUtils::getInstance();
|
||||||
|
|
||||||
|
int x = s.width/2,
|
||||||
|
y = s.height/5;
|
||||||
|
Label* label = nullptr;
|
||||||
|
|
||||||
|
std::string dir = "中文路径/";
|
||||||
|
std::string filename = "测试文件.test";
|
||||||
|
|
||||||
|
std::string act;
|
||||||
|
char msg[512];
|
||||||
|
auto getMsg = [&act, &msg](bool b, const std::string& path)->const char *
|
||||||
|
{
|
||||||
|
snprintf((char *)msg, 512, "%s for %s path: \"%s\"", b ? "success" : "failed", act.c_str(), path.c_str());
|
||||||
|
return msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check whether unicode dir should be create or not
|
||||||
|
std::string dirPath = util->getWritablePath() + dir;
|
||||||
|
if (!util->isDirectoryExist(dirPath))
|
||||||
|
{
|
||||||
|
util->createDirectory(dirPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
act = "create";
|
||||||
|
bool isExist = util->isDirectoryExist(dirPath);
|
||||||
|
label = Label::createWithSystemFont(getMsg(isExist, dirPath), "", 12, Size(s.width, 0));
|
||||||
|
label->setPosition(x, y * 4);
|
||||||
|
this->addChild(label);
|
||||||
|
|
||||||
|
if (isExist)
|
||||||
|
{
|
||||||
|
// Check whether unicode file should be create or not
|
||||||
|
std::string filePath = dirPath + filename;
|
||||||
|
if (! util->isFileExist(filePath))
|
||||||
|
{
|
||||||
|
std::string writeDataStr = " 测试字符串.";
|
||||||
|
Data writeData;
|
||||||
|
writeData.copy((unsigned char *)writeDataStr.c_str(), writeDataStr.size());
|
||||||
|
util->writeDataToFile(writeData, filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
isExist = util->isFileExist(filePath);
|
||||||
|
label = Label::createWithSystemFont(getMsg(isExist, filePath), "", 12, Size(s.width, 0));
|
||||||
|
label->setPosition(x, y * 3);
|
||||||
|
this->addChild(label);
|
||||||
|
|
||||||
|
act = "remove";
|
||||||
|
if (isExist)
|
||||||
|
{
|
||||||
|
// read file content and log it
|
||||||
|
unsigned char* buffer = nullptr;
|
||||||
|
Data readData = util->getDataFromFile(filePath);
|
||||||
|
buffer = (unsigned char*)malloc(sizeof(unsigned char) * (readData.getSize() + 1));
|
||||||
|
memcpy(buffer, readData.getBytes(), readData.getSize());
|
||||||
|
buffer[readData.getSize()] = '\0';
|
||||||
|
// vc can't treat unicode string correctly, don't use unicode string in code
|
||||||
|
log("The content of file from writable path: %s", buffer);
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
// remove test file
|
||||||
|
label = Label::createWithSystemFont(getMsg(util->removeFile(filePath), filePath), "", 12, Size(s.width, 0));
|
||||||
|
label->setPosition(x, y * 2);
|
||||||
|
this->addChild(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove test dir
|
||||||
|
label = Label::createWithSystemFont(getMsg(util->removeDirectory(dirPath), dirPath), "", 12, Size(s.width, 0));
|
||||||
|
label->setPosition(x, y * 1);
|
||||||
|
this->addChild(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestUnicodePath::onExit()
|
||||||
|
{
|
||||||
|
|
||||||
|
FileUtils *sharedFileUtils = FileUtils::getInstance();
|
||||||
|
sharedFileUtils->purgeCachedEntries();
|
||||||
|
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
|
||||||
|
FileUtilsDemo::onExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestUnicodePath::title() const
|
||||||
|
{
|
||||||
|
return "FileUtils: check unicode path";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestUnicodePath::subtitle() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
|
@ -60,6 +60,17 @@ public:
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TestIsDirectoryExist : public FileUtilsDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(TestIsDirectoryExist);
|
||||||
|
|
||||||
|
virtual void onEnter() override;
|
||||||
|
virtual void onExit() override;
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
};
|
||||||
|
|
||||||
class TestFileFuncs : public FileUtilsDemo
|
class TestFileFuncs : public FileUtilsDemo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -134,4 +145,16 @@ public:
|
||||||
virtual std::string title() const override;
|
virtual std::string title() const override;
|
||||||
virtual std::string subtitle() const override;
|
virtual std::string subtitle() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TestUnicodePath : public FileUtilsDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(TestUnicodePath);
|
||||||
|
|
||||||
|
virtual void onEnter() override;
|
||||||
|
virtual void onExit() override;
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* __FILEUTILSTEST_H__ */
|
#endif /* __FILEUTILSTEST_H__ */
|
||||||
|
|
|
@ -95,6 +95,7 @@ LOCAL_SRC_FILES := main.cpp \
|
||||||
../../../Classes/NewAudioEngineTest/NewAudioEngineTest.cpp \
|
../../../Classes/NewAudioEngineTest/NewAudioEngineTest.cpp \
|
||||||
../../../Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp \
|
../../../Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp \
|
||||||
../../../Classes/NewRendererTest/NewRendererTest.cpp \
|
../../../Classes/NewRendererTest/NewRendererTest.cpp \
|
||||||
|
../../../Classes/NavMeshTest/NavMeshTest.cpp \
|
||||||
../../../Classes/NodeTest/NodeTest.cpp \
|
../../../Classes/NodeTest/NodeTest.cpp \
|
||||||
../../../Classes/OpenURLTest/OpenURLTest.cpp \
|
../../../Classes/OpenURLTest/OpenURLTest.cpp \
|
||||||
../../../Classes/ParallaxTest/ParallaxTest.cpp \
|
../../../Classes/ParallaxTest/ParallaxTest.cpp \
|
||||||
|
@ -201,10 +202,10 @@ LOCAL_SRC_FILES := main.cpp \
|
||||||
../../../Classes/UnitTest/UnitTest.cpp \
|
../../../Classes/UnitTest/UnitTest.cpp \
|
||||||
../../../Classes/UserDefaultTest/UserDefaultTest.cpp \
|
../../../Classes/UserDefaultTest/UserDefaultTest.cpp \
|
||||||
../../../Classes/VisibleRect.cpp \
|
../../../Classes/VisibleRect.cpp \
|
||||||
|
../../../Classes/VibrateTest/VibrateTest.cpp \
|
||||||
../../../Classes/ZwoptexTest/ZwoptexTest.cpp \
|
../../../Classes/ZwoptexTest/ZwoptexTest.cpp \
|
||||||
../../../Classes/controller.cpp \
|
../../../Classes/controller.cpp \
|
||||||
../../../Classes/testBasic.cpp \
|
../../../Classes/testBasic.cpp
|
||||||
../../../Classes/NavMeshTest/NavMeshTest.cpp
|
|
||||||
|
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes \
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes \
|
||||||
$(LOCAL_PATH)/../../../../..
|
$(LOCAL_PATH)/../../../../..
|
||||||
|
|
|
@ -799,6 +799,7 @@
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\Classes\NavMeshTest\NavMeshTest.cpp">
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\Classes\NavMeshTest\NavMeshTest.cpp">
|
||||||
<Filter>Classes\NavMeshTest</Filter>
|
<Filter>Classes\NavMeshTest</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\Classes\UITest\CocoStudioGUITest\UIRadioButtonTest\UIRadioButtonTest.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\Classes\ActionManagerTest\ActionManagerTest.cpp">
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\Classes\ActionManagerTest\ActionManagerTest.cpp">
|
||||||
|
@ -1260,9 +1261,6 @@
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\Classes\UITest\CocoStudioGUITest\UICheckBoxTest\UICheckBoxTest_Editor.cpp">
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\Classes\UITest\CocoStudioGUITest\UICheckBoxTest\UICheckBoxTest_Editor.cpp">
|
||||||
<Filter>Classes\UITest\CocostudioGUISceneTest\UICheckBoxTest</Filter>
|
<Filter>Classes\UITest\CocostudioGUISceneTest\UICheckBoxTest</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\Classes\UITest\CocoStudioGUITest\UIRadioButtonTest\UIRadioButtonTest.cpp">
|
|
||||||
<Filter>Classes\UITest\CocostudioGUISceneTest\UIRadioButtonTest</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\Classes\UITest\CocoStudioGUITest\UIFocusTest\UIFocusTest.cpp">
|
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\Classes\UITest\CocoStudioGUITest\UIFocusTest\UIFocusTest.cpp">
|
||||||
<Filter>Classes\UITest\CocostudioGUISceneTest\UIFocusTest</Filter>
|
<Filter>Classes\UITest\CocostudioGUISceneTest\UIFocusTest</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
Loading…
Reference in New Issue