aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/utils/IOUtils.cpp
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-02-29 10:15:57 +0000
committersaturneric <[email protected]>2024-02-29 10:15:57 +0000
commitc1f5b3336836e15d193582e9b8f3e044f7d8bc1b (patch)
tree35e9edb2e8f0c80dbafb76cc05ad6fe92c2c11d0 /src/core/utils/IOUtils.cpp
parentfeat: upgrade module system (diff)
downloadGpgFrontend-c1f5b3336836e15d193582e9b8f3e044f7d8bc1b.tar.gz
GpgFrontend-c1f5b3336836e15d193582e9b8f3e044f7d8bc1b.zip
feat: add module controller and continue to work on module system
1. speed up building by reducing build info sheader including 2. add module controller 3. continue to work on module system
Diffstat (limited to 'src/core/utils/IOUtils.cpp')
-rw-r--r--src/core/utils/IOUtils.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/core/utils/IOUtils.cpp b/src/core/utils/IOUtils.cpp
index 1002badd..79b879f9 100644
--- a/src/core/utils/IOUtils.cpp
+++ b/src/core/utils/IOUtils.cpp
@@ -180,4 +180,42 @@ auto GetFullExtension(const QString& path) -> QString {
return filename.mid(dot_index);
}
+auto CalculateBinaryChacksum(const QString& path) -> QString {
+ // check file info and access rights
+ QFileInfo info(path);
+ if (!info.exists() || !info.isFile() || !info.isReadable()) {
+ GF_CORE_LOG_ERROR("get info for file {} error, exists: {}", info.filePath(),
+ info.exists());
+ return {};
+ }
+
+ // open and read file
+ QFile f(info.filePath());
+ if (!f.open(QIODevice::ReadOnly)) {
+ GF_CORE_LOG_ERROR("open {} to calculate checksum error: {}",
+ path.toStdString(), f.errorString().toStdString());
+ return {};
+ }
+
+ QCryptographicHash hash_sha(QCryptographicHash::Sha256);
+
+ // read data by chunks
+ const qint64 buffer_size = 8192; // Define a suitable buffer size
+ while (!f.atEnd()) {
+ QByteArray buffer = f.read(buffer_size);
+ if (buffer.isEmpty()) {
+ GF_CORE_LOG_ERROR("error reading file {} during checksum calculation",
+ path.toStdString());
+ return {};
+ }
+ hash_sha.addData(buffer);
+ }
+
+ // close the file
+ f.close();
+
+ // return the SHA-256 hash of the file
+ return hash_sha.result().toHex();
+}
+
} // namespace GpgFrontend \ No newline at end of file