Hash calculation uses wxCryptoHash::HashFile() method now.

This commit is contained in:
Simon Rozman 2016-04-01 19:19:14 +02:00
parent c425de942c
commit 348e4a461f

View File

@ -469,26 +469,18 @@ bool wxUpdCheckApp::ReadUpdatePackageMeta()
bool wxUpdCheckApp::DownloadUpdatePackage(const wxString &fileName) bool wxUpdCheckApp::DownloadUpdatePackage(const wxString &fileName)
{ {
if (wxFileExists(fileName)) { // Calculate file hash (if exists).
// The update package file already exists. Do the integrity check. wxCryptoHashSHA1 ch(*m_cs);
wxFFile file(fileName, wxT("rb")); if (ch.HashFile(fileName)) {
if (file.IsOpened()) { wxMemoryBuffer buf;
// Calculate file hash. ch.GetValue(buf);
wxCryptoHashSHA1 ch(*m_cs);
wxMemoryBuffer buf(4*1024);
char *data = (char*)buf.GetData();
size_t nBlock = buf.GetBufSize();
while (!file.Eof())
ch.Hash(data, file.Read(data, nBlock));
ch.GetValue(buf);
if (buf.GetDataLen() == m_hash.GetDataLen() && if (buf.GetDataLen() == m_hash.GetDataLen() &&
memcmp(buf.GetData(), m_hash.GetData(), buf.GetDataLen()) == 0) memcmp(buf.GetData(), m_hash.GetData(), buf.GetDataLen()) == 0)
{ {
// Update package file exists and its hash is correct. // Update package file exists and its hash is correct.
wxLogStatus(wxT("Update package file already downloaded.")); wxLogStatus(wxT("Update package file already downloaded."));
return true; return true;
}
} }
} }