mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.0 KiB
C++
37 lines
1.0 KiB
C++
3 years ago
|
#include "hash.hpp"
|
||
|
|
||
|
#include <components/misc/hash.hpp>
|
||
|
|
||
|
#include <cstdint>
|
||
|
#include <functional>
|
||
|
#include <istream>
|
||
|
#include <string>
|
||
|
|
||
|
namespace Files
|
||
|
{
|
||
|
std::uint64_t getHash(const std::string& fileName, std::istream& stream)
|
||
|
{
|
||
|
std::uint64_t hash = std::hash<std::string> {}(fileName);
|
||
|
try
|
||
|
{
|
||
|
const auto start = stream.tellg();
|
||
|
const auto exceptions = stream.exceptions();
|
||
|
stream.exceptions(std::ios_base::badbit);
|
||
|
while (stream)
|
||
|
{
|
||
|
std::uint64_t value = 0;
|
||
|
stream.read(reinterpret_cast<char*>(&value), sizeof(value));
|
||
|
Misc::hashCombine(hash, value);
|
||
|
}
|
||
|
stream.exceptions(exceptions);
|
||
|
stream.clear();
|
||
|
stream.seekg(start);
|
||
|
}
|
||
|
catch (const std::exception& e)
|
||
|
{
|
||
|
throw std::runtime_error("Error while reading \"" + fileName + "\" to get hash: " + std::string(e.what()));
|
||
|
}
|
||
|
return hash;
|
||
|
}
|
||
|
}
|