Fixed: Plugin manager doesn't download openssl.exe #4313
Refactored use of DataDownloader in PluginManager
This commit is contained in:
parent
450435d062
commit
bce1d5be64
|
@ -64,14 +64,11 @@ QString CoreInterface::run(const QStringList& args, const QString& input)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.waitForFinished()) {
|
if (process.waitForFinished()) {
|
||||||
output = process.readAllStandardOutput();
|
output = process.readAllStandardOutput().trimmed();
|
||||||
error = process.readAllStandardError();
|
error = process.readAllStandardError().trimmed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output = output.trimmed();
|
|
||||||
error = error.trimmed();
|
|
||||||
|
|
||||||
int code = process.exitCode();
|
int code = process.exitCode();
|
||||||
if (!error.isEmpty() || !success || code != 0)
|
if (!error.isEmpty() || !success || code != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
#include "DataDownloader.h"
|
#include "DataDownloader.h"
|
||||||
|
|
||||||
DataDownloader::DataDownloader(QObject* parent) :
|
DataDownloader::DataDownloader(QObject* parent) :
|
||||||
QObject(parent)
|
QObject(parent),
|
||||||
|
m_IsFinished(false)
|
||||||
{
|
{
|
||||||
connect(&m_NetworkManager, SIGNAL(finished(QNetworkReply*)),
|
connect(&m_NetworkManager, SIGNAL(finished(QNetworkReply*)),
|
||||||
SLOT(complete(QNetworkReply*)));
|
SLOT(complete(QNetworkReply*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
DataDownloader::~DataDownloader()
|
DataDownloader::~DataDownloader()
|
||||||
|
@ -34,6 +35,7 @@ void DataDownloader::complete(QNetworkReply* reply)
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
if (!m_Data.isEmpty()) {
|
if (!m_Data.isEmpty()) {
|
||||||
|
m_IsFinished = true;
|
||||||
emit isComplete();
|
emit isComplete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
QByteArray data() const;
|
QByteArray data() const;
|
||||||
void cancel();
|
void cancel();
|
||||||
void download(QUrl url);
|
void download(QUrl url);
|
||||||
|
bool isFinished() const { return m_IsFinished; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void isComplete();
|
void isComplete();
|
||||||
|
@ -46,6 +47,7 @@ private:
|
||||||
QNetworkAccessManager m_NetworkManager;
|
QNetworkAccessManager m_NetworkManager;
|
||||||
QByteArray m_Data;
|
QByteArray m_Data;
|
||||||
QNetworkReply* m_pReply;
|
QNetworkReply* m_pReply;
|
||||||
|
bool m_IsFinished;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATADOWNLOADER_H
|
#endif // DATADOWNLOADER_H
|
||||||
|
|
|
@ -25,8 +25,9 @@
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
static QString kPluginsBaseUrl = "http://synergy-project.org/files/plugins/";
|
static QString kBaseUrl = "http://synergy-project.org/files";
|
||||||
static const char kWinProcessorArch32[] = "Windows-x86";
|
static const char kWinProcessorArch32[] = "Windows-x86";
|
||||||
static const char kWinProcessorArch64[] = "Windows-x64";
|
static const char kWinProcessorArch64[] = "Windows-x64";
|
||||||
static const char kMacProcessorArch[] = "MacOSX-i386";
|
static const char kMacProcessorArch[] = "MacOSX-i386";
|
||||||
|
@ -34,7 +35,6 @@ static const char kLinuxProcessorArchDeb32[] = "Linux-i686-deb";
|
||||||
static const char kLinuxProcessorArchDeb64[] = "Linux-x86_64-deb";
|
static const char kLinuxProcessorArchDeb64[] = "Linux-x86_64-deb";
|
||||||
static const char kLinuxProcessorArchRpm32[] = "Linux-i686-rpm";
|
static const char kLinuxProcessorArchRpm32[] = "Linux-i686-rpm";
|
||||||
static const char kLinuxProcessorArchRpm64[] = "Linux-x86_64-rpm";
|
static const char kLinuxProcessorArchRpm64[] = "Linux-x86_64-rpm";
|
||||||
static QString kOpenSSLBaseUrl = "http://synergy-foss.org/files/tools/";
|
|
||||||
static QString kCertificateLifetime = "365";
|
static QString kCertificateLifetime = "365";
|
||||||
static QString kCertificateSubjectInfo = "/CN=Synergy";
|
static QString kCertificateSubjectInfo = "/CN=Synergy";
|
||||||
static QString kCertificateFilename = "Synergy.pem";
|
static QString kCertificateFilename = "Synergy.pem";
|
||||||
|
@ -54,8 +54,7 @@ static const char kLinuxPluginExt[] = ".so";
|
||||||
|
|
||||||
PluginManager::PluginManager(QStringList pluginList) :
|
PluginManager::PluginManager(QStringList pluginList) :
|
||||||
m_PluginList(pluginList),
|
m_PluginList(pluginList),
|
||||||
m_DownloadIndex(-1),
|
m_DownloadIndex(-1)
|
||||||
m_pPluginDownloader(NULL)
|
|
||||||
{
|
{
|
||||||
m_PluginDir = m_CoreInterface.getPluginDir();
|
m_PluginDir = m_CoreInterface.getPluginDir();
|
||||||
if (m_PluginDir.isEmpty()) {
|
if (m_PluginDir.isEmpty()) {
|
||||||
|
@ -70,14 +69,11 @@ PluginManager::PluginManager(QStringList pluginList) :
|
||||||
|
|
||||||
PluginManager::~PluginManager()
|
PluginManager::~PluginManager()
|
||||||
{
|
{
|
||||||
if (m_pPluginDownloader != NULL) {
|
|
||||||
delete m_pPluginDownloader;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginManager::downloadPlugins()
|
void PluginManager::downloadPlugins()
|
||||||
{
|
{
|
||||||
if (m_pPluginDownloader != NULL) {
|
if (m_DataDownloader.isFinished()) {
|
||||||
savePlugin();
|
savePlugin();
|
||||||
if (m_DownloadIndex != m_PluginList.size() - 1) {
|
if (m_DownloadIndex != m_PluginList.size() - 1) {
|
||||||
emit downloadNext();
|
emit downloadNext();
|
||||||
|
@ -98,11 +94,9 @@ void PluginManager::downloadPlugins()
|
||||||
}
|
}
|
||||||
url.setUrl(pluginUrl);
|
url.setUrl(pluginUrl);
|
||||||
|
|
||||||
if (m_pPluginDownloader == NULL) {
|
connect(&m_DataDownloader, SIGNAL(isComplete()), this, SLOT(downloadPlugins()));
|
||||||
m_pPluginDownloader = new DataDownloader();
|
|
||||||
connect(m_pPluginDownloader, SIGNAL(isComplete()), this, SLOT(downloadPlugins()));
|
m_DataDownloader.download(url);
|
||||||
}
|
|
||||||
m_pPluginDownloader->download(url);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,12 +116,12 @@ void PluginManager::saveOpenSSLBinary()
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
if (!file.open(QIODevice::WriteOnly)) {
|
if (!file.open(QIODevice::WriteOnly)) {
|
||||||
emit error(
|
emit error(
|
||||||
tr("Failed to download OpenSSl to location: %1")
|
tr("Failed to save certificate tool to: %1")
|
||||||
.arg(m_ProfileDir));
|
.arg(m_ProfileDir));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.write(m_pPluginDownloader->data());
|
file.write(m_DataDownloader.data());
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
emit openSSLBinaryReady();
|
emit openSSLBinaryReady();
|
||||||
|
@ -160,14 +154,14 @@ void PluginManager::savePlugin()
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
if (!file.open(QIODevice::WriteOnly)) {
|
if (!file.open(QIODevice::WriteOnly)) {
|
||||||
emit error(
|
emit error(
|
||||||
tr("Failed to download plugin %1 to location: %2")
|
tr("Failed to download '%1' plugin to: %2")
|
||||||
.arg(m_PluginList.at(m_DownloadIndex))
|
.arg(m_PluginList.at(m_DownloadIndex))
|
||||||
.arg(m_PluginDir));
|
.arg(m_PluginDir));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.write(m_pPluginDownloader->data());
|
file.write(m_DataDownloader.data());
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,8 +211,9 @@ QString PluginManager::getPluginUrl(const QString& pluginName)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QString result;
|
QString result = kBaseUrl;
|
||||||
result = kPluginsBaseUrl.append(pluginName).append("/1.0/");
|
result.append("/plugins/");
|
||||||
|
result.append(pluginName).append("/1.0/");
|
||||||
result.append(archName);
|
result.append(archName);
|
||||||
result.append("/");
|
result.append("/");
|
||||||
result.append(getPluginOSSpecificName(pluginName));
|
result.append(getPluginOSSpecificName(pluginName));
|
||||||
|
@ -229,8 +224,11 @@ QString PluginManager::getPluginUrl(const QString& pluginName)
|
||||||
QString PluginManager::getOpenSSLBinaryUrl()
|
QString PluginManager::getOpenSSLBinaryUrl()
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
result = kOpenSSLBaseUrl.append(kWinOpenSSLBinary);
|
result = kBaseUrl;
|
||||||
|
result.append("/tools/");
|
||||||
|
result.append(kWinOpenSSLBinary);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -251,20 +249,13 @@ QString PluginManager::getPluginOSSpecificName(const QString& pluginName)
|
||||||
|
|
||||||
bool PluginManager::checkOpenSSLBinary()
|
bool PluginManager::checkOpenSSLBinary()
|
||||||
{
|
{
|
||||||
bool exist = false;
|
// assume OpenSSL is unavailable on Windows,
|
||||||
|
// but always available on both Mac and Linux
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
QString openSSLFilename = m_ProfileDir;
|
return false;
|
||||||
openSSLFilename.append("\\").append(kWinOpenSSLBinary);
|
|
||||||
QDir dir(openSSLFilename);
|
|
||||||
if (dir.exists()) {
|
|
||||||
exist = true;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
// assume OpenSSL is always installed on both Mac and Linux
|
return true;
|
||||||
exist = true;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return exist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginManager::downloadOpenSSLBinary()
|
void PluginManager::downloadOpenSSLBinary()
|
||||||
|
@ -275,21 +266,22 @@ void PluginManager::downloadOpenSSLBinary()
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
QString pluginUrl = getOpenSSLBinaryUrl();
|
QString openSslUrl = getOpenSSLBinaryUrl();
|
||||||
url.setUrl(pluginUrl);
|
url.setUrl(openSslUrl);
|
||||||
|
|
||||||
disconnect(
|
disconnect(
|
||||||
m_pPluginDownloader,
|
&m_DataDownloader,
|
||||||
SIGNAL(isComplete()),
|
SIGNAL(isComplete()),
|
||||||
this,
|
this,
|
||||||
SLOT(downloadPlugins()));
|
SLOT(downloadPlugins()));
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
m_pPluginDownloader,
|
&m_DataDownloader,
|
||||||
SIGNAL(isComplete()),
|
SIGNAL(isComplete()),
|
||||||
this,
|
this,
|
||||||
SLOT(saveOpenSSLBinary()));
|
SLOT(saveOpenSSLBinary()));
|
||||||
|
|
||||||
m_pPluginDownloader->download(url);
|
m_DataDownloader.download(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginManager::doGenerateCertificate()
|
void PluginManager::doGenerateCertificate()
|
||||||
|
@ -332,9 +324,26 @@ void PluginManager::doGenerateCertificate()
|
||||||
arguments.append("-out");
|
arguments.append("-out");
|
||||||
arguments.append(filename);
|
arguments.append(filename);
|
||||||
|
|
||||||
// update command and arguments
|
QProcess process;
|
||||||
CommandProcess commandProcess(openSSLFilename, arguments);
|
process.start(openSSLFilename, arguments);
|
||||||
commandProcess.run();
|
bool success = process.waitForStarted();
|
||||||
|
|
||||||
|
QString standardOutput, standardError;
|
||||||
|
if (success && process.waitForFinished())
|
||||||
|
{
|
||||||
|
standardOutput = process.readAllStandardOutput().trimmed();
|
||||||
|
standardError = process.readAllStandardError().trimmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
int code = process.exitCode();
|
||||||
|
if (!standardError.isEmpty() || !success || code != 0)
|
||||||
|
{
|
||||||
|
emit error(
|
||||||
|
QString("Failed to generate certificate.\n\nCode: %1\nError: %2")
|
||||||
|
.arg(process.exitCode())
|
||||||
|
.arg(standardError.isEmpty() ? "Unknown" : standardError));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
emit generateCertificateFinished();
|
emit generateCertificateFinished();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "CoreInterface.h"
|
#include "CoreInterface.h"
|
||||||
|
#include "DataDownloader.h"
|
||||||
class DataDownloader;
|
|
||||||
|
|
||||||
class PluginManager : public QObject
|
class PluginManager : public QObject
|
||||||
{
|
{
|
||||||
|
@ -62,7 +61,7 @@ private:
|
||||||
QString m_PluginDir;
|
QString m_PluginDir;
|
||||||
QString m_ProfileDir;
|
QString m_ProfileDir;
|
||||||
int m_DownloadIndex;
|
int m_DownloadIndex;
|
||||||
DataDownloader* m_pPluginDownloader;
|
DataDownloader m_DataDownloader;
|
||||||
CoreInterface m_CoreInterface;
|
CoreInterface m_CoreInterface;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue