Skip to content

Commit 01a0075

Browse files
committed
make process not blocking
onProcessFinished callback takes care of resetting env and command args
1 parent 38f76b1 commit 01a0075

File tree

6 files changed

+69
-26
lines changed

6 files changed

+69
-26
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ pillow
33
cryptography
44
pycurl
55
tqdm
6-
git+https://github.com/ueber-devel/ueberzug.git

src/File.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* TombRaiderLinuxLauncher
2+
* Martin Bångens Copyright (C) 2025
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*/

src/File.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* TombRaiderLinuxLauncher
2+
* Martin Bångens Copyright (C) 2025
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*/
13+
#ifndef SRC_FILE_HPP_
14+
#define SRC_FILE_HPP_
15+
16+
#include <QString>
17+
#include <QFileInfo>
18+
#include <QFile>
19+
#include <QDir>
20+
21+
class File {
22+
};
23+
24+
#endif // SRC_FILE_HPP_

src/FileManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <QByteArray>
2121
#include <QDataStream>
2222
#include "../src/GameFileTree.hpp"
23-
#include "../miniz/miniz.h"
23+
#include "../miniz/miniz.h" // IWYU pragma: keep
2424
#include "../miniz/miniz_zip.h"
2525
#include "../src/gameFileTreeData.hpp"
2626
#include "../src/binary.hpp"

src/Runner.cpp

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
Runner::Runner() : m_env(QProcessEnvironment::systemEnvironment()) {
2020
m_status = 0;
2121
m_setupFlag = false;
22+
23+
// Merge stderr into stdout
24+
m_process.setProcessChannelMode(QProcess::MergedChannels);
25+
26+
// Connect single output handler
27+
QObject::connect(&m_process, &QProcess::readyReadStandardOutput,
28+
this, &Runner::handleOutput);
29+
30+
31+
// Connect to clean up and singnal View function
32+
QObject::connect(
33+
&m_process,
34+
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
35+
this,
36+
&Runner::onProcessFinished);
2237
}
2338

2439
Runner::Runner(const QString& cmd)
@@ -47,47 +62,41 @@ void Runner::setWorkingDirectory(const QString& cwd) {
4762
m_process.setWorkingDirectory(cwd);
4863
}
4964

50-
5165
void Runner::toggleSetupFlag() {
5266
m_setupFlag = !m_setupFlag;
5367
}
5468

5569
void Runner::run() {
56-
int status = 1;
57-
5870
m_process.setProcessEnvironment(m_env);
5971
m_process.setProgram(m_command);
72+
6073
if (m_setupFlag) {
6174
m_arguments << "-setup";
6275
}
6376
m_process.setArguments(m_arguments);
6477

65-
// Merge stderr into stdout
66-
m_process.setProcessChannelMode(QProcess::MergedChannels);
67-
68-
// Connect single output handler
69-
QObject::connect(&m_process, &QProcess::readyReadStandardOutput,
70-
this, &Runner::handleOutput);
71-
7278
m_process.start();
73-
bool hasStarted = m_process.waitForStarted();
74-
75-
if (hasStarted) {
76-
bool finished = false;
77-
finished = m_process.waitForFinished();
78-
if (finished) {
79-
status = 0;
80-
}
79+
if (!m_process.waitForStarted()) {
80+
qWarning() << "Process failed to start!";
81+
qWarning() << "Error: " << m_process.errorString();
82+
m_status = 1;
8183
}
84+
}
8285

83-
if (status != 0) {
84-
qWarning() << "Failed to start or finish process!";
86+
void Runner::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) {
87+
if (exitStatus == QProcess::NormalExit) {
88+
qDebug() << "Process exited normally with code:" << exitCode;
89+
m_status = exitCode;
90+
} else {
91+
qWarning() << "Process crashed or was killed!";
92+
m_status = 1;
8593
}
8694

8795
m_env.clear();
96+
m_env.insert(QProcessEnvironment::systemEnvironment());
97+
8898
m_arguments.clear();
8999
m_setupFlag = false;
90-
m_status = status;
91100
}
92101

93102
void Runner::handleOutput() {

src/Runner.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ class Runner : public QObject {
3535
void clearArguments();
3636
void toggleSetupFlag();
3737

38-
signals:
39-
void started();
40-
void stopped();
38+
private slots:
39+
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
4140

4241
private:
4342
void handleOutput();

0 commit comments

Comments
 (0)