diff --git a/cocos/platform/win32/CCFileUtils-win32.cpp b/cocos/platform/win32/CCFileUtils-win32.cpp index 93152f114c..74155a1b20 100644 --- a/cocos/platform/win32/CCFileUtils-win32.cpp +++ b/cocos/platform/win32/CCFileUtils-win32.cpp @@ -231,11 +231,11 @@ void FileUtilsWin32::listFilesRecursively(const std::string& dirPath, std::vecto // Error getting file break; } - std::string fileName = StringWideCharToChar(file.name); + std::string fileName = StringWideCharToMultiByte(file.name); if (fileName != "." && fileName != "..") { - std::string filepath = StringWideCharToChar(file.path); + std::string filepath = StringWideCharToMultiByte(file.path); if (file.is_dir) { filepath.push_back('/'); @@ -289,7 +289,7 @@ std::vector FileUtilsWin32::listFiles(const std::string& dirPath) c break; } - std::string filepath = StringWideCharToChar(file.path); + std::string filepath = StringWideCharToMultiByte(file.path); if (file.is_dir) { filepath.push_back('/'); @@ -359,7 +359,7 @@ string FileUtilsWin32::getWritablePath() const retPath = retPath.substr(0, retPath.rfind(L"\\") + 1); } - return convertPathFormatToUnixStyle(StringWideCharToChar(retPath)); + return convertPathFormatToUnixStyle(StringWideCharToMultiByte(retPath)); } bool FileUtilsWin32::renameFile(const std::string &oldfullpath, const std::string& newfullpath) const @@ -444,7 +444,7 @@ bool FileUtilsWin32::createDirectory(const std::string& dirPath) const { subpath += dirs[i]; - std::string utf8Path = StringWideCharToChar(subpath); + std::string utf8Path = StringWideCharToMultiByte(subpath); if (!isDirectoryExist(utf8Path)) { BOOL ret = CreateDirectory(subpath.c_str(), NULL); @@ -500,7 +500,7 @@ bool FileUtilsWin32::removeDirectory(const std::string& dirPath) const if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { temp += '/'; - ret = ret && this->removeDirectory(StringWideCharToChar(temp)); + ret = ret && this->removeDirectory(StringWideCharToMultiByte(temp)); } else { diff --git a/cocos/platform/win32/CCUtils-win32.cpp b/cocos/platform/win32/CCUtils-win32.cpp index 75e6e942df..1e3d6c01cf 100644 --- a/cocos/platform/win32/CCUtils-win32.cpp +++ b/cocos/platform/win32/CCUtils-win32.cpp @@ -55,31 +55,6 @@ std::wstring StringUtf8ToWideChar(const std::string& strUtf8) return ret; } -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; -} - std::string StringWideCharToMultiByte(const std::wstring& strWideChar, unsigned int cp) { int cchMultiByte = WideCharToMultiByte(cp, 0, strWideChar.c_str(), static_cast(strWideChar.length()), NULL, 0, NULL, NULL); diff --git a/cocos/platform/win32/CCUtils-win32.h b/cocos/platform/win32/CCUtils-win32.h index b53167e061..1e6da505e0 100644 --- a/cocos/platform/win32/CCUtils-win32.h +++ b/cocos/platform/win32/CCUtils-win32.h @@ -32,8 +32,7 @@ THE SOFTWARE. NS_CC_BEGIN std::wstring CC_DLL StringUtf8ToWideChar(const std::string& strUtf8); -std::string CC_DLL StringWideCharToUtf8(const std::wstring& strWideChar); -std::string CC_DLL StringWideCharToChar(const std::wstring& strWideChar, unsigned int cp = CP_ACP); +std::string CC_DLL StringWideCharToMultiByte(const std::wstring& strWideChar, unsigned int cp = CP_ACP); std::string CC_DLL UTF8StringToMultiByte(const std::string& strUtf8); NS_CC_END