Skip to content

Commit

Permalink
Merge pull request #1147 from dsm/fix_tool_path
Browse files Browse the repository at this point in the history
fix launchTool method.
  • Loading branch information
ra3xdh authored Dec 18, 2024
2 parents c04edc6 + fe6c33a commit 8dcde7e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
3 changes: 2 additions & 1 deletion qucs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,8 @@ int main(int argc, char *argv[])
QucsDir.cdUp();
#endif

QucsSettings.BinDir = QucsApplicationPath.contains("bin") ? QucsApplicationPath : QucsDir.absoluteFilePath("bin");
QucsSettings.BinDir = QucsApplicationPath.contains("bin") ?
(QucsApplicationPath + QDir::separator()) : QucsDir.absoluteFilePath("bin/");
QucsSettings.LangDir = QucsDir.canonicalPath() + "/share/" QUCS_NAME "/lang/";

QucsSettings.LibDir = QucsDir.canonicalPath() + "/share/" QUCS_NAME "/library/";
Expand Down
44 changes: 26 additions & 18 deletions qucs/qucs_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,32 +898,40 @@ void QucsApp::slotCallSPAR_Viewer()
void QucsApp::launchTool(const QString& prog, const QString& progDesc, const QStringList &args,
bool qucs_tool)
{
QProcess *tool = new QProcess();
QString tooldir = qucs_tool ? QucsSettings.QucsatorDir : QucsSettings.BinDir;

QString tooldir;
if (qucs_tool) tooldir = QucsSettings.QucsatorDir;
else tooldir = QucsSettings.BinDir;
// Create command path based on the platform
QString cmd;
#if defined(_WIN32) || defined(__MINGW32__)
QString cmd = QDir::toNativeSeparators("\""+tooldir + prog + ".exe\"");
cmd = QDir(tooldir).absoluteFilePath(prog + ".exe");
#elif __APPLE__
QString cmd = QDir::toNativeSeparators(tooldir + prog + ".app/Contents/MacOS/" + prog);
cmd = QDir(tooldir).absoluteFilePath(prog + ".app/Contents/MacOS/" + prog);
#else
QString cmd = QDir::toNativeSeparators(tooldir + prog);
cmd = QDir(tooldir).absoluteFilePath(prog);
#endif

tool->setWorkingDirectory(tooldir);
qDebug() << "Command :" << cmd;
tool->start(cmd,args);
// Validate if the file exists before attempting to execute
if (!QFileInfo(cmd).exists()) {
QMessageBox::critical(this, tr("Error"),
tr("Executable %1 not found! \n\n(%2)").arg(progDesc, cmd));
return;
}

if(!tool->waitForStarted(1000) ) {
QMessageBox::critical(this, tr("Error"),
tr("Cannot start %1 program! \n\n(%2)").arg(progDesc, cmd));
delete tool;
return;
}
QProcess *tool = new QProcess();

qDebug() << "Command :" << cmd;
tool->setWorkingDirectory(tooldir);
tool->start(cmd,args);

// to kill the application first before qucs finishes exiting
connect(this, SIGNAL(signalKillEmAll()), tool, SLOT(kill()));
if(!tool->waitForStarted(1000) ) {
QMessageBox::critical(this, tr("Error"),
tr("Cannot start %1 program! \n\n(%2)").arg(progDesc, cmd));
delete tool;
return;
}

// to kill the application first before qucs finishes exiting
connect(this, SIGNAL(signalKillEmAll()), tool, SLOT(kill()));
}


Expand Down

0 comments on commit 8dcde7e

Please sign in to comment.