mirror of https://github.com/axmolengine/axmol.git
Add utils::getMD5Hash (#17520)
* Add FileUtils::getMD5Hash * Improve name
This commit is contained in:
parent
e8c752126d
commit
68fc0dbfa9
|
@ -271,6 +271,7 @@ LOCAL_STATIC_LIBRARIES += cocos_tiff_static
|
|||
LOCAL_STATIC_LIBRARIES += cocos_webp_static
|
||||
LOCAL_STATIC_LIBRARIES += cocos_chipmunk_static
|
||||
LOCAL_STATIC_LIBRARIES += cocos_zlib_static
|
||||
LOCAL_STATIC_LIBRARIES += cocos_ssl_static
|
||||
LOCAL_STATIC_LIBRARIES += recast_static
|
||||
LOCAL_STATIC_LIBRARIES += bullet_static
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
|||
|
||||
#include <cmath>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/md5.h>
|
||||
|
||||
#include "base/CCDirector.h"
|
||||
#include "base/CCAsyncTaskPool.h"
|
||||
|
@ -408,6 +409,21 @@ Node* findChild(Node* levelRoot, int tag)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::string getFileMD5Hash(const std::string &filename)
|
||||
{
|
||||
unsigned char digest[MD5_DIGEST_LENGTH];
|
||||
Data d;
|
||||
FileUtils::getInstance()->getContents(filename, &d);
|
||||
|
||||
MD5(d.getBytes(), d.getSize(), (unsigned char*)&digest);
|
||||
|
||||
std::string mdString;
|
||||
mdString.reserve(32);
|
||||
for(int i = 0; i < 16; i++)
|
||||
sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);
|
||||
return mdString;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -140,7 +140,7 @@ namespace utils
|
|||
|
||||
* @return Returns found node or nullptr
|
||||
*/
|
||||
CC_DLL Node* findChild(Node* levelRoot, int tag);
|
||||
CC_DLL Node* findChild(Node* levelRoot, int tag);
|
||||
|
||||
/**
|
||||
* Find a child by name recursively
|
||||
|
@ -163,6 +163,13 @@ namespace utils
|
|||
{
|
||||
return dynamic_cast<T>(findChild(levelRoot, tag));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the md5 hash for the given file.
|
||||
* @param filename The file to calculate md5 hash.
|
||||
* @return The md5 hash for the file
|
||||
*/
|
||||
CC_DLL std::string getFileMD5Hash(const std::string &filename);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -822,12 +822,12 @@ public:
|
|||
const std::unordered_map<std::string, std::string>& getFullPathCache() const { return _fullPathCache; }
|
||||
|
||||
/**
|
||||
* Gets the new filename from the filename lookup dictionary.
|
||||
* It is possible to have a override names.
|
||||
* @param filename The original filename.
|
||||
* @return The new filename after searching in the filename lookup dictionary.
|
||||
* If the original filename wasn't in the dictionary, it will return the original filename.
|
||||
*/
|
||||
* Gets the new filename from the filename lookup dictionary.
|
||||
* It is possible to have a override names.
|
||||
* @param filename The original filename.
|
||||
* @return The new filename after searching in the filename lookup dictionary.
|
||||
* If the original filename wasn't in the dictionary, it will return the original filename.
|
||||
*/
|
||||
virtual std::string getNewFilename(const std::string &filename) const;
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue