forked from qt-creator/qt-creator
Core: Use QtcProcess instead of SynchronousProcess helpers in PatchTool
Change-Id: I8acb326579bf4bf201fb94d1b3b0db65eed51a55 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -26,11 +26,10 @@
|
|||||||
#include "patchtool.h"
|
#include "patchtool.h"
|
||||||
#include "messagemanager.h"
|
#include "messagemanager.h"
|
||||||
#include "icore.h"
|
#include "icore.h"
|
||||||
#include <utils/synchronousprocess.h>
|
|
||||||
#include <utils/environment.h>
|
|
||||||
|
|
||||||
#include <QProcess>
|
#include <utils/environment.h>
|
||||||
#include <QProcessEnvironment>
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
@@ -38,6 +37,8 @@ static const char settingsGroupC[] = "General";
|
|||||||
static const char patchCommandKeyC[] = "PatchCommand";
|
static const char patchCommandKeyC[] = "PatchCommand";
|
||||||
static const char patchCommandDefaultC[] = "patch";
|
static const char patchCommandDefaultC[] = "patch";
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
QString PatchTool::patchCommand()
|
QString PatchTool::patchCommand()
|
||||||
@@ -79,12 +80,12 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QProcess patchProcess;
|
QtcProcess patchProcess;
|
||||||
if (!workingDirectory.isEmpty())
|
if (!workingDirectory.isEmpty())
|
||||||
patchProcess.setWorkingDirectory(workingDirectory);
|
patchProcess.setWorkingDirectory(workingDirectory);
|
||||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
Environment env = Environment::systemEnvironment();
|
||||||
Utils::Environment::setupEnglishOutput(&env);
|
Environment::setupEnglishOutput(&env);
|
||||||
patchProcess.setProcessEnvironment(env);
|
patchProcess.setEnvironment(env);
|
||||||
QStringList args;
|
QStringList args;
|
||||||
// Add argument 'apply' when git is used as patch command since git 2.5/Windows
|
// Add argument 'apply' when git is used as patch command since git 2.5/Windows
|
||||||
// no longer ships patch.exe.
|
// no longer ships patch.exe.
|
||||||
@@ -103,7 +104,8 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
|||||||
.arg(QDir::toNativeSeparators(workingDirectory),
|
.arg(QDir::toNativeSeparators(workingDirectory),
|
||||||
QDir::toNativeSeparators(patch),
|
QDir::toNativeSeparators(patch),
|
||||||
args.join(QLatin1Char(' '))));
|
args.join(QLatin1Char(' '))));
|
||||||
patchProcess.start(patch, args);
|
patchProcess.setCommand({patch, args});
|
||||||
|
patchProcess.start();
|
||||||
if (!patchProcess.waitForStarted()) {
|
if (!patchProcess.waitForStarted()) {
|
||||||
MessageManager::writeFlashing(
|
MessageManager::writeFlashing(
|
||||||
QApplication::translate("Core::PatchTool", "Unable to launch \"%1\": %2")
|
QApplication::translate("Core::PatchTool", "Unable to launch \"%1\": %2")
|
||||||
@@ -114,8 +116,8 @@ static bool runPatchHelper(const QByteArray &input, const QString &workingDirect
|
|||||||
patchProcess.closeWriteChannel();
|
patchProcess.closeWriteChannel();
|
||||||
QByteArray stdOut;
|
QByteArray stdOut;
|
||||||
QByteArray stdErr;
|
QByteArray stdErr;
|
||||||
if (!Utils::SynchronousProcess::readDataFromProcess(patchProcess, 30, &stdOut, &stdErr, true)) {
|
if (!patchProcess.readDataFromProcess(30, &stdOut, &stdErr, true)) {
|
||||||
Utils::SynchronousProcess::stopProcess(patchProcess);
|
patchProcess.stopProcess();
|
||||||
MessageManager::writeFlashing(
|
MessageManager::writeFlashing(
|
||||||
QApplication::translate("Core::PatchTool", "A timeout occurred running \"%1\"")
|
QApplication::translate("Core::PatchTool", "A timeout occurred running \"%1\"")
|
||||||
.arg(patch));
|
.arg(patch));
|
||||||
|
Reference in New Issue
Block a user