Utility: Added function versionOfInstalledBinary()

It calls the binary with param --version and returns the first line of
the output. For owncloud, that is the version string.
This commit is contained in:
Klaas Freitag 2015-07-16 18:16:16 +02:00
Родитель d284b48db4
Коммит 2f2ae09190
3 изменённых файлов: 47 добавлений и 0 удалений

Просмотреть файл

@ -393,6 +393,35 @@ void Utility::crash()
*a = 1; *a = 1;
} }
// read the output of the owncloud --version command from the owncloud
// version that is on disk. This works for most versions of the client,
// because clients that do not yet know the --version flag return the
// version in the first line of the help output :-)
//
// This version only delivers output on linux, as Mac and Win get their
// restarting from the installer.
QByteArray Utility::versionOfInstalledBinary( const QString& command )
{
QByteArray re;
if( isLinux() ) {
QString binary(command);
if( binary.isEmpty() ) {
binary = qApp->arguments()[0];
}
QStringList params;
params << QLatin1String("--version");
QProcess process;
process.start(binary, params);
process.waitForFinished(); // sets current thread to sleep and waits for pingProcess end
re = process.readAllStandardOutput();
int newline = re.indexOf(QChar('\n'));
if( newline > 0 ) {
re.truncate( newline );
}
}
return re;
}
static const char STOPWATCH_END_TAG[] = "_STOPWATCH_END"; static const char STOPWATCH_END_TAG[] = "_STOPWATCH_END";
void Utility::StopWatch::start() void Utility::StopWatch::start()

Просмотреть файл

@ -98,6 +98,13 @@ namespace Utility
// if false, the two cases are two different files. // if false, the two cases are two different files.
OWNCLOUDSYNC_EXPORT bool fsCasePreserving(); OWNCLOUDSYNC_EXPORT bool fsCasePreserving();
// Call the given command with the switch --version and retrun the first line
// of the output.
// If command is empty, the function calls the running application which, on
// Linux, might have changed while this one is running.
// For Mac and Windows, it returns QString()
OWNCLOUDSYNC_EXPORT QByteArray versionOfInstalledBinary(const QString& command = QString() );
class OWNCLOUDSYNC_EXPORT StopWatch { class OWNCLOUDSYNC_EXPORT StopWatch {
private: private:
QHash<QString, quint64> _lapTimes; QHash<QString, quint64> _lapTimes;

Просмотреть файл

@ -103,6 +103,17 @@ private slots:
} }
void testVersionOfInstalledBinary()
{
if( isLinux() ) {
QString ver = versionOfInstalledBinary("/home/kf/owncloud.com/buildmirall/bin/owncloud");
qDebug() << "Version of installed ownCloud Binary: " << ver;
QVERIFY( !ver.isEmpty());
} else {
QVERIFY( versionOfInstalledBinary().isEmpty());
}
}
}; };
#endif #endif