[General] Add Utils methods for checksums

fix/skillcap
David Cernat 7 years ago
parent 9445db61b4
commit 22b2b7a9c6

@ -1,7 +1,3 @@
//
// Created by koncord on 24.01.16.
//
#include "Utils.hpp" #include "Utils.hpp"
#include <cstdio> #include <cstdio>
@ -42,6 +38,16 @@ std::string Utils::convertPath(std::string str)
#undef _SEP_ #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() void Utils::timestamp()
{ {
time_t ltime; time_t ltime;
@ -97,6 +103,8 @@ unsigned int Utils::getNumberOfDigits(int integer)
return digits; return digits;
} }
std::string Utils::toString(int num) std::string Utils::toString(int num)
{ {
std::ostringstream stream; std::ostringstream stream;
@ -208,3 +216,10 @@ string Utils::intToHexStr(unsigned val)
sstr << "0x" << setfill('0') << setw(8) << uppercase << hex << val; sstr << "0x" << setfill('0') << setw(8) << uppercase << hex << val;
return sstr.str(); return sstr.str();
} }
unsigned int Utils::hexStrToInt(std::string hexString)
{
unsigned int intValue;
sscanf(hexString.c_str(), "%x", &intValue);
return intValue;
}

@ -21,6 +21,7 @@ int setenv(const char *name, const char *value, int overwrite);
namespace Utils namespace Utils
{ {
std::string convertPath(std::string str); std::string convertPath(std::string str);
bool doesFileHaveChecksum(std::string filePath, unsigned int requiredChecksum);
void timestamp(); void timestamp();
@ -48,6 +49,8 @@ namespace Utils
void printVersion(std::string appName, std::string version, std::string commitHash, int protocol); void printVersion(std::string appName, std::string version, std::string commitHash, int protocol);
void printWithWidth(std::ostringstream &sstr, std::string str, size_t width); void printWithWidth(std::ostringstream &sstr, std::string str, size_t width);
std::string intToHexStr(unsigned val); std::string intToHexStr(unsigned val);
unsigned int hexStrToInt(std::string hexString);
} }
#endif //UTILS_HPP #endif //UTILS_HPP

Loading…
Cancel
Save