mirror of https://github.com/axmolengine/axmol.git
Merge pull request #15448 from xpol/remove-internal-use-of-getFileData
Fixes deprecated warnings
This commit is contained in:
commit
b182adae5b
|
@ -140,6 +140,16 @@ static const char *COLOR_INFO = "color";
|
|||
static const char *CONFIG_FILE_PATH = "config_file_path";
|
||||
static const char *CONTENT_SCALE = "content_scale";
|
||||
|
||||
|
||||
static std::string readFileContent(const std::string& filename, bool binary) {
|
||||
auto fs = FileUtils::getInstance();
|
||||
if (binary) {
|
||||
Data data(fs->getDataFromFile(filename));
|
||||
return std::string((const char*)data.getBytes(), data.getSize());
|
||||
}
|
||||
return fs->getStringFromFile(filename);
|
||||
};
|
||||
|
||||
namespace cocostudio {
|
||||
|
||||
|
||||
|
@ -300,14 +310,9 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath)
|
|||
// Read content from file
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||
bool isbinaryfilesrc = fileExtension == ".csb";
|
||||
std::string filemode("r");
|
||||
if(isbinaryfilesrc)
|
||||
filemode += "b";
|
||||
ssize_t filesize;
|
||||
|
||||
_dataReaderHelper->_getFileMutex.lock();
|
||||
unsigned char *pBytes = FileUtils::getInstance()->getFileData(filePath, filemode.c_str(), &filesize);
|
||||
std::string contentStr((const char*)pBytes,filesize);
|
||||
std::string contentStr(readFileContent(fullPath, isbinaryfilesrc));
|
||||
_dataReaderHelper->_getFileMutex.unlock();
|
||||
|
||||
DataInfo dataInfo;
|
||||
|
@ -326,8 +331,6 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath)
|
|||
{
|
||||
DataReaderHelper::addDataFromBinaryCache(contentStr.c_str(),&dataInfo);
|
||||
}
|
||||
|
||||
free(pBytes);
|
||||
}
|
||||
|
||||
void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, Ref *target, SEL_SCHEDULE selector)
|
||||
|
@ -409,26 +412,13 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const
|
|||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||
|
||||
bool isbinaryfilesrc = fileExtension == ".csb";
|
||||
std::string filereadmode("r");
|
||||
if (isbinaryfilesrc) {
|
||||
filereadmode += "b";
|
||||
}
|
||||
ssize_t size;
|
||||
// FIXME: fileContent is being leaked
|
||||
|
||||
// This getFileData only read exportJson file, it takes only a little time.
|
||||
// This only read exportJson file, it takes only a little time.
|
||||
// Large image files are loaded in DataReaderHelper::addDataFromJsonCache(dataInfo) asynchronously.
|
||||
_dataReaderHelper->_getFileMutex.lock();
|
||||
unsigned char *pBytes = FileUtils::getInstance()->getFileData(fullPath, filereadmode.c_str(), &size);
|
||||
data->fileContent.assign(readFileContent(fullPath, isbinaryfilesrc));
|
||||
_dataReaderHelper->_getFileMutex.unlock();
|
||||
|
||||
Data bytecpy;
|
||||
bytecpy.copy(pBytes, size);
|
||||
data->fileContent = std::string((const char*)bytecpy.getBytes(), size);
|
||||
|
||||
// fix memory leak for v3.3
|
||||
free(pBytes);
|
||||
|
||||
if (fileExtension == ".xml")
|
||||
{
|
||||
data->configType = DragonBone_XML;
|
||||
|
|
|
@ -62,8 +62,7 @@ extern "C"
|
|||
}
|
||||
|
||||
// search file in package.path
|
||||
unsigned char* chunk = nullptr;
|
||||
ssize_t chunkSize = 0;
|
||||
Data chunk;
|
||||
std::string chunkName;
|
||||
FileUtils* utils = FileUtils::getInstance();
|
||||
|
||||
|
@ -88,7 +87,7 @@ extern "C"
|
|||
chunkName = prefix.substr(0, pos) + filename + BYTECODE_FILE_EXT;
|
||||
if (utils->isFileExist(chunkName))
|
||||
{
|
||||
chunk = utils->getFileData(chunkName.c_str(), "rb", &chunkSize);
|
||||
chunk = utils->getDataFromFile(chunkName);
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
@ -96,7 +95,7 @@ extern "C"
|
|||
chunkName = prefix.substr(0, pos) + filename + NOT_BYTECODE_FILE_EXT;
|
||||
if (utils->isFileExist(chunkName))
|
||||
{
|
||||
chunk = utils->getFileData(chunkName.c_str(), "rb", &chunkSize);
|
||||
chunk = utils->getDataFromFile(chunkName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -105,11 +104,11 @@ extern "C"
|
|||
next = searchpath.find_first_of(";", begin);
|
||||
} while (begin < (int)searchpath.length());
|
||||
|
||||
if (chunk)
|
||||
if (chunk.getSize() > 0)
|
||||
{
|
||||
LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
|
||||
stack->luaLoadBuffer(L, (char*)chunk, (int)chunkSize, chunkName.c_str());
|
||||
free(chunk);
|
||||
stack->luaLoadBuffer(L, reinterpret_cast<const char*>(chunk.getBytes()),
|
||||
static_cast<int>(chunk.getSize()), chunkName.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue