From 4d9024347b0780afb955f0dbbda5d38907fe5200 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sat, 4 Sep 2021 15:18:45 +0800 Subject: Modified ResultAnalyse. Add Test. --- src/gpg/function/GpgCommandExecutor.cpp | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/gpg/function/GpgCommandExecutor.cpp (limited to 'src/gpg/function/GpgCommandExecutor.cpp') diff --git a/src/gpg/function/GpgCommandExecutor.cpp b/src/gpg/function/GpgCommandExecutor.cpp new file mode 100644 index 00000000..98743ed4 --- /dev/null +++ b/src/gpg/function/GpgCommandExecutor.cpp @@ -0,0 +1,45 @@ +/** + * 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. + * + * Foobar 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 Foobar. If not, see . + * + * The initial version of the source code is inherited from gpg4usb-team. + * Their source code version also complies with GNU General Public License. + * + * The source code version of this software was modified and released + * by Saturneric starting on May 12, 2021. + * + */ +#include "gpg/function/GpgCommandExecutor.h" + + +void GpgFrontend::GpgCommandExecutor::execute(const QStringList &arguments, + const std::function &interactFunc) { + QEventLoop looper; + auto *gpgProcess = new QProcess(&looper); + gpgProcess->setProcessChannelMode(QProcess::MergedChannels); + connect(gpgProcess, qOverload(&QProcess::finished), &looper, &QEventLoop::quit); + connect(gpgProcess, &QProcess::errorOccurred, []() -> void { qDebug("Error in Process"); }); + connect(gpgProcess, &QProcess::errorOccurred, &looper, &QEventLoop::quit); + connect(gpgProcess, &QProcess::started, []() -> void { qDebug() << "Gpg Process Started Success"; }); + connect(gpgProcess, &QProcess::readyReadStandardOutput, [interactFunc, gpgProcess]() { + qDebug() << "Function Called"; + interactFunc(gpgProcess); + }); + gpgProcess->setProgram(ctx.getInfo().appPath); + gpgProcess->setArguments(arguments); + gpgProcess->start(); + looper.exec(); + +} -- cgit v1.2.3 From 39440522111abf3adeef6b56cb23722119fbf3c2 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sun, 5 Sep 2021 15:02:19 +0000 Subject: Rewrite the core. Adjust the structure. --- src/gpg/function/GpgCommandExecutor.cpp | 42 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'src/gpg/function/GpgCommandExecutor.cpp') diff --git a/src/gpg/function/GpgCommandExecutor.cpp b/src/gpg/function/GpgCommandExecutor.cpp index 98743ed4..c36cb2b6 100644 --- a/src/gpg/function/GpgCommandExecutor.cpp +++ b/src/gpg/function/GpgCommandExecutor.cpp @@ -23,23 +23,27 @@ */ #include "gpg/function/GpgCommandExecutor.h" - -void GpgFrontend::GpgCommandExecutor::execute(const QStringList &arguments, - const std::function &interactFunc) { - QEventLoop looper; - auto *gpgProcess = new QProcess(&looper); - gpgProcess->setProcessChannelMode(QProcess::MergedChannels); - connect(gpgProcess, qOverload(&QProcess::finished), &looper, &QEventLoop::quit); - connect(gpgProcess, &QProcess::errorOccurred, []() -> void { qDebug("Error in Process"); }); - connect(gpgProcess, &QProcess::errorOccurred, &looper, &QEventLoop::quit); - connect(gpgProcess, &QProcess::started, []() -> void { qDebug() << "Gpg Process Started Success"; }); - connect(gpgProcess, &QProcess::readyReadStandardOutput, [interactFunc, gpgProcess]() { - qDebug() << "Function Called"; - interactFunc(gpgProcess); - }); - gpgProcess->setProgram(ctx.getInfo().appPath); - gpgProcess->setArguments(arguments); - gpgProcess->start(); - looper.exec(); - +void GpgFrontend::GpgCommandExecutor::Execute( + const QStringList &arguments, + const std::function &interact_func) { + QEventLoop looper; + auto *gpg_process = new QProcess(&looper); + gpg_process->setProcessChannelMode(QProcess::MergedChannels); + connect(gpg_process, + qOverload(&QProcess::finished), &looper, + &QEventLoop::quit); + connect(gpg_process, &QProcess::errorOccurred, + []() -> void { qDebug("Error in Process"); }); + connect(gpg_process, &QProcess::errorOccurred, &looper, &QEventLoop::quit); + connect(gpg_process, &QProcess::started, + []() -> void { qDebug() << "Gpg Process Started Success"; }); + connect(gpg_process, &QProcess::readyReadStandardOutput, + [interact_func, gpg_process]() { + qDebug() << "Function Called"; + interact_func(gpg_process); + }); + gpg_process->setProgram(ctx.GetInfo().appPath.c_str()); + gpg_process->setArguments(arguments); + gpg_process->start(); + looper.exec(); } -- cgit v1.2.3 From e2d30cc0194db74b77e3c06dbaf9c597bb82c860 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sun, 5 Sep 2021 21:41:00 +0000 Subject: Adjust the code structure. Introduce log library. Remove Qt from the core code. --- src/gpg/function/GpgCommandExecutor.cpp | 50 ++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'src/gpg/function/GpgCommandExecutor.cpp') diff --git a/src/gpg/function/GpgCommandExecutor.cpp b/src/gpg/function/GpgCommandExecutor.cpp index c36cb2b6..dc4750ef 100644 --- a/src/gpg/function/GpgCommandExecutor.cpp +++ b/src/gpg/function/GpgCommandExecutor.cpp @@ -23,27 +23,33 @@ */ #include "gpg/function/GpgCommandExecutor.h" +#include + +using boost::process::async_pipe; + void GpgFrontend::GpgCommandExecutor::Execute( - const QStringList &arguments, - const std::function &interact_func) { - QEventLoop looper; - auto *gpg_process = new QProcess(&looper); - gpg_process->setProcessChannelMode(QProcess::MergedChannels); - connect(gpg_process, - qOverload(&QProcess::finished), &looper, - &QEventLoop::quit); - connect(gpg_process, &QProcess::errorOccurred, - []() -> void { qDebug("Error in Process"); }); - connect(gpg_process, &QProcess::errorOccurred, &looper, &QEventLoop::quit); - connect(gpg_process, &QProcess::started, - []() -> void { qDebug() << "Gpg Process Started Success"; }); - connect(gpg_process, &QProcess::readyReadStandardOutput, - [interact_func, gpg_process]() { - qDebug() << "Function Called"; - interact_func(gpg_process); - }); - gpg_process->setProgram(ctx.GetInfo().appPath.c_str()); - gpg_process->setArguments(arguments); - gpg_process->start(); - looper.exec(); + StringArgsRef arguments, + const std::function &interact_func) { + + using namespace boost::process; + + boost::asio::io_service ios; + + std::vector buf; + + async_pipe in_pipe_stream(ios); + async_pipe out_pipe_stream(ios); + + child child_process(ctx.GetInfo().appPath.c_str(), arguments, + std_out > in_pipe_stream, std_in < out_pipe_stream); + + boost::asio::async_read( + in_pipe_stream, boost::asio::buffer(buf), + [&](const boost::system::error_code &ec, std::size_t size) { + interact_func(in_pipe_stream, out_pipe_stream); + }); + + ios.run(); + child_process.wait(); + int result = child_process.exit_code(); } -- cgit v1.2.3 From 4d792921af4170e8574e9b2841fe54e796902833 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sat, 11 Sep 2021 14:50:48 +0800 Subject: Improve and optimize the code. --- src/gpg/function/GpgCommandExecutor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gpg/function/GpgCommandExecutor.cpp') diff --git a/src/gpg/function/GpgCommandExecutor.cpp b/src/gpg/function/GpgCommandExecutor.cpp index dc4750ef..b5e6ccae 100644 --- a/src/gpg/function/GpgCommandExecutor.cpp +++ b/src/gpg/function/GpgCommandExecutor.cpp @@ -51,5 +51,5 @@ void GpgFrontend::GpgCommandExecutor::Execute( ios.run(); child_process.wait(); - int result = child_process.exit_code(); + child_process.exit_code(); } -- cgit v1.2.3 From 5874147d9ec0f94a5058241a06c69f586b766a3b Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sun, 12 Sep 2021 21:56:18 +0800 Subject: Continue to write core test code. --- src/gpg/function/GpgCommandExecutor.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/gpg/function/GpgCommandExecutor.cpp') diff --git a/src/gpg/function/GpgCommandExecutor.cpp b/src/gpg/function/GpgCommandExecutor.cpp index b5e6ccae..efe1446f 100644 --- a/src/gpg/function/GpgCommandExecutor.cpp +++ b/src/gpg/function/GpgCommandExecutor.cpp @@ -29,8 +29,7 @@ using boost::process::async_pipe; void GpgFrontend::GpgCommandExecutor::Execute( StringArgsRef arguments, - const std::function &interact_func) { - + const std::function& interact_func) { using namespace boost::process; boost::asio::io_service ios; @@ -40,12 +39,12 @@ void GpgFrontend::GpgCommandExecutor::Execute( async_pipe in_pipe_stream(ios); async_pipe out_pipe_stream(ios); - child child_process(ctx.GetInfo().appPath.c_str(), arguments, + child child_process(ctx.GetInfo().AppPath.c_str(), arguments, std_out > in_pipe_stream, std_in < out_pipe_stream); boost::asio::async_read( in_pipe_stream, boost::asio::buffer(buf), - [&](const boost::system::error_code &ec, std::size_t size) { + [&](const boost::system::error_code& ec, std::size_t size) { interact_func(in_pipe_stream, out_pipe_stream); }); -- cgit v1.2.3 From 1ae8663decb3163b92d32b80cefb46eb678a5af6 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Thu, 2 Dec 2021 01:25:46 +0800 Subject: Add i18n Support 1. Remove Qt Linguist. 2. Add GNU gettext libraries. 3. Modified source codes to meet with i18n support. --- src/gpg/function/GpgCommandExecutor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gpg/function/GpgCommandExecutor.cpp') diff --git a/src/gpg/function/GpgCommandExecutor.cpp b/src/gpg/function/GpgCommandExecutor.cpp index efe1446f..a494d4a8 100644 --- a/src/gpg/function/GpgCommandExecutor.cpp +++ b/src/gpg/function/GpgCommandExecutor.cpp @@ -1,7 +1,7 @@ /** - * This file is part of GPGFrontend. + * This file is part of GpgFrontend. * - * GPGFrontend is free software: you can redistribute it and/or modify + * 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. -- cgit v1.2.3 From ea7c0113486f336f3fe14435e1ce5eb55ad4eca9 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Fri, 3 Dec 2021 06:44:09 +0800 Subject: Fixed 1. Ci Fixed for New Version. 2. Bugs fixed for cross-platform. 3. Bugs fixed for i18n. --- src/gpg/function/GpgCommandExecutor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gpg/function/GpgCommandExecutor.cpp') diff --git a/src/gpg/function/GpgCommandExecutor.cpp b/src/gpg/function/GpgCommandExecutor.cpp index a494d4a8..9b99b400 100644 --- a/src/gpg/function/GpgCommandExecutor.cpp +++ b/src/gpg/function/GpgCommandExecutor.cpp @@ -22,8 +22,11 @@ * */ #include "gpg/function/GpgCommandExecutor.h" - +#ifndef WINDOWS #include +#endif + +#ifndef WINDOWS using boost::process::async_pipe; @@ -52,3 +55,5 @@ void GpgFrontend::GpgCommandExecutor::Execute( child_process.wait(); child_process.exit_code(); } + +#endif -- cgit v1.2.3