src: applied clang-format
This commit is contained in:
@@ -4,57 +4,60 @@
|
||||
#include <set>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QSysInfo>
|
||||
#include <QThread>
|
||||
#include <qprocessordetection.h>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "ApplicationSettings.h"
|
||||
#include "logging.h"
|
||||
#include "AppPath.h"
|
||||
#include "ApplicationSettings.h"
|
||||
#include "UserPaths.h"
|
||||
#include "logging.h"
|
||||
#include "utilityString.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
void logProcessStreams(QProcess& process, std::wstring& outputBuffer, std::wstring& errorBuffer)
|
||||
void logProcessStreams(QProcess& process, std::wstring& outputBuffer, std::wstring& errorBuffer)
|
||||
{
|
||||
{
|
||||
outputBuffer += QString(process.readAllStandardOutput()).toStdWString();
|
||||
std::vector<std::wstring> outputLines = utility::split<std::vector<std::wstring>>(
|
||||
outputBuffer, L"\n");
|
||||
for (size_t i = 0; i < outputLines.size() - 1; i++)
|
||||
{
|
||||
outputBuffer += QString(process.readAllStandardOutput()).toStdWString();
|
||||
std::vector<std::wstring> outputLines = utility::split<std::vector<std::wstring>>(outputBuffer, L"\n");
|
||||
for (size_t i = 0; i < outputLines.size() - 1; i++)
|
||||
if (outputLines[i].back() == L'\r')
|
||||
{
|
||||
if (outputLines[i].back() == L'\r')
|
||||
{
|
||||
outputLines[i].pop_back();
|
||||
}
|
||||
LOG_INFO_BARE(L"Process output: " + outputLines[i]);
|
||||
outputLines[i].pop_back();
|
||||
}
|
||||
outputBuffer = outputLines.back();
|
||||
LOG_INFO_BARE(L"Process output: " + outputLines[i]);
|
||||
}
|
||||
outputBuffer = outputLines.back();
|
||||
}
|
||||
{
|
||||
errorBuffer += QString(process.readAllStandardError()).toStdWString();
|
||||
std::vector<std::wstring> errorLines = utility::split<std::vector<std::wstring>>(
|
||||
errorBuffer, L"\n");
|
||||
for (size_t i = 0; i < errorLines.size() - 1; i++)
|
||||
{
|
||||
errorBuffer += QString(process.readAllStandardError()).toStdWString();
|
||||
std::vector<std::wstring> errorLines = utility::split<std::vector<std::wstring>>(errorBuffer, L"\n");
|
||||
for (size_t i = 0; i < errorLines.size() - 1; i++)
|
||||
if (errorLines[i].back() == L'\r')
|
||||
{
|
||||
if (errorLines[i].back() == L'\r')
|
||||
{
|
||||
errorLines[i].pop_back();
|
||||
}
|
||||
LOG_ERROR_BARE(L"Process error: " + errorLines[i]);
|
||||
errorLines[i].pop_back();
|
||||
}
|
||||
errorBuffer = errorLines.back();
|
||||
LOG_ERROR_BARE(L"Process error: " + errorLines[i]);
|
||||
}
|
||||
errorBuffer = errorLines.back();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace utility
|
||||
{
|
||||
std::mutex s_runningProcessesMutex;
|
||||
std::set<QProcess*> s_runningProcesses;
|
||||
}
|
||||
std::mutex s_runningProcessesMutex;
|
||||
std::set<QProcess*> s_runningProcesses;
|
||||
} // namespace utility
|
||||
|
||||
std::pair<int, std::string> utility::executeProcess(const std::string& command, const FilePath& workingDirectory, const int timeout)
|
||||
std::pair<int, std::string> utility::executeProcess(
|
||||
const std::string& command, const FilePath& workingDirectory, const int timeout)
|
||||
{
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
@@ -66,7 +69,8 @@ std::pair<int, std::string> utility::executeProcess(const std::string& command,
|
||||
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
QStringList envlist = env.toStringList();
|
||||
envlist.replaceInStrings(QRegularExpression("^(?i)PATH=(.*)"), "PATH=/opt/local/bin:/usr/local/bin:$HOME/bin:\\1");
|
||||
envlist.replaceInStrings(
|
||||
QRegularExpression("^(?i)PATH=(.*)"), "PATH=/opt/local/bin:/usr/local/bin:$HOME/bin:\\1");
|
||||
process.setEnvironment(envlist);
|
||||
|
||||
{
|
||||
@@ -90,7 +94,8 @@ std::pair<int, std::string> utility::executeProcess(const std::string& command,
|
||||
return std::make_pair(exitCode, utility::trim(processoutput));
|
||||
}
|
||||
|
||||
std::string utility::executeProcessUntilNoOutput(const std::string& command, const FilePath& workingDirectory, const int waitTime)
|
||||
std::string utility::executeProcessUntilNoOutput(
|
||||
const std::string& command, const FilePath& workingDirectory, const int waitTime)
|
||||
{
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
@@ -102,7 +107,8 @@ std::string utility::executeProcessUntilNoOutput(const std::string& command, con
|
||||
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
QStringList envlist = env.toStringList();
|
||||
envlist.replaceInStrings(QRegularExpression("^(?i)PATH=(.*)"), "PATH=/opt/local/bin:/usr/local/bin:$HOME/bin:\\1");
|
||||
envlist.replaceInStrings(
|
||||
QRegularExpression("^(?i)PATH=(.*)"), "PATH=/opt/local/bin:/usr/local/bin:$HOME/bin:\\1");
|
||||
process.setEnvironment(envlist);
|
||||
|
||||
{
|
||||
@@ -117,7 +123,9 @@ std::string utility::executeProcessUntilNoOutput(const std::string& command, con
|
||||
const std::string currentOutput = process.readAll().toStdString();
|
||||
if (currentOutput.empty())
|
||||
{
|
||||
LOG_WARNING("Canceling process because it did not generate any output during the last " + std::to_string(waitTime / 1000) + " seconds.");
|
||||
LOG_WARNING(
|
||||
"Canceling process because it did not generate any output during the last " +
|
||||
std::to_string(waitTime / 1000) + " seconds.");
|
||||
break;
|
||||
}
|
||||
else
|
||||
@@ -144,45 +152,47 @@ int utility::executeProcessAndGetExitCode(
|
||||
const FilePath& workingDirectory,
|
||||
const int timeout,
|
||||
bool logProcessOutput,
|
||||
std::wstring* errorMessage
|
||||
){
|
||||
std::wstring* errorMessage)
|
||||
{
|
||||
bool finished = false;
|
||||
|
||||
QProcess process;
|
||||
|
||||
QObject::connect(&process, &QProcess::errorOccurred, [&finished, errorMessage, commandPath](QProcess::ProcessError error)
|
||||
{
|
||||
finished = true;
|
||||
if (errorMessage != nullptr)
|
||||
{
|
||||
switch (error)
|
||||
QObject::connect(
|
||||
&process,
|
||||
&QProcess::errorOccurred,
|
||||
[&finished, errorMessage, commandPath](QProcess::ProcessError error) {
|
||||
finished = true;
|
||||
if (errorMessage != nullptr)
|
||||
{
|
||||
case QProcess::FailedToStart:
|
||||
*errorMessage = L"File not found or resource error occurred.";
|
||||
break;
|
||||
case QProcess::Crashed:
|
||||
*errorMessage = L"Process crashed.";
|
||||
break;
|
||||
case QProcess::Timedout:
|
||||
*errorMessage = L"Process timed out.";
|
||||
break;
|
||||
case QProcess::ReadError:
|
||||
*errorMessage = L"A read error occurred while executing process.";
|
||||
break;
|
||||
case QProcess::WriteError:
|
||||
*errorMessage = L"A write error occurred while executing process.";
|
||||
break;
|
||||
case QProcess::UnknownError:
|
||||
*errorMessage = L"An unknown error occurred while executing process.";
|
||||
break;
|
||||
}
|
||||
};
|
||||
});
|
||||
switch (error)
|
||||
{
|
||||
case QProcess::FailedToStart:
|
||||
*errorMessage = L"File not found or resource error occurred.";
|
||||
break;
|
||||
case QProcess::Crashed:
|
||||
*errorMessage = L"Process crashed.";
|
||||
break;
|
||||
case QProcess::Timedout:
|
||||
*errorMessage = L"Process timed out.";
|
||||
break;
|
||||
case QProcess::ReadError:
|
||||
*errorMessage = L"A read error occurred while executing process.";
|
||||
break;
|
||||
case QProcess::WriteError:
|
||||
*errorMessage = L"A write error occurred while executing process.";
|
||||
break;
|
||||
case QProcess::UnknownError:
|
||||
*errorMessage = L"An unknown error occurred while executing process.";
|
||||
break;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
QObject::connect(&process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), [&finished](int exitCode, QProcess::ExitStatus exitStatus)
|
||||
{
|
||||
finished = true;
|
||||
});
|
||||
QObject::connect(
|
||||
&process,
|
||||
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
||||
[&finished](int exitCode, QProcess::ExitStatus exitStatus) { finished = true; });
|
||||
|
||||
|
||||
if (!workingDirectory.empty())
|
||||
@@ -191,14 +201,15 @@ int utility::executeProcessAndGetExitCode(
|
||||
}
|
||||
|
||||
QString command = QString::fromStdWString(commandPath);
|
||||
for (const std::wstring& commandArgument : commandArguments)
|
||||
for (const std::wstring& commandArgument: commandArguments)
|
||||
{
|
||||
command += " " + QString::fromStdWString(commandArgument);
|
||||
}
|
||||
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
QStringList envlist = env.toStringList();
|
||||
envlist.replaceInStrings(QRegularExpression("^(?i)PATH=(.*)"), "PATH=/opt/local/bin:/usr/local/bin:$HOME/bin:\\1");
|
||||
envlist.replaceInStrings(
|
||||
QRegularExpression("^(?i)PATH=(.*)"), "PATH=/opt/local/bin:/usr/local/bin:$HOME/bin:\\1");
|
||||
process.setEnvironment(envlist);
|
||||
|
||||
{
|
||||
@@ -246,7 +257,7 @@ int utility::executeProcessAndGetExitCode(
|
||||
void utility::killRunningProcesses()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_runningProcessesMutex);
|
||||
for (QProcess* process : s_runningProcesses)
|
||||
for (QProcess* process: s_runningProcesses)
|
||||
{
|
||||
process->kill();
|
||||
}
|
||||
@@ -284,24 +295,25 @@ std::string utility::getOsTypeString()
|
||||
// WARNING: Don't change these string. The server API relies on them.
|
||||
switch (utility::getOsType())
|
||||
{
|
||||
case OS_WINDOWS:
|
||||
return "windows";
|
||||
case OS_MAC:
|
||||
return "macOS";
|
||||
case OS_LINUX:
|
||||
return "linux";
|
||||
default:
|
||||
break;
|
||||
case OS_WINDOWS:
|
||||
return "windows";
|
||||
case OS_MAC:
|
||||
return "macOS";
|
||||
case OS_LINUX:
|
||||
return "linux";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
ApplicationArchitectureType utility::getApplicationArchitectureType()
|
||||
{
|
||||
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) || defined(WIN64)
|
||||
return APPLICATION_ARCHITECTURE_X86_64;
|
||||
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) || \
|
||||
defined(WIN64)
|
||||
return APPLICATION_ARCHITECTURE_X86_64;
|
||||
#else
|
||||
return APPLICATION_ARCHITECTURE_X86_32;
|
||||
return APPLICATION_ARCHITECTURE_X86_32;
|
||||
#endif
|
||||
return APPLICATION_ARCHITECTURE_UNKNOWN;
|
||||
return APPLICATION_ARCHITECTURE_UNKNOWN;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user