mirror of https://github.com/axmolengine/axmol.git
Add FileUtils::getSuitableFOpen[window-universal]
This commit is contained in:
parent
1839564fbb
commit
26c9be7881
|
@ -1364,10 +1364,67 @@ bool FileUtils::isPopupNotify() const
|
|||
return s_popupNotify;
|
||||
}
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||
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
|
||||
|
||||
|
|
|
@ -333,7 +333,6 @@ public:
|
|||
/**
|
||||
* Windows fopen can't support UTF-8 filename
|
||||
* Need convert all parameters fopen and other 3rd-party libs
|
||||
* CC_PLATFORM_WP8 and CC_PLATFORM_WINRT the same needs?
|
||||
*
|
||||
* @param filename std::string name file for convertation from utf-8
|
||||
* @return std::string ansi filename in current locale
|
||||
|
|
|
@ -56,81 +56,6 @@ static inline std::string convertPathFormatToUnixStyle(const std::string& path)
|
|||
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 StringUtf8ToAnsi(const std::string& strUtf8)
|
||||
{
|
||||
std::string ret;
|
||||
if (!strUtf8.empty())
|
||||
{
|
||||
std::wstring strWideChar = NS_CC::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()
|
||||
{
|
||||
if (0 == s_resourcePath.length())
|
||||
|
@ -460,11 +385,6 @@ string FileUtilsWin32::getWritablePath() const
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::string FileUtilsWin32::getSuitableFOpen(const std::string& filenameUtf8) const
|
||||
{
|
||||
return StringUtf8ToAnsi(filenameUtf8);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
|
|
|
@ -54,17 +54,6 @@ public:
|
|||
protected:
|
||||
|
||||
virtual bool isFileExistInternal(const std::string& strFilePath) const;
|
||||
|
||||
|
||||
/**
|
||||
* Windows fopen can't support UTF-8 filename
|
||||
* Need convert all parameters fopen and other 3rd-party libs
|
||||
* CC_PLATFORM_WP8 and CC_PLATFORM_WINRT the same needs?
|
||||
*
|
||||
* @param filename std::string name file for convertation from utf-8
|
||||
* @return std::string ansi filename in current locale
|
||||
*/
|
||||
virtual std::string getSuitableFOpen(const std::string& filenameUtf8) const override;
|
||||
|
||||
/**
|
||||
* Gets resource file data
|
||||
|
|
|
@ -111,9 +111,9 @@ bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const
|
|||
strPath.insert(0, _defaultResRootPath);
|
||||
}
|
||||
|
||||
const char* path = strPath.c_str();
|
||||
strPath = getSuitableFOpen(strPath);
|
||||
|
||||
if (path && strlen(path) && (pf = fopen(path, "rb")))
|
||||
if (!strPath.empty() && (pf = fopen(strPath.c_str(), "rb")))
|
||||
{
|
||||
ret = true;
|
||||
fclose(pf);
|
||||
|
@ -121,7 +121,6 @@ bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool CCFileUtilsWinRT::isAbsolutePath(const std::string& strPath) const
|
||||
{
|
||||
if ( strPath.length() > 2
|
||||
|
@ -181,8 +180,6 @@ static Data getData(const std::string& filename, bool forString)
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string CCFileUtilsWinRT::getStringFromFile(const std::string& filename)
|
||||
{
|
||||
Data data = getData(filename, true);
|
||||
|
@ -194,8 +191,6 @@ std::string CCFileUtilsWinRT::getStringFromFile(const std::string& filename)
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
string CCFileUtilsWinRT::getWritablePath() const
|
||||
{
|
||||
auto localFolderPath = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
|
||||
|
|
Loading…
Reference in New Issue