diff --git a/components/openmw-mp/Utils.cpp b/components/openmw-mp/Utils.cpp index bca6ca3bd..f6bd80144 100644 --- a/components/openmw-mp/Utils.cpp +++ b/components/openmw-mp/Utils.cpp @@ -1,7 +1,3 @@ -// -// Created by koncord on 24.01.16. -// - #include "Utils.hpp" #include @@ -42,6 +38,16 @@ std::string Utils::convertPath(std::string str) #undef _SEP_ } +bool Utils::doesFileHaveChecksum(std::string filePath, unsigned int requiredChecksum) +{ + unsigned int fileChecksum = crc32Checksum(filePath); + + if (fileChecksum == requiredChecksum) + return true; + + return false; +} + void Utils::timestamp() { time_t ltime; @@ -97,6 +103,8 @@ unsigned int Utils::getNumberOfDigits(int integer) return digits; } + + std::string Utils::toString(int num) { std::ostringstream stream; @@ -208,3 +216,10 @@ string Utils::intToHexStr(unsigned val) sstr << "0x" << setfill('0') << setw(8) << uppercase << hex << val; return sstr.str(); } + +unsigned int Utils::hexStrToInt(std::string hexString) +{ + unsigned int intValue; + sscanf(hexString.c_str(), "%x", &intValue); + return intValue; +} diff --git a/components/openmw-mp/Utils.hpp b/components/openmw-mp/Utils.hpp index c18e29231..e69ef6459 100644 --- a/components/openmw-mp/Utils.hpp +++ b/components/openmw-mp/Utils.hpp @@ -21,6 +21,7 @@ int setenv(const char *name, const char *value, int overwrite); namespace Utils { std::string convertPath(std::string str); + bool doesFileHaveChecksum(std::string filePath, unsigned int requiredChecksum); void timestamp(); @@ -48,6 +49,8 @@ namespace Utils void printVersion(std::string appName, std::string version, std::string commitHash, int protocol); void printWithWidth(std::ostringstream &sstr, std::string str, size_t width); + std::string intToHexStr(unsigned val); + unsigned int hexStrToInt(std::string hexString); } #endif //UTILS_HPP