mirror of https://github.com/axmolengine/axmol.git
Added function for calculating md5 hash from Data. (#17762)
* Added function for calculating md5 hash from Data. getFileMD5Hash now use getDataMD5Hash. For example, AssetsManagerEx VerifyCallback. Get Data from file, check equal size, if equal to get md5 hash. * Data::isNull check size equal 0 * Build on linux and android.
This commit is contained in:
parent
5c3993836e
commit
973d6aa955
|
@ -410,18 +410,28 @@ Node* findChild(Node* levelRoot, int tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getFileMD5Hash(const std::string &filename)
|
std::string getFileMD5Hash(const std::string &filename)
|
||||||
|
{
|
||||||
|
Data data;
|
||||||
|
FileUtils::getInstance()->getContents(filename, &data);
|
||||||
|
|
||||||
|
return getDataMD5Hash(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getDataMD5Hash(const Data &data)
|
||||||
{
|
{
|
||||||
static const unsigned int MD5_DIGEST_LENGTH = 16;
|
static const unsigned int MD5_DIGEST_LENGTH = 16;
|
||||||
|
|
||||||
Data d;
|
if (data.isNull())
|
||||||
FileUtils::getInstance()->getContents(filename, &d);
|
{
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
md5_state_t state;
|
md5_state_t state;
|
||||||
md5_byte_t digest[MD5_DIGEST_LENGTH];
|
md5_byte_t digest[MD5_DIGEST_LENGTH];
|
||||||
char hexOutput[(MD5_DIGEST_LENGTH << 1) + 1] = { 0 };
|
char hexOutput[(MD5_DIGEST_LENGTH << 1) + 1] = { 0 };
|
||||||
|
|
||||||
md5_init(&state);
|
md5_init(&state);
|
||||||
md5_append(&state, (const md5_byte_t *)d.getBytes(), (int)d.getSize());
|
md5_append(&state, (const md5_byte_t *)data.getBytes(), (int)data.getSize());
|
||||||
md5_finish(&state, digest);
|
md5_finish(&state, digest);
|
||||||
|
|
||||||
for (int di = 0; di < 16; ++di)
|
for (int di = 0; di < 16; ++di)
|
||||||
|
|
|
@ -29,6 +29,7 @@ THE SOFTWARE.
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "2d/CCNode.h"
|
#include "2d/CCNode.h"
|
||||||
#include "base/ccMacros.h"
|
#include "base/ccMacros.h"
|
||||||
|
#include "base/CCData.h"
|
||||||
|
|
||||||
/** @file ccUtils.h
|
/** @file ccUtils.h
|
||||||
Misc free functions
|
Misc free functions
|
||||||
|
@ -170,6 +171,14 @@ namespace utils
|
||||||
* @return The md5 hash for the file
|
* @return The md5 hash for the file
|
||||||
*/
|
*/
|
||||||
CC_DLL std::string getFileMD5Hash(const std::string &filename);
|
CC_DLL std::string getFileMD5Hash(const std::string &filename);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the md5 hash for the given buffer.
|
||||||
|
* @param data The buffer to calculate md5 hash.
|
||||||
|
* @return The md5 hash for the data
|
||||||
|
*/
|
||||||
|
CC_DLL std::string getDataMD5Hash(const Data &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
Loading…
Reference in New Issue