Revision: 2669 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2669&view=rev Author: rorthomas Date: 2012-05-26 00:09:28 +0000 (Sat, 26 May 2012) Log Message: ----------- added new util function "generateHashFromDataStream"
Modified Paths: -------------- trunk/source/main/utils/utils.cpp trunk/source/main/utils/utils.h Modified: trunk/source/main/utils/utils.cpp =================================================================== --- trunk/source/main/utils/utils.cpp 2012-05-25 21:38:30 UTC (rev 2668) +++ trunk/source/main/utils/utils.cpp 2012-05-26 00:09:28 UTC (rev 2669) @@ -27,6 +27,8 @@ #include <iconv.h> #endif //WIN32 +#include "sha1.h" + #include "Ogre.h" using namespace Ogre; @@ -368,3 +370,30 @@ return value; } + +Ogre::String generateHashFromDataStream(Ogre::DataStreamPtr &ds) +{ + // copy whole file into a buffer + uint8_t *buf = 0; + ds->seek(0); // from start + // alloc buffer + uint32_t bufSize = ds->size(); + buf = (uint8_t *)malloc(bufSize); + // read into buffer + ds->read(buf, bufSize); + + // and build the hash over it + char hash_result[250]; + memset(hash_result, 0, 249); + RoR::CSHA1 sha1; + sha1.UpdateHash(buf, bufSize); + sha1.Final(); + sha1.ReportHash(hash_result, RoR::CSHA1::REPORT_HEX_SHORT); + + // revert DS to start + ds->seek(0); + // release memory + free(buf); + + return String(hash_result); +} Modified: trunk/source/main/utils/utils.h =================================================================== --- trunk/source/main/utils/utils.h 2012-05-25 21:38:30 UTC (rev 2668) +++ trunk/source/main/utils/utils.h 2012-05-26 00:09:28 UTC (rev 2669) @@ -26,6 +26,7 @@ #include <OgrePrerequisites.h> #include <OgreUTFString.h> +#include <OgreDataStream.h> #ifdef USE_MYGUI #include <MyGUI.h> @@ -135,4 +136,6 @@ Ogre::Real Round(Ogre::Real value, unsigned short ndigits = 0); +// generates a hash from a Datastream, beware, its loading the whole thing into a bufer, so its not suited for big files +Ogre::String generateHashFromDataStream(Ogre::DataStreamPtr &ds); #endif //UTILS_H_ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Rigsofrods-devel mailing list Rigsofrods-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel