1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2023 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "thread_startup.h"
25 #include <MUtils/Global.h>
29 #include <QElapsedTimer>
32 //-------------------------------------
34 //-------------------------------------
36 StarupThread::StarupThread(void)
40 StarupThread::~StarupThread(void)
44 //-------------------------------------
46 //-------------------------------------
48 QStringList
StarupThread::runProcess(const QString
&exePath
, const QStringList
&arguments
, const QStringList
*const extraPaths
)
53 const QString fileName
= QFileInfo(exePath
).fileName().toUpper();
55 //Setup process object
56 MUtils::init_process(process
, QDir::tempPath(), true, extraPaths
);
58 //Try to start process
59 process
.start(exePath
, arguments
);
60 if (!process
.waitForStarted())
62 qWarning("Failed to launch %s -> %s", MUTILS_UTF8(fileName
), MUTILS_UTF8(process
.errorString()));
70 //Wait until process has finished
71 QStringList processOutput
;
72 while (process
.state() != QProcess::NotRunning
)
74 process
.waitForReadyRead(1250);
75 while (process
.canReadLine())
77 const QString line
= QString::fromUtf8(process
.readLine()).simplified();
80 processOutput
<< line
;
83 if ((process
.state() != QProcess::NotRunning
) && timer
.hasExpired(15000))
85 process
.waitForFinished(125);
86 if (process
.state() != QProcess::NotRunning
)
88 qWarning("%s process encountered a deadlock -> aborting now!", MUTILS_UTF8(fileName
));
94 QThread::yieldCurrentThread(); /*yield*/
98 //Make sure process has terminated!
99 process
.waitForFinished(1250);
100 if (process
.state() != QProcess::NotRunning
)
102 qWarning("%s process still running, going to kill it!", MUTILS_UTF8(fileName
));
104 process
.waitForFinished(-1);
108 while (process
.bytesAvailable() > 0)
110 const QString line
= QString::fromUtf8(process
.readLine()).simplified();
113 processOutput
<< line
;
118 if (process
.exitCode() != 0)
120 qWarning("%s failed with code 0x%08X -> discarding all output!", MUTILS_UTF8(fileName
), process
.exitCode());
121 return QStringList();
124 return processOutput
;