Core: Switch Hashable struct to HashAppend function

Former-commit-id: 2a20eca0e75bf4067d390f4f5e446de78f26799c
This commit is contained in:
Lynix
2015-11-18 18:28:56 +01:00
parent 00423c4211
commit 167f3e4a27
9 changed files with 45 additions and 60 deletions

View File

@@ -3,8 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/AbstractHash.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
@@ -18,39 +17,6 @@ namespace Nz
{
return Nz::ComputeHash(hash, File(filePath));
}
template<>
struct Hashable<File>
{
bool operator()(const Nz::File& originalFile, AbstractHash* hash) const
{
File file(originalFile.GetPath());
if (!file.Open(OpenMode_ReadOnly))
{
NazaraError("Unable to open file");
return false;
}
UInt64 remainingSize = file.GetSize();
char buffer[NAZARA_CORE_FILE_BUFFERSIZE];
while (remainingSize > 0)
{
unsigned int size = static_cast<unsigned int>(std::min(remainingSize, static_cast<UInt64>(NAZARA_CORE_FILE_BUFFERSIZE)));
if (file.Read(&buffer[0], sizeof(char), size) != sizeof(char)*size)
{
NazaraError("Unable to read file");
return false;
}
remainingSize -= size;
hash->Append(reinterpret_cast<UInt8*>(&buffer[0]), size);
}
return true;
}
};
}
#include <Nazara/Core/DebugOff.hpp>