|
19 | 19 | */ |
20 | 20 |
|
21 | 21 | #include <profileclimanager.h> |
| 22 | +#include <QStandardPaths> |
22 | 23 |
|
23 | 24 | Q_LOGGING_CATEGORY(CAT_PROFILECLIMANAGER, "ProfileCliManager") |
24 | 25 |
|
@@ -60,24 +61,40 @@ QString ProfileCliManager::getCliPath() const { return m_cliPath; } |
60 | 61 | // CLI Detection (based on iio-oscilloscope profile_gen_cli_get_cmd) |
61 | 62 | bool ProfileCliManager::detectCli() |
62 | 63 | { |
63 | | - // Search for CLI tool in common locations |
64 | | - QStringList searchPaths = {"/usr/bin/", "/usr/local/bin/", "/opt/analog/bin/", |
65 | | - QCoreApplication::applicationDirPath() + "/", QDir::homePath() + "/.local/bin/"}; |
| 64 | + QStringList searchPaths; |
| 65 | +// Search for CLI tool in common locations |
| 66 | +#ifdef Q_OS_WIN |
| 67 | + // Windows-specific paths |
| 68 | + searchPaths.append("C:/Program Files/Analog Devices/bin/"); |
| 69 | + searchPaths.append("C:/Program Files (x86)/Analog Devices/bin/"); |
| 70 | + searchPaths.append(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/"); |
| 71 | + searchPaths.append(QCoreApplication::applicationDirPath() + "/"); |
| 72 | +#else |
| 73 | + // Unix-like systems (Linux, macOS) |
| 74 | + searchPaths.append("/usr/bin/"); |
| 75 | + searchPaths.append("/usr/local/bin/"); |
| 76 | + searchPaths.append("/opt/analog/bin/"); |
| 77 | + searchPaths.append(QCoreApplication::applicationDirPath() + "/"); |
| 78 | + searchPaths.append(QDir::homePath() + "/.local/bin/"); |
| 79 | +#endif |
66 | 80 |
|
67 | 81 | for(const QString &path : searchPaths) { |
68 | 82 | QString fullPath = path + CLI_NAME; |
| 83 | +#ifdef Q_OS_WIN |
| 84 | + if(!fullPath.endsWith(".exe")) { |
| 85 | + fullPath += ".exe"; |
| 86 | + } |
| 87 | +#endif |
69 | 88 | if(QFile::exists(fullPath) && QFileInfo(fullPath).isExecutable()) { |
70 | | - m_cliPath = fullPath; |
| 89 | + m_cliPath = QDir::toNativeSeparators(fullPath); |
71 | 90 | return validateCliVersion(); |
72 | 91 | } |
73 | 92 | } |
74 | 93 |
|
75 | | - // Also check PATH environment variable (like iio-oscilloscope) |
76 | | - QProcess process; |
77 | | - process.start("which", QStringList() << CLI_NAME); |
78 | | - process.waitForFinished(3000); |
79 | | - if(process.exitCode() == 0) { |
80 | | - m_cliPath = process.readAllStandardOutput().trimmed(); |
| 94 | + // Also check PATH environment variable |
| 95 | + QString pathResult = QStandardPaths::findExecutable(CLI_NAME); |
| 96 | + if(!pathResult.isEmpty()) { |
| 97 | + m_cliPath = QDir::toNativeSeparators(pathResult); |
81 | 98 | return validateCliVersion(); |
82 | 99 | } |
83 | 100 |
|
@@ -347,10 +364,24 @@ bool ProfileCliManager::writeConfigToTempFile(const QString &filename, const Rad |
347 | 364 | // CLI Execution |
348 | 365 | bool ProfileCliManager::executeCli(const QStringList &arguments, QString &output, QString &errorOutput) |
349 | 366 | { |
| 367 | + QString workingDir = QFileInfo(m_cliPath).absolutePath(); |
| 368 | + |
350 | 369 | QProcess process; |
351 | | - process.start(m_cliPath, arguments); |
| 370 | + process.setProgram(m_cliPath); |
| 371 | + process.setArguments(arguments); |
| 372 | + process.setWorkingDirectory(workingDir); |
| 373 | + process.start(); |
| 374 | + |
| 375 | + if(!process.waitForStarted(5000)) { |
| 376 | + errorOutput = QString("Failed to start CLI: %1").arg(process.errorString()); |
| 377 | + return false; |
| 378 | + } |
352 | 379 |
|
353 | 380 | if(!process.waitForFinished(CLI_TIMEOUT_MS)) { |
| 381 | + process.kill(); |
| 382 | + if(!process.waitForFinished(3000)) { // Give it time to cleanup |
| 383 | + process.terminate(); // Force terminate if kill didn't work |
| 384 | + } |
354 | 385 | errorOutput = "CLI execution timeout"; |
355 | 386 | return false; |
356 | 387 | } |
|
0 commit comments