Fixed: Specify working directory for getVersionFromExecutable

This commit is contained in:
kervala 2016-11-21 16:36:12 +01:00
parent c6fa3ad931
commit 2d4ba17851
4 changed files with 7 additions and 5 deletions

View file

@ -693,7 +693,7 @@ int CConfigFile::compareInstallersVersion() const
// if installer not found in installation directory // if installer not found in installation directory
if (!QFile::exists(installerDst)) return 1; if (!QFile::exists(installerDst)) return 1;
QString installedVersion = getVersionFromExecutable(installerDst); QString installedVersion = getVersionFromExecutable(installerDst, getInstallationDirectory());
// if unable to get version, copy it // if unable to get version, copy it
if (installedVersion.isEmpty()) return 1; if (installedVersion.isEmpty()) return 1;

View file

@ -226,20 +226,21 @@ void CProfilesDialog::updateExecutableVersion(int index)
if (index < 0) return; if (index < 0) return;
const CProfile &profile = m_model->getProfiles()[index]; const CProfile &profile = m_model->getProfiles()[index];
const CServer &server = CConfigFile::getInstance()->getServer(profile.server);
QString executable = profile.executable; QString executable = profile.executable;
// file empty, use default one // file empty, use default one
if (executable.isEmpty()) if (executable.isEmpty())
{ {
executable += CConfigFile::getInstance()->getServer(profile.server).getClientFullPath(); executable = server.getClientFullPath();
} }
// file doesn't exist // file doesn't exist
if (executable.isEmpty() || !QFile::exists(executable)) return; if (executable.isEmpty() || !QFile::exists(executable)) return;
// convert output to string // convert output to string
QString versionString = getVersionFromExecutable(executable); QString versionString = getVersionFromExecutable(executable, server.getDirectory());
if (!versionString.isEmpty()) if (!versionString.isEmpty())
{ {

View file

@ -406,7 +406,7 @@ QString appendShortcutExtension(const QString &shortcut)
return shortcut + extension; return shortcut + extension;
} }
QString getVersionFromExecutable(const QString &path) QString getVersionFromExecutable(const QString &path, const QString &workingDirectory)
{ {
// check if file exists // check if file exists
if (!QFile::exists(path)) if (!QFile::exists(path))
@ -426,6 +426,7 @@ QString getVersionFromExecutable(const QString &path)
// launch executable with --version argument // launch executable with --version argument
QProcess process; QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels); process.setProcessChannelMode(QProcess::MergedChannels);
process.setWorkingDirectory(workingDirectory);
process.start(path, QStringList() << "--version", QIODevice::ReadOnly); process.start(path, QStringList() << "--version", QIODevice::ReadOnly);
if (!process.waitForStarted()) if (!process.waitForStarted())

View file

@ -76,7 +76,7 @@ bool resolveShortcut(const QWidget &window, const QString &shortcut, QString &pa
QString appendShortcutExtension(const QString &shortcut); QString appendShortcutExtension(const QString &shortcut);
// launch an executable with --version parameter and parse version string // launch an executable with --version parameter and parse version string
QString getVersionFromExecutable(const QString &path); QString getVersionFromExecutable(const QString &path, const QString &workingDirectory);
// write a resource in QRC to disk // write a resource in QRC to disk
bool writeResource(const QString &resource, const QString &path); bool writeResource(const QString &resource, const QString &path);