Add <client dir> for preload script path

master
wh201906 1 year ago
parent aee621c196
commit e6be456cfa
No known key found for this signature in database

@ -63,6 +63,7 @@ void PM3Process::connectPM3(const QString& path, const QStringList args)
}
else
{
qDebug() << "unexpected output:" << (result.isEmpty() ? "(empty)" : result);
emit HWConnectFailed();
kill();
}

@ -160,6 +160,14 @@ void MainWindow::on_PM3_connectButton_clicked()
QString port = ui->PM3_portBox->currentData().toString();
QString startArgs = ui->Set_Client_startArgsEdit->text();
QString clientPath = ui->PM3_pathEdit->text();
QFileInfo clientFile(clientPath);
if(!clientFile.exists())
{
QMessageBox::information(this, tr("Info"), tr("The client path is invalid"), QMessageBox::Ok);
return;
}
// on RRG repo, if no port is specified, the client will search the available port
if(port == "" && startArgs.contains("<port>")) // has <port>, no port
@ -172,25 +180,29 @@ void MainWindow::on_PM3_connectButton_clicked()
port = ""; // a symbol
QStringList args = startArgs.replace("<port>", port).split(' ');
saveClientPath(ui->PM3_pathEdit->text());
saveClientPath(clientPath);
QProcess envSetProcess;
QFileInfo envScriptPath(ui->Set_Client_envScriptEdit->text());
if(envScriptPath.exists())
QString envScriptPath = ui->Set_Client_envScriptEdit->text();
if(envScriptPath.contains("<client dir>"))
envScriptPath.replace("<client dir>", clientFile.absoluteDir().absolutePath());
QFileInfo envScript(envScriptPath);
if(envScript.exists())
{
qDebug() << envScriptPath.absoluteFilePath();
qDebug() << envScript.absoluteFilePath();
// use the shell session to keep the environment then read it
#ifdef Q_OS_WIN
// cmd /c "<path>">>nul && set
envSetProcess.start("cmd", {}, QProcess::Unbuffered | QProcess::ReadWrite | QProcess::Text);
envSetProcess.write(QString("\"" + envScriptPath.absoluteFilePath() + "\">>nul\n").toLatin1());
envSetProcess.write(QString("\"" + envScript.absoluteFilePath() + "\">>nul\n").toLatin1());
envSetProcess.waitForReadyRead(10000);
envSetProcess.readAll();
envSetProcess.write("set\n");
#else
// need implementation(or test if space works)
// sh -c '. "<path>">>/dev/null && env'
envSetProcess.start("sh -c \' . \"" + envScriptPath.absoluteFilePath() + "\">>/dev/null && env");
envSetProcess.start("sh -c \' . \"" + envScript.absoluteFilePath() + "\">>/dev/null && env");
#endif
envSetProcess.waitForReadyRead(10000);
QString envSetResult = QString(envSetProcess.readAll());
@ -219,7 +231,7 @@ void MainWindow::on_PM3_connectButton_clicked()
emit setWorkingDir(clientWorkingDir->absolutePath());
loadConfig();
emit connectPM3(ui->PM3_pathEdit->text(), args);
emit connectPM3(clientPath, args);
if(port != "" && !keepClientActive)
emit setSerialListener(port, true);
else if(!keepClientActive)
@ -232,7 +244,7 @@ void MainWindow::onPM3ErrorOccurred(QProcess::ProcessError error)
{
qDebug() << "PM3 Error:" << error << pm3->errorString();
if(error == QProcess::FailedToStart)
QMessageBox::information(this, tr("Info"), tr("Failed to start the client"));
QMessageBox::information(this, tr("Info"), tr("Failed to start the client") + "\n" + pm3->errorString());
}
void MainWindow::onPM3HWConnectFailed()

@ -2714,7 +2714,8 @@ or the communication between a tag and a reader.</string>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>If the client requires some enviroment variables, you can make a script file(*.bat on Windows or *.sh on Linux) to configure them, then put the path of the script there.</string>
<string>If the client requires some enviroment variables, you can make a script file(*.bat on Windows or *.sh on Linux) to configure them, then put the path of the script there.
The &quot;&lt;client dir&gt;&quot; will be replaced by the directory of the &quot;Client Path&quot;</string>
</property>
<property name="wordWrap">
<bool>true</bool>

Loading…
Cancel
Save