Added lamexp_init_process() function, which can be used to setup a QProcess object.
This commit is contained in:
parent
2fa32af174
commit
6a862013eb
@ -35,7 +35,7 @@
|
|||||||
#define VER_LAMEXP_MINOR_LO 9
|
#define VER_LAMEXP_MINOR_LO 9
|
||||||
#define VER_LAMEXP_TYPE Alpha
|
#define VER_LAMEXP_TYPE Alpha
|
||||||
#define VER_LAMEXP_PATCH 5
|
#define VER_LAMEXP_PATCH 5
|
||||||
#define VER_LAMEXP_BUILD 1435
|
#define VER_LAMEXP_BUILD 1437
|
||||||
#define VER_LAMEXP_CONFG 1348
|
#define VER_LAMEXP_CONFG 1348
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -3868,30 +3868,31 @@ void MainWindow::showCustomParamsHelpScreen(const QString &toolName, const QStri
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QProcess *process = new QProcess();
|
QProcess process;
|
||||||
process->setProcessChannelMode(QProcess::MergedChannels);
|
lamexp_init_process(process, QFileInfo(binary).absolutePath());
|
||||||
process->setReadChannel(QProcess::StandardOutput);
|
|
||||||
process->start(binary, command.isEmpty() ? QStringList() : QStringList() << command);
|
process.start(binary, command.isEmpty() ? QStringList() : QStringList() << command);
|
||||||
|
|
||||||
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
|
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||||
|
|
||||||
if(process->waitForStarted(15000))
|
if(process.waitForStarted(15000))
|
||||||
{
|
{
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
process->waitForFinished(15000);
|
process.waitForFinished(15000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(process->state() != QProcess::NotRunning)
|
if(process.state() != QProcess::NotRunning)
|
||||||
{
|
{
|
||||||
process->kill();
|
process.kill();
|
||||||
process->waitForFinished(-1);
|
process.waitForFinished(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
qApp->restoreOverrideCursor();
|
qApp->restoreOverrideCursor();
|
||||||
QStringList output; bool spaceFlag = true;
|
QStringList output; bool spaceFlag = true;
|
||||||
|
|
||||||
while(process->canReadLine())
|
while(process.canReadLine())
|
||||||
{
|
{
|
||||||
QString temp = QString::fromUtf8(process->readLine());
|
QString temp = QString::fromUtf8(process.readLine());
|
||||||
TRIM_STRING_RIGHT(temp);
|
TRIM_STRING_RIGHT(temp);
|
||||||
if(temp.isEmpty())
|
if(temp.isEmpty())
|
||||||
{
|
{
|
||||||
@ -3903,8 +3904,6 @@ void MainWindow::showCustomParamsHelpScreen(const QString &toolName, const QStri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LAMEXP_DELETE(process);
|
|
||||||
|
|
||||||
if(output.count() < 1)
|
if(output.count() < 1)
|
||||||
{
|
{
|
||||||
qWarning("Empty output, cannot show help screen!");
|
qWarning("Empty output, cannot show help screen!");
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "Dialog_LogView.h"
|
#include "Dialog_LogView.h"
|
||||||
#include "Model_Settings.h"
|
#include "Model_Settings.h"
|
||||||
#include "WinSevenTaskbar.h"
|
#include "WinSevenTaskbar.h"
|
||||||
|
#include "Tool_Abstract.h"
|
||||||
|
|
||||||
//Qt includes
|
//Qt includes
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
@ -649,9 +650,7 @@ bool UpdateDialog::getFile(const QString &url, const QString &outFile, unsigned
|
|||||||
}
|
}
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
lamexp_init_process(process, output.absolutePath());
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.setWorkingDirectory(output.absolutePath());
|
|
||||||
|
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args << "--no-cache" << "--no-dns-cache" << QString().sprintf("--max-redirect=%u", maxRedir);
|
args << "--no-cache" << "--no-dns-cache" << QString().sprintf("--max-redirect=%u", maxRedir);
|
||||||
@ -724,9 +723,7 @@ bool UpdateDialog::checkSignature(const QString &file, const QString &signature)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
lamexp_init_process(process, QFileInfo(file).absolutePath());
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.setWorkingDirectory(QFileInfo(file).absolutePath());
|
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
|
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
|
||||||
@ -884,6 +881,8 @@ void UpdateDialog::applyUpdate(void)
|
|||||||
QStringList args;
|
QStringList args;
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
|
|
||||||
|
lamexp_init_process(process, QFileInfo(m_binaryUpdater).absolutePath());
|
||||||
|
|
||||||
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
|
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
|
||||||
connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
|
connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
|
||||||
|
|
||||||
@ -903,7 +902,7 @@ void UpdateDialog::applyUpdate(void)
|
|||||||
if(updateStarted)
|
if(updateStarted)
|
||||||
{
|
{
|
||||||
m_updaterProcess = lamexp_process_id(&process);
|
m_updaterProcess = lamexp_process_id(&process);
|
||||||
loop.exec();
|
loop.exec(QEventLoop::ExcludeUserInputEvents);
|
||||||
}
|
}
|
||||||
m_updaterProcess = NULL;
|
m_updaterProcess = NULL;
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
|
@ -2846,7 +2846,14 @@ bool lamexp_change_process_priority(const int priority)
|
|||||||
*/
|
*/
|
||||||
bool lamexp_change_process_priority(const QProcess *proc, const int priority)
|
bool lamexp_change_process_priority(const QProcess *proc, const int priority)
|
||||||
{
|
{
|
||||||
return lamexp_change_process_priority(proc->pid()->hProcess, priority);
|
if(Q_PID qPid = proc->pid())
|
||||||
|
{
|
||||||
|
return lamexp_change_process_priority(qPid->hProcess, priority);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3045,6 +3052,47 @@ bool lamexp_open_media_file(const QString &mediaFilePath)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Setup QPorcess object
|
||||||
|
*/
|
||||||
|
void lamexp_init_process(QProcess &process, const QString &wokringDir)
|
||||||
|
{
|
||||||
|
//Environment variable names
|
||||||
|
static const char *const s_envvar_names[] =
|
||||||
|
{
|
||||||
|
"WGETRC", "SYSTEM_WGETRC", "HTTP_PROXY", "FTP_PROXY", "NO_PROXY", "GNUPGHOME", "LC_ALL", "LC_COLLATE", "LC_CTYPE", "LC_MESSAGES", "LC_MONETARY", "LC_NUMERIC", "LC_TIME", "LANG", NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
const QString tempDir = QDir::toNativeSeparators(lamexp_temp_folder2());
|
||||||
|
|
||||||
|
QProcessEnvironment env = process.processEnvironment();
|
||||||
|
if(env.isEmpty()) env = QProcessEnvironment::systemEnvironment();
|
||||||
|
|
||||||
|
//Setup TEMP directory
|
||||||
|
env.insert("TEMP", tempDir);
|
||||||
|
env.insert("TMP", tempDir);
|
||||||
|
env.insert("TMPDIR", tempDir);
|
||||||
|
env.insert("HOME", tempDir);
|
||||||
|
env.insert("USERPROFILE", tempDir);
|
||||||
|
env.insert("HOMEPATH", tempDir);
|
||||||
|
|
||||||
|
//Setup PATH variable
|
||||||
|
const QString path = env.value("PATH", QString());
|
||||||
|
env.insert("PATH", path.isEmpty() ? tempDir : QString("%1;%2").arg(tempDir, path));
|
||||||
|
|
||||||
|
//Clean a number of enviroment variables that might affect our tools
|
||||||
|
for(size_t i = 0; s_envvar_names[i]; i++)
|
||||||
|
{
|
||||||
|
env.remove(QString::fromLatin1(s_envvar_names[i]));
|
||||||
|
env.remove(QString::fromLatin1(s_envvar_names[i]).toLower());
|
||||||
|
}
|
||||||
|
|
||||||
|
process.setWorkingDirectory(wokringDir);
|
||||||
|
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||||
|
process.setReadChannel(QProcess::StandardOutput);
|
||||||
|
process.setProcessEnvironment(env);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Entry point checks
|
* Entry point checks
|
||||||
*/
|
*/
|
||||||
|
@ -218,8 +218,10 @@ unsigned __int64 lamexp_current_file_time(void);
|
|||||||
void lamexp_natural_string_sort(QStringList &list, const bool bIgnoreCase);
|
void lamexp_natural_string_sort(QStringList &list, const bool bIgnoreCase);
|
||||||
bool lamexp_open_media_file(const QString &mediaFilePath);
|
bool lamexp_open_media_file(const QString &mediaFilePath);
|
||||||
QString lamexp_path_to_short(const QString &longPath);
|
QString lamexp_path_to_short(const QString &longPath);
|
||||||
|
void lamexp_init_process(QProcess &process, const QString &wokringDir);
|
||||||
void lamexp_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage = NULL);
|
void lamexp_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage = NULL);
|
||||||
|
|
||||||
|
|
||||||
//Debug-only functions
|
//Debug-only functions
|
||||||
unsigned long lamexp_dbg_private_bytes(void);
|
unsigned long lamexp_dbg_private_bytes(void);
|
||||||
|
|
||||||
|
@ -297,9 +297,8 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
|
|||||||
QRegExp rxDuration("Duration\\s*:\\s*(\\d\\d):(\\d\\d):(\\d\\d).(\\d\\d)", Qt::CaseInsensitive);
|
QRegExp rxDuration("Duration\\s*:\\s*(\\d\\d):(\\d\\d):(\\d\\d).(\\d\\d)", Qt::CaseInsensitive);
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
lamexp_init_process(process, m_outputDir);
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.setWorkingDirectory(m_outputDir);
|
|
||||||
process.start(m_soxBin, args);
|
process.start(m_soxBin, args);
|
||||||
|
|
||||||
if(!process.waitForStarted())
|
if(!process.waitForStarted())
|
||||||
|
@ -180,8 +180,8 @@ const AudioFileModel AnalyzeTask::analyzeFile(const QString &filePath, int *type
|
|||||||
params << QDir::toNativeSeparators(filePath);
|
params << QDir::toNativeSeparators(filePath);
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
lamexp_init_process(process, QFileInfo(m_mediaInfoBin).absolutePath());
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.start(m_mediaInfoBin, params);
|
process.start(m_mediaInfoBin, params);
|
||||||
|
|
||||||
if(!process.waitForStarted())
|
if(!process.waitForStarted())
|
||||||
@ -513,8 +513,8 @@ void AnalyzeTask::retrieveCover(AudioFileModel &audioFile, cover_t coverType, co
|
|||||||
bool AnalyzeTask::analyzeAvisynthFile(const QString &filePath, AudioFileModel &info)
|
bool AnalyzeTask::analyzeAvisynthFile(const QString &filePath, AudioFileModel &info)
|
||||||
{
|
{
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
lamexp_init_process(process, QFileInfo(m_avs2wavBin).absolutePath());
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.start(m_avs2wavBin, QStringList() << QDir::toNativeSeparators(filePath) << "?");
|
process.start(m_avs2wavBin, QStringList() << QDir::toNativeSeparators(filePath) << "?");
|
||||||
|
|
||||||
if(!process.waitForStarted())
|
if(!process.waitForStarted())
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "LockedFile.h"
|
#include "LockedFile.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
|
#include "Tool_Abstract.h"
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
@ -463,8 +464,8 @@ void InitializationThread::initNeroAac(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
lamexp_init_process(process, neroFileInfo[0].absolutePath());
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.start(neroFileInfo[0].canonicalFilePath(), QStringList() << "-help");
|
process.start(neroFileInfo[0].canonicalFilePath(), QStringList() << "-help");
|
||||||
|
|
||||||
if(!process.waitForStarted())
|
if(!process.waitForStarted())
|
||||||
@ -569,8 +570,8 @@ void InitializationThread::initFhgAac(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
lamexp_init_process(process, fhgFileInfo[0].absolutePath());
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.start(fhgFileInfo[0].canonicalFilePath(), QStringList() << "--version");
|
process.start(fhgFileInfo[0].canonicalFilePath(), QStringList() << "--version");
|
||||||
|
|
||||||
if(!process.waitForStarted())
|
if(!process.waitForStarted())
|
||||||
@ -667,8 +668,8 @@ void InitializationThread::initQAac(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
lamexp_init_process(process, qaacFileInfo[0].absolutePath());
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.start(qaacFileInfo[0].canonicalFilePath(), QStringList() << "--check");
|
process.start(qaacFileInfo[0].canonicalFilePath(), QStringList() << "--check");
|
||||||
|
|
||||||
if(!process.waitForStarted())
|
if(!process.waitForStarted())
|
||||||
|
@ -96,15 +96,8 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
emit messageLogged(commandline2string(program, args) + "\n");
|
emit messageLogged(commandline2string(program, args) + "\n");
|
||||||
|
lamexp_init_process(process, QFileInfo(program).absolutePath());
|
||||||
|
|
||||||
QProcessEnvironment env = process.processEnvironment();
|
|
||||||
if(env.isEmpty()) env = QProcessEnvironment::systemEnvironment();
|
|
||||||
env.insert("TEMP", QDir::toNativeSeparators(lamexp_temp_folder2()));
|
|
||||||
env.insert("TMP", QDir::toNativeSeparators(lamexp_temp_folder2()));
|
|
||||||
process.setProcessEnvironment(env);
|
|
||||||
|
|
||||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.start(program, args);
|
process.start(program, args);
|
||||||
|
|
||||||
if(process.waitForStarted())
|
if(process.waitForStarted())
|
||||||
|
Loading…
Reference in New Issue
Block a user