aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/function/FileOperator.cpp
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-03-19 06:09:55 +0000
committerSaturneric <[email protected]>2022-03-19 06:09:55 +0000
commitdad03e9ccc57da0a04d058ec418ce0068ce3841d (patch)
treee3d6bec71f3c070139ef5dfa7cca0cf70acb4dd1 /src/core/function/FileOperator.cpp
parent<fix>(ui): Fix the problem that the file cannot be signed (diff)
downloadGpgFrontend-dad03e9ccc57da0a04d058ec418ce0068ce3841d.tar.gz
GpgFrontend-dad03e9ccc57da0a04d058ec418ce0068ce3841d.zip
<fix>(core, ui): Fix path double-byte encoding problem under Windows
Diffstat (limited to 'src/core/function/FileOperator.cpp')
-rw-r--r--src/core/function/FileOperator.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/core/function/FileOperator.cpp b/src/core/function/FileOperator.cpp
index d0a3df23..4977b3a9 100644
--- a/src/core/function/FileOperator.cpp
+++ b/src/core/function/FileOperator.cpp
@@ -55,15 +55,18 @@ bool GpgFrontend::FileOperator::WriteFile(const QString& file_name,
bool GpgFrontend::FileOperator::ReadFileStd(
const std::filesystem::path& file_name, std::string& data) {
QByteArray byte_data;
- bool res = ReadFile(QString::fromStdString(file_name.string()), byte_data);
+#ifdef WINDOWS
+ bool res = ReadFile(QString::fromStdU16String(file_name.u16string()).toUtf8(), byte_data);
+#else
+ bool res = ReadFile(QString::fromStdString(file_name.u8string()).toUtf8(), byte_data);
+#endif
data = byte_data.toStdString();
return res;
}
bool GpgFrontend::FileOperator::WriteFileStd(
const std::filesystem::path& file_name, const std::string& data) {
- return WriteFile(QString::fromStdString(file_name.string()),
- QByteArray::fromStdString(data));
+ return WriteFile(QString::fromStdString(file_name.u8string()).toUtf8(), QByteArray::fromStdString(data));
}
std::string GpgFrontend::FileOperator::CalculateHash(
@@ -75,7 +78,7 @@ std::string GpgFrontend::FileOperator::CalculateHash(
if (info.isFile() && info.isReadable()) {
ss << "[#] " << _("File Hash Information") << std::endl;
ss << " " << _("filename") << _(": ")
- << file_path.filename().string().c_str() << std::endl;
+ << file_path.filename().u8string().c_str() << std::endl;
QFile f(info.filePath());