2017-12-26 04:27:18 +00:00
|
|
|
#include "Common.hpp"
|
2017-12-27 00:48:34 +00:00
|
|
|
#include <QStringList>
|
2018-01-03 23:53:01 +00:00
|
|
|
#include <csignal>
|
2017-12-27 00:48:34 +00:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2017-12-26 04:27:18 +00:00
|
|
|
|
|
|
|
#if __APPLE__
|
|
|
|
const QString CurPlatformString = QStringLiteral("macos");
|
|
|
|
#elif _WIN32
|
|
|
|
const QString CurPlatformString = QStringLiteral("win32");
|
|
|
|
#elif __linux__
|
|
|
|
const QString CurPlatformString = QStringLiteral("linux");
|
|
|
|
#else
|
|
|
|
#error HECL does not know which OS to fetch for
|
|
|
|
#endif
|
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QString PlatformToString(Platform plat) {
|
|
|
|
switch (plat) {
|
|
|
|
case Platform::MacOS:
|
|
|
|
return QStringLiteral("macos");
|
|
|
|
case Platform::Win32:
|
|
|
|
return QStringLiteral("win32");
|
|
|
|
case Platform::Linux:
|
|
|
|
return QStringLiteral("linux");
|
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
2017-12-26 04:27:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-27 00:48:34 +00:00
|
|
|
Architecture CurArchitecture = Architecture::Invalid;
|
|
|
|
QString CurArchitectureString;
|
2017-12-26 04:27:18 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
Platform StringToPlatform(const QString& str) {
|
|
|
|
for (int i = 1; i < int(Platform::MAXPlatform); ++i)
|
|
|
|
if (!str.compare(PlatformToString(Platform(i)), Qt::CaseInsensitive))
|
|
|
|
return Platform(i);
|
|
|
|
return Platform::Invalid;
|
2017-12-26 04:27:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QString ArchitectureToString(Architecture arch) {
|
|
|
|
switch (arch) {
|
|
|
|
case Architecture::X86:
|
|
|
|
return QStringLiteral("x86");
|
|
|
|
case Architecture::X86_64:
|
|
|
|
return QStringLiteral("x86_64");
|
|
|
|
case Architecture::ARM:
|
|
|
|
return QStringLiteral("arm");
|
2021-03-29 17:23:02 +00:00
|
|
|
case Architecture::ARM64:
|
|
|
|
return QStringLiteral("arm64");
|
2018-12-08 05:19:40 +00:00
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
2017-12-26 04:27:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
Architecture StringToArchitecture(const QString& str) {
|
|
|
|
for (int i = 1; i < int(Architecture::MAXArchitecture); ++i)
|
|
|
|
if (!str.compare(ArchitectureToString(Architecture(i)), Qt::CaseInsensitive))
|
|
|
|
return Architecture(i);
|
|
|
|
return Architecture::Invalid;
|
2017-12-26 04:27:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QString VectorISAToString(VectorISA visa) {
|
|
|
|
switch (visa) {
|
|
|
|
case VectorISA::X87:
|
|
|
|
return QStringLiteral("x87");
|
|
|
|
case VectorISA::SSE:
|
|
|
|
return QStringLiteral("sse");
|
|
|
|
case VectorISA::SSE2:
|
|
|
|
return QStringLiteral("sse2");
|
|
|
|
case VectorISA::SSE3:
|
|
|
|
return QStringLiteral("sse3");
|
|
|
|
case VectorISA::SSE41:
|
|
|
|
return QStringLiteral("sse41");
|
|
|
|
case VectorISA::AVX:
|
|
|
|
return QStringLiteral("avx");
|
|
|
|
case VectorISA::AVX2:
|
|
|
|
return QStringLiteral("avx2");
|
2021-03-29 17:23:02 +00:00
|
|
|
case VectorISA::AVX512:
|
|
|
|
return QStringLiteral("avx512");
|
2018-12-08 05:19:40 +00:00
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
2017-12-26 04:27:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
VectorISA StringToVectorISA(const QString& str) {
|
|
|
|
for (int i = 1; i < int(VectorISA::MAXVectorISA); ++i)
|
|
|
|
if (!str.compare(VectorISAToString(VectorISA(i)), Qt::CaseInsensitive))
|
|
|
|
return VectorISA(i);
|
|
|
|
return VectorISA::Invalid;
|
2017-12-26 04:27:18 +00:00
|
|
|
}
|
2017-12-27 00:48:34 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
URDEVersion::URDEVersion(const QString& filename) {
|
|
|
|
int idx;
|
|
|
|
QString useFilename = filename;
|
2021-03-29 17:23:02 +00:00
|
|
|
if ((idx = filename.lastIndexOf(QLatin1Char{'.'})) > filename.lastIndexOf(QLatin1Char{'-'})) {
|
2018-12-08 05:19:40 +00:00
|
|
|
m_extension = QString(filename).remove(0, idx);
|
|
|
|
useFilename.truncate(idx);
|
|
|
|
}
|
2019-08-28 01:35:51 +00:00
|
|
|
|
|
|
|
const QStringList list = useFilename.split(QLatin1Char{'-'});
|
2020-04-18 10:08:11 +00:00
|
|
|
enum {
|
|
|
|
version,
|
|
|
|
platform,
|
|
|
|
architecture,
|
|
|
|
vectorISA,
|
|
|
|
extra
|
|
|
|
} state = version;
|
|
|
|
for (size_t i = 1; i < list.size(); ++i) {
|
|
|
|
if (state == version) {
|
|
|
|
if (m_version.isEmpty()) {
|
|
|
|
m_version = list[i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bool ok;
|
|
|
|
int patch = list[i].toInt(&ok);
|
|
|
|
if (ok) {
|
|
|
|
m_version += QLatin1Char('-') + QString::number(patch);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
state = platform;
|
|
|
|
}
|
|
|
|
if (state == platform) {
|
2021-03-29 17:23:02 +00:00
|
|
|
if (list[i] == QStringLiteral("dirty")) {
|
|
|
|
m_version += QLatin1Char{'-'} + list[i];
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-18 10:08:11 +00:00
|
|
|
state = architecture;
|
|
|
|
Platform platValue = StringToPlatform(list[i]);
|
|
|
|
if (platValue != Platform::Invalid) {
|
|
|
|
m_platform = platValue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (state == architecture) {
|
2021-03-19 04:31:34 +00:00
|
|
|
state = extra;
|
2020-04-18 10:08:11 +00:00
|
|
|
Architecture archValue = StringToArchitecture(list[i]);
|
|
|
|
if (archValue != Architecture::Invalid) {
|
|
|
|
m_architecture = archValue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2021-03-19 04:31:34 +00:00
|
|
|
// if (state == vectorISA) {
|
|
|
|
// state = extra;
|
|
|
|
// VectorISA isa = StringToVectorISA(list[i]);
|
|
|
|
// if (isa != VectorISA::Invalid) {
|
|
|
|
// m_vectorISA = isa;
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// }
|
2020-04-18 10:08:11 +00:00
|
|
|
m_extra += QLatin1Char('-') + list[i];
|
2019-08-28 01:35:51 +00:00
|
|
|
}
|
2017-12-27 00:48:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QString URDEVersion::fileString(bool withExtension) const {
|
2020-04-18 10:08:11 +00:00
|
|
|
if (m_version.isEmpty()) {
|
2018-12-08 05:19:40 +00:00
|
|
|
return {};
|
2019-08-28 01:35:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (withExtension && !m_extension.isEmpty()) {
|
2021-04-07 01:24:14 +00:00
|
|
|
return QStringLiteral("metaforce-%1-%2-%3%4%5")
|
2021-03-19 04:31:34 +00:00
|
|
|
.arg(m_version, PlatformToString(m_platform), ArchitectureToString(m_architecture), m_extra, m_extension);
|
2019-08-28 01:35:51 +00:00
|
|
|
} else {
|
2021-04-07 01:24:14 +00:00
|
|
|
return QStringLiteral("metaforce-%1-%2-%3%4")
|
2021-03-19 04:31:34 +00:00
|
|
|
.arg(m_version, PlatformToString(m_platform), ArchitectureToString(m_architecture), m_extra);
|
2019-08-28 01:35:51 +00:00
|
|
|
}
|
2017-12-27 00:48:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 06:19:48 +00:00
|
|
|
#ifndef _WIN32
|
2018-01-03 23:53:01 +00:00
|
|
|
static void HUPHandler(int) {}
|
2018-01-10 06:19:48 +00:00
|
|
|
#endif
|
2018-01-03 23:53:01 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
void InitializePlatform() {
|
2018-01-10 06:19:48 +00:00
|
|
|
#ifndef _WIN32
|
2018-12-08 05:19:40 +00:00
|
|
|
/* This can happen when terminating hecl - do nothing */
|
|
|
|
signal(SIGHUP, HUPHandler);
|
2018-01-10 06:19:48 +00:00
|
|
|
#endif
|
2018-01-03 23:53:01 +00:00
|
|
|
|
2017-12-27 00:48:34 +00:00
|
|
|
#if ZEUS_ARCH_X86_64
|
2018-12-08 05:19:40 +00:00
|
|
|
const_cast<Architecture&>(CurArchitecture) = Architecture::X86_64;
|
2017-12-27 00:48:34 +00:00
|
|
|
#elif ZEUS_ARCH_X86
|
|
|
|
#if !defined(__APPLE__) && !defined(_WIN32)
|
2018-12-08 05:19:40 +00:00
|
|
|
const_cast<Architecture&>(CurArchitecture) = (sysconf(_SC_WORD_BIT) == 64 ? Architecture::X86_64 : Architecture::X86);
|
2017-12-27 00:48:34 +00:00
|
|
|
#elif _WIN32
|
2018-12-08 05:19:40 +00:00
|
|
|
bool isWOW = false;
|
|
|
|
IsWow64Process(GetCurrentProcess(), &isWOW);
|
|
|
|
const_cast<Architecture&>(CurArchitecture) = (isWOW ? Architecture::X86_64 : Architecture::X86);
|
2017-12-27 00:48:34 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-12-08 05:19:40 +00:00
|
|
|
const_cast<QString&>(CurArchitectureString) = ArchitectureToString(CurArchitecture);
|
2017-12-27 00:48:34 +00:00
|
|
|
}
|