Remove getSuitableFopen, we never reduce performance for win32 only

This commit is contained in:
halx99 2019-11-25 02:54:00 +08:00
parent ab7ccf0a58
commit 797e85ba30
7 changed files with 5 additions and 84 deletions

View File

@ -1507,7 +1507,7 @@ void Console::commandUpload(int fd)
static std::string writablePath = FileUtils::getInstance()->getWritablePath();
std::string filepath = writablePath + std::string(buf);
FILE* fp = fopen(FileUtils::getInstance()->getSuitableFOpen(filepath).c_str(), "wb");
FILE* fp = fopen(filepath.c_str(), "wb");
if(!fp)
{
const char err[] = "can't create file!\n";

View File

@ -584,10 +584,8 @@ FileUtils::Status FileUtils::getContents(const std::string& filename, ResizableB
if (fullPath.empty())
return Status::NotExists;
std::string suitableFullPath = fs->getSuitableFOpen(fullPath);
struct stat statBuf;
if (stat(suitableFullPath.c_str(), &statBuf) == -1) {
if (stat(fullPath.c_str(), &statBuf) == -1) {
return Status::ReadFailed;
}
@ -595,7 +593,7 @@ FileUtils::Status FileUtils::getContents(const std::string& filename, ResizableB
return Status::NotRegularFileType;
}
FILE *fp = fopen(suitableFullPath.c_str(), "rb");
FILE *fp = fopen(fullPath.c_str(), "rb");
if (!fp)
return Status::OpenFailed;
@ -1182,12 +1180,6 @@ bool FileUtils::renameFile(const std::string &path, const std::string &oldname,
return false;
}
std::string FileUtils::getSuitableFOpen(const std::string& filenameUtf8) const
{
CCASSERT(false, "getSuitableFOpen should be override by platform FileUtils");
return filenameUtf8;
}
long FileUtils::getFileSize(const std::string &filepath) const
{
CCASSERT(false, "getFileSize should be override by platform FileUtils");
@ -1363,11 +1355,6 @@ bool FileUtils::renameFile(const std::string &path, const std::string &oldname,
return this->renameFile(oldPath, newPath);
}
std::string FileUtils::getSuitableFOpen(const std::string& filenameUtf8) const
{
return filenameUtf8;
}
long FileUtils::getFileSize(const std::string &filepath) const
{
CCASSERT(!filepath.empty(), "Invalid path");

View File

@ -610,15 +610,6 @@ public:
*/
virtual void writeValueVectorToFile(ValueVector vecData, const std::string& fullPath, std::function<void(bool)> callback) const;
/**
* Windows fopen can't support UTF-8 filename
* Need convert all parameters fopen and other 3rd-party libs
*
* @param filenameUtf8 std::string name file for conversion from utf-8
* @return std::string ansi filename in current locale
*/
virtual std::string getSuitableFOpen(const std::string& filenameUtf8) const;
// Converts the contents of a file to a ValueVector.
// This method is used internally.
virtual ValueVector getValueVectorFromFile(const std::string& filename) const;

View File

@ -1977,7 +1977,7 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
png_infop info_ptr;
png_bytep *row_pointers;
fp = fopen(FileUtils::getInstance()->getSuitableFOpen(filePath).c_str(), "wb");
fp = fopen(filePath.c_str(), "wb");
CC_BREAK_IF(nullptr == fp);
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
@ -2123,7 +2123,7 @@ bool Image::saveImageToJPG(const std::string& filePath)
/* Now we can initialize the JPEG compression object. */
jpeg_create_compress(&cinfo);
CC_BREAK_IF((outfile = fopen(FileUtils::getInstance()->getSuitableFOpen(filePath).c_str(), "wb")) == nullptr);
CC_BREAK_IF((outfile = fopen(filePath.c_str(), "wb")) == nullptr);
jpeg_stdio_dest(&cinfo, outfile);

View File

@ -118,11 +118,6 @@ bool FileUtilsWin32::isDirectoryExistInternal(const std::string& dirPath) const
return false;
}
std::string FileUtilsWin32::getSuitableFOpen(const std::string& filenameUtf8) const
{
return UTF8StringToMultiByte(filenameUtf8);
}
long FileUtilsWin32::getFileSize(const std::string &filepath)
{
WIN32_FILE_ATTRIBUTE_DATA fad;

View File

@ -49,7 +49,6 @@ public:
bool init();
virtual std::string getWritablePath() const override;
virtual bool isAbsolutePath(const std::string& strPath) const override;
virtual std::string getSuitableFOpen(const std::string& filenameUtf8) const override;
virtual long getFileSize(const std::string &filepath);
protected:

View File

@ -32767,56 +32767,6 @@ int lua_cocos2dx_FileUtils_fullPathFromRelativeFile(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_FileUtils_getSuitableFOpen(lua_State* tolua_S)
{
int argc = 0;
cocos2d::FileUtils* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.FileUtils",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::FileUtils*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_getSuitableFOpen'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.FileUtils:getSuitableFOpen");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_getSuitableFOpen'", nullptr);
return 0;
}
std::string ret = cobj->getSuitableFOpen(arg0);
lua_pushlstring(tolua_S,ret.c_str(),ret.length());
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:getSuitableFOpen",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_getSuitableFOpen'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_FileUtils_writeValueMapToFile(lua_State* tolua_S)
{
int argc = 0;
@ -33527,7 +33477,6 @@ int lua_register_cocos2dx_FileUtils(lua_State* tolua_S)
tolua_function(tolua_S,"isFileExist",lua_cocos2dx_FileUtils_isFileExist);
tolua_function(tolua_S,"purgeCachedEntries",lua_cocos2dx_FileUtils_purgeCachedEntries);
tolua_function(tolua_S,"fullPathFromRelativeFile",lua_cocos2dx_FileUtils_fullPathFromRelativeFile);
tolua_function(tolua_S,"getSuitableFOpen",lua_cocos2dx_FileUtils_getSuitableFOpen);
tolua_function(tolua_S,"writeValueMapToFile",lua_cocos2dx_FileUtils_writeValueMapToFile);
tolua_function(tolua_S,"getFileExtension",lua_cocos2dx_FileUtils_getFileExtension);
tolua_function(tolua_S,"setWritablePath",lua_cocos2dx_FileUtils_setWritablePath);