[General] Add Utils methods for checksums

pull/471/head
David Cernat 7 years ago
parent 9445db61b4
commit 22b2b7a9c6

@ -1,7 +1,3 @@
//
// Created by koncord on 24.01.16.
//
#include "Utils.hpp"
#include <cstdio>
@ -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;
}

@ -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

Loading…
Cancel
Save