Revision: 2736
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2736&view=rev
Author:   rorthomas
Date:     2012-05-28 15:43:25 +0000 (Mon, 28 May 2012)
Log Message:
-----------
disabled hash fct for now

Modified Paths:
--------------
    trunk/source/main/terrain/TerrainManager.cpp
    trunk/source/main/utils/Utils.cpp
    trunk/source/main/utils/Utils.h

Modified: trunk/source/main/terrain/TerrainManager.cpp
===================================================================
--- trunk/source/main/terrain/TerrainManager.cpp        2012-05-28 15:05:17 UTC 
(rev 2735)
+++ trunk/source/main/terrain/TerrainManager.cpp        2012-05-28 15:43:25 UTC 
(rev 2736)
@@ -69,7 +69,7 @@
        }
 
        // now generate the hash of it
-       fileHash = generateHashFromDataStream(ds);
+       generateHashFromDataStream(ds.get(), fileHash);
 
        mTerrainConfig.load(ds, "\t:=", false);
 

Modified: trunk/source/main/utils/Utils.cpp
===================================================================
--- trunk/source/main/utils/Utils.cpp   2012-05-28 15:05:17 UTC (rev 2735)
+++ trunk/source/main/utils/Utils.cpp   2012-05-28 15:43:25 UTC (rev 2736)
@@ -369,36 +369,45 @@
        return value;
 }
 
-String generateHashFromDataStream(DataStreamPtr &ds)
+void generateHashFromDataStream(DataStream *ds, Ogre::String &hash)
 {
+       // TODO: fix memory corruption going on below
+       hash = "nothashed";
+       return;
+
+       size_t location = ds->tell();
        // 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);
+       buf = (uint8_t *)malloc(bufSize+1);
        // 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);
+       {
+               RoR::CSHA1 sha1;
+               sha1.UpdateHash(buf, bufSize);
+               sha1.Final();
+               sha1.ReportHash(hash_result, RoR::CSHA1::REPORT_HEX_SHORT);
+       }
+
+       // revert DS to previous position
+       ds->seek(location);
        // release memory
        free(buf);
+       buf = 0;
        
-       return String(hash_result);
+       hash = String(hash_result);
 }
 
-String generateHashFromFile(String filename)
+void generateHashFromFile(String filename, Ogre::String &hash)
 {
        // no exception handling in here
        DataStreamPtr ds = 
ResourceGroupManager::getSingleton().openResource(filename, 
ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
-       return generateHashFromDataStream(ds);
+       generateHashFromDataStream(ds.get(), hash);
 }

Modified: trunk/source/main/utils/Utils.h
===================================================================
--- trunk/source/main/utils/Utils.h     2012-05-28 15:05:17 UTC (rev 2735)
+++ trunk/source/main/utils/Utils.h     2012-05-28 15:43:25 UTC (rev 2736)
@@ -135,7 +135,7 @@
 Ogre::Real Round(Ogre::Real value, unsigned short ndigits = 0);
 
 // generates a hash from a DataStream, beware, its loading the whole thing 
into a buffer, so its not suited for big files
-Ogre::String generateHashFromDataStream(Ogre::DataStreamPtr &ds);
-Ogre::String generateHashFromFile(Ogre::String filename);
+void generateHashFromDataStream(Ogre::DataStream *ds, Ogre::String &hash);
+void generateHashFromFile(Ogre::String filename, Ogre::String &hash);
 
 #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
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to