From e6be456cfa28d8c8213186a9430be72df338604c Mon Sep 17 00:00:00 2001 From: wh201906 Date: Sun, 4 Jun 2023 00:53:15 +0800 Subject: [PATCH] Add for preload script path --- src/common/pm3process.cpp | 1 + src/ui/mainwindow.cpp | 28 ++++++++++++++++++++-------- src/ui/mainwindow.ui | 3 ++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/common/pm3process.cpp b/src/common/pm3process.cpp index 2b46748..d73fac3 100644 --- a/src/common/pm3process.cpp +++ b/src/common/pm3process.cpp @@ -63,6 +63,7 @@ void PM3Process::connectPM3(const QString& path, const QStringList args) } else { + qDebug() << "unexpected output:" << (result.isEmpty() ? "(empty)" : result); emit HWConnectFailed(); kill(); } diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 1b08764..baab385 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -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("")) // has , no port @@ -172,25 +180,29 @@ void MainWindow::on_PM3_connectButton_clicked() port = ""; // a symbol QStringList args = startArgs.replace("", 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("")) + envScriptPath.replace("", 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 "">>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 '. "">>/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() diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui index 0b0122d..b001624 100644 --- a/src/ui/mainwindow.ui +++ b/src/ui/mainwindow.ui @@ -2714,7 +2714,8 @@ or the communication between a tag and a reader. - 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. + 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 "<client dir>" will be replaced by the directory of the "Client Path" true