Simplified logic to detect Linux 64/32 deb/rpm #4565
This commit is contained in:
parent
e479f16705
commit
e8a43dd020
|
@ -1132,12 +1132,12 @@ void MainWindow::downloadBonjour()
|
|||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
QUrl url;
|
||||
int arch = checkProcessorArch();
|
||||
if (arch == Win_x86) {
|
||||
int arch = getProcessorArch();
|
||||
if (arch == kProcessorArchWin32) {
|
||||
url.setUrl(bonjourBaseUrl + bonjourFilename32);
|
||||
appendLogNote("downloading 32-bit Bonjour");
|
||||
}
|
||||
else if (arch == Win_x64) {
|
||||
else if (arch == kProcessorArchWin64) {
|
||||
url.setUrl(bonjourBaseUrl + bonjourFilename64);
|
||||
appendLogNote("downloading 64-bit Bonjour");
|
||||
}
|
||||
|
|
|
@ -31,13 +31,13 @@
|
|||
|
||||
static const char kBaseUrl[] = "http://synergy-project.org/files";
|
||||
static const char kDefaultVersion[] = "1.1";
|
||||
static const char kWinProcessorArch32[] = "Windows-x86";
|
||||
static const char kWinProcessorArch64[] = "Windows-x64";
|
||||
static const char kMacProcessorArch[] = "MacOSX%1-i386";
|
||||
static const char kLinuxProcessorArchDeb32[] = "Linux-i686-deb";
|
||||
static const char kLinuxProcessorArchDeb64[] = "Linux-x86_64-deb";
|
||||
static const char kLinuxProcessorArchRpm32[] = "Linux-i686-rpm";
|
||||
static const char kLinuxProcessorArchRpm64[] = "Linux-x86_64-rpm";
|
||||
static const char kWinPackagePlatform32[] = "Windows-x86";
|
||||
static const char kWinPackagePlatform64[] = "Windows-x64";
|
||||
static const char kMacPackagePlatform32[] = "MacOSX%1-i386";
|
||||
static const char kLinuxPackagePlatformDeb32[] = "Linux-i686-deb";
|
||||
static const char kLinuxPackagePlatformDeb64[] = "Linux-x86_64-deb";
|
||||
static const char kLinuxPackagePlatformRpm32[] = "Linux-i686-rpm";
|
||||
static const char kLinuxPackagePlatformRpm64[] = "Linux-x86_64-rpm";
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
static const char kWinPluginExt[] = ".dll";
|
||||
|
@ -158,10 +158,10 @@ QString PluginManager::getPluginUrl(const QString& pluginName)
|
|||
try {
|
||||
QString coreArch = m_CoreInterface.getArch();
|
||||
if (coreArch.startsWith("x86")) {
|
||||
archName = kWinProcessorArch32;
|
||||
archName = kWinPackagePlatform32;
|
||||
}
|
||||
else if (coreArch.startsWith("x64")) {
|
||||
archName = kWinProcessorArch64;
|
||||
archName = kWinPackagePlatform64;
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
|
@ -181,22 +181,43 @@ QString PluginManager::getPluginUrl(const QString& pluginName)
|
|||
return "";
|
||||
#endif
|
||||
|
||||
archName = QString(kMacProcessorArch).arg(macVersion);
|
||||
archName = QString(kMacPackagePlatform).arg(macVersion);
|
||||
|
||||
#else
|
||||
|
||||
int arch = checkProcessorArch();
|
||||
if (arch == Linux_rpm_i686) {
|
||||
archName = kLinuxProcessorArchRpm32;
|
||||
QString program("dpkg");
|
||||
QStringList args;
|
||||
args << "-s" << "synergy";
|
||||
|
||||
QProcess process;
|
||||
process.setReadChannel(QProcess::StandardOutput);
|
||||
process.start(program, args);
|
||||
bool success = process.waitForStarted();
|
||||
|
||||
if (!success || !process.waitForFinished())
|
||||
{
|
||||
emit error(tr("Could not get Linux package type."));
|
||||
return "";
|
||||
}
|
||||
else if (arch == Linux_rpm_x86_64) {
|
||||
archName = kLinuxProcessorArchRpm64;
|
||||
|
||||
bool isDeb = (process.exitCode() == 0);
|
||||
|
||||
int arch = getProcessorArch();
|
||||
if (arch == kProcessorArchLinux32) {
|
||||
if (isDeb) {
|
||||
archName = kLinuxPackagePlatformDeb32;
|
||||
}
|
||||
else {
|
||||
archName = kLinuxPackagePlatformRpm32;
|
||||
}
|
||||
}
|
||||
else if (arch == Linux_deb_i686) {
|
||||
archName = kLinuxProcessorArchDeb32;
|
||||
}
|
||||
else if (arch == Linux_deb_x86_64) {
|
||||
archName = kLinuxProcessorArchDeb64;
|
||||
else if (arch == kProcessorArchLinux64) {
|
||||
if (isDeb) {
|
||||
archName = kLinuxPackagePlatformDeb64;
|
||||
}
|
||||
else {
|
||||
archName = kLinuxPackagePlatformRpm64;
|
||||
}
|
||||
}
|
||||
else {
|
||||
emit error(tr("Could not get Linux architecture type."));
|
||||
|
|
|
@ -15,18 +15,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROCESSORARCH_H
|
||||
#define PROCESSORARCH_H
|
||||
#pragma once
|
||||
|
||||
enum qProcessorArch {
|
||||
Win_x86,
|
||||
Win_x64,
|
||||
Mac_i386,
|
||||
Linux_rpm_i686,
|
||||
Linux_rpm_x86_64,
|
||||
Linux_deb_i686,
|
||||
Linux_deb_x86_64,
|
||||
unknown
|
||||
kProcessorArchWin32,
|
||||
kProcessorArchWin64,
|
||||
kProcessorArchMac32,
|
||||
kProcessorArchMac64,
|
||||
kProcessorArchLinux32,
|
||||
kProcessorArchLinux64,
|
||||
kProcessorArchUnknown
|
||||
};
|
||||
|
||||
#endif // PROCESSORARCH_H
|
||||
|
|
|
@ -29,12 +29,6 @@
|
|||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
static const char kLinuxI686[] = "i686";
|
||||
static const char kLinuxX8664[] = "x86_64";
|
||||
static const char kUbuntu[] = "Ubuntu";
|
||||
#endif
|
||||
|
||||
void setIndexFromItemData(QComboBox* comboBox, const QVariant& itemData)
|
||||
{
|
||||
for (int i = 0; i < comboBox->count(); ++i)
|
||||
|
@ -68,7 +62,7 @@ QString getFirstMacAddress()
|
|||
return mac;
|
||||
}
|
||||
|
||||
int checkProcessorArch()
|
||||
qProcessorArch getProcessorArch()
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
SYSTEM_INFO systemInfo;
|
||||
|
@ -76,97 +70,27 @@ int checkProcessorArch()
|
|||
|
||||
switch (systemInfo.wProcessorArchitecture) {
|
||||
case PROCESSOR_ARCHITECTURE_INTEL:
|
||||
return Win_x86;
|
||||
return kProcessorArchWin32;
|
||||
case PROCESSOR_ARCHITECTURE_IA64:
|
||||
return Win_x64;
|
||||
return kProcessorArchWin64;
|
||||
case PROCESSOR_ARCHITECTURE_AMD64:
|
||||
return Win_x64;
|
||||
return kProcessorArchWin64;
|
||||
default:
|
||||
return unknown;
|
||||
}
|
||||
#elif defined(Q_OS_MAC)
|
||||
return Mac_i386;
|
||||
#else
|
||||
bool version32 = false;
|
||||
bool debPackaging = false;
|
||||
|
||||
QString program1("uname");
|
||||
QStringList args1("-m");
|
||||
QProcess process1;
|
||||
process1.setReadChannel(QProcess::StandardOutput);
|
||||
process1.start(program1, args1);
|
||||
bool success = process1.waitForStarted();
|
||||
|
||||
QString out, error;
|
||||
if (success)
|
||||
{
|
||||
if (process1.waitForFinished()) {
|
||||
out = process1.readAllStandardOutput();
|
||||
error = process1.readAllStandardError();
|
||||
}
|
||||
}
|
||||
|
||||
out = out.trimmed();
|
||||
error = error.trimmed();
|
||||
|
||||
if (out.isEmpty() ||
|
||||
!error.isEmpty() ||
|
||||
!success ||
|
||||
process1.exitCode() != 0)
|
||||
{
|
||||
return unknown;
|
||||
}
|
||||
|
||||
if (out == kLinuxI686) {
|
||||
version32 = true;
|
||||
}
|
||||
|
||||
QString program2("python");
|
||||
QStringList args2("-mplatform");
|
||||
QProcess process2;
|
||||
process2.setReadChannel(QProcess::StandardOutput);
|
||||
process2.start(program2, args2);
|
||||
success = process2.waitForStarted();
|
||||
|
||||
if (success)
|
||||
{
|
||||
if (process2.waitForFinished()) {
|
||||
out = process2.readAllStandardOutput();
|
||||
error = process2.readAllStandardError();
|
||||
}
|
||||
}
|
||||
|
||||
out = out.trimmed();
|
||||
error = error.trimmed();
|
||||
|
||||
if (out.isEmpty() ||
|
||||
!error.isEmpty() ||
|
||||
!success ||
|
||||
process2.exitCode() != 0)
|
||||
{
|
||||
return unknown;
|
||||
}
|
||||
|
||||
if (out.contains(kUbuntu)) {
|
||||
debPackaging = true;
|
||||
}
|
||||
|
||||
if (version32) {
|
||||
if (debPackaging) {
|
||||
return Linux_deb_i686;
|
||||
}
|
||||
else {
|
||||
return Linux_rpm_i686;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (debPackaging) {
|
||||
return Linux_deb_x86_64;
|
||||
}
|
||||
else {
|
||||
return Linux_rpm_x86_64;
|
||||
}
|
||||
return kProcessorArchUnknown;
|
||||
}
|
||||
#endif
|
||||
return unknown;
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
return kProcessorArchMac;
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
#ifdef __i386__
|
||||
return kProcessorArchLinux32;
|
||||
#else
|
||||
return kProcessorArchLinux64;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return kProcessorArchUnknown;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "ProcessorArch.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QVariant>
|
||||
#include <QCryptographicHash>
|
||||
|
@ -25,4 +27,4 @@
|
|||
void setIndexFromItemData(QComboBox* comboBox, const QVariant& itemData);
|
||||
QString hash(const QString& string);
|
||||
QString getFirstMacAddress();
|
||||
int checkProcessorArch();
|
||||
qProcessorArch getProcessorArch();
|
||||
|
|
Loading…
Reference in New Issue