From ee7aeda91ee834986e94748fb16d54e4e5507128 Mon Sep 17 00:00:00 2001 From: wh201906 Date: Tue, 6 Jun 2023 20:00:04 +0800 Subject: [PATCH] Fix a bug in finding client In commit e6be456cfa, I uses QFileInfo::exists() to check if the client exists. However, it doesn't work for client with extensions in environment variable %PATHEXT% when specifying the path without extension --- src/ui/mainwindow.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index f80cf5b..2100451 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -170,8 +170,29 @@ void MainWindow::on_PM3_connectButton_clicked() QString startArgs = ui->Set_Client_startArgsEdit->text(); QString clientPath = ui->PM3_pathBox->currentText(); QFileInfo clientFile(clientPath); + bool clientExist = false; - if(!clientFile.exists()) + QStringList extList = {""}; +#ifdef Q_OS_WIN + if(clientFile.suffix().isEmpty()) + { + QString pathExt = QProcessEnvironment::systemEnvironment().value("pathext"); + extList += pathExt.split(";", Qt::SkipEmptyParts); + if(extList.size() == 1) + extList += ".exe"; + } +#endif + for(const QString& ext : extList) + { + QFileInfo executable(clientFile.filePath() + ext); + if(executable.isFile()) + { + clientExist = true; + break; + } + } + + if(!clientExist) { QMessageBox::information(this, tr("Info"), tr("The client path is invalid"), QMessageBox::Ok); return;