From dff2cb34be264974b3a060c522f316d3e3baec19 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Wed, 26 Nov 2014 15:05:53 +0000 Subject: [PATCH] Download Bonjour installer according to system architecture --- src/gui/src/MainWindow.cpp | 48 +++++++++++++++++++++++++++++++++++--- src/gui/src/MainWindow.h | 7 ++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 4ed634ab..0fff11cf 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -43,6 +43,7 @@ #endif #if defined(Q_OS_WIN) +#define _WIN32_WINNT 0x0501 #define WIN32_LEAN_AND_MEAN #include #endif @@ -50,7 +51,9 @@ #if defined(Q_OS_WIN) static const char synergyConfigName[] = "synergy.sgc"; static const QString synergyConfigFilter(QObject::tr("Synergy Configurations (*.sgc);;All files (*.*)")); -static const char bonjourUrl[] = "http://synergy-project.org/bonjour/BonjourPSSetup.exe"; +static const char bonjourUrl[] = "http://synergy-project.org/bonjour/"; +static const char bonjour32Url[] = "http://synergy-project.org/bonjour/Bonjour.msi"; +static const char bonjour64Url[] = "http://synergy-project.org/bonjour/Bonjour64.msi"; static const char bonjourInstaller[] = "BonjourSetup.exe"; #else static const char synergyConfigName[] = "synergy.conf"; @@ -829,6 +832,26 @@ void MainWindow::serverDetected(const QString name) } } +int MainWindow::checkWinArch() +{ +#if defined(Q_OS_WIN) + SYSTEM_INFO systemInfo; + GetNativeSystemInfo(&systemInfo); + + switch (systemInfo.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_INTEL: + return x86; + case PROCESSOR_ARCHITECTURE_IA64: + return x64; + case PROCESSOR_ARCHITECTURE_AMD64: + return x64; + default: + appendLogNote("failed to detect system architecture"); + } +#endif + return unknown; +} + void MainWindow::on_m_pGroupClient_toggled(bool on) { m_pGroupServer->setChecked(!on); @@ -1019,7 +1042,26 @@ bool MainWindow::isBonjourRunning() void MainWindow::downloadBonjour() { #if defined(Q_OS_WIN) - QUrl url(bonjourUrl); + + QUrl url; + int arch = checkWinArch(); + if (arch == x86) { + url.setUrl(bonjour32Url); + appendLogNote("downloading 32-bit Bonjour"); + } + else if (arch == x64) { + url.setUrl(bonjour64Url); + appendLogNote("downloading 64-bit Bonjour"); + } + else { + QString msg("Failed to detect system architecture.\n" + "Please download the installer manually from this link:\n"); + QMessageBox::warning( + this, tr("Synergy"), + msg + bonjourUrl); + return; + } + if (m_pDataDownloader != NULL) { delete m_pDataDownloader; m_pDataDownloader = NULL; @@ -1055,7 +1097,7 @@ void MainWindow::installBonjour() if (!file.open(QIODevice::WriteOnly)) { m_DownloadMessageBox->hide(); - QMessageBox::critical( + QMessageBox::warning( this, "Synergy", "Failed to download Bonjour installer to location: " + tempLocation + "\n" diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index 7162cea0..782c7bf3 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -82,6 +82,12 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase Info }; + enum qProcessorArch { + x86, + x64, + unknown + }; + public: MainWindow(QSettings& settings, AppConfig& appConfig); ~MainWindow(); @@ -104,6 +110,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase void autoAddScreen(const QString name); void updateZeroconfService(); void serverDetected(const QString name); + int checkWinArch(); public slots: void appendLogRaw(const QString& text);