Added lamexp_init_process() function, which can be used to setup a QProcess object.

This commit is contained in:
LoRd_MuldeR 2013-10-29 02:05:43 +01:00
parent 2fa32af174
commit 6a862013eb
9 changed files with 84 additions and 43 deletions

View File

@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 9
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 5
#define VER_LAMEXP_BUILD 1435
#define VER_LAMEXP_BUILD 1437
#define VER_LAMEXP_CONFG 1348
///////////////////////////////////////////////////////////////////////////////

View File

@ -3868,30 +3868,31 @@ void MainWindow::showCustomParamsHelpScreen(const QString &toolName, const QStri
return;
}
QProcess *process = new QProcess();
process->setProcessChannelMode(QProcess::MergedChannels);
process->setReadChannel(QProcess::StandardOutput);
process->start(binary, command.isEmpty() ? QStringList() : QStringList() << command);
QProcess process;
lamexp_init_process(process, QFileInfo(binary).absolutePath());
process.start(binary, command.isEmpty() ? QStringList() : QStringList() << command);
qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
if(process->waitForStarted(15000))
if(process.waitForStarted(15000))
{
qApp->processEvents();
process->waitForFinished(15000);
process.waitForFinished(15000);
}
if(process->state() != QProcess::NotRunning)
if(process.state() != QProcess::NotRunning)
{
process->kill();
process->waitForFinished(-1);
process.kill();
process.waitForFinished(-1);
}
qApp->restoreOverrideCursor();
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);
if(temp.isEmpty())
{
@ -3903,8 +3904,6 @@ void MainWindow::showCustomParamsHelpScreen(const QString &toolName, const QStri
}
}
LAMEXP_DELETE(process);
if(output.count() < 1)
{
qWarning("Empty output, cannot show help screen!");

View File

@ -31,6 +31,7 @@
#include "Dialog_LogView.h"
#include "Model_Settings.h"
#include "WinSevenTaskbar.h"
#include "Tool_Abstract.h"
//Qt includes
#include <QClipboard>
@ -649,9 +650,7 @@ bool UpdateDialog::getFile(const QString &url, const QString &outFile, unsigned
}
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);
process.setWorkingDirectory(output.absolutePath());
lamexp_init_process(process, output.absolutePath());
QStringList args;
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;
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);
process.setWorkingDirectory(QFileInfo(file).absolutePath());
lamexp_init_process(process, QFileInfo(file).absolutePath());
QEventLoop loop;
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
@ -884,6 +881,8 @@ void UpdateDialog::applyUpdate(void)
QStringList args;
QEventLoop loop;
lamexp_init_process(process, QFileInfo(m_binaryUpdater).absolutePath());
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
@ -903,7 +902,7 @@ void UpdateDialog::applyUpdate(void)
if(updateStarted)
{
m_updaterProcess = lamexp_process_id(&process);
loop.exec();
loop.exec(QEventLoop::ExcludeUserInputEvents);
}
m_updaterProcess = NULL;
QApplication::restoreOverrideCursor();

View File

@ -2846,7 +2846,14 @@ bool lamexp_change_process_priority(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;
}
/*
* 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
*/

View File

@ -218,8 +218,10 @@ unsigned __int64 lamexp_current_file_time(void);
void lamexp_natural_string_sort(QStringList &list, const bool bIgnoreCase);
bool lamexp_open_media_file(const QString &mediaFilePath);
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);
//Debug-only functions
unsigned long lamexp_dbg_private_bytes(void);

View File

@ -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);
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);
process.setWorkingDirectory(m_outputDir);
lamexp_init_process(process, m_outputDir);
process.start(m_soxBin, args);
if(!process.waitForStarted())

View File

@ -180,8 +180,8 @@ const AudioFileModel AnalyzeTask::analyzeFile(const QString &filePath, int *type
params << QDir::toNativeSeparators(filePath);
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);
lamexp_init_process(process, QFileInfo(m_mediaInfoBin).absolutePath());
process.start(m_mediaInfoBin, params);
if(!process.waitForStarted())
@ -513,8 +513,8 @@ void AnalyzeTask::retrieveCover(AudioFileModel &audioFile, cover_t coverType, co
bool AnalyzeTask::analyzeAvisynthFile(const QString &filePath, AudioFileModel &info)
{
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);
lamexp_init_process(process, QFileInfo(m_avs2wavBin).absolutePath());
process.start(m_avs2wavBin, QStringList() << QDir::toNativeSeparators(filePath) << "?");
if(!process.waitForStarted())

View File

@ -24,6 +24,7 @@
#include "LockedFile.h"
#include "Tools.h"
#include "Tool_Abstract.h"
#include <QFileInfo>
#include <QCoreApplication>
@ -463,8 +464,8 @@ void InitializationThread::initNeroAac(void)
}
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);
lamexp_init_process(process, neroFileInfo[0].absolutePath());
process.start(neroFileInfo[0].canonicalFilePath(), QStringList() << "-help");
if(!process.waitForStarted())
@ -569,8 +570,8 @@ void InitializationThread::initFhgAac(void)
}
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);
lamexp_init_process(process, fhgFileInfo[0].absolutePath());
process.start(fhgFileInfo[0].canonicalFilePath(), QStringList() << "--version");
if(!process.waitForStarted())
@ -667,8 +668,8 @@ void InitializationThread::initQAac(void)
}
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);
lamexp_init_process(process, qaacFileInfo[0].absolutePath());
process.start(qaacFileInfo[0].canonicalFilePath(), QStringList() << "--check");
if(!process.waitForStarted())

View File

@ -96,15 +96,8 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
}
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);
if(process.waitForStarted())