This commit is contained in:
Nick Bolton 2015-02-26 12:31:19 +00:00
commit 6971f4551d
19 changed files with 217 additions and 198 deletions

View File

@ -55,7 +55,7 @@ SOURCES += src/main.cpp \
src/WebClient.cpp \
src/PluginWizardPage.cpp \
src/PluginManager.cpp \
src/DirectoryManager.cpp
src/CoreInterface.cpp
HEADERS += src/MainWindow.h \
src/AboutDialog.h \
src/ServerConfig.h \
@ -97,7 +97,7 @@ HEADERS += src/MainWindow.h \
src/PluginWizardPage.h \
src/ProcessorArch.h \
src/PluginManager.h \
src/DirectoryManager.h
src/CoreInterface.h
RESOURCES += res/Synergy.qrc
RC_FILE = res/win/Synergy.rc
macx {

View File

@ -145,7 +145,7 @@
<item row="0" column="0">
<widget class="QCheckBox" name="m_pCheckBoxEnableCrypto">
<property name="text">
<string>Enable OpenSSL (unique certificate)</string>
<string>Use &amp;OpenSSL encryption (unique certificate)</string>
</property>
</widget>
</item>

View File

@ -0,0 +1,86 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2015 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CoreInterface.h"
#include <QCoreApplication>
#include <QProcess>
#include <stdexcept>
static const char kCoreBinary[] = "syntool";
CoreInterface::CoreInterface()
{
}
QString CoreInterface::getPluginDir()
{
QStringList args("--get-plugin-dir");
return run(args);
}
QString CoreInterface::getProfileDir()
{
QStringList args("--get-profile-dir");
return run(args);
}
QString CoreInterface::getArch()
{
QStringList args("--get-arch");
return run(args);
}
QString CoreInterface::run(const QStringList& args, const QString& input)
{
QString program(
QCoreApplication::applicationDirPath()
+ "/" + kCoreBinary);
QProcess process;
process.setReadChannel(QProcess::StandardOutput);
process.start(program, args);
bool success = process.waitForStarted();
QString output, error;
if (success)
{
if (!input.isEmpty()) {
process.write(input.toStdString().c_str());
}
if (process.waitForFinished()) {
output = process.readAllStandardOutput();
error = process.readAllStandardError();
}
}
output = output.trimmed();
error = error.trimmed();
int code = process.exitCode();
if (!error.isEmpty() || !success || code != 0)
{
throw std::runtime_error(
QString("Code: %1\nError: %2")
.arg(process.exitCode())
.arg(error.isEmpty() ? "Unknown" : error)
.toStdString());
}
return output;
}

View File

@ -15,22 +15,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DIRECTORYMANAGER_H
#define DIRECTORYMANAGER_H
#pragma once
#include <QString>
#include <QStringList>
class DirectoryManager
class CoreInterface
{
public:
DirectoryManager();
CoreInterface();
static QString getPluginDir();
static QString getProfileDir();
private:
static QString getDirViaSyntool(QStringList& args);
QString getPluginDir();
QString getProfileDir();
QString getArch();
QString run(const QStringList& args, const QString& input = "");
};
#endif // DIRECTORYMANAGER_H

View File

@ -1,81 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2015 Synergy Si Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DirectoryManager.h"
#include <QCoreApplication>
#include <QProcess>
#include <QMessageBox>
#include <QObject>
static const char kGetPluginDirArg[] = "--get-plugin-dir";
static const char kGetProfileDirArg[] = "--get-profile-dir";
DirectoryManager::DirectoryManager()
{
}
QString DirectoryManager::getPluginDir()
{
QStringList args(kGetPluginDirArg);
return getDirViaSyntool(args);
}
QString DirectoryManager::getProfileDir()
{
QStringList args(kGetProfileDirArg);
return getDirViaSyntool(args);
}
QString DirectoryManager::getDirViaSyntool(QStringList& args)
{
QString program(QCoreApplication::applicationDirPath() + "/syntool");
QProcess process;
process.setReadChannel(QProcess::StandardOutput);
process.start(program, args);
bool success = process.waitForStarted();
QString out, error;
if (success)
{
if (process.waitForFinished()) {
out = process.readAllStandardOutput();
error = process.readAllStandardError();
}
}
out = out.trimmed();
error = error.trimmed();
if (out.isEmpty() ||
!error.isEmpty() ||
!success ||
process.exitCode() != 0)
{
QMessageBox::critical(
NULL, QObject::tr("Synergy"),
QObject::tr("An error occured while calling syntool "
"with the first arg %1. Code: %2\nError: %3")
.arg(args.at(0))
.arg(process.exitCode())
.arg(error.isEmpty() ? "Unknown" : error));
return "";
}
return out;
}

View File

@ -17,7 +17,7 @@
#include "PluginManager.h"
#include "DirectoryManager.h"
#include "CoreInterface.h"
#include "CommandProcess.h"
#include "DataDownloader.h"
#include "QUtility.h"
@ -57,12 +57,12 @@ PluginManager::PluginManager(QStringList pluginList) :
m_DownloadIndex(-1),
m_pPluginDownloader(NULL)
{
m_PluginDir = DirectoryManager::getPluginDir();
m_PluginDir = m_CoreInterface.getPluginDir();
if (m_PluginDir.isEmpty()) {
emit error(tr("Failed to get plugin directory."));
}
m_ProfileDir = DirectoryManager::getProfileDir();
m_ProfileDir = m_CoreInterface.getProfileDir();
if (m_ProfileDir.isEmpty()) {
emit error(tr("Failed to get profile directory."));
}
@ -173,37 +173,53 @@ void PluginManager::savePlugin()
QString PluginManager::getPluginUrl(const QString& pluginName)
{
QString result;
result = kPluginsBaseUrl.append(pluginName).append("/1.0/");
QString archName;
int arch = checkProcessorArch();
if (arch == Win_x86) {
result.append(kWinProcessorArch32);
#if defined(Q_OS_WIN)
try {
QString coreArch = m_CoreInterface.getArch();
if (coreArch.startsWith("x86")) {
archName = kWinProcessorArch32;
}
else if (arch == Win_x64) {
result.append(kWinProcessorArch64);
else if (coreArch.startsWith("x64")) {
archName = kWinProcessorArch64;
}
else if (arch == Mac_i386) {
result.append(kMacProcessorArch);
}
else if (arch == Linux_rpm_i686) {
result.append(kLinuxProcessorArchRpm32);
}
else if (arch == Linux_rpm_x86_64) {
result.append(kLinuxProcessorArchRpm64);
}
else if (arch == Linux_deb_i686) {
result.append(kLinuxProcessorArchDeb32);
}
else if (arch == Linux_deb_x86_64) {
result.append(kLinuxProcessorArchDeb64);
}
else {
emit error(
tr("Failed to get the url of plugin %1 .")
.arg(pluginName));
catch (...) {
emit error(tr("Could not get Windows architecture type."));
return "";
}
#elif defined(Q_OS_MAC)
archName = kMacProcessorArch;
#else
int arch = checkProcessorArch();
if (arch == Linux_rpm_i686) {
archName = kLinuxProcessorArchRpm32;
}
else if (arch == Linux_rpm_x86_64) {
archName = kLinuxProcessorArchRpm64;
}
else if (arch == Linux_deb_i686) {
archName = kLinuxProcessorArchDeb32;
}
else if (arch == Linux_deb_x86_64) {
archName = kLinuxProcessorArchDeb64;
}
else {
emit error(tr("Could not get Linux architecture type."));
return "";
}
#endif
QString result;
result = kPluginsBaseUrl.append(pluginName).append("/1.0/");
result.append(archName);
result.append("/");
result.append(getPluginOSSpecificName(pluginName));

View File

@ -22,9 +22,11 @@
#include <QStringList>
#include <QObject>
#include "CoreInterface.h"
class DataDownloader;
class PluginManager: public QObject
class PluginManager : public QObject
{
Q_OBJECT
@ -61,6 +63,7 @@ private:
QString m_ProfileDir;
int m_DownloadIndex;
DataDownloader* m_pPluginDownloader;
CoreInterface m_CoreInterface;
};
#endif // PLUGINMANAGER_H

View File

@ -63,7 +63,7 @@ void PluginWizardPage::changeEvent(QEvent *e)
void PluginWizardPage::showError(QString error)
{
updateStatus(error);
updateStatus(tr("Error: %1").arg(error));
showFinished();
}

View File

@ -18,7 +18,7 @@
#include "SettingsDialog.h"
#include "DirectoryManager.h"
#include "CoreInterface.h"
#include "SynergyLocale.h"
#include "QSynergyApplication.h"
#include "QUtility.h"
@ -57,7 +57,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
m_pCheckBoxElevateMode->hide();
#endif
QString pluginDir = DirectoryManager::getPluginDir();
QString pluginDir = m_CoreInterface.getPluginDir();
QDir dir(pluginDir);
int fileNum = dir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count();
if (fileNum == 0) {

View File

@ -23,6 +23,7 @@
#include <QDialog>
#include "ui_SettingsDialogBase.h"
#include "SynergyLocale.h"
#include "CoreInterface.h"
class AppConfig;
@ -44,6 +45,7 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase
private:
AppConfig& m_AppConfig;
SynergyLocale m_Locale;
CoreInterface m_CoreInterface;
bool m_SuppressElevateWarning;
private slots:

View File

@ -144,40 +144,7 @@ QString WebClient::request(
const QString& password,
QStringList& args)
{
QString program(QCoreApplication::applicationDirPath() + "/syntool");
QProcess process;
process.setReadChannel(QProcess::StandardOutput);
process.start(program, args);
bool success = process.waitForStarted();
QString out, error;
if (success)
{
// hash password in case it contains interesting chars.
QString credentials(email + ":" + hash(password) + "\n");
process.write(credentials.toStdString().c_str());
if (process.waitForFinished()) {
out = process.readAllStandardOutput();
error = process.readAllStandardError();
}
}
out = out.trimmed();
error = error.trimmed();
if (out.isEmpty() ||
!error.isEmpty() ||
!success ||
process.exitCode() != 0)
{
throw std::runtime_error(
QString("Code: %1\nError: %2")
.arg(process.exitCode())
.arg(error.isEmpty() ? "Unknown" : error)
.toStdString());
}
return out;
return m_CoreInterface.run(args, credentials);
}

View File

@ -22,6 +22,8 @@
#include <QStringList>
#include <QObject>
#include "CoreInterface.h"
class QMessageBox;
class QWidget;
class QStringList;
@ -55,6 +57,7 @@ private:
QString m_Email;
QString m_Password;
QStringList m_PluginList;
CoreInterface m_CoreInterface;
};
#endif // WEBCLIENT_H

View File

@ -64,7 +64,6 @@ ArchPluginUnix::load()
while ((de = readdir(dir)) != NULL) {
// ignore hidden files and diretories like .. and .
if (de->d_name[0] != '.') {
LOG((CLOG_DEBUG "load plugin %s", de->d_name));
plugins.push_back(de->d_name);
}
}
@ -77,11 +76,13 @@ ArchPluginUnix::load()
void* library = dlopen(path.c_str(), RTLD_LAZY);
if (library == NULL) {
LOG((CLOG_ERR "failed to load plugin: %s", (*it).c_str()));
throw XArch(dlerror());
}
String filename = synergy::string::removeFileExt(*it);
m_pluginTable.insert(std::make_pair(filename, library));
LOG((CLOG_ERR "loaded plugin: %s", (*it).c_str()));
}
}

View File

@ -56,16 +56,19 @@ ArchPluginWindows::load()
std::vector<String>::iterator it;
for (it = plugins.begin(); it != plugins.end(); ++it) {
LOG((CLOG_DEBUG "loading plugin: %s", (*it).c_str()));
String path = String(getPluginsDir()).append("\\").append(*it);
String path = String(dir).append("\\").append(*it);
HINSTANCE library = LoadLibrary(path.c_str());
if (library == NULL) {
LOG((CLOG_ERR "failed to load plugin: %s %d", (*it).c_str(), GetLastError()));
throw XArch(new XArchEvalWindows);
}
void* lib = reinterpret_cast<void*>(library);
String filename = synergy::string::removeFileExt(*it);
m_pluginTable.insert(std::make_pair(filename, lib));
LOG((CLOG_ERR "loaded plugin: %s", (*it).c_str()));
}
}

View File

@ -65,6 +65,20 @@ if (WIN32)
..\\..\\..\\..\\..\\lib\\${CMAKE_CFG_INTDIR}\\ns.dll
..\\..\\..\\..\\..\\bin\\${CMAKE_CFG_INTDIR}\\plugins\\
)
add_custom_command(
TARGET ns
POST_BUILD
COMMAND xcopy /Y /Q
..\\..\\..\\..\\..\\ext\\openssl\\out32dll\\libeay32.dll
..\\..\\..\\..\\..\\bin\\${CMAKE_CFG_INTDIR}
)
add_custom_command(
TARGET ns
POST_BUILD
COMMAND xcopy /Y /Q
..\\..\\..\\..\\..\\ext\\openssl\\out32dll\\ssleay32.dll
..\\..\\..\\..\\..\\bin\\${CMAKE_CFG_INTDIR}
)
else()
if (APPLE)
add_custom_command(

View File

@ -169,18 +169,22 @@ ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv)
args.m_loginAuthenticate = true;
return true;
}
if (isArg(i, argc, argv, NULL, "--get-plugin-list", 0)) {
else if (isArg(i, argc, argv, NULL, "--get-plugin-list", 0)) {
args.m_getPluginList = true;
return true;
}
if (isArg(i, argc, argv, NULL, "--get-plugin-dir", 0)) {
else if (isArg(i, argc, argv, NULL, "--get-plugin-dir", 0)) {
args.m_getPluginDir = true;
return true;
}
if (isArg(i, argc, argv, NULL, "--get-profile-dir", 0)) {
else if (isArg(i, argc, argv, NULL, "--get-profile-dir", 0)) {
args.m_getProfileDir = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--get-arch", 0)) {
args.m_getArch = true;
return true;
}
else {
return false;
}

View File

@ -79,6 +79,9 @@ ToolApp::run(int argc, char** argv)
else if (m_args.m_getProfileDir) {
std::cout << ARCH->getProfileDirectory() << std::endl;
}
else if (m_args.m_getArch) {
std::cout << ARCH->getPlatformName() << std::endl;
}
else {
throw XSynergy("Nothing to do");
}

View File

@ -29,4 +29,5 @@ public:
bool m_getPluginList;
bool m_getPluginDir;
bool m_getProfileDir;
bool m_getArch;
};

View File

@ -90,6 +90,8 @@
<File Source="$(var.BinPath)/synergyc.exe" />
<File Source="$(var.BinPath)/syntool.exe" />
<File Source="$(var.BinPath)/synwinhk.dll" />
<File Source="$(var.BinPath)/libeay32.dll" />
<File Source="$(var.BinPath)/ssleay32.dll" />
</Component>