diff options
Diffstat (limited to 'src/core/utils')
-rw-r--r-- | src/core/utils/BuildInfoUtils.cpp | 26 | ||||
-rw-r--r-- | src/core/utils/BuildInfoUtils.h | 82 | ||||
-rw-r--r-- | src/core/utils/CommonUtils.cpp | 2 | ||||
-rw-r--r-- | src/core/utils/IOUtils.cpp | 38 | ||||
-rw-r--r-- | src/core/utils/IOUtils.h | 9 |
5 files changed, 156 insertions, 1 deletions
diff --git a/src/core/utils/BuildInfoUtils.cpp b/src/core/utils/BuildInfoUtils.cpp new file mode 100644 index 00000000..a7d914ef --- /dev/null +++ b/src/core/utils/BuildInfoUtils.cpp @@ -0,0 +1,26 @@ + +#include "BuildInfoUtils.h" + +#include "GpgFrontendBuildInfo.h" + +namespace GpgFrontend { + +auto GetProjectVersion() -> QString { + return QString("v") + VERSION_MAJOR + "." + VERSION_MINOR + "." + + VERSION_PATCH; +} + +auto GetProjectBuildVersion() -> QString { return BUILD_VERSION; } + +auto GetProjectBuildTimestamp() -> QDateTime { + return QDateTime::fromString(BUILD_TIMESTAMP, Qt::ISODate); +} + +auto GetProjectBuildGitBranchName() -> QString { return GIT_BRANCH_NAME; } + +auto GetProjectBuildGitCommitHash() -> QString { return GIT_COMMIT_HASH; } + +auto GetProjectBuildGitVersion() -> QString { return GIT_VERSION; } + +auto GetHttpRequestUserAgent() -> QString { return HTTP_REQUEST_USER_AGENT; } +}; // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/utils/BuildInfoUtils.h b/src/core/utils/BuildInfoUtils.h new file mode 100644 index 00000000..bac5d8a5 --- /dev/null +++ b/src/core/utils/BuildInfoUtils.h @@ -0,0 +1,82 @@ +/** + * Copyright (C) 2021 Saturneric <[email protected]> + * + * This file is part of GpgFrontend. + * + * GpgFrontend is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GpgFrontend is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. + * + * The initial version of the source code is inherited from + * the gpg4usb project, which is under GPL-3.0-or-later. + * + * All the source code of GpgFrontend was modified and released by + * Saturneric <[email protected]> starting on May 12, 2021. + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +namespace GpgFrontend { + +/** + * @brief + * + * @return QString + */ +auto GPGFRONTEND_CORE_EXPORT GetProjectVersion() -> QString; + +/** + * @brief + * + * @return QString + */ +auto GPGFRONTEND_CORE_EXPORT GetProjectBuildVersion() -> QString; + +/** + * @brief + * + * @return QString + */ +auto GPGFRONTEND_CORE_EXPORT GetProjectBuildTimestamp() -> QDateTime; + +/** + * @brief + * + * @return QString + */ +auto GPGFRONTEND_CORE_EXPORT GetProjectBuildGitBranchName() -> QString; + +/** + * @brief + * + * @return QString + */ +auto GPGFRONTEND_CORE_EXPORT GetProjectBuildGitCommitHash() -> QString; + +/** + * @brief + * + * @return QString + */ +auto GPGFRONTEND_CORE_EXPORT GetProjectBuildGitVersion() -> QString; + +/** + * @brief + * + * @return QString + */ +auto GPGFRONTEND_CORE_EXPORT GetHttpRequestUserAgent() -> QString; + +} // namespace GpgFrontend
\ No newline at end of file diff --git a/src/core/utils/CommonUtils.cpp b/src/core/utils/CommonUtils.cpp index 36dfe0a7..20851cca 100644 --- a/src/core/utils/CommonUtils.cpp +++ b/src/core/utils/CommonUtils.cpp @@ -72,7 +72,7 @@ auto CompareSoftwareVersion(const QString& a, const QString& b) -> int { return 0; } -auto GPGFRONTEND_CORE_EXPORT GFStrDup(const QString& str) -> char* { +auto GFStrDup(const QString& str) -> char* { auto utf8_str = str.toUtf8(); auto* c_str = static_cast<char*>(SecureMalloc((utf8_str.size() + 1) * sizeof(char))); 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 diff --git a/src/core/utils/IOUtils.h b/src/core/utils/IOUtils.h index 2c48f38c..3e18394d 100644 --- a/src/core/utils/IOUtils.h +++ b/src/core/utils/IOUtils.h @@ -85,6 +85,15 @@ auto GPGFRONTEND_CORE_EXPORT CalculateHash(const QString &file_path) -> QString; * @brief * * @param path + * @return QString + */ +auto GPGFRONTEND_CORE_EXPORT CalculateBinaryChacksum(const QString &path) + -> QString; + +/** + * @brief + * + * @param path * @param out_buffer * @return true * @return false |