Support for file hashing added.

This commit is contained in:
Simon Rozman 2016-04-01 15:04:15 +02:00
parent ccd5dc8a19
commit b004239b29

View File

@ -22,6 +22,7 @@
#include "common.h" #include "common.h"
#include <wx/buffer.h> #include <wx/buffer.h>
#include <wx/ffile.h>
#include <wx/string.h> #include <wx/string.h>
#include <Wincrypt.h> #include <Wincrypt.h>
@ -152,6 +153,33 @@ public:
} }
///
/// Hashes a file
///
/// \param[in] fileName The path of the file to calculate hash of
///
/// \returns
/// - true if hashing succeeded
/// - false otherwise
///
inline bool HashFile(const wxString &fileName)
{
wxFFile file(fileName, wxT("rb"));
if (file.IsOpened()) {
wxMemoryBuffer buf(4*1024);
char *data = (char*)buf.GetData();
size_t nBlock = buf.GetBufSize();
while (!file.Eof())
Hash(data, file.Read(data, nBlock));
return true;
} else {
wxLogError(wxT("Can not open %s file for reading."), fileName.c_str());
return false;
}
}
/// ///
/// Finish hashing and return hash data. /// Finish hashing and return hash data.
/// ///